Project 1

Jump to: test cases, turnin info

Extending a grammar and using ANTLR to build an abstract syntax tree

For part 1 of your project, you are to take a grammar for a small language called Simple (see the Examples section) and extend it to parse and build an AST for the features described in what follows.

The grammar for Simple describes a very limited programming language made of a single block of statements enclosed within a begin..end pair. The only statements available are

 Your assignment is to augment this grammar to recognize the following language:

The explcit required additions are:
In designing your abstract syntax tree nodes, keep in mind the information that will be necessary in order to interpret or translate any node.  You many use any combination of built-in and customized tree construction that you choose.  Do make sure that you can tell what kind of node is constructed by any of your syntax rules.

Note the following operator precedence holds:

   HIGHEST
      not, unary-minus, parentheses
      * /
      + - .
      = <> < > <= >=
      and
      or
   LOWEST
For now, assume all binary operators associate left-to-right.

Test cases

Here are a few test files, with some sample output. Your output needn't match mine exactly (though it would be convenient for this project if it did); all that matters is that your parse tree unambigously communicates the information in the original source files.

Turnin information

To turn in the project, make sure you have set up workon, and then do
   workon  cs4240
   turnin  prj1  simple.g  Main.java

Last updated on Tue Oct 5 01:33:06 EDT 1999 by Brian McNamara