CS 50200 - Programming Assignment 6

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

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

In the zip file there is a file LanguageHw6.g in which you should write an Antlr grammar for the language defined in cs50200-language-Hw6.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 cs50200-language-hw6.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 LanguageHw6_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 cs50200-language-hw7, but it is needed as a node in the AST for cs50200-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 LanguageHw6_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 LanguageHw6.g and LanguageHw6_AST.g, along with all of the files needed to compile and run TestInterpreter.java.

This assignment is due Friday, May 10.


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


compliments and criticisms