國立清華大學資訊工程學系
CS 3404 --- 編譯器設計
Assignment #3
Due: 5:00 p.m., May 25, 1999
In this assignment, you will use yacc to generate the AST (a parse tree
representation) for any program written in Macro.
The grammar definition is here.
(You may reference Appendix A of the textbook for the language.)
You will start with a skeleton (parser.tgz),
which is a parser for Micro.
You have the following to do:
- Download parser.tgz and uncompress it into a directory called
parser.
- Use make to build the parser and run the resultant mc
on the test case (test-1) for Micro.
Study the output.
You are supposed to create the similar output for Macro source input when
using the -d flag.
- Modify ast.h and ast.c (the printing part) to
incoorperate more AST node types, according to the grammar definition of
Macro.
- Use your previous .l file as scanner and INCLUDE y.tab.h,
not lexicon.h!
- Main part: Write your own .y file to generate the parser for Macro.
Please use the token names in the lexicon.h of Assignment 2.
- Modify Makefile to include your code, and use the
test cases to check your parser.
Acknowledgement
This assignment is from CS 4410/6415 (Introduction to Compiler
Design) of Georgia Institute of Technology, offered by Dr. Richard
LeBlanc in Fall, 1998.