90 likes | 338 Views
Programming Exercise #2: Syntax Analysis. J. H. Wang Nov. 15, 2011. Syntax Analysis with Yacc. Goal: Using Yacc to generate a parser for your target language Input: a Yacc source program Output: a parser for your target language. Input: Yacc Program.
E N D
Programming Exercise #2:Syntax Analysis J. H. Wang Nov. 15, 2011
Syntax Analysis with Yacc • Goal: Using Yacc to generate a parser for your target language • Input: a Yacc source program • Output: a parser for your target language
Input: Yacc Program • First, you have to decide a target language to be analyzed • Ex: Simple programming languages such as: Decaf, Espresso, Cool, … • http://www.stanford.edu/class/cs143/ • You can design your own language for any purpose • Music scores, games, computer graphics, matrix operations, calculators, … • Then, write the Yacc program for the target language
Output: Parser • Run Yacc to generate the parser • You are allowed to use Yacc or other parser generators • Test your parser with some example test files written in your target language • At least one test file should be submitted
Some Parser Generators • Yacc: on UNIX/Linux(http://dinosaur.compilertools.net/) • Bison: GNU (http://www.gnu.org/software/bison/) • Bison for Windows: on GnuWin32(http://gnuwin32.sourceforge.net/packages/bison.htm) • CUP: LALR parser generator for Java(http://www2.cs.tum.edu/projects/cup/) • Antlr: recursive-descent parser generator(http://www.antlr.org/) • LLGen: an LL(1)-based parser generator(http://www.cs.vu.nl/~ceriel/LLgen.html) • …
Submission • Your submission *must* include • The source code (and optionally your executable file) • Your Yacc program • At least one example test files in the target language • A README file that includes • A description of your target language (at least the syntactical structure) • Special requirements for compilation or execution environments (ex: Yacc version, compilation instructions, …) • The names and the responsible parts for each individual member should be clearly identified
How to Submit • Team-based (at most 2 persons per team) • Due: two weeks (Dec. 6, 2011)
Evaluation • Minimum requirement: correctness • Your Yacc program will be used as input to Yacc, and the generated parser will be checked using your example test cases for correctness • Optional bonus depends on the complexity and originality in the syntax of your target language