您的位置:首页 > 其它

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
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: