华南理工大学计算机全英班编译原理实验1

上传者: z_y_r12138 | 上传时间: 2021-11-05 14:58:00 | 文件大小: 1.23MB | 文件类型: -
Compiler Construction Experiment 1 Implementing a Scanner for TINY+ You are to write a lexical analyzer/scanner for the language TINY+. Goals 1The input of the scanner is a source code file and the output of the scanner is a stream of tokens. 2Your scanner should go for longest possible match i.e. a string ‘:=’ is to be identified as ‘ass-symbol’ rather than ‘:’ and ‘=’. 3Token is represented as (Kind, Value). We use the following symbols to denote different kinds of tokens KEY denotes reserved words SYM denotes special symbols ID denotes identifiers NUM denotes numeric constants STR denotes string constants 4Check lexical errors: giving meaning error messages and the lines where errors occur. The kinds of lexical errors are: Illegal character, that is, scanner may recognize a character that is not in the alphabet of TINY+, such as $ is an illegal character The right bracket of a STRING is lost, such as ' scanner The right delimiter of a comment is lost, such as: {this is an example Requirements 1Write your program in C or C++ 2This experiment must be finished in 4 periods. You will submit a report and the source code Example output for some TINY+ programs Test1 or and int bool char while do if then else end repeat until read write , ; := + - * / ( ) = a2c 123 'EFG' The scanner should give the outputs: (KEY, or) (KEY, and) (KEY, int) (KEY, bool) (KEY, char) (KEY, while) (KEY, do) (KEY, if) (KEY, then) (KEY, else) (KEY, end) (KEY, repeat) (KEY, until) (KEY, read) (KEY, write) (SYM, ,) (SYM, ;) (SYM, :=) (SYM, +) (SYM, -) (SYM, *) (SYM, /) (SYM, ( ) (SYM, )) (SYM, ) (SYM, =) (ID, a2c) (NUM, 123) (STR, EFG) Test2 {this is an example} int A,B; bool C1, C2, C3; char D; D:= 'scanner'; while A<=B do A:=A*2 end The scanner should give the outputs: (KEY, int) (ID, A) (SYM, ,) (ID, B) (SYM, ;) (KEY, bool) (ID, C1) (SYM, ,) (ID, C2) (SYM, ,) (ID, C3

文件下载

评论信息

免责申明

【只为小站】的资源来自网友分享,仅供学习研究,请务必在下载后24小时内给予删除,不得用于其他任何用途,否则后果自负。基于互联网的特殊性,【只为小站】 无法对用户传输的作品、信息、内容的权属或合法性、合规性、真实性、科学性、完整权、有效性等进行实质审查;无论 【只为小站】 经营者是否已进行审查,用户均应自行承担因其传输的作品、信息、内容而可能或已经产生的侵权或权属纠纷等法律责任。
本站所有资源不代表本站的观点或立场,基于网友分享,根据中国法律《信息网络传播权保护条例》第二十二条之规定,若资源存在侵权或相关问题请联系本站客服人员,zhiweidada#qq.com,请把#换成@,本站将给予最大的支持与配合,做到及时反馈和处理。关于更多版权及免责申明参见 版权及免责申明