Requirements for the second homework:
- parse variables
- interpret assignments and keep a symbol table
- treat assignments as expressions, i.e. handle statements such as “x = y = 5”
As usual, follow a test-driven programming style, and write unit test for each feature of your interpreter.
Hint: use the grammar given in the lecture to check your interpreter logic.
block ::= stat* stat ::= expr | assign assign ::= name '=' expr expr ::= term ('+'|'-' term)* term ::= factor ('*'|'/' factor)* factor ::= number | '(' expr ')' | name number ::= '0'...'9' name ::= 'a'...'z' | 'A'...'Z'
When handling assignments like expressions, you have to extend this grammar in some way.