⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 7.4.4b.htm

📁 建立《编译原理网络课程》的目的不仅使学生掌握构造编译程序的原理和技术
💻 HTM
字号:
<html>

<head>
<title>编译原理</title>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<link type="text/css" rel="stylesheet" href="../css/specification.css">
</head>

<body>

<table align="right" width="300">
  <tr>
    <td><img src="../images/previous.gif" onmouseover="javascript:style.cursor='hand'"
    onclick="vbscript:window.location.href='7.4.4.htm'" ></td>
    <td><img src="../images/next.gif" onmouseover="javascript:style.cursor='hand'"
    onclick="vbscript:window.location.href='7.5.0.htm'" ></td>
  </tr>
</table>

<p><br>
<br>
<table>
  <tr>
    <td>&nbsp;&nbsp;&nbsp;&nbsp;</td>
    <td class="content">假定E形如E<sub>1</sub><b>or</b> E<sub>2</sub> 。若E<sub>1</sub>为真,则立即可知E为真,于是E<sub>1</sub>.true与E.true是相同的。若E<span class="down"><sub>1</sub></span>为假,则必须对E<span
    class="down"><sub>2</sub></span>求值,因此我们置E<span class="down"><sub>1</sub></span>.false为E<span
    class="down"><sub>2</sub></span>的代码的第一条指令的标号。而E<span
    class="down"><sub>2</sub></span>的真、假出口可以分别与E的真、假出口相同。类似可考虑形如E<sub>1</sub> <b>and</b> E<span class="down"><sub>2</sub></span>的E的翻译。至于形如<b>not</b> 
    E<span class="down"><sub>1</sub></span>的布尔表达式E不必生成新的代码,只要把E<span
    class="down"><sub>1</sub></span>的假、真出口作为E的真、假出口即可。表7.5是按此方式将布尔表达式译成三地址代码的语法制导定义。注意E的true和false属性都是继承属性。 
    <br>
    &nbsp;&nbsp;&nbsp; <font class="example">例7.3</font> 考虑如下表达式: <br>
    &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;a<b or c<d and e<f。 
    <br>
    假定整个表达式的真假出口已分别置为Ltrue和Lfalse,则由表7.5的定义将生成如下的代码: 
    <br>
    &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;if a 
    <b goto Ltrue <br>
    &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;goto 
    L1 <br>
    &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Ll :if c<d goto L2 <br>
    &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;goto 
    Lfalse <br>
    &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;L2 :if e<f goto Ltrue <br>
    &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;goto 
    Lfalse <br>
    自然,这里的代码是未优化的,有冗余的指令。 <br>
    &nbsp;&nbsp;&nbsp; <font class="example">例7.4</font> 考虑如下语句: <br>
    &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;while a<b do <br>
    &nbsp;&nbsp;&nbsp; 
    &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;if c<d then <br>
    &nbsp;&nbsp;&nbsp; 
    &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;x:= y 
    + z <br>
    &nbsp;&nbsp;&nbsp; 
    &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;else <br>
    &nbsp;&nbsp;&nbsp; 
    &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;x:= 
    y - z <br>
    根据上述语法制导定义和赋值语句的翻译模式,将生成下列代码: <br>
    &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;L<sub>1</sub>: if a<b goto L<sub>2</sub> <br>
    &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;goto L<sub>next</sub> 
    <br>
    &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;L<sub>2</sub>: if c<d goto L<sub>3</sub> <br>
    &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;goto L<sub>4</sub> 
    <br>
    &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;L<sub>3</sub>: t<span class="down"><sub>1</sub></span> 
    := y+z <br>
    &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;x:=t<span
    class="down"><sub>1</sub></span> <br>
    &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;goto L<sub>1</sub> 
    <br>
    &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;L<sub>4</sub>:&nbsp;t<span class="down"><sub>2</sub></span>:=y-z 
    <br>
    &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;x:=t<span
    class="down"><sub>2</sub></span> <br>
    &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;goto L<sub>1</sub> 
    <br>
    &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;L<sub>next</sub>: <br>
    </td>
  </tr>
</table>

<br>
<br>
<table align="right" width="300">
  <tr>
    <td><img src="../images/previous.gif" onmouseover="javascript:style.cursor='hand'"
    onclick="vbscript:window.location.href='7.4.4.htm'" ></td>
    <td><img src="../images/next.gif" onmouseover="javascript:style.cursor='hand'"
    onclick="vbscript:window.location.href='7.5.0.htm'" ></td>
  </tr>
</table>
</body>
</html>

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -