编译原理--TINY扩充语言的语法分析

实验三:TINY扩充语言的语法分析
一、实验内容:
扩充的语法规则有:实现 while、do while、for语句、大于>比较运算符号以及求余计算式子,具体文法规则自行构造。
可参考:P97及P136的文法规则。
(1). While-stmt --> while  exp  do  stmt-sequence  endwhile
(2). Dowhile-stmt-->do  stmt-sequence  while(exp); 
(3). for-stmt-->for identifier:=simple-exp  to  simple-exp  do  stmt-sequence enddo    步长递增1
(4). for-stmt-->for identifier:=simple-exp  downto  simple-exp  do  stmt-sequence enddo    步长递减1
(5). 大于>比较运算符号以及求余计算式子的文法规则请自行组织。
(6). 把TINY语言原有的if语句书写格式
if_stmt-->if exp then stmt-sequence end | if exp then stmt-sequence else stmt-sequence end
改写为:if_stmt-->if(exp) stmt-sequence | if(exp) stmt-sequence else stmt-sequence

实验三运行截图如下(语法分析):

猜你喜欢

转载自blog.csdn.net/qq_39573547/article/details/88343297