I would like to design an LL1 grammar for arithmetic equations and variable assignments. I began with this grammar:
I have a nonambiguous grammar for arithmetic expressions:
E → T E’
E’ → | + E
T → id T’
T’ → | * T
However, I'm not sure how to incorporate variable assignments into the E productions.
How I tried previously was:
stmt -> assignment SEMI | RETURN stmt_prime
| LBRACE stmt_list RBRACE
| IF LPAREN assignment RPAREN stmt stmt_prime_prime
| FOR LPAREN assignment SEMI assignment SEMI assignment RPAREN stmt |
stmt_prime -> SEMI | -> assignment SEMI
stmt_prime_prime -> NOELSE
| ELSE stmt
assignment -> ID typ ASSIGN expr | expr
expr -> TE*
E* -> + TE* | -TE* | epsilon
T -> FT*
T* -> * FT* | / FT* | epsilon
F -> (E) | int_literal | TRUE | FALSE