CS 50200 - Programming Assignment 7

This assignment makes use of the files contained in this zip file. This assignment is due Friday, December 17.

In this assignment, you will write an Antlr "front end" for the interpreter that you wrote for Language-Hw4 in homework assignment 4. In the zip file there is a text file Language-Hw7.txt that defines the syntax of the language you are to write an Antlr parser for.

In the zip file there is a file LanguageHw7.g in which you should write an Antlr grammar for the language defined in Language-Hw7.txt. Make this a pure grammar, with no actions, so that you can test your grammar with the least amount of complexity. You will need to modify the grammar from Language-Hw7.txt in order to make it a grammar suitable for Antlr. Use the program TestParser.java to test the execution of your grammar. (You can also use ANTLRWorks.)

When your Antlr grammar is debugged, copy it into the file LanguageHw7_AST.g and start adding actions to the grammar to create an AST. When you are building the AST, you will need to make use of a few "imaginary tokens". These are "tokens" that do not come from the token stream that you are parsing, but they are needed as root nodes for subtrees of the AST. A good example of this is "apply". The keyword "apply" never appears in the syntax of Language-Hw7, but it is needed as a node in the AST for Language-Hw4. So you need to declare an APPLY imaginary token in your Antlr grammar. There is some explanation of this on page 80 of our textbook. Also see the following page from the Antlr documentation.

When you have finished implementing LanguageHw7_AST.g, then the file TestInterpreter.java should compile and run. The output from running this program should look exactly like the file output.txt. In order to run TestInterpreter.java, you will need all of the following files from your solution to homework assignment 4.

  • AST2infix.java
  • BuildTree.java
  • Environment.java
  • EvalException.java
  • Evaluate.java
  • FunctionEnvironment.java
  • ParseException.java
  • PrettyPrinter.java
  • Tokenizer.java
  • Tree.java
  • Value.java

Use the script file antlr-command-lines.cmd to help you compile your Antlr grammars and Java programs. You will need to set the Java JDK and Antlr jar file paths appropriately. You can either run the script from within a command shell window, or use it as a basis for creating compiler tools in your favorite development environment.

Turn in a zip file containing your versions of LanguageHw7.g and LanguageHw7_AST.g, along with all of the files needed to compile and run TestInterpreter.java.

This assignment is due Friday, December 17.


Return to the main homework page.
Return to the CS 50200 home page.


compliments and criticisms