COS 320 - Assignment 5

Compiling Techniques, Spring 2012, Princeton University.      Due date: Monday 12 March.
You can submit this homework up to 7 days late without penalty. However, I strongly suggest you complete it on time, because related material may be on the midterm exam.

Parsing

In this assignment, you will use ML-Yacc to build a parser for the Fun language. Chapter 3 of your textbook (particularly 3.4) explains many of the concepts you'll need to know to complete this assignment. There is also documentation on ML-Yacc here. You will also need to refer to the Fun language reference.
  1. Make a new directory as5 for this assignment, and copy all your as4 files into it. Then unpack as5.zip to get some new files: sources.cm fun.grm parse.sml compile.sml all.fun testcases.sml.This will overwrite your sources.cm with a new one.
  2. For this assignment you will use the fun.lex you built in assignment 4. If yours doesn't work well enough to be usable, then use fun.lex.sml that you unpacked in assignment 2.
  3. Edit fun.grm until it specifies a parser for the Fun language. Don't worry at first about filling in the semantic actions; just get the parsing and grammar disambiguation taken care of.
  4. Once you have your grammar disambiguated and debugged, fill in the parser's semantic actions. These should generate abstract syntax in the Fun intermediate language. Here are a list of concerns to keep in mind.
  5. Add some support for detection and correction of common errors, using ML-Yacc constructs such as "%value" and "%change" described on pages 80-81 of MCIinML and in the ML-Yacc manual. Explain the support you add in your README file.
  6. The file all.fun tests all syntactic constructs in a trivial way but you will certainly want to write other fun files to debug your compiler. If you want to submit additional test files, please do so. We might use them to test the other projects! You can also send them to the cos320 mailing list for others to use. In a /* comment */ at the beginning of each test file, explain what particularly is being tested; if your test is supposed to produce parsing errors, copy the expected error messages into the comment.
  7. Submit your README, fun.grm, and any *.fun test files you wish to. You can also use this feature to submit a new version of your lexer, provided you describe the changes you made in the README. Upload your submissions to dropbox here.


Back to COS 320 front page