龙书第六章参考答案
编译原理(龙书)
![编译原理(龙书)](https://img.taocdn.com/s3/m/fdfe30f2aef8941ea66e0506.png)
4
16
2013-12-11计算机学院
符号表的接口: 符号表的作用就是存放字符串或词素 当一个字符串或词素被保存时,与之相对 应的记号也被保存
符号表上的操作: Insert(s,t):将符号串s和记号t插入符号
表,返回相应表项的指针 Lookup(s):在符号表中查找字符串s,查找 成功返回相应指针,否则返回0
33
2013-12-11计算机学院
辛明影
赋值、分支、循环语句: S → id=E S → if B then S S → if B then S else S S → while B do S S →{ L } L → L ;S L→S
2013-12-11计算机学院
辛明影
34
调用语句: S→call id(Elist) Elist →Elist,E
辛明影
31
主要语句的形式描述:
表达式:
E→E+T E→E-T E→T T→T*F T→T/F T→F F→(E) F→ id
2013-12-11计算机学院
辛明影
32
布尔表达式: B→ B or B B→ B and B B→ not B B→(E) B→ id relop id B→ true B→ false
其它
T 7
*
30
二.语法规则
语法规则规定了如何从单词符号形成更 大的结构(即语法单位),换言之,语法 规则是语法单位的形成规则 一般的程序设计语言的语法单位有: 表达式 、语句 、分程序 、 函数 、 过程和程序等
下推自动机理论和上下 文无关文法是我们讨论语法 分析的理论基础
2013-12-11计算机学院
编译原理 龙书 第二版 第5、6章
![编译原理 龙书 第二版 第5、6章](https://img.taocdn.com/s3/m/38c909e4e009581b6bd9eb98.png)
2)E->T
E.type=T.type
3)T->num
T.type=integer
4)T->num.num
T.type=float
(2)
产生式
语义规则
1)E->E1+T
If E1.type ==T.type then E.type=E1.type
Else begin
E.type=float
105: goto–
6)按照产生式B->B1 || M B2进行归约
7)按照产生式B->(B1)进行归约
8)按照产生式B->B1 && M B2进行归约
9)各子表达式的truelist和falselist在上图中已标出
3)三元式序列
4)间接三元式序列
答:(1)抽象语法树
(2) 四元式序列
t1=b+c
t2=minus t1
t3=a+t2
op
Arg1
result
0
+
b
c
T1
1
minus
T1
T2
2
+
a
T2
T3
(3)三元式序列
op
Arg1
Arg2
0
+
b
c
1
minus
(0)
2
+
a
(1)
(4)间接三元式序列
10
(0)
E.type=T.type; E.val=T.val
3)T->num
T.type=integer; T.val=num
龙书第二章部分答案
![龙书第二章部分答案](https://img.taocdn.com/s3/m/915f1911fc4ffe473368ab46.png)
第二章2.2 Exercises for Section 2.22.2.1Consider the context-free grammar:S -> S S + | S S * | a1Show how the string aa+a* can be generated by this grammar.2Construct a parse tree for this string.3What language does this grammar generate? Justify your answer.answer4S -> S S * -> S S + S * -> a S + S * -> a a + S * -> a a + a *56L = {Postfix expression consisting of digits, plus and multiple signs}2.2.2What language is generated by the following grammars? In each case justify your answer.7S -> 0 S 1 | 0 18S -> + S S | - S S | a9S -> S ( S ) S | ε10S -> a S b S | b S a S | ε11⧗ S -> a | S + S | S S | S * | ( S )answer12L = {0n1n | n>=1}13L = {Prefix expression consisting of plus and minus signs}14L = {Matched brackets of arbitrary arrangement and nesting, includes ε} 15L = {String has the same amount of a and b, includes ε}16?2.2.3Which of the grammars in Exercise 2.2.2 are ambiguousanswer17No18NoYesYesYes2.2.4Construct unambiguous context-free grammars for each of the following languages. In each case show that your grammar is correct.19Arithmetic expressions in postfix notation.20Left-associative lists of identifiers separated by commas.21Right-associative lists of identifiers separated by commas.22Arithmetic expressions of integers and identifiers with the four binary operators +, - , *, /.answer1. E -> E E op | num2. list -> list , id | id3. list -> id , list | id4. expr -> expr + term | expr - term | termterm -> term * factor | term / factor | factorfactor -> id | num | (expr)5. expr -> expr + term | expr - term | termterm -> term * unary | term / unary | unaryunary -> + factor | - factorfactor - > id | num | (expr)2.2.5Show that all binary strings generated by the following grammar have values divisible by 3. Hint. Use induction on the number of nodes in a parse tree.num -> 11 | 1001 | num 0 | num numDoes the grammar generate all binary strings with values divisible by 3?answerproveany string derived from the grammar can be considered to be a sequence consisting of 11, 1001 and 0, and not prefixed with 0.the sum of this string is:sum= Σn (21 + 20) * 2 n + Σm (23 + 20) * 2m= Σn 3 * 2 n + Σm 9 * 2mIt is obviously can divisible by 3.No. Consider string "10101", it is divisible by 3, but cannot derived from the grammar. Question: any general prove?2.2.6Construct a context-free grammar for roman numerals.Note: we just consider a subset of roman numerals which is less than 4k.answerwikipedia: Roman_numeralsvia wikipedia, we can categorize the single noman numerals into 4 groups:I, II, III | I V | V, V I, V II, V III | I Xthen get the production:digit -> smallDigit | I V | V smallDigit | I XsmallDigit -> I | II | III | εand we can find a simple way to map roman to arabic numerals. For example: o XII => X, II => 10 + 2 => 12o CXCIX => C, XC, IX => 100 + 90 + 9 => 199o MDCCCLXXX => M, DCCC, LXXX => 1000 + 800 + 80 => 1880 via the upper two rules, we can derive the production:romanNum -> thousand hundred ten digitthousand -> M | MM | MMM | εhundred -> smallHundred | C D | D smallHundred | C MsmallHundred -> C | CC | CCC | εten -> smallTen | X L | L smallTen | X CsmallTen -> X | XX | XXX | εdigit -> smallDigit | I V | V smallDigit | I XsmallDigit -> I | II | III | ε2.3 Exercises for Section 2.32.3.1Construct a syntax-directed translation scheme that translates arithmetic expressions from infix notation into prefix notation in which an operator appears before its operands; e.g. , -xy is the prefix notation for x - y . Give annotated parse trees for the inputs 9-5+2 and 9-5*2.。
20240619参考答案
![20240619参考答案](https://img.taocdn.com/s3/m/56a95d7cfd4ffe4733687e21af45b307e971f977.png)
高一语文参考答案1.A2.D3.B4. ①拉开距离/错位差距②情感系统失衡/远离平衡③反馈和调节④审美价值/艺术感染力【1点1分,意思对即可】5.(1)该笔法有利于拉开人物心理距离,增强了小说的艺术感染力。
(2)使人物在儿童的躯壳内逾越常规地发展,进而表现作者对情感理想性的吁求。
③有利于展现人物形象的复杂性、深刻性。
【1点2分,答出2点满分】6.C(“羡慕之情”错)7.B(体现其“老监生”的身份不准确,“对祥林嫂的嫌弃”以偏概全)8.回答了上文祥林嫂出逃和绑回的原因。
照应下文祥林嫂再到鲁镇的内容(为下文祥林嫂再到鲁镇做铺垫)。
串联祥林嫂两次出场时外在形象的变化。
答出“结构有波澜,情节更曲折”酌情给分。
【1点2分,共6分】9.最有价值的材料:逼婚再嫁。
(2分)深意:人物命运悲惨;人性冷漠无情;山民野蛮落后;礼教戕害百姓。
【1点2分,答出2点即可。
】如学生答“大伯收屋驱逐”“阿毛之死”并言之有理,给一半分。
10.ACE 11.D (“君”名作动) 12.C(与“艺术成就”无关)13.把材料中画横线的句子翻译成现代汉语。
(8分)(1)礼的作用是在坏事发生前就加以禁止,法的作用是在坏事发生后加以处置;法起的作用是比较容易看得见的,而礼起的防患作用就难以被人们所理解。
”【1个分句1分】(2)假如我们凭借着这样大的国家,而自取下策(降低身份)重蹈六国灭亡的旧事,这就是又在六国之下了。
【苟、定语后置、故事、是,1点1分】14. ①《春秋》阐明治世之道(王道),辨明为人处事的法则(人事)。
②《春秋》拨正一个混乱的社会,使其回归正道,切近有效。
③不通晓《春秋》,君臣父子都将承受天下最大的罪名。
(或阐明君臣父子之道)【1点1分,意思对即可】15.B (“就要到水影中苦苦寻觅”错)16.①写风,写云要表现出风云变幻的意态;写花草树木,要写你从花草树木中发现的生机与精神(独特的个性)。
②写大海不是要写大海的外形,要写出大海的波澜变化;写山要突出的是山的嶙峋奇绝。
高一语文必修上册人教版课后习题 第六单元 13 读书 目的和前提 上图书馆
![高一语文必修上册人教版课后习题 第六单元 13 读书 目的和前提 上图书馆](https://img.taocdn.com/s3/m/960e10ea970590c69ec3d5bbfd0a79563c1ed42a.png)
13 读书:目的和前提上图书馆课后篇一起巩固一、夯实基础1.下列各组词语中字形与加点字的注音无误的一组是( )A.跋.涉(bá)麻痹.(bì)戕.害(qiāng)视而不见B.狭隘.(yì)消遣.(qiǎn)时髦.(máo)卷帙浩繁C.慰藉.(jí)瞬.间(shùn)蓬.勃(péng)汪洋兴叹D.殿.宇(diàn)苍穹.(qióng)白炽.灯(zhì)豁然开郎项,“隘”读“ài”;C项,“藉”读“jiè”,“汪洋兴叹”应为“望洋兴叹”;D项,“炽”读“chì”,“豁然开郎”应为“豁然开朗”。
2.下列各句中加点成语的使用,全都不正确的一项是( )①历尽磨难的少年中国如今已经长大成人,然而每一个屋檐下的变革都与国家命运息息相通....。
②经典小说的情节没有展开前,势必有很大的篇幅交代背景,需要用耐心去拨开迷雾,才能渐入佳境,最后豁然开朗....。
③不少教师在批改学生造句练习的作业时,仅满足于学生掌握了词语的意义和用法,却对学生造句所存在的各种思想问题无足轻重....。
④放了暑假,终于拥有了休闲度假的时间,我和朋友来到浩瀚的大海边,面对滚滚的海浪,不禁望洋兴叹....,激情澎湃。
⑤这首诗既经得起细读,又非由观念敷衍而成篇,可谓在感性与诗意的交织中自动绵延生发,言其臻于佳境....,也不为过。
⑥关于挪亚方舟,大家还是当个神话看看就好,没有必要非得牵强附会....地在现实世界中找到所谓的依据。
A.①④⑤B.②③⑥C.①③④D.②⑤⑥:呼吸相关联,形容关系密切。
此处语境强调的是每一次的“变革”都与国家的命运相关,侧重的是“祸福”,故改成“休戚相关”更恰当。
②豁然开朗:比喻对于百思不得其解的事物,突然开阔了思路。
使用正确。
③无足轻重:没有它并不轻些,有它也并不重些。
指无关紧要。
不合语境,应改为“视而不见”。
人教版高中语文必修上册课后习题 第6单元 13 读书目的和前提 上图书馆
![人教版高中语文必修上册课后习题 第6单元 13 读书目的和前提 上图书馆](https://img.taocdn.com/s3/m/09856c4ca31614791711cc7931b765ce04087a48.png)
第六单元13 读书:目的和前提上图书馆A级必备知识基础练1.下列词语中,加点字的注音全都正确的一项是( )A.时髦.(máo)慰藉.(jí)兴.奋(ú)麻痹.(bì)跋.涉(bá)教.养(jiào)C.戕.害(qiāng)强.迫(qiǎnɡ)孜.孜(zī)魅.力(mèi)D.卷帙.(yì)厌恶.(wù)消磨.(mó)沉浸.(jìn)2.填入下面文段横线处的词语,最恰当的一项是( )读书①靠几分钟热度就能完成的, ②应该是一种长期坚持的行为。
真正的读书人不会太在意读书的形式, ③遇到一本好书, ④何时何地,都会品读,在他们看来,天天都是“读书日”。
A.不仅还因为不管B.不必就如果不论C.不是而只要不论D.并非可只有尽管3.下列各句中,没有语病的一项是( )A.更多的中国人如果能够多读书,能够让自己的心平静下来,能在书里慢慢找到幸福感并且找到自己,中国就会变得更好。
B.当下流行的网络文艺作品能否切实、丰盈地表现“中国精神”,很大程度上取决于准确把握中华五千年文化的精华。
C.“书香雅韵”是丰富学生课余生活,引导学生爱读书、会读书、读好书,使读书成为体现学生精神追求的生活方式。
D.王国维先生用他早年学到的西方美学思想和文学理论对《红楼梦》的人物形象、思想艺术等方面做了全面系统的评价。
4.下面是某地图书馆一则启事的片段,其中有五处词语使用不当,请找出并修改。
要求修改后语意准确,语体风格一致。
感谢您一直以来对市图书馆的抬爱!在新的一年里,市图书馆全体人员将竭诚为您效命。
今年,市图书馆开通了微信公众号,您可以在微信上物色“市图书馆”公众号并关注。
您进入公众号后,可在线阅读图书、期刊,也可在线办理书目查询及图书续借等事情。
该公众号难免有不完善之处,欢迎您对公众号的改进提出浅见!B级能力素养提升练阅读下面的文字,完成5~9题。
部编版九年级语文下册第6课《变色龙》课后练习题(附答案解析)
![部编版九年级语文下册第6课《变色龙》课后练习题(附答案解析)](https://img.taocdn.com/s3/m/2c2d4d010622192e453610661ed9ad51f01d5431.png)
部编版九年级语文下册第6课《变色龙》课后练习题(附答案解析)一、知识点拨与学法引导(一)整体感知《变色龙》这篇小说作者采用夸张变形的手法,从日常生活中选取片断场面作为素材,经过提炼加工,用极其幽默的笔调和富有讽刺意味的语言描绘了沙皇走狗诌媚权贵、欺压百姓的丑恶嘴脸,深刻揭露了沙皇统治的黑暗现实和俄国警察制度的反动和虚伪,批判了沙皇政权腐朽反动的本质。
“变色龙”已超越了时间和国界,成为世界文化艺术长廊中见风使舵、反复无常之流的典型。
(二)学法引导阅读课文,理清小说的故事情节,结合故事情节,着重分析警官奥楚蔑洛夫的人物形象,理解小说的主题思想,本文中的细节描写、环境描写也需留心体会。
(三)审美鉴赏富有个性的语言美《变色龙》中的人物语言是高度个性化的。
“变色龙”奥楚蔑洛夫是个沙皇警犬,因此他的语言具有骄横和谄上欺下的特点。
他对老百姓大逞威风、专横跋扈,对大官僚则奴颜婢膝、趋炎附势。
在这两种特点的统一中表现出他的厚颜无耻。
赫留金的语言也是个性化的。
他既是一个庸俗的小市民,又是一个有所恳求的“小人物”。
他的语言完全符合他的性格。
他向巡官申诉的那一段著名的话,是相当出色的,形象地反映出他的粗俗鄙陋、虚荣夸张、逢迎官长和想趁机捞一把的特点,这一段申诉和下面一段辩词(骂“独眼鬼”那一段),把这个小市民的性格活龙活现地表现出来了。
(四)重点难点突破1、本文以“变色龙”为题,具有怎样的表达效果?[析]题目是文章的眼睛,好的题目,不近能吸引读者,而且能对表现主题等起到画龙点睛得作用。
[参考答案]“变色龙”原是一种晰蜴,它皮肤的颜色会随着四周物体颜色的变化而变化,变色为保护色。
小说主人公奥楚蔑洛夫警官在处理狗咬人事件中反复无常的态度和变色龙极为相似,用“变色龙”作小说的题目,含蓄形象地揭露了这个人物的丑恶面目。
2、“商店和饭馆的门无精打采地敞着,面对着上帝创造的这个世界,就跟许多饥饿的嘴巴一样;门口连一个乞丐也没有。
”这句话运用了哪些修辞手法,表现了什么?[析]文学作品的语言,往往是形象生动,意蕴丰富。
compiler-龙书-习题解答-学生
![compiler-龙书-习题解答-学生](https://img.taocdn.com/s3/m/7aa99700f12d2af90242e660.png)
3.7.6 ............ p166 3.6节的练习 ............ p103 Exercise 3.7.1 练习3.6.1NFA确定化NFA确定化‘+’代表终态3.9.9 ............ p186Exercise 3.9.4a)补充已知正则表达式,构造最小化自动机a) (a|b)*a(a|b)最小化:Π0: {1,2} {3,4}Π1: {1} {2} {3,4} 将1和2分开的原因: 1遇到a 转移到{1,2}; 2遇到a 转移到{3,4} Π2: {1} {2} {3} {4} 将3和4分开的原因: 3遇到a 转移到{3,4}; 4遇到a 转移到{2} 所以, 最小化结果与确定化结果相同S ABa abbNFAChapter 44.2.8 ............ p2064.2节的练习 ............ p119Exercise 4.2.1练习4.2.1推导、语法树、二义、语言答案 略……Exercise 4.2.3练习4.2.3设计文法a)* b)*1)* 2)*a)G: S → 1S | 0A | ε A → 1S b)G: S → 0S0 | 1S1 | ε4.3.6 ............ p2164.3节的练习 ............ p126Exercise 4.3.1练习4.3.1 提左公因子,消左递归,LL1判别a) ...... b) ......c) 消除左递归E → TE ’E ’→ +TE ’ | ε T → FT ’ T ’→ FT ’ | εF → PF ’ F ’→ *F ’ | ε P → a | bExercise 4.3.2练习4.3.2 提左公因子,消左递归,LL1判别a) ......1) ......AS4.4.6 ............ p231 4.4节的练习 ............ p136 Exercise 4.4.1练习4.4.1预测分析表d) e) 4) 5)d) S →S+S | S S | (S) | S* | a消除左递归G’: S → (S)B | aBB → +SB | SB | *B | εe) S → (L) | aL → L,S | S消除左递归G’: S → (L) | aL → SL’L’→ ,SL’ | εExercise 4.4.3练习4.4.3First集合、Follow集Exercise 4.4.4练习4.4.4First集合、Follow集b) c) f) g) 2) 3) 6) 7)f) S → aSbS | bSaS | εg)将文法简写为:E → E o T | TT → T a F | FF → n F | (E) | t | f4.5.5 ............ p2404.5节的练习 ............ p141Exercise 4.5.1练习4.5.1句柄a) 010********* 句柄: 0311 b) 0102S1112 句柄: 02S11Exercise 4.5.2练习4.5.2句柄a) c)1) 3)a) S 1S 2S 3+a++ 句柄: S 2S 3+ c) a 1a 2a 3*a 4++句柄: a 14.6.6 ............ p2574.6节的练习 ............ p153Exercise 4.6.1练习4.6.1描述文法的活前缀a)1)a) S → 0S1 | 01构造识别文法所有活前缀的自动机:活前缀的正则表达式:S | 00*S1 | 00*1I 0:S ’ → • S S → • 0S1 S → • 01I 1:S ’ → S •SI 2:S →0 • S1 S →0 • 1 S → • 0S1 S → • 01 0I 3:S →0S • 1S1I 4:S →01 •1I 5:S →0S1 • SS11S → SS+ | SS* | aG ’ : S ’→ S (0) S → SS+ (1) S → SS* (2) S → a(3)FIRST FOLLOW $ a + *$I 0:S ’ → • S S → • SS+ S → • SS* S → • a I 1:S ’ → S • S → S • S+ S → S • S* S → • SS+ S → • SS* S → • a Sa I 2:S → a •r3SI 3:S → SS • + S → SS • * S → S • S+ S → S • S* S → • SS+ S → • SS* S → • aa+I 4:S → SS+ • r1 *I 5:S → SS* •r2 Sar0Exercise 4.6.5练习4.6.5LL(1)判别、SLR判别G’ : S’→ S (0)S → AaAb (1)S → BbBa (2)A →ε(3)LL(1)文法。
编译原理 龙书 第二版 第5、6章
![编译原理 龙书 第二版 第5、6章](https://img.taocdn.com/s3/m/9017fa05eefdc8d376ee3267.png)
4)L’->BL1’
L1’.m=L’.m*L’.m;L1’.side=L’.side
L1’.inh=L’.inh*L’.side+B*L1’.m
L’.syn=L1’.syn
5)L’->ε
L’.syn=L’.inh
6)B->0
B.val=0
7)B->1
B.val=1
练习5.3.1:下面是涉及运算符+和整数或浮点运算分量的表达式文法。区分浮点数的方法是看它有无小数点。
E-〉E+T|T T-〉num.num|num
1)给出一个SDD来确定每个项T和表达式E的类型
2)扩展(1)中得到的SDD,使得它可以把表达式转换成为后缀表达式。使用一个单目运算符intToFloat把一个整数转换为相等的浮点数
答:
(1)
产生式
语义规则
1)E->E1+T
If E1.type ==T.type then E.type=E1.type
2)四元式序列
3)三元式序列
4)间接三元式序列
答:(1)抽象语法树
(2) 四元式序列
t1=b+c
t2=minus t1
t3=a+t2
op
Arg1
Arg2
result
0
+
b
c
T1
1
minus
T1
T2
2
+
a
T2
T3
(3)三元式序列
op
Arg1
Arg2
0
+
b
c
1
minus
(0)
龙书第二章答案Snooze
![龙书第二章答案Snooze](https://img.taocdn.com/s3/m/0682285ecc175527072208dd.png)
龙书第二章答案SnoozeCS 431, Assignment 3, Book Questions on Chapter 2Plus One Other QuestionQuestions that you need to answer are listed below, and some solutions or partial solutions are also given. The solutions are not presented as the only possible answers, and what is given may not be complete. It may only be a starting point for thinking about a complete, correct answer. Your goal in working the problems should be to come up with a solution, and if in doubt about your answer, compare with what’s gi ven here. In theory, even if your answer is not exactly the same, you should see the sense or understand the direction of the suggestions. If your answer is at odds with what I have suggested you might want to check with me. It is possible that I am off base. It is also possible that you need some things clarified.Book problems: 2.1, a-c; 2.2, a-e; 2.3; 2.4, a-e, and 2.8. Suggested answers to these questions are given after the following question.Last problem: There is an additional problem that is not from the book. It is stated here. Implement Java code that will correctly translate infix expressions with + and – (no parentheses and no other operators) to postfix expressions. A problem solution is given in the book in C code, so your task is mainly one of adaptation. A starting point for this problem is posted on the Web page. You may use the file InfixToPostfixCut.java as given and simply add the needed methods. You can also do the problem from scratch if you want to. I think it would be preferable if you left your implementation recursive rather than changing it to a loop, but that is your choice. Hand in a printout of the methods you added along with your answers to the problems listed above.Starting points for thinking about solutions:2.1. Consider the following context-free grammarS → S S + (1)S → S S * (2)S → a (3)a) Show how the string aa+a* can be generated by this grammar.Production (3) allows you to generate a string S0 which consists of a.Using S0 as a starting point, production (1) allows you to generate a string S1 which consists of aa+.Production (3) again allows you to generate a string S2 which consists of a.Then production (2) allows you to generate a string S3 = S1S2* = aa+a*.b) Construct a parse tree for this string.c) What language is generated by this grammar? Justify your answer. Assuming a is an identifier for a numeric value, for example, then the grammar generates a language consisting of all possible arithmetic combinations of a using only the operations + and * and postfix notation. (No particular justification is given. Check to see if you agree.)2.2. What language is generated by the following grammars? In each case justify your answer. (No justifications are given.)a) S → 0 S 1 | 0 1All strings divided evenly between 0’s and 1’s, with the sequence of 0’s coming first and the sequence of 1’s coming second.b) S → + S S | - S S | aThis is the prefix analog to question 2.1.c) S → S ( S ) S | εThis will generate arbitrary sequences of adjacent and nested, matched pairs of parentheses.d) S → a S b S | b S a S | εAll possible strings containing equal numbers of a’s and b’s, with the a’s and b’s arranged in no particular order.e) S → a | S + S | S S | S * | ( S )I don’t see a pattern to this that I can verbally describe.2.3. Which of the grammars in Exercise 2.2 are ambiguous?To show ambiguity it is sufficient to find any single string that can be parsed in more than one way using the grammar. No such strings spring immediately tomind for the grammars of a through d. (That does not mean that there aren’t any.) However, e is clearly ambiguous. Let the string S + S * be given. Here are two possible parsings:2.4. Construct unambiguous context-free grammars for each of the following languages. In each case show that your grammar is correct. (Correctness is not shown.)a) Arithmetic expressions in postfix notation.list → list list + list → list list – list → digitlist → 0 | 1 | 2 | … | 9b) Left-associative lists of identifiers separated by commas.list → list, id list → idc) Right-associative lists of identifiers separated by commas.list → id, list list → idd) Arithmetic expressions of integers and identifiers with the four binary operators +, -, *, /.Add the following rule to the grammar given at the end of section 2.2: factor → identifiere) Add unary plus and minus to the arithmetic operators of (d).Add the following rules to the grammar:factor → +factorfactor → -factor2.8 Construct a syntax-directed translation scheme that translates arithmetic expressions from postfix notation to infix notation. Give annotated parse trees for the inputs 95-2* and 952*-.Here is a simple grammar that can serve as a starting point for the solution of the problem:string → digit string operator| string digit operator| digitdigit →0 | 1 | 2 | … | 9operator → * | / | + | -Here is an annotated parse tree of the first expression:The first production applied in forming this tree was: string → string digit operator. Notice that it would have been just as possible to apply the production: string → digit string operator. If that had been done you would have then had to parse the string “5-2”. This result would not parse and it would be necessary to backtrack and choose to apply the other production. At the next level down it doesn’t matter which production is chosen.In this example there is no choice about which production to apply first. At the second level there is a choice but it doesn’t make a difference. The lack of choice at the first level illustrates clearly how you could tell whether or not the production you have chosen is the correct one, assuming you could look that far ahead: If the string that you have parsed on the right hand side does not end in an operator, then the production choice is not correct. It is also possible to see that if you could specify the order in which productions are tried, you could avoid backtracking. If you always tried to parse using this production first: string string digit operator and tried the other one if that one failed to apply, you would avoid backtracking. But again, such an approach is not allowed. The question of backtracking is discussed on pages 45 and 46 of the book. The upshot of the matter is that this grammar isn’t suitable for predictive parsing.There is another matter that will require a change in the grammar so that a syntax-directed translation scheme can be devised. At the top of page 39 in the book the term “simple” is defined as it applies to a syntax-directed definition. The requirement is that the order of non-terminals on the right hand side of a production agree with the order of the corresponding symbols generated as the desired output. Other symbols or terminals may come before, between, or after the output for the non-terminals. Under this condition the output can be generated from a depth first traversal of the annotated tree. The problem with the grammar given above is that all of the operators are symbolized using the non-terminal “operator”. However, in the translation from postfix to infix, it is the position of the operator that changes. That means that even though tedious, for practical reasons the productions have to be rewritten with the operator symbols in-line as terminals:string → digit string *| digit string /| digit string +| digit string –| string digit *| string digit /| string digit +| string digit –| digitdigit →0 | 1 | 2 | … | 9The problem only gets better and better, or worse and worse, depending on your point of view. Postfix notation does not require parentheses. The relative positions of the operands and operators unambiguously determine the order of operations. This means that an arbitrary postfix expression may enforce an order of operations which would not occur naturally in an unparenthesized infix expression. In particular, 95-2* does not translate to 9 – 5 * 2, where the multiplication would be done first. It translates to (9 – 5) * 2. It is not an attractive proposition to try and implement a translation scheme that would only insert parentheses when needed. It is much more convenient to fully parenthesize the infix translation whether needed or not. The unneeded parentheses do not adversely affect the meaning of the arithmetic.Having said all of the above, here is my suggested syntax-directed translation scheme, that is, a context-free grammar with embedded semantic actions that will generate the infix translation of a postfix input:string →{print(“(“)} digit {print(“*”)} string * {print(“)”)}| {print(“(“)} digit {print(“/”)} string / {print(“)”)}| {print(“(“)} digit {print(“+”)} string + {print(“)”)}| {print(“(“)} digit {print(“-”)} string - {print(“)”)}| {print(“(“)} string {print(“*”)} digit * {print(“)”)}| {print(“(“)} string {print(“/”)} digit / {print(“)”)}| {print(“(“)} string {print(“+”)} digit + {print(“)”)}| {print(“(“)} string {print(“-”)} digit - {print(“)”)}digit →0 {print(“0”)}| 1 {print(“1”)}etc.The parse tree for 95-2* showing semantic actions follows.And here is the parse tree for 952*- showing semantic actions.If there are no mistakes in the parse trees, traversing them in depth-first order and executing the print statements as you go should cause the correct, parenthesized, infix translation of the postfix input to be emitted.。
第六单元阅读理解精选题(含答案)2023-2024学年语文六年级上册
![第六单元阅读理解精选题(含答案)2023-2024学年语文六年级上册](https://img.taocdn.com/s3/m/6237bc282f3f5727a5e9856a561252d380eb2037.png)
第六单元阅读理解精选题语文六年级上册统编版1.课内阅读。
①人类生活所需要的水资源、土地资源、生物资源等,本来是可以不断再生,长期给人类作贡献的。
但是,因为人们随意毁坏自然资源,不顾后果地滥用化学品,不但使它们不能再生,还造成了一系列生态灾难,给人类生存带来了严重的威胁。
②有人会说,成宙空间不是大得很吗,那里有数不清的星球,在地球资源枯竭的时候,我们不能移居到别的星球上去吗?③科学家已经证明,至少在以地球为中心的四十万亿千米的范围内,没有适合人类居住的第二个星球。
人类不能指望地球被破坏以后再移居到别的星球上去。
④不错,科学家们提出了许多设想,例如,在火星或者月球上建造移民基地。
但是,即使这些设想能实现,也是遥远的事情。
再说,又有多少人能够去居住呢?⑤“我们这个地球太可爱了,同时又太容易破碎了!”这是宇航员遨游太空目睹地球时发出的感叹。
(1)选文提到的可再生资源有、。
(2)判断。
①选文中的“本来”一词不能去掉,因为“本来”一词准确地点明可再生资源已经遭受破坏,以及这些资源以前的可再生性和现在的不可再生性,给人们以警示。
( )②“我们这个地球太可爱了,同时又太容易破碎了!”这句话写出了地球容易被破坏,旨在提醒人们要保护好我们的地球。
( )(3)读选文的第①段,你想到了生活中的哪些现象?针对这些现象设计一条宣传标语。
生活中的现象:______________________________________________________宣传标语:______________________________________________________阅读材料,完成下面小题。
飞机的舷窗为什么是圆的黄沛然为什么飞机的舷窗是圆的?这要从飞机的演变历程说起。
其实,最初的飞机舷窗并不是圆角的,而是方形的。
1952年,英国德·哈维兰公司研制的“彗星”喷气式客机横空出世,本以为乘坐这架飞机可以扶摇直上,但是结果惨不忍睹。
2023-2024学年初中语文部编版五四制六年级下第六单元单元测试(含答案解析)
![2023-2024学年初中语文部编版五四制六年级下第六单元单元测试(含答案解析)](https://img.taocdn.com/s3/m/8bcc977f4a73f242336c1eb91a37f111f0850d58.png)
2023-2024学年部编版五四制初中语文单元测试学校:__________ 班级:__________ 姓名:__________ 考号:__________注意事项:1.答题前填写好自己的姓名、班级、考号等信息;2.请将答案正确填写在答题卡上;一、文言文阅读(本大题共计1小题,每题15分,共计15分)1.(1)解释下列句子中画线的词语。
①权谓吕蒙曰_______________ ②见往事耳_______________③肃意尚轻蒙_______________ ④权悉以兵并蒙_______________1.(2)把语段中画横线的句子翻译成现代汉语。
士别三日,即更刮目相待,大兄何见事之晚乎!1.(3)阅读两则语段,说说你对吕蒙的三点看法。
1.(4)语段(一)和语段(二)有何异同点?请结合语段简要分析。
【答案】(1)①对……说, ②了解, ③轻视,藐视, ④全部,全都【解析】(1)①孙权对吕蒙说。
谓:对......说。
②了解历史罢了见:了解。
③当时鲁肃还是轻视吕蒙的。
轻:轻视,藐视。
④孙权想把这三人的军兵全都给吕蒙。
悉,全,都。
【答案】(2)君子分别了几天,就要重新以新的眼光看待,长兄你怎么知晓事情这么晚呢!【解析】(2)更:另,另外。
刮目相待:拭目相看,用新的眼光看待他。
见事:知晓事情。
【答案】(3)①勤奋好学;②勇而有谋,识军计;③善于听取别人意见;④忠贞爱国;⑤对朋友忠诚,照顾朋友的儿子。
【解析】(3)(一)文中“卿今者才略,非复吴下阿蒙!”“肃遂拜蒙母,结友而别”是写他善于听取别人意见,勤奋好学而卓有成效。
(二)文结合“‘今东西虽为一家,而关羽实熊虎也,计安可不豫定?’因为肃画五策”分析,从正面展现了吕蒙的才略。
“书三上,权乃听。
蒙于是又为择师,使辅导之,其操心率如此。
”可以看出对朋友忠诚,照顾朋友的儿子。
【答案】(4)共同点:都揭示了开卷有益、虚心学习的道理。
不同点:《孙权劝学》是正面揭示,《鲁肃过蒙屯下》是侧面反映。
部编版小学六年级课外阅读书目阅读训练题及答案
![部编版小学六年级课外阅读书目阅读训练题及答案](https://img.taocdn.com/s3/m/6ce8a6fc240c844769eaeeb8.png)
小学六年级课外阅读书目阅读训练题及答案01《论语》阅读答案检测试卷(201711新增)02《水浒传》阅读答案检测试卷(201711新增)03城南旧事阅读答案检测试卷(201711新增)04格列佛游记阅读答案检测试卷(201711新增)05《论语》阅读测试题及阅读答案(201804新增)06《狼图腾》阅读测试题及阅读答案(201804新增)07《居里夫人自传》阅读测试题及阅读答案(201804新增)08《老人与海》阅读测试题及阅读答案(201804新增)09“国学经典诵读”阅读答案阅读测试题10《简•爱》阅读测试题阅读答案(六上)11《简爱》阅读答案阅读测试题(六上)12《城南旧事》阅读答案阅读测试题(六上)13《丛林之书》阅读答案阅读测试题(六上)14《鲁滨逊漂流记》阅读答案阅读测试题(六上)15《科瓦奇讲天文地理》阅读答案(六上)16《鲁滨逊漂流记》阅读测试题阅读答案(六下选读)17《哈利波特与凤凰社》阅读答案阅读测试题(六上选读)18《中国四大民间故事》阅读检测题19《快乐王子》阅读测试题阅读答案20《莫泊桑短篇小说精选》阅读试题阅读答案21《悲惨世界》阅读测试题阅读答案22《家》阅读测试题阅读答案23《春》阅读测试题阅读答案24《秋》阅读测试题阅读答案25《古今贤文》阅读测试题阅读答案26《巴黎圣母院》阅读测试题阅读答案27《女生日记》阅读测试题阅读答案28《季羡林散文选集》阅读测试题阅读答案29《一片叶子落下来》阅读测试题阅读答案(六下)30《今天我是升旗手》阅读测试题阅读答案(六下)31《今天我是升旗手》阅读测试题及阅读答案(六下)32《狼图腾》阅读测试题阅读答案(六下)33《老人与海》阅读测试题阅读答案(六下)34《西游记》阅读测试题阅读答案(六下)35《蓝调江南》阅读答案阅读测试题(六下选读)36《潘家铮院士科幻作品集》阅读测试题阅读答案(六下选读)37《绿山墙的安妮》阅读测试题阅读答案(六下选读)38《少女的红发卡》阅读测试题阅读答案(六下选读)39《听见颜色的女孩》阅读测试题阅读答案(六下选读)40《中国民间故事》阅读测试题阅读答案(六下选读)41《居里夫人自传》阅读测试题阅读答案(六下选读)42《谁动了我的奶酪》阅读测试题阅读答案(六下选读)43《诺贝尔奖获得者与儿童的对话》阅读测试题阅读答案(六下选读)44《热爱生命》阅读测试题阅读答案(六下选读)01《论语》阅读答案检测试卷一、填空题。
【金翔龙 著作】金翔龙阅读答案
![【金翔龙 著作】金翔龙阅读答案](https://img.taocdn.com/s3/m/752d82f97e192279168884868762caaedd33ba06.png)
【金翔龙著作】金翔龙阅读答案(实用版)编制人:__________________审核人:__________________审批人:__________________编制单位:__________________编制时间:____年____月____日序言下载提示:该文档是本店铺精心编制而成的,希望大家下载后,能够帮助大家解决实际问题。
文档下载后可定制修改,请根据实际需要进行调整和使用,谢谢!并且,本店铺为大家提供各种类型的实用资料,如成语大全、谜语大全、汉语拼音、美文、教案大全、实用模板、话题作文、写作指导、试题题库、其他资料等等,想了解不同资料格式和写法,敬请关注!Download tips: This document is carefully compiled by this editor.I hope that after you download it, it can help you solve practical problems. The document can be customized and modified after downloading, please adjust and use it according to actual needs, thank you!In addition, this store provides various types of practical materials for everyone, such as idioms, riddles, pinyin, American writing, lesson plans, practical templates, topic essays, writing instructions, test question banks, other materials, etc. If you want to know different materials Format and writing, please pay attention!【金翔龙著作】金翔龙阅读答案【阅读答案】20xx年11月,金翔龙出生在江苏省南京市一个知识分子家庭。
2022年六年级语文下册第六单元主题阅读——非连续性文本(含答
![2022年六年级语文下册第六单元主题阅读——非连续性文本(含答](https://img.taocdn.com/s3/m/9d1c5a926e1aff00bed5b9f3f90f76c661374c06.png)
六年级语文下册第六单元主题阅读答题技巧第一,寻找所需的信息(1)通读全文,抓住文中包含关键信息的词语或者句子。
(2)剔除和阅读无关的信息,锁定目标,抓住答题点和得分点。
第二,整合就能得出结论(1)把文本中关联的信息进行加工,通过归纳、比较、综合等手段加工处理(2)判断出题者真实意图,整合得出有效的结论。
第三,建构文本的意义(1)提炼文本中心。
(2)找出文本写作目的,为材料排序。
(3)联系文本不同资料,结合自己知识想法经验,提出独特见解。
六年级语文下册第六单元主题阅读——非连续性文本【主题阅读1】小学生互联网使用行为调查报告[材料一]本次调查的()是探讨互联网在小学生网民中的使用情况、家长是如何看待孩子使用互联使用互联网的、目前小学生网民使用互联网尤其是网络专属产品的现状如何以及小学生网民使用互联网对其学习和生活有何影响。
[材料二]调查的()是北京、上海和武汉三市的小学生及其家长。
调查实施的()为2020年5月18日至5月31日。
在三个城市共收集有效样本2400份,学生及家长分别1200份。
[材料三]从本次调查所展现的数据可以得出(),网络已经渗透到小学生的日常生活中,小学生的上网行为等各方面也体现出其独特的表现形式。
1.依次填入材料括号中的词语,正确的一项是()A.结论对象目的时间B.目的对象时间结论C.目的结论时间对象D.对象目的结论时间2.以上材料是关于小学生互联网()的调查报告。
A.使用次数B.使用时间C.使用行为D.使用效果3.本次调查是为了()(多选)A.探讨小学生网民的人数。
B.探讨互联网在小学生网民中的使用情况。
C.了解家长对孩子使用互联网的态度。
D.了解小学生每天使用互联网的时间。
E.探讨小学生网民使用互联网特别是网络专属产品的现状。
F.探讨小学生网民使用互联网对其学习和生活的影响。
4.“网络已经渗透到小学生的日常生活中”这个说法可信吗?联系实际谈一谈互联网给你的学习生活带来的影响。
06第六章原文呈现-整本书阅读《鲁滨逊漂流记》名著阅读与练习
![06第六章原文呈现-整本书阅读《鲁滨逊漂流记》名著阅读与练习](https://img.taocdn.com/s3/m/c47bad3b793e0912a21614791711cc7931b778e0.png)
《鲁滨逊漂流记》名著阅读与练习06 第六章原文呈现可是,我一连跑去挤了两三天奶,什么也没有看到,我的胆子稍稍大了一点。
我想,其实没有什么事情,都是我的想象罢了。
但我还不能使自己确信那一定是自己的脚印,除非我再到海边去一趟,亲自看看那个脚印,用自己的脚去比一比,看看是不是一样大;只有这样,我才能确信那是我自己的脚樱不料,我一到那边,首先发现的是,当初我停放小船时,绝不可能在那儿上岸;其次,当我用自己的脚去比那脚印时,发现我的脚小得多。
这两个情况又使我马上胡思乱想起来,并使我忧心忡忡,忐忑不安。
结果我吓得浑身颤抖,好像发疟疾一样。
我马上跑回家里,深信至少一个人或一些人上过岸。
总之,岛上已经有人了,说不定什么时候会对我进行突然袭击,使我措手不及。
至于我应采取什么措施进行防卫,却仍毫无头绪。
唉!人在恐惧中所作出的决定是多么荒唐可笑啊!凡是理智提供他们保护自己的种种办法,一旦恐惧心占了上风,他们就不知道如何使用这些办法了。
我的第一个想法,就是把那些围墙拆掉,把所有围地中的羊放回树林,任凭它们变成野羊,免得敌人发现之后,为了掠夺更多的羊而经常上岛骚扰;其次,我又打算索性把那两块谷物田也挖掉,免得他们在那里发现这种谷物后,再常常到岛上来劫掠。
最后,我甚至想把乡间茅舍和海边住所的帐篷都通通毁掉,免得他们会发现住人的痕迹,从而会进行搜索,找出住在这里的人。
这些都是我第二次从发现脚印的海边回家之后在晚上想到的种种问题。
那时候,我又像第一次发现脚印后那样,惊魂不定,心里充满疑虑,心情忧郁低落。
由此可见,对危险的恐惧比看到危险本身更可怕千百倍;而焦虑不安给人的思想负担又大大超过我们所真正担忧的坏事。
更糟糕的是,我以前总能听天由命,从中获得安慰;而现在祸到临头,却不能使自己听从天命了,因而也无法获得任何安慰。
我觉得我像《圣经》里的扫罗,不仅埋怨非利士人攻击他,并且埋怨上帝离弃了他。
因为我现在没有用应有的办法来安定自己的心情,没有在危难中大声向上帝呼吁,也没有像以前那样把自己的安全和解救完全交托给上帝,听凭上帝的旨意。
- 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
- 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
- 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。
b
c
(0)
a
(1)
arg1
b
c
(0)
a
(1)
instruction (0) (1) (2)
3) = t3 a
三元式 0) =[] b i 1) =[] c j 2) + (0) (1) 3) = a (2)
间接三元式 0) =[] b i 1) =[] c j 2) + (0) (1) 3) = a (2)
x = a[i] + b[j] x = a[i][j] + b[i][j] ! x = a[b[i][j]][c[k]]
解答 x = a[i] + b[j] 语法分析树 :
1
id
a
2
id
b
3
+
1
2
4
+
3
3
a+b+a+b
1
id
a
2
id
b
3
1
5
+
4
2
a+a+(a+a+a+(a+a+a+a))
1
id
a
2
+
1
1
3
+
2
1
4
+
3
1
5
+
3
4
6
+
2
5
6.2 节的练习
6.2.1
将算数表达式 a+-(b+c) 翻译成
抽象语法树 四元式序列 三元式序列 间接三元式序列
解答
抽象语法树
E -> E1 * E2 E -> +E1
解答
产生式
语义规则
E -> E1 * E2 { E.addr = new Temp(); E.code = E1.code || E2.code || gen(E.addr '=' E1.addr '*' E2.addr); }
| +E1 { E.addr = E1.addr; E.code = E1.code; }
三元式 0) + y 1 1) param (0)
2) call f 1 3) + (2) 2 4) = x (3)
间接三元式 0) + y 1 1) param (0) 2) call f 1 3) + (2) 2 4) = x (3)
0) 1) 2) 3) 4)
参考 数组元素的取值和赋值
6.2.3 ! 说明如何对一个三地址代码序列进行转换,使得每个被定值的变量都有唯一的变量名。 6.3 节的练习 6.3.1 确定下列声明序列中各个标识符的类型和相对地址。
给出类 Evn 的一个实现。该实现支持符号表链,使得子类可以重定义一个字段名, 也可以直接引用某个超类中的字段名。
给出一个翻译方案,该方案能够为类中的字段分配连续的数据区域,这些字段中包 含继承而来的域。继承而来的字段必须保持在对超类进行存储分配时获得的相对地址。
6.4 节的练习
6.4.1 向图 6-19 的翻译方案中加入对应于下列产生式的规则:
6.1 节的练习 为下面的表达式构造 DAG ((x+y)-((x+y)*(x-y)))+((x+y)*(x-y))
解答
为下列表达式构造 DAG,且指出他们每个子表达式的值编码。假定
a+b+(a+b) a+b+a+b a+a+(a+a+a+(a+a+a+a))
解答 a+b+(a+b)
+ 是左结合的。
float x; record {float x; float y;} p; record {int tag; float x; float y;} q;
解答 SDT
S ->
{top = new Evn(); offset = 0;}
D
D -> T id;
{top.put(id.lexeme, T.type, offset);
6.4.2 使用图 6-20 的增量式翻译方案重复练习 6.4.1 解答
产生式
语义规则
E -> E1 * E2 { E.addr = new Temp(); gen(E.addr '=' E1.addr '*' E2.addr; }
| +E1 { E.addr = E1.addr; }
6.4.3 使用图 6-22 的翻译方案来翻译下列赋值语句:
offset += T.width}
D1
D -> ε
T -> int
{T.type = interget; T.width = 4;}
T -> float
{T.type = float; T.width = 8;}
T -> record '{'
{Evn.push(top), top = new Evn();
1) x float 0 1
2) x float 0 2 2) y float 8 2 2) p record() 8 1
3) tag int 0 3 3) x float 4 3 3) y float 12 3 3) q record() 24 1
6.3.2 ! 将图 6-18 对字段名的处理方法扩展到类和单继承的层次结构。
Stack.push(offset), offset = 0;}
D '}'
{T.type = record(top); T.width = offset;
top = Evn.top(); offset = Stack.pop();}
标识符类型和相对地址 line id type offset Evn
间接三元式 0) * b c 1) * b d 2) - (0) (1) 3) []= a i 4) = (3) (2) 0) 1) 2) 3) 4) x = f(y+1) + 2 四元式 0) + y 1 t1 1) param t1 2) call f 1 t2 3) + t2 2 t3 4) = t3 x
0) 1) 2) 3)
a[i] = b*c - b*d 四元式 0) * b c t1 1) * b d t2 2) - t1 t2 t3
3) []= a i t4 4) = t3 t4
三元式 0) * b c 1) * b d 2) - (0) (1) 3) []= a i 4) = (3) (2)
四元式序列
0 1 2 三元式序列
op + minus +
arg1
arg2
b
c
t1
t1
t2
a
t2
t3
op
arg1
0 1 2 间接三元式序列
0 1 2
+ minus +
op + minus +
0 1 2
参考
间接三元式更详细的讲解 6.2.2 对下列赋值语句重复练习 6.2.1
a = b[i] + c[j] a[i] = b*c - b*d x = f(y+1) + 2 x = *p + &y 解答 a = b[i] + c[j] 四元式