华南理工大学《编译原理》实验报告.docVIP

  • 123
  • 0
  • 约1.75万字
  • 约 23页
  • 2019-01-18 发布于浙江
  • 举报

华南理工大学《编译原理》实验报告.doc

华南理工大学 编译原理课程实验报告 实验题目: 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

文档评论(0)

1亿VIP精品文档

相关文档