- 123
- 0
- 约1.75万字
- 约 23页
- 2019-01-18 发布于浙江
- 举报
华南理工大学
编译原理课程实验报告
实验题目: Implement parser, analyzer, code generator for TINY+
姓名: 黄炜杰 学号: 201230590051
班级: 12计创 组别: 无
合作者: 无
指导教师: 刘欣欣
实验概述
【实验目的及要求】
Purpose: Implement the parser, semantic analyzer and code generator part to construct the whole complier.
ParserRequirement:
Parser
Complete a recursive–descent parser for TINY+. Parser gives syntax analysis to the tokens generated by the scanner. Output of the parser is an abstract syntax tree. The parser should follow the these EBNF grammar rules:?
program - declarations stmt-sequence
declarations - decl ; declarations |ε
decl - type-specifier varlist
type-specifier - int | bool | char
varlist - identifier { , identifier }
stmt-sequence - statement { ; statement }
statement - if-stmt | repeat-stmt | assign-stmt | read-stmt | write-stmt | while-stmt
while-stmt - while bool-exp do stmt-sequence end
bool-exp - bterm { or bterm }
bterm - bfactor { and bfactor}
bfactor - comparison-exp
comparison-exp - arithmetic-exp comparison-op arithmetic-exp
comparison-op - | = | | = | =
arithmetic-exp - term { addop term }
term - factor { mulop factor }
factor - (arithmetic-exp) | number | identifier
if-stmt - if bool-exp then stmt-sequence [else stmt-sequence] end
repeat-stmt - repeat stmt-sequence until bool-exp
assign-stmt - identifier:=exp
read-stmt - read identifier
write-stmt - write exp
exp - arithmetic-exp | bool-exp | string-exp
addop - + | -
mulop - * | /
string-exp - string
Semantic analyzer
Semantic analyzer
Builds the symbol table and check semantic errors. The following syntax errors and semantic errors should be detected:
Syntax errors
Start symbol and following symbol error.
Identifiers error, such as int is not followed by an identifier.
Parenthesis matching error, such as ( and ) do not match.
Symbol error, such as in assignment the symbol should be ‘:=’, while in compare expressions the symbol should be ‘=’.
Semantic errors
An identifier is used before the declaration
您可能关注的文档
最近下载
- 年产420吨锆废料回收项目可行性研究报告.docx
- 2025年加州驾照常考题库及答案.doc VIP
- 《现代汉语(下册语法部分)》PPT课件.ppt VIP
- 无人机测绘技术(微课版)03无人机测绘数据采集.pptx VIP
- 2025年房地产经纪人继承房产涉及的贷款问题处理专题试卷及解析.pdf VIP
- 2026年高考第一次模拟考试:地理一模突破卷02(新高考全国通用)(考试版).docx VIP
- 2025年互联网营销师绿色营销风险识别与管理专题试卷及解析.pdf VIP
- 2025年项目管理专业国际成本补偿合同汇率风险管理专题试卷及解析.pdf VIP
- 2025年拍卖师着装中的色彩搭配技巧与禁忌专题试卷及解析.pdf VIP
- 2025年无人机驾驶员执照敏感区域(如核设施)空域管控专题试卷及解析.pdf VIP
原创力文档

文档评论(0)