Re: Parsing expressions without outer parentheses

Frank Heckenbach <frank@g-n-u.de>
24 May 2003 17:01:04 -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: Frank Heckenbach <frank@g-n-u.de>
Newsgroups: comp.compilers
Date: 24 May 2003 17:01:04 -0400
Organization: Compilers Central
References: 03-05-061
Keywords: parse, comment
Posted-Date: 24 May 2003 17:01:03 EDT

Hannah Schroeter <hannah@schlund.de> wrote:


> Frank Heckenbach <frank@g-n-u.de> wrote:
> >[...]
>
> >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.
>
> >[...]
>
> How about creating a syntax tree node for parens, too? ...
>
> Then you could just check whether the expression tree's root is a
> "()" node and if so, reject the input.
>
> Afterwards, you can remove the paren nodes (except if you want to use
> them to inhibit optimizing transforms that would change the associative
> order, like required in Fortran).


Thanks for the hint. I might try this. Though this solution seems a
little "unclean" from a grammar point of view. But perhaps I've just
got to take such a compromise if the alternative would blow up the
grammar too much.


Frank


--
Frank Heckenbach, frank@g-n-u.de, http://fjf.gnu.de/
GnuPG and PGP keys: http://fjf.gnu.de/plan (7977168E)
Pascal code, BP CRT bugfix: http://fjf.gnu.de/programs.html
Free GNU Pascal Compiler: http://www.gnu-pascal.de/
[In the absence of attribute grammars, if you want to add N bits of
state to a token, you have to represent it as 2^N tokens. That's why
yacc parsers usually move a lot of work into the semantics to keep
the grammar to a reasonable size. -John]


Post a followup to this message

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