COS 320, Spring 2000. Programming Assignment

Programming Assignment 4: Abstract Syntax Generation

Described in Modern Compiler Implementation, Chapter 4.

Abstract syntax generation using ml-yacc

  1. Make a new directory as4 for this assignment.
  2. Copy the files /u/cos320/chap4/* into as4.
  3. Please, familiarize yourself with the code that is already there.
  4. Copy your working tiger.lex from assignment 3 into as4. If your lexer is not working, then do NOT copy it into as4. In this case, CM.make(); will automatically use the file tiger.lex.sml that is provided.
  5. As in assignment 3, your tiger.lex should contain the following code:
  6. Copy your working tiger.grm from assignment 3 into as4. Add useful type definitions to the %nonterm declarations.
  7. Add semantic actions to your grammar rules to produce the Absyn tree that corresponds to the Tiger program being parsed.
  8. Fields of type bool ref that are named escape should be initialized to ref true. Likewise, the slmode ref in the definition of dec must be initialized to ref EscapingSL. (Later analyses may provide less conservative approximations, but they are not part of this assignment.)
  9. Compile using CM.make(); This will automatically run ml-lex and ml-yacc as necessary.
  10. Test your parser by invoking Test.parse "filename". This will invoke the parser and, upon completion, print the resulting Absyn tree. Debug, edit, recompile, test. Repeat.
  11. Submit your solution with submit 4 tiger.grm.