University of Texas at El Paso
Compuer Science
Assignment 2 Minimize    

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:

  1. When there is a constant declaration, put the ID and the value in the hash table.
  2. When there is a variable declaration, put the ID and the default value zero in the hash table.
  3. 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.
  4. 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 (

  1. the grammar.
  2. a sample Mini-Triangle program that causes the parser to use every rule.
Documents Minimize    

 TitleOwnerCategoryModified DateSize (Kb) 
Expr.gLuc Longpre 9/16/20101.20Download