|
Hmk4 Semantic Analyzer Experience
Instructor: Zhiyao Liang
Macau University of Science and Technology 2019 FAll
Purpose
Experience with coding a semantic analyzer for the N language. The computation is based on a parse tree that is provided by a parser. The above picture is found from the internet, which demonstrate
:
some idea of the semantic analyzer, to embellish the tree with more particles (more data like info of types and symbol tables). The language N has be introduced in the previous homeworks.
Preparation
In the folder code there are some provided code to help you. You can modify the code as you desire, or fix errors if found some. For example, you can change the token types and content of a parse tree node according to your work of previous homeworks. Read and understand the provided code.
The algorithm of a semantic analyzer has been discussed in class, and documented in details in the file cminus.pdf .
The task
1. Provide the missing code of the functions. The comments of the functions should provided sufficient information about them.
In the file , which include:
In the file
: build the symbol tables and detect some error of names.
: assign the type fields of the nodes and detect some error of types.
2. [bonus +15] Make the program complete and executable. Test your code with some .n files, print the symbol tables, detect some semantic errors of names and types.
How to submit
Submit before Monday, January 6, 2020.
Attach all of your source code file. If created some .n files for testing, also attached them. Please use a file readme.txt to describe your work, like the achievements and problems of your work, and how to compile and run your code (if you have done the bonus part).
At most three students can form a group to do the homework together and submit the homework together with an email. If you can do the homework by yourself (a one-person group), it surely will be fine.
symbol_table.c
st_insert_dcl()
st_insert_ref()
st_lookup()
s_analyzer.c
pre_proc()
post_proc()
Submit the homework by sending an email (to ) with attached program files (together with the file of the grammar rules). The details of how to submit your homework is in the file how_to_submit_homeworks.pdf .
References
1. Kenneth C. Louden. Compiler Construction Principles and Practice. PWS Publishing Company, 1997. ISBN 0-534-93972-4 http://www.cs.sjsu.edu/~louden/cmptext/.
2. Andrew W. Appel. Modern Compiler Implementation in C: Basic Tech- niques. Cambridge University Press, New York, NY, USA, 1997.
[email protected]
Reviews
There are no reviews yet.