Thư viện tri thức trực tuyến
Kho tài liệu với 50,000+ tài liệu học thuật
© 2023 Siêu thị PDF - Kho tài liệu học thuật hàng đầu Việt Nam

Tutorial 2
Nội dung xem thử
Mô tả chi tiết
Assignment 2: Syntax Analysis
I. Introduction
In this assignment, you are required to implement a parser manually for MC programs.
The parser performs a syntax analysis process that receives a sequence of tokens
produced by the scanner, which should have been implemented in Assignment 1, and
verifies if the token sequence is grammatically correct or not.
In order to complete the assignment, the following tasks are to be fulfilled:
- Construct a context-free grammar for the MC language.
- Implement a parser according to the constructed grammar.
You can either employ a top-down or bottom-up parsing technique for your parser.
You must adopt the scanner provided by the course’s staffs to perform lexical analysis
for your parser. Thus, the used token set must be the same as that previously specified in
Assigment 1.
You should refer to lecture notes and textbooks as well as the MC language specification
carefully to find out the grammar rules that precisely reflect the MC program structures.
II. Operational Instructions
The programming language used to implement the scanner must be Java. You should
install Java JDK 5.0, which includes a java compiler and a java virtual machine as done
in Assignment 1.
To implement the parser, you first download provided file ass2.zip, which will be
uploaded after the due date of Assignment 1, and decompress it in a directory, called
supposedly $ROOT$ as done in Assignment 1. In your $ROOT$ directory, you will have
an MC directory whose structure is as follows (bold names are folder, the remaining are
files):
MC
|__ lexicalanalysis
| |___Scanner.java, SourcePosition.java, Token.java, ErrorReport.java
|__ syntaxanalysis
| |___ grammar
| | |____grammar.txt
| |___ test
| | |____test.txt
| | |____solution.txt
| |___ Parser.java
|__MCCompiler.java