实验一 TINY语言的词法分析
一、实验目的
(评价依据,描述是否准确到位)
构造tiny语言的词法分析器(扫描器),要求利用第三方的lex工具进行构造。实验结果:构造出的扫描器,能够读入教材样例中给出的tiny语言的示例代码,分解成token输出。
二、实验设计
(评价依据实验方案设计是否合理)
一. Tiny语言记号
Reserved words Special Symbols Other
If +
Then -
Else * number(1 or more digits)
End <
Repeat =
Until /
Read (
Write ) identifier(1 or more letters)
:
:=
二、构造Tiny语言DFA
ID:letter(letter)*
Number:digit(digit)*
三、内容和步骤
1代码:
下面是tiny语言的代码如书上:
{ sample progarm
in tiny language -
computer factorial
}
read x;{ input an integer }
if x < 0 then { don’t compute if x <= 0}
fact := 1;
repeat
fact := fact * x;
x := x - 1
until x = 0;
write fact {output fac