University of Texas at El Paso
Banner
Compuer Science
   
Assignment 5 Minimize    

Compilers and Interpreters: Assignment 5

October 17, 2008

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 an expression in the program, output its value based on the current contents of the hash table. If some ID is not in the hash table, you choose what to do: either consider it to be zero, or issue an error message. Consider the result of an operation that yields a boolean as 0 or 1 for false and true, respectively. The backslash means 'not'. 'not' applied to a non-zero is zero, and to zero is 1. Implement the following precedence in your grammar.
    • Unary operators: first.
    • * and /: second.
    • + and -: third.
    • Comparisons: fourth.
  4. Whenever there is an assignment, update the value in the hash table.

For now, don't worry about scopes. A compiler does not in general evaluate expressions, it generates code to evaluate expressions. We're including actions here to get familiar with the concept. So what our compiler does for now is rather meaningless. It's not really an interpreter either.

Due Wednesday, October 29, befire the start of class. E-mail to the instructor (longpre@utep.edu) and to the teaching assistant (nskanagala@gmail.com):

  1. the grammar.
  2. a sample Mini-Triangle program that causes the parser to execute every action.
  3. the output generated by the parser on your program.