Re: LL(1) Grammar for Expressions with Assignment

jos@and.nl (Jos A. Horsmeier)
Fri, 30 Jun 1995 09:56:51 GMT

          From comp.compilers

Related articles
LL(1) Grammar for Expressions with Assignment bergmann@elvis.rowan.edu (1995-06-27)
Re: LL(1) Grammar for Expressions with Assignment jos@and.nl (1995-06-30)
Re: LL(1) Grammar for Expressions with Assignment parrt@lonewolf.parr-research.com (1995-07-01)
| List of all articles for this month |

Newsgroups: comp.compilers
From: jos@and.nl (Jos A. Horsmeier)
Keywords: parse, LL(1)
Organization: AND Software B.V. Rotterdam
References: 95-06-075
Date: Fri, 30 Jun 1995 09:56:51 GMT

bergmann@elvis.rowan.edu (Seth Bergmann) wrote:


|I've been trying to find an LL(1) grammar for the language of
|expressions involving addition, subtraction, multiplication, division,
|unary minus, unary plus, and assignment (as in C). Included would be
|expressions such as:
|
| (a=3+b) * (c = 3)
|
|but excluded would be things like:
|
| 3+a=4 and 2 = a
|
|The compiler books I've checked all seem to either use lookahead (i.e.
|LL(2)) or check for a proper lvalue for the assignment during semantic
|analysis. I suspect this language of expressions is not LL(1). Can
|anyone point me to a reference on this?


How about this grammar:


E -> T E' ;
E' -> [+-] T E' | ;
T -> U T'
T' -> [*/] U T' | ;
U -> [+-] U' | F ;
U' -> [+-] U' | F' ;
F -> constant | ident I | ( E ) ;
F' -> constant | ident | ( E ) ;
I -> = E | ;


If I'm not mistaken (I just checked this thingy manually) this
grammar does exactly what you want ...


kind regards,


Jos aka jos@and.nl
--


Post a followup to this message

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