Compilers and Interpreters: Assignment 2
September 16, 2010
Make an ANTLR grammar for Mini-Triangle, as described in pages 8-9 of our textbook. Feel free to modify the BNF as you feel suited.
Your grammar should implement the following actions:
- When there is a constant declaration, put the ID and the value in the hash table.
- When there is a variable declaration, put the ID and the default value zero in the hash table.
- Whenever there is a variable in an expression, output the name of the variable and its value if it was declared, "undef." otherwise. Don't worry about scopes for now.
- Your grammar should reflect the following precedence of operators.
- Unary operators: first.
- * and /: second.
- + and -: third.
- Comparisons: fourth.
Due Wednesday, September 28, by 11 pm. E-mail to the instructor (email@example.com):
- the grammar.
- a sample Mini-Triangle program that causes the parser to use every rule.