第19讲 控制语句的翻译
新概念英语第三册课文翻译及学习笔记:Lesson19
![新概念英语第三册课文翻译及学习笔记:Lesson19](https://img.taocdn.com/s3/m/9abed1169b6648d7c1c746e5.png)
新概念英语第三册课文翻译及学习笔记:Lesson19【课文】Kidnappers are rarely interested in animals, but they recently took considerable interest in Mrs. Eleanor Ramsay's cat. Mrs. Eleanor Ramsay, a very wealthy old lady, has shared a flat with her cat, Rastus, for a great many years. Rastus leads an orderly life. He usually takes a short walk in the evenings and is always home by seven o'clock. One evening, however, he failed to arrive. Mrs. Ramsay got very worried. She looked everywhere for him but could not find him.Three days after Rastus' disappearance, Mrs. Ramsay received an anonymous letter. The writer stated that Rastus was in safe hands and would be returned immediately if Mrs. Ramsay paid a ransom of $1,000. Mrs. Ramsay was instructed to place the money in a cardboard box and to leave it outside her door. At first she decided to go to the police, but fearing that she would never see Rastus again -- the letter had made that quite clear -- she changed her mind. She withdrew $1000 from her bank and followed the kidnapper's instructions. The next morning, the box had disappeared but Mrs. Ramsay was sure that the kidnapper would keep his word. Sure enough, Rastus arrived punctually at seven o'clock that evening. He looked very well though he was rather thirsty,for he drank half a bottle of milk. The police were astounded when Mrs. Ramsay told them what she had done. She explained that Rastus was very dear to her. Considering the amount she paid, he was dear in more ways than one!【课文翻译】绑架者很少对动物感兴趣。
4.5 控制语句的翻译
![4.5 控制语句的翻译](https://img.taocdn.com/s3/m/500715a569dc5022abea0017.png)
图4–9 条件语句if(E)S1;else S2的代码结构
பைடு நூலகம்
非终结符E具有两项语义值E.tc和E.fc。
E.tc :指出了尚待回填的真出口的四元式串; 它的值只有在扫描完布尔表达式E后的“)” 时才能知道,
E.fc :指出了尚待回填的假出口的四元式串; 它的值则需要处理过S1之后并且到else时才 能明确。这就是说,必须把E.fc的值传下去, 以便到达相应的else时才进行回填。
2016/6/23 6
S1语句执行完就意味着整个if-else语句也已 执行完毕,因此,在S1的编码之后应产生一 条无条件转移指令,这条转移指令将导致程 序控制离开整个if-else语句。 在完成S2的翻译之前,这条无条件转移指令 的转移目标是不知道的,甚至在翻译完S2之 后仍无法确定,这种情形是由语句的嵌套性 所引起的。例如下面的语句: if (E1) if (E2) S1; else S2;else S3 在S1代码之后的那条无条件转移指令不仅应 跨越S2,而且应跨越 S3。这也就是说,转移 目标的确定和语句所处的环境密切相关。
3
4.5.1 条件语句if的翻译 1.条件语句if的代码结构
我们按下面的条件语句if的模式进行讨论:
if (E) S1; else S2
条件语句if (E); else S2中布尔表达式E的 作用仅在于控制对S1和S2的选择,因此可将 作为转移条件的布尔式 E 赋予两种“出口”: 一是“真”出口,指向S1;一是“假”出口, 指向S2。于是,条件语句可以翻译成如图4– 9所示的代码结构。
2016/6/23
Wd.quad= W.quad; }
新概念英语第二册第19课重点语法句型
![新概念英语第二册第19课重点语法句型](https://img.taocdn.com/s3/m/49f1a74ca216147916112828.png)
新概念英语第二册第19课重点语法句型一、重要句型或语法1、情态动词can与may本课主要侧重学习can和may表请求和表猜测时的用法区别。
当表请求时,may的语气更为委婉;当表猜测时,can要用can't形式,而且表达的是把握较大的猜测,而may则表示把握较小的猜测。
如:He can't have gone to Beijing, because I saw him on the street just now.He may have been in Beijing, for I haven't seen him since yesterday.二、课文主要语言点'The play may begin at any moment,' he said.1)句中的may表示对将来时间的猜测,所以采用的是may do的形式。
2)at any moment,随时。
'It may have begun already,' Susan answered.1)句中的may表示对过去时间的猜测,苏伊采用的是may have done的形式。
2)句中的already一反常规,放到句末,起到了强调作用,说明Susan想强调自己的猜测的把握度较大。
I hurried to the ticket office.1)hurry to+地点,赶到什么地方。
2)the ticket office,售票处。
'May I have two tickets please?' I asked. 'I'm sorry,we've sold out,' the girl said.1)句中的May I...语气比Can I...更委婉,显得更礼貌。
2)have表示购买,相当于sell。
3)句中的we've sold out后面省略了all the tickets。
新概念第二册Lesson 19笔记
![新概念第二册Lesson 19笔记](https://img.taocdn.com/s3/m/c3452720bd64783e09122bf5.png)
Lesson 19 Sold out 售完一、Grammar:1、表能力表示现在的能力:Can you speak English?表示过去的能力:Could you speak English then(那时)?Can/could2、表许可请求:Can[Could] I come in?允许:一般只用can,不用could;上面的问题回答:Yes,you can。
注:如果有明确表示过去时间的标志,就用could表示许可。
3、表推测:对现在或将来推测can通常只用于否、疑问句中:It can’t/couldn’t be true.那一定不是真的。
What can/could they be doing?他们会在干什么呢?Could用于肯、否和疑问句:We could go to Japan this summer.对过去的推测:can have done(否、疑)She can’t/couldn’t have left so soon.她不可能走得那么早。
Where can/could he have gone?他能到哪里去了呢?Could have done(肯、否、疑)He could have gone home.他可能已经回家了。
注:could have done除了表示推测外,另外有两种用法:“本来可以…”He could have told her,but he didn’t choose to.委婉责备某人过去应该做而没去做,“本来应该…”You could have helped him.你本来应该帮助他的。
May和might:表示许可:对现在或将来的许可请求:May/Might I come in?允许:一般用may,不用might。
上句回答:Yes,you may.对过去的许可:He said I might borrow his car.might比may可能性小,一般用于肯定句表示推测:对现在或将来的推测:may/might+V原和否定句,用于疑问句时一般放在句中而非句首。
Lesson19课文原文翻译及重点冀教版七年级英语下册
![Lesson19课文原文翻译及重点冀教版七年级英语下册](https://img.taocdn.com/s3/m/c07fc0b38662caaedd3383c4bb4cf7ec4bfeb67c.png)
冀教版英语七班级下册课文原文及翻译Lesson 19第19课约吃晚餐Hey, Steven!嘿,史蒂文!What day is it today?今日星期几?It's Monday.今日星期一。
Would you like to e over fordinner tomorrow?你明天过来吃晚饭好吗?Sorry, Jim. I can't.对不起,吉姆,不行的。
I have volleyball practice tomorrow.我明天练习排球。
How about Wednesday?星期三怎么样呢?Hmm... Wednesday is not good for me.嗯...星期三我不便利。
I'm going to the chess club after school.放学后我要去象棋俱乐部。
How about Thursday?星期四呢?I usually volunteer at the Old AgeHome on Thursdays.我星期四通常去养老院做志愿者。
They often tell me lots of interesting stories.他们常常给我讲许多好玩的故事。
And sometimes we play bingo.有时我们还会玩宾戈嬉戏。
Maybe Friday?那么星期五呢?I have math classes on Fridays.我星期五上数学课。
I'm not doing well in math this year.我今年数学成果不太好。
What are you going to do this weekend?这个周末你要做什么?I'm going to the countryside with my dad.我要和爸爸去乡下。
We are going to plant trees.我们要去植树。
Hmm... We're both busy all week.嗯...我们俩这一周都很忙呀。
新概念英语第三册逐句精讲语言点第19课(5)
![新概念英语第三册逐句精讲语言点第19课(5)](https://img.taocdn.com/s3/m/d7338c73a32d7375a4178052.png)
新概念英语第三册逐句精讲语言点第19课(5)A Very Dear Cat 一只贵重的宝贝猫Kidnappers are rarely interested in animals, but theyrecently took considerable interest in Mrs. Eleanor Ramsay's cat. Mrs. Eleanor Ramsay, a very wealthy old lady, has shared a flat with her cat, Rastus, for a great many years. Rastus leads an orderly life. He usually takes a short walk in the evenings and is always home by seven o'clock. One evening, however, he failed to arrive. Mrs. Ramsay got very worried. She looked everywhere for him but could not find him.Three days after Rastus' disappearance, Mrs. Ramsay received an anonymous letter. The writer stated that Rastus was insafe hands and would be returned immediately if Mrs. Ramsay paid a ransom of $1,000. Mrs. Ramsay was instructed to place the money in a cardboard box and to leave it outside her door. At first she decided to go to the police, but fearing thatshe would never see Rastus again-the letter had made thatquite clear-she changed her mind. She withdrew $1000 from her bank and followed the kidnapper's instructions. The next morning, the box had disappeared but Mrs. Ramsay was surethat the kidnapper would keep his word. Sure enough, Rastus arrived punctually at seven o'clock that evening. He looked very well though he was rather thirsty, for he drank half a bottle of milk. The police were astounded when Mrs. Ramsaytold them what she had done. She explained that Rastus wasvery dear to her. Considering the amount she paid, he wasdear in more ways than one!13. The next morning, the box had disappeared but Mrs. Ramsay was sure that the kidnapper would keep his word.第二天早晨,放钱的盒子不见了。
第19讲 VHDL顺序描述语句(4)1
![第19讲 VHDL顺序描述语句(4)1](https://img.taocdn.com/s3/m/1790d13b43323968011c9275.png)
上例是一个对两个输入整数取最大值的功能描述,在结构体的进程中定义 了一个取最大值的函数。在函数体中正是通过RETURN语句将比较得到的 最大值返回的,并结束该函数体的执行。
NULL语句
NULL语句是空操作语句,不完成任何操作,执行NULL语句
只是让程序运行流程走到下一个语句。
NULL语句的书写格式为:NULL; 常用于CASE语句中,利用NULL来表示所余的不用的条件下 的操作行为,以满足CASE语句对条件值全部列举的要求。 CASE Opcode IS WHEN "001" => tmp := rega AND regb ; WHEN "101" => tmp := rega OR regb ; WHEN "110" => tmp := NOT rega ; WHEN OTHERS => NULL ; END CASE ;
LIBRARY IEEE; USE IEEE. STD_LOGIC_1164.ALL; ENTITY rsff IS
PORT(s :IN BIT;
r :IN BIT; q :OUT BIT; qb :OUT BIT); END rsff; ARCHITECTURE rtl OF rsff IS BEGIN PROCESS(s,r) VARIABLE last_state :BIT;
last_state := 0;
ELSE last_state := 1;
END IF;
q <= last_state; qb <= not(last_state);
END PROCESS;
END rtl;
上例中,如果 r 和 s 都为‘1’时,表示一种不定 状态。在进程中先是设定了一条断言语句,目的是: 当判断 r 和 s 都为‘1’时,输出终端将显示字符串 “Both s and r equal to‘1’.”,同时可能终止模 拟过程,并显示错误的严重程度。接下来用IF语句判 别触发器的其他三种情况,最后将值送到触发器的
新概念英语第二册:第19课课文详解及语法解析
![新概念英语第二册:第19课课文详解及语法解析](https://img.taocdn.com/s3/m/24f07025f011f18583d049649b6648d7c1c7080a.png)
【导语】新概念英语作为家喻户晓的经典之作,它有着全新的教学理念,有趣的课⽂内容及其全⾯的技能训练,为⼴⼤的英语学习者提供帮助!如果你也想学好英语,⼜怎能错过新概念英语?下⾯为您提供了相关内容,希望对您有所帮助! 课⽂详注 Further notes on the text 1.The play may begin at any moment. 剧马上就要开演了。
The guests may arrive at any moment. 客⼈们马上就要来了。
It may/might rain (at) any moment. 这天⽓随时都可能下⾬。
2.I'm sorry, we've sold out. 对不起,票已售完。
(1)这句话中⽤了缩略形式 I'm(=I am) 和we've(=we have)。
缩略形式⼀般⽤于⼝语和⾮正式⽂体中。
在正式⽂体中要避免使⽤。
(2)sell out为固定短语,可指“(店主)售完(某种货物)”、“(货)被售完”: They have sold out of eggs. 他们的鸡蛋卖完了。
Tickets for tonight's performance are sold out. 今晚演出的门票已售完。
3.What a pity! 真可惜! 这是⼀个常⽤的表⽰可惜、遗憾的感叹句。
我们还可以说: What a pity (it is) you can't see their performance! 你不能观看他们的演出真是遗憾! 4.I went back to the ticket office at once. 我马上⼜回到售票处。
at once 为固定短语,在这⾥可译为“马上”、“⽴刻”: When he heard the news, he went home at once. 听到这消息,他⽴刻就回家了。
新概念第二册课文翻译及学习笔记【Lesson19、20、21】
![新概念第二册课文翻译及学习笔记【Lesson19、20、21】](https://img.taocdn.com/s3/m/1d34e6bd172ded630a1cb64f.png)
新概念第二册课文翻译及学习笔记【Lesson19、20、21】【课文】First listen and then answer the question.听录音,然后回答以下问题。
When will the writer see the play?'The play may begin at any moment,' I said.'It may have begun already,' Susan answered.I hurried to the ticket office. 'May I have two tickets please?' I asked.'I'm sorry, we've sold out,' the girl said.'What a pity!' Susan exclaimed.Just then, a man hurried to the ticket office.'Can I return these two tickets?' he asked.'Certainly,' the girl said.I went back to the ticket office at once.'Could I have those two tickets please?' I asked.'Certainly,' the girl said, 'but they're for next Wednesday's performance. Do you still want them?''I might as well have them,' I said sadly.【课文翻译】“剧马上就要开演了,”我说。
新概念英语第三册Lesson 19惯用语整理
![新概念英语第三册Lesson 19惯用语整理](https://img.taocdn.com/s3/m/83afc8b3f61fb7360b4c65ab.png)
新概念英语第三册Lesson 19惯用语整理Lesson 191.done vt.做完了,完成了have done with 完成(finish, complete, be through with)例句:1.Have you done with the book I lent you?我借给你的书读完了没有?2.When I left the bar, Tom had done with three bottles of beer.当我离开酒吧时,汤姆已经喝完了三瓶啤酒。
have sth.done 让某人做某事(get someone else to perform a certain task)例句:1.I'm looking for the best quality paper to have my thesis typed on.我想找些质量的纸让人把我的毕业论文打印在上面。
2.I'll just have my teeth cleaned.我仅仅(让医生)洗洗牙就行了。
2.instruction n. 指示,命令instruction sheet 说明书(同instruction manual)例句:I'm trying to figure out how to work the new machine but just look at this instruction sheet.我想琢磨出怎样使用这台新机器,可你看看这份说明书。
3.keep v. 保留,留下;保持;存放;连续keep one's opinions to oneself 有想法不跟别人说,自己闷在心里例句:Robert tends to keep his opinions to himself.罗伯特总是有想法不跟别人说。
4.very well 好,非常好It is all very well to say that 说起来还不错,说起来容易(it is easier said than done)A:You should never let in any one like that unless you are expecting him.A:你真不应该让那种人进来,除非你盼着他来。
语文s版二年级下册第19课爱发脾气的孩子课文
![语文s版二年级下册第19课爱发脾气的孩子课文](https://img.taocdn.com/s3/m/d5720236cec789eb172ded630b1c59eef8c79ade.png)
语文s版二年级下册第19课爱发脾气的孩子课文《爱发脾气的孩子》是二年级语文课文,这篇课文揭示了做人的道理。
店铺为二年级师生整理了语文课文《爱发脾气的孩子》资料,希望大家有所收获!语文s版二年级下册第19课《爱发脾气的孩子》课文原文有个男孩儿,脾气很不好,不管遇(yù)到什么事,稍(shāo)有不顺心,就大发雷霆(tínɡ)。
虽然事情过后,他也能认识到自己的错误,向别人道歉(qiàn),但是,他的朋友还是越来越少。
爸爸对他的这个缺点提出了批(pī)评,他却满不在乎地说:“我不是已经道歉了吗?”一天,爸爸交给他一盒钉(dīnɡ)子和一把锤(chuí)子,然后把他领到院子里的一个木桩(zhuānɡ)前,说:“下次你再要发脾气,就往这个木桩上钉[dìng]一颗钉子,等你想道歉了,再把这颗钉子拔出来。
”男孩儿不理解爸爸的用意,不过还是点了点头。
很快,爸爸看到木桩上钉了很多钉子。
过了一段(duàn)时间,爸爸发现新钉的钉子少了,开始有了拔出钉子留下的洞。
到后来,几个星期才有一颗新钉子。
终于有一天,男孩儿来到爸爸面前,把当初(chū)爸爸交给他的钉子和锤子还给了爸爸。
他说:“爸爸,我已经不需要这些东西了,我现在可以控制(kònɡzhì)自己,不再乱发脾气了。
”爸爸让男孩儿讲一讲原因。
男孩儿说:“当我拔出第一颗钉子的时候,看到一个那么深的洞,再也填(tián)不平,我的心受到很大的震(zhèn)动。
以后每钉一颗钉子,我心里都非常难受,因为我知道,这又是一个无法填平的洞。
”语文s版二年级下册第19课《爱发脾气的孩子》课文分析第1自然段讲男孩儿爱发脾气,朋友越来越少。
第2至4自然段介绍男孩儿改掉爱发脾气毛病的经过。
后来男孩儿的爸爸要他发脾气时往木桩上钉一颗钉子,不生气了,再把钉子拔出来,男孩儿答应了。
刚开始,木桩上钉很多钉子,过了一段时间,钉子少了,后来几个星期才有一个新钉子。
工作控制语言语句 英语
![工作控制语言语句 英语](https://img.taocdn.com/s3/m/323f0a5d6d85ec3a87c24028915f804d2b16870e.png)
工作控制语言语句英语English: A work control language statement is a command or instruction used in a programming language to control the flow of a program. These statements are used to determine the order in which certain tasks or operations are executed, based on specific conditions or criteria. Work control language statements are crucial in programming as they allow developers to create efficient and effective code by organizing and controlling how the program runs. These statements can include loops, conditional statements, and function calls, among others. By using work control language statements, programmers can create more complex and interactive programs that respond to user input or handle different scenarios dynamically. Overall, work control language statements play a vital role in ensuring that programs run smoothly and as intended, by providing a way to manage the execution of tasks within the program.中文翻译:工作控制语言语句是编程语言中用于控制程序流程的指令或命令。
控制方法 名言
![控制方法 名言](https://img.taocdn.com/s3/m/52e06852c4da50e2524de518964bcf84b8d52d53.png)
控制方法名言Control methods are essential in various aspects of life, from managing personal finances to regulating traffic flow on the streets. As the famous saying goes, "With great power comes great responsibility," control methods play a crucial role in ensuring that power is wielded effectively and responsibly. Without proper control methods in place, chaos and confusion can easily arise, leading to undesirable outcomes.控制方法在生活的各个方面都是必不可少的,从管理个人财务到规范街道上的交通流量。
正如一句名言所说,“伟大的力量的背后总是伴随着伟大的责任”,控制方法在确保权力被有效和负责任地行使方面起着至关重要的作用。
如果没有适当的控制方法,混乱和困惑很容易出现,导致不良结果。
In a personal context, control methods help individuals manage their resources, time, and emotions more effectively. For instance, someone who uses a budgeting app to track their expenses is employing a control method to ensure they do not overspend. Similarly, practicing mindfulness meditation can be a control method to regulate one's emotions and maintain mental well-being. Byadopting and utilizing control methods, individuals can lead more organized and balanced lives.在个人背景下,控制方法帮助个人更有效地管理他们的资源、时间和情绪。
句法控制的名词解释
![句法控制的名词解释](https://img.taocdn.com/s3/m/d5cf4c3a178884868762caaedd3383c4ba4cb44b.png)
句法控制的名词解释句法控制是语言学中的一个重要概念,它涉及到句子中名词与其他成分之间的关系,这种关系是通过语法规则来控制的。
在语法中,名词是句子的核心成分之一,它可以是主语、宾语或其他补语。
而句法控制则是指名词在这些不同的语法角色中如何被语法规则所控制和限制。
句法控制涉及到两个重要概念,即“控制者”和“受控者”。
控制者通常是一个动词或介词短语,它对句法规则起着指导作用,决定了名词的语法角色。
受控者则是由控制者所决定的名词,它在句子中扮演特定的语法角色,与控制者之间存在着一种依赖关系。
一个常见的句法控制现象是主谓关系中的主语控制。
在一个句子中,主语通常由谓语动词所控制。
例如,这个句子:“小明吃草。
”中,“小明”就是主语,它受到谓语动词“吃”所控制。
句子的结构决定了名词“小明”在这个句子中扮演的角色是主语,而非宾语或其他补语。
另外一个常见的句法控制现象是宾语控制。
宾语通常由及物动词或介词所控制。
例如,这个句子:“我喜欢音乐。
”中,“音乐”就是宾语,它受到动词“喜欢”所控制。
句子的结构决定了名词“音乐”在这个句子中扮演的角色是宾语,并且与动词“喜欢”之间存在着一种语法上的依存关系。
除了主谓关系和宾语控制,句法控制还可以出现在其他语法角色中,例如补语或其他修饰成分中。
由于句法控制的规则涉及到不同的句法成分之间的关系,因此对于句法控制的研究对于理解语法规则的运作机制具有重要意义。
句法控制不仅仅是一种抽象的语法现象,它在实际语言使用中起着重要的作用。
通过句法控制,我们可以理解各种句子的结构和意义,同时也可以进行语法分析和表达正确的语义关系。
理解句法控制的规则对于语言学家、翻译工作者和语言教师来说,都是非常重要的。
总之,句法控制是语言学中一个重要的概念,它涉及到名词与其他成分之间的语法关系。
句法控制通过语法规则来决定名词的语法角色,从而确保句子的结构和意义的准确表达。
对于理解语法规则的运作机制和正确理解句子的结构和意义来说,掌握句法控制的概念是至关重要的。
新概念第二册课文翻译及学习笔记【Lesson19、20、21】
![新概念第二册课文翻译及学习笔记【Lesson19、20、21】](https://img.taocdn.com/s3/m/52a76455d4d8d15abf234e7e.png)
新概念第二册课文翻译及学习笔记【Lesson19 、20 、21】课文】First listen and then answer the question.听录音,然后回答以下问题。
When will the writer see the play?'The play may begin at any moment,' I said.'It may have begun already,' Susan answered.I hurried to the ticket office. 'May I have two tickets please?' I asked.'I'm sorry, we've sold out,' the girl said.'What a pity!' Susan exclaimed.Just then, a man hurried to the ticket office.'Can I return these two tickets?' he asked.'Certainly,' the girl said.I went back to the ticket office at once.'Could I have those two tickets please?' I asked.'Certainly,' the girl said, 'but they're for next Wednesday's performance. Do you still want them?' 'I might as well have them,' I said sadly.课文翻译】剧马上就要开演了,”我说。
- 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
- 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
- 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。
M→ε { M.quad:=nextquad }
100 ( j<, a, b, 1002 ) 101 ( j, -, -, 1007 ) 102 ( j<, c, d, 1004 ) 103 ( j, -, -, 1000 ) 104 (+, y, z, T ) 105 (:=, T, -, x ) 106 ( j, -, -, 100 ) 107
2. L → L1; M S { backpatch(L1.nextlist, M.quad); L.nextlist := S.nextlist }
3. M → ε { M.quad := nextquad }
视频区域
其它几个语句的翻译
1. S → A 2. L → S
{ S.nextlist := makelist( ) } { L.nextlist := S.nextlist }
(L1,Lnext) S
S ( -, L1)
E(L2, Lnext) E (L3, L4)
S( -, L1) E
EE
视频区域S( -, L1) E
EE
while a < b do if c < d then x := y + z else x := y - z
L1: if a<b goto L2 goto Lnext
while-do语句的翻译模式
1. S → while M1 E do M2 S1 { backpatch(E.truelist, M2.quad);
backpatch(S1.nextlist, M1.quad); S.nextlist := E.falselist; emit(‘j,-,-,’ M1.quad) }
E(L2, Lnext) E (L3, L4)
EE
EE
while a < b do if c < d then x := y + z else x := y - z
if a<b goto L2 goto Lnext if c<d goto L3 goto L4
(L1,Lnext) S
S ( -, L1)
E.true: E.false:
E.code S1.code
……
To E.true To E.false
if-then-else语句的语义
S → if E then S1 else S2
E.true: E.false: S.next
E.code
S1.code goto S.next
S2.code
E.place:=newtemp; E.code:=E1.code || E2.code || gen(E.place ‘:=’ E1.place ‘+’ E2.place)
if a<b goto L2 goto Lnext if c<d goto L3 goto L4 T1 :=y+z x:=T1 goto L1 T2 :=y-z x:=T2
……
To E.true To E.false
视频区域
if-then-else语句的属性文法
产生式
S→if E then S1 else S2
语义规则
E.true:=newlabel;
E.false:=newlabel;
SSS.12c..nnoeedxxett:::===noeedxxett; ||
视频区域
if 语句的翻译模式
1. S→if E then M S1 { backpatch(E.truelist, M.quad);
S.nextlist:=merge(E.falselist, S1.nextlist) }
if-then的语义
2. S→if E then M1 S1 N else M2 S2 { backpatch(E.truelist, M1.quad);
goto S.begin
E.false:
……
To E.true 视频区域 To E.false
while-do语句的属性文法
产生式
S→while E do S1
语义规则
S.begin:=newlabel;
E.true:=newlabel;
E.false:=S.next;
SS.1c.noedxet::==gSe.bne(Sg.inb;egin
2. M → ε { M.quad := nextquad }
视频区域
复合语句的文法
相关产生式 S → begin L end L→L; S | S
改写后的产生式 S → begin L end L → L1; M S | S
M→ε
视频区域
复合语句的翻译模式
1. S → begin L end { S.nextlist := L.nextlist }
编译原理
控制语句的翻译
编译程序总框
源程序
词法分析器
单词符号
符
语法分析器
号
表
语法单位
管
语义分析与中间代码生成器
理
中间代码(四元式)
优化段
中间代码(四元式)
目标代码生成器
目标代码
出 视频区域 错 处 理
常用的控制语句
S → if E then S1 S → if E then S1 else S2 S → while E do S1 其中E为布尔表达式
S( -, L1) E
视频区域S( -, L1) E
E(L2, Lnext) E (L3, L4)
EE
EE
while a < b do if c < d then x := y + z else x := y - z
产生式 S→id:=E
E→E1+E2
语义规则 S.code:=E.code || gen(id.place ‘:=’ E.place)
视频区域
编译原理
if语句的属性文法
if-then语句的语义
S → if E then S1
E.true: E.false:
E.code S1.code
……
To E.true To E.false
视频区域
if-then语句的属性文法
产生式
S→if E then S1
语义规则
E.true:=newlabel; E.flase:=S.next; SS.1c.noedxet::==oedxet || gen(E.true ‘:’) |视| S频1区.c域ode
(L1,Lnext) S
L2: if c<d goto L3 goto L4
L3: T1 :=y+z x:=T1 goto L1
L4: T2 :=y-z x:=T2 goto L1
E(L2, Ln(L3, L4)
S( -, L1) E
EE
while a < b do if c < d then x := y + z
E.true: E.false: S.next
E.code
S1.code goto S.next
S2.code
……
To E.true To E.false
视频区域
if 语句的文法
相关产生式 S → if E then S1 S → if E then S1 else S2
改写后的产生式 S → if E then M S1 S → if E then M1 S1 N else M2 S2 M→ε N→ε
视频区域
编译原理
一遍扫描翻译控制语句示例
示例:翻译语句
将下面的语句翻译为四元式 while a<b do if c<d then x:=y+z;
视频区域
SSE{→→{bbEaiiwfddac.th1:ckrE=ikuprlEepeatlaltohMicstipechft1:nh{(pi=EEd(≠mEp2M.ndt:.ra=itoulrkluSteoMehelo1liei2slksinstSut,(tep,1nMm(Mei.dxqi2t.tu.(nqpaaud‘ma:)=d;e’));E; .place)
视频区域
S表示语句,L表示语句表,A为赋值语句,E表 示布尔表达式
if 语句的文法
相关产生式 S → if E then S1 S → if E then S1 else S2
视频区域
if 语句的文法
相关产生式 S → if E then S1 S → if E then S1 else S2
backpatch(E.falselist, M2.quad); S.nextlist:=merge(S1.nextlist, N.nextlist, S2.nextlist) }