• 词法分析器

    设计SAMPLE语言的词法分析器 检查要求: 启动程序后,先输出作者姓名、班级、学号(可用汉语、英语或拼音); 请求输入测试程序名,键入程序名后自动开始词法分析并输出结果; 输出结果为单词的二元式序列(样式见样板输出1和2); 要求能发现下列词法错误和指出错误性质和位置: 非法字符,即不是SAMPLE字符集的符号; 字符常数缺右边的单引号(字符常数要求左、右边用单引号界定,不能跨行); 注释部分缺右边的界符*/(注释要求左右边分别用/*和*/界定,不能跨行); 发现错误后要能够继续编译下去,不能只报一个错误; 实验一测试程序与样板输出 测试程序1: 程序名TEST1 and array begin bool call case char constant dim do else end false for if input integer not of or output procedure program read real repeat set stop then to true until var while write abc 123 'EFG' ( ) * + , - . .. / : := ; < <= <> = > >= [ ] 样板输出1:(要求在屏幕上显示) ( 1 , and) ( 2 , array ) ( 3 , begin ) ( 4 ,bool ) ( 5 , call ) ( 6 , case) ( 7 , char) ( 8 , constant) ( 9 , dim) (10 , do ) (11 , else) (12 , end) (13 ,false) (14 ,for) (15 ,if) (16 ,input) (17 ,integer) (18 ,not) (19 ,of) (20 ,or) (21 , output) (22 ,procedure) (23 ,program) (24 ,read) (25 ,real) (26 ,repeat) (27 ,set) (28 ,stop) (29 ,then) (30 ,to) (31 ,true) (32 ,until) (33 ,var) (34 ,while) (35 ,write) (36 ,abc) (37 ,123) (38 ,EFG) (39 , ( ) (40 , ) ) (41 , * ) (43 , + ) (44 , , ) (45 , - ) (46 , . ) (47 , .. ) (48 , / ) (50 , : ) (51 , := ) (52 , ; ) (53 , < ) (54 , <= ) (55 , <> ) (56 , = ) (57 , > ) (58 , >= ) (59 , [ ) (60 , ]) 测试程序2:程序名TEST2 program example2; var A,B,C:integer; X,Y:bool; begin /* this is an example */ A:=B*C+37; X:= 'ABC'; end. 样板输出2:(要求在屏幕上显示) (23 , program ) (36 , example2 ) (52 , ; ) (33 , var ) (36 , A ) (44 , , ) (36 , B ) (44 , , ) (36 , C ) (50 , : ) (17 , integer ) (52 , ; ) (36 , X ) (44 , , ) (36 , Y ) (50 , : ) ( 4 , bool ) (52 , ; ) ( 3 , begin ) (36 , A ) (51 , := ) (36 , B ) (41 , * ) (36 , C ) (43 , + ) (37 , 37 ) (52 , ; ) (36 , X ) (51 , := ) (38 , ABC ) (52, ; ) (12 , end ) (46 , . )

    3
    212
    8KB
    2011-12-17
    10
  • c++税收管理系统教程

    教你如何独自完成c++税收管理系统的教程,关于员工工资的录入还是读取~并对员工工资的统计,并输出,得出其所应该缴纳的税。其程序还可以实现税率的修改。至于效果如何,下载了就知道了~

    4
    90
    653KB
    2010-09-13
    10
关注 私信
上传资源赚积分or赚钱