Homework 2: Parser

Due Tuesday, 5 February 2008, 6 PM

Homework 2 is to build a parser for Appel's Tiger language using ML-Yacc. The Tiger language is defined in Appendix A of the course textbook. The ML-Yacc user's manual is available online, and also (in less detail) in chapters three and four of the textbook.

Your parser should produce an abstract syntax tree using the datatypes defined in the Absyn structure defined in the file $TIGER/chap4/absyn.sml.

Skeleton files to get you started are available in the $TIGER/chap3/ and $TIGER/chap4/ directories, which you can find at Appel's textbook homepage. In particular, these files will be useful:

Skeleton ML-Yacc file to get you started
Test driver
Top-level test driver code
AST datatypes
Support library providing symbols
table.sml, table.sig
Support library providing tables
Useful library for printing ASTs

Remember to update your sources.cm file. Be certain to add ml-yacc-lib.cm to it if you haven't already, in addition to any other new files you are using. You'll want to remove tokens.sml from it, because a tokens file will be automatically generated by ML-Yacc now. Also, you'll need to update some header information in your lex file—see the end of Chapter 3 for details.

You should submit:

Anything subtle about your grammar, such as ambiguity resolutions of various kinds, should be clearly commented. You knew that, of course.

Your parser should use the same error-reporting machinery you employ in your lexer.

Some advice:

See the course text for more information, in particular Chapters 3 and 4 and Appendix A.

Good luck and have fun.

Last updated 18 February 2008.

Valid XHTML 1.1 Valid CSS!