|LL(1) Grammar for Expressions with Assignment firstname.lastname@example.org (1995-06-27)|
|Re: LL(1) Grammar for Expressions with Assignment email@example.com (1995-06-30)|
|Re: LL(1) Grammar for Expressions with Assignment firstname.lastname@example.org (1995-07-01)|
|From:||email@example.com (Jos A. Horsmeier)|
|Organization:||AND Software B.V. Rotterdam|
|Date:||Fri, 30 Jun 1995 09:56:51 GMT|
firstname.lastname@example.org (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 ...
Jos aka email@example.com
Return to the
Search the comp.compilers archives again.