CSE 3341: Context-Free Grammar for simpleC, Projects 1 and 2
<program> ::= <decl-list> <stmt-list>
<decl-list> ::= ε | <decl> <decl-list>
<decl> ::= int id ; | int id = <expr>;
<stmt-list> ::= ε | <stmt> <stmt-list>
<stmt> ::= <expr> ; | ε ; | read id ; | print <expr> ; | if ( <expr> ) <stmt> | if ( <expr> ) <stmt> else <stmt> | { <stmt-list> }
<expr> ::= const | id | ( <expr> ) | <binary-expr>
<binary-expr> ::= <expr> + <expr> | <expr> - <expr> | <expr> * <expr> | <expr> / <expr> | <expr> % <expr> | id = <expr>
For simplicity, this grammar is ambiguous. The parser implementation should ensure that: (1) operators *, /, and % are left-associative and have the same precedence, which is higher that the precedence for the remaining operators; (2) operators + and - are left-associative and have higher precedence than the assignment operator =; (3) the assignment operator = is right-associative and has the lowest precedence.