Re: Parsing expressions without outer parentheses

"SLK Parsers" <slk15@earthlink.net>
6 May 2003 01:28:25 -0400

          From comp.compilers

Related articles
Parsing expressions without outer parentheses frank@g-n-u.de (Frank Heckenbach) (2003-04-27)
Re: Parsing expressions without outer parentheses cfc@world.std.com (Chris F Clark) (2003-05-05)
Re: Parsing expressions without outer parentheses slk15@earthlink.net (SLK Parsers) (2003-05-06)
Re: Parsing expressions without outer parentheses pjj@cs.man.ac.uk (Pete Jinks) (2003-05-06)
Re: Parsing expressions without outer parentheses hannah@schlund.de (Hannah Schroeter) (2003-05-12)
Re: Parsing expressions without outer parentheses frank@g-n-u.de (Frank Heckenbach) (2003-05-24)
Re: Parsing expressions without outer parentheses frank@g-n-u.de (Frank Heckenbach) (2003-05-24)
| List of all articles for this month |
From: "SLK Parsers" <slk15@earthlink.net>
Newsgroups: comp.compilers
Date: 6 May 2003 01:28:25 -0400
Organization: Parsers Inc.
References: 03-04-093
Keywords: parse
Posted-Date: 06 May 2003 01:28:25 EDT

> expression: simple_expression | expression '=' simple_expression;
> simple_expression: term | simple_expression '+' term;
> term: factor | term '*' factor;
> factor: primary | factor '^' primary;
> primary: constant | '(' expression ')';
>
> Now I want to accept only expressions which are not completely
> enclosed in a pair of parentheses, e.g. `(1) + (2)' would be
> accepted, but `(1 + 2)' would not.


Seems like this could be handled semantically. If an expression begins
with an open parenthesis, and the parentheses nesting level does not
drop to zero before the end of the expression, then "error: outer
parentheses." You need another production to delimit the
expression. Something like


expression : {action} inner_expression {action} ;


And then change expression to inner_expression in the grammar fragment shown
above.


http://parsers.org


Post a followup to this message

Return to the comp.compilers page.
Search the comp.compilers archives again.