[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Fwd: Delimiting 'rules' by semicolon/new_line
-------- Original Message --------
Sender: nowonder@hyperion.informatik.rwth-aachen.de
Message-ID: <3B837DD8.D9260DBD@i2.informatik.rwth-aachen.de>
Date: Wed, 22 Aug 2001 11:39:36 +0200
From: Peter Schneider-Kamp <nowonder@hyperion.informatik.rwth-aachen.de>
Subject: Delimiting 'rules' by semicolon/new_line
Hi everybody!
To avoid ambiguity in parsing some functional programs I need to enforce
delimiting of the so called 'rules' by either a newline or a semicolon.
The problem is that I want to ignore whitespace, i.e. (13|10|9|' ')+
everewhere else.
I have attached my 'solution', which is ugly (and not complete).
The idea is that I do not ignore newlines, but allow them in certain
places (ignoring them in the parse cycle) while using them as
delimiter for rules.
Is there a better way to do this?
Thanks,
Peter
--
Peter Schneider-Kamp mailto:nowonder@i2.informatik.rwth-aachen.de
LuFG Informatik II
http://www-i2.informatik.rwth-aachen.de/~nowonder
RWTH Aachen mobile phone: ++49 178 495 1040
--------------8062CA73D609EEC5B6AD5131
Content-Type: text/plain; charset=us-ascii;
name="fp.grammar"
Content-Transfer-Encoding: 7bit
Content-Disposition: inline;
filename="fp.grammar"
Package fp;
Helpers
digit = ['0' .. '9'];
letter = [['a' .. 'z'] + ['A' .. 'Z']];
blank = 9 | ' ';
Tokens
open = '(';
close = ')';
colon = ':';
equal = '=';
dequal = '==';
comma = ',';
semi = ';';
blanks = (9 | ' ')+;
nl = [10 + 13];
arrow = '->';
if = 'if';
then = 'then';
else = 'else';
structure = 'structure';
function = 'function';
id = (letter | digit | '_' )+;
line_comments = '#' [[0..0xffff]-[10+13]]*(10|13|10 13)+;
full_comments = '~' [[0..0xffff]-'~']*'~'[10+13]*;
Ignored Tokens
blanks, line_comments, full_comments;
Productions
program = decl+;
decl =
{struct} struct |
{funct} funct;
struct = structure [structname]:id nl* constr+;
constr = [cons]:id colon idlist? [return]:id nl*;
idlist = idcomma* id arrow;
idcomma = id comma;
funct = function [functname]:id colon idlist? [return]:id nl* rule+;
rule = [left]:term equal [right]:term rule_delimiter nl*;
rule_delimiter =
{semicolon} semi |
{new_line} nl;
term =
{p1} p1 |
{if_long} if [cond_term]:term then [then_term]:term else
[else_term]:term |
{if_short} if open [cond_term]:term [comma1]:comma [then_term]:term
[comma2]:comma [else_term]:term close;
p1 =
{p2} p2 |
{dequal} p1 dequal p2;
p2 =
{const_var} id |
{funct_app} id open termlist close |
{par} open term close;
termlist = termcomma* term;
termcomma = term comma;
--------------8062CA73D609EEC5B6AD5131--