编译原理_实验报告(10)

2021-01-28 20:40

编译原理实验

递归子程序法:

对于每个非终结符,编写一个子程序,由该子程序负责识别该语法单位是否正确。表达式的文法

〈表达式〉∷=[+|-]〈项〉{(+|-)〈项〉}

〈项〉∷=〈因子〉{(*|/)〈因子〉}

〈因子〉∷=〈标识符〉|〈无符号整数〉|‘(’〈表达式〉‘)’

〈表达式〉的递归子程序实现

procedure expr;

begin

if sym in [ plus, minus ] then

begin

getsym; term;

end

else term;

while sym in [plus, minus] do

begin

getsym; term;

end

end;

〈项〉∷=〈因子〉{(*|/)〈因子〉}

〈项〉的递归子程序实现

procedure term;

begin

factor;

while sym in [ times, slash ] do

begin

getsym; factor;

end

end;

〈因子〉∷=〈标识符〉|〈无符号整数〉|‘(’〈表达式〉‘)’

〈因子〉的递归子程序实现

procedure factor;

begin

if sym <> ident then

if sym <> number then

if sym = ‘(‘ then

begin

getsym;

expr;

if sym = ‘)’ then getsym

else error

end

else error

else getsym

else getsym

end;

10


编译原理_实验报告(10).doc 将本文的Word文档下载到电脑 下载失败或者文档不完整,请联系客服人员解决!

下一篇:肉牛饲养管理技术

相关阅读
本类排行
× 注册会员免费下载(下载后可以自由复制和排版)

马上注册会员

注:下载文档有可能“只有目录或者内容不全”等情况,请下载之前注意辨别,如果您已付费且无法下载或内容有问题,请联系我们协助你处理。
微信: QQ: