5.3LR(k)分析技术
2016-06-30 00:00
218 查看
摘要: 我在苦逼的学习编译原理
它是一种自底向上的分析技术
37、接受{0,1}上包含101这样的串的正规式是:________。
选项A. (0|1)*101*(00|11)*
选项B. (0|1)*101(0|1)* 去嗲哦星号的部分
选项C. (00|11)*1*01(0|1)*
选项D. (0|1)*101*1*01(0|1)*
答案:B
41、对条件语句的翻译方案如下:
S∷=if( E ) S1 else S2
{ E.true:=newlabel;E.false:=newlabel;
S.next:=newlabel;
S1.next:=S.next; S2.next:=S.next;
S.code:=E.code
‖gencode('CMP',E.place,'#1')
‖gencode('CJ=',E.true,)
‖gencode('GOTO',E.false)
‖gencode(E.true, ':')
‖S1.code‖gencode('GOTO',S1.next)
‖gencode(E.false, ':')‖S2.code
‖gencode(S.next, ':')
}
对逻辑表达式求值得翻译方案如下:
E∷=E1 || E2
{ E.place:=newtemp;
E.code:=E1.code‖E2.code
‖gencode('MOV',E1.place,E.place)
‖gencode('OR', E2.place,E.place)
}
E∷=E1 && E2
{ E.place:=newtemp;
E.code:=E1.code‖E2.code
‖gencode('MOV',E1.place,E.place)
‖gencode('AND',E2.place,E.place)
}
E∷=! E1
{ E.place:=newtemp;
E.code:=E1.code
‖gencode('MOV', E1.place,E.place)
‖gencode('NOT', E.place, E.place)
}
E∷=id1 relop id2
{ E.place:=newtemp; t:=newtemp;
E.code:=gencode('MOV', id1.place, t )
‖gencode('CMP', t, id2.place )
‖gencode('CJ'‖relop, '*+8')
‖gencode('GOTO', '*+12')
‖gencode('MOV', '#1',E.place )
‖gencode('GOTO', '*+8')
‖gencode('MOV', '#0',E.place ) }
E::=true
{E.place:=newtemp;
gencode(“MOV”,”#1”,E.place)}
}
E::=false
{E.place:=newtemp;
gencode(“MOV”,”#0”,E.place)}
}
下列条件语句的目标代码如下:
if(a<b && a>0) x=b-a; else x=a-b;
请选择正确的答案(D不懂)。
MOV a, t2
CMP t2, b
_______________
GOTO *+12
MOV #1, t1
GOTO *+8
MOV #0, t1
MOV a, t4
CMP t4, #0
GOTO *+12
MOV #1, t3
GOTO *+8
MOV #0, t3
MOV t1, t5
AND t3, t5
CMP t5, #1
CJ= L1
GOTO L2
L1: MOV b, t6
SUB a, t6
MOV t6, x
GOTO L3
L2: MOV a, t7
SUB b, t7
MOV t7, x
选项A. CJ< *+5
选项B. CJ< *+6
选项C. CJ< *+7
选项D. CJ< *+8
答案:D
它是一种自底向上的分析技术
37、接受{0,1}上包含101这样的串的正规式是:________。
选项A. (0|1)*101*(00|11)*
选项B. (0|1)*101(0|1)* 去嗲哦星号的部分
选项C. (00|11)*1*01(0|1)*
选项D. (0|1)*101*1*01(0|1)*
答案:B
41、对条件语句的翻译方案如下:
S∷=if( E ) S1 else S2
{ E.true:=newlabel;E.false:=newlabel;
S.next:=newlabel;
S1.next:=S.next; S2.next:=S.next;
S.code:=E.code
‖gencode('CMP',E.place,'#1')
‖gencode('CJ=',E.true,)
‖gencode('GOTO',E.false)
‖gencode(E.true, ':')
‖S1.code‖gencode('GOTO',S1.next)
‖gencode(E.false, ':')‖S2.code
‖gencode(S.next, ':')
}
对逻辑表达式求值得翻译方案如下:
E∷=E1 || E2
{ E.place:=newtemp;
E.code:=E1.code‖E2.code
‖gencode('MOV',E1.place,E.place)
‖gencode('OR', E2.place,E.place)
}
E∷=E1 && E2
{ E.place:=newtemp;
E.code:=E1.code‖E2.code
‖gencode('MOV',E1.place,E.place)
‖gencode('AND',E2.place,E.place)
}
E∷=! E1
{ E.place:=newtemp;
E.code:=E1.code
‖gencode('MOV', E1.place,E.place)
‖gencode('NOT', E.place, E.place)
}
E∷=id1 relop id2
{ E.place:=newtemp; t:=newtemp;
E.code:=gencode('MOV', id1.place, t )
‖gencode('CMP', t, id2.place )
‖gencode('CJ'‖relop, '*+8')
‖gencode('GOTO', '*+12')
‖gencode('MOV', '#1',E.place )
‖gencode('GOTO', '*+8')
‖gencode('MOV', '#0',E.place ) }
E::=true
{E.place:=newtemp;
gencode(“MOV”,”#1”,E.place)}
}
E::=false
{E.place:=newtemp;
gencode(“MOV”,”#0”,E.place)}
}
下列条件语句的目标代码如下:
if(a<b && a>0) x=b-a; else x=a-b;
请选择正确的答案(D不懂)。
MOV a, t2
CMP t2, b
_______________
GOTO *+12
MOV #1, t1
GOTO *+8
MOV #0, t1
MOV a, t4
CMP t4, #0
GOTO *+12
MOV #1, t3
GOTO *+8
MOV #0, t3
MOV t1, t5
AND t3, t5
CMP t5, #1
CJ= L1
GOTO L2
L1: MOV b, t6
SUB a, t6
MOV t6, x
GOTO L3
L2: MOV a, t7
SUB b, t7
MOV t7, x
选项A. CJ< *+5
选项B. CJ< *+6
选项C. CJ< *+7
选项D. CJ< *+8
答案:D
相关文章推荐
- VMware EXSI 6.0 体验
- 简单语句实现用户添加、删除
- mysql 日志维护
- 布隆算法(BloomFilter)
- Baby's User-level Threads
- iOS画板实现
- python django post提交403
- PHP MySQL递归查询
- Linux 时间、日期、时区
- Maven简介
- NoHttp网络请求框架简析——Android网络请求(二)
- velocity 参考文档
- 排名前50的开源爬虫
- Android学习--01-架构
- Python argparse 模块参考手册
- imagecreatefromjpegAllowed memory size of 13421772
- 推荐7个 CSS3 制作的创意下拉菜单效果
- css3选择器-选择范围
- whisper数据库
- graphite-web render api