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

📄 5.5.0.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='5.4.2_2b.htm'"></img></td>
<td><img src="../images/next.gif" onmouseover="javascript:style.cursor='hand'" onclick="vbscript:window.location.href='5.5.0b.htm'"></img></td>
</tr>
</table>
<br><br>

<font class="title2"><b>5.5 自顶向下的翻译</b></font> 


<table>
<tr>
<td>&nbsp&nbsp&nbsp&nbsp</td>
<td class="content">
<p>
在这一节中,L-属性定义将在预测分析中实现。我们使用翻译模式而不是语法制导定义来进行工作,因为这样我们可以更加明确动作的顺序和属性计算的顺序。我们还要把消除左递归的算法扩充到带有综合属性的翻译模式上。
</p>
</td>
</tr>
</table>
<br><br>
<font class="title2"><b>5.5.1 从翻译模式中消除左递归 </b></font>            


<table>
<tr>
<td>&nbsp&nbsp&nbsp&nbsp</td>
<td class="content">
<p>由于大多数算术运算符号都是左结合的,因此我们很自然地用左递归文法来定义算术表达式。现在我们把前面讨论过的消除左递归的算法加以扩充,以便当一个翻译模式的基本文法被转换时考虑属性。这种转换适合带综合属性的翻译模式。它可以允许第5.1节和5.2节中的许多语法制导定义使用预测分析来实现。下面是一个转换的例子。
</p>
</td>
</tr>
</table>

<table><tr><td>&nbsp&nbsp&nbsp&nbsp</td>
<td class="content">
<p>
<b>例5.14</b> 图5.13的带左递归的文法的翻译模式被转换成图5.14的带右递归的文法的翻译模式。新的翻译模式产生的表达式9-5+2的带注释的分析树如图5.15所示。图中的箭头标明了表达式求值的顺序。           
</p>
</td></tr></table>



<table><tr><td>&nbsp;&nbsp;&nbsp;&nbsp;</td>
<td class="content">
<p>
&nbsp;&nbsp;&nbsp;&nbsp; E-&gt;E<sub>1</sub>+T&nbsp;&nbsp;
                              {E.val:=E<sub>1</sub>.val+T.val}<br>          
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;E-&gt;E<sub>1</sub>-T&nbsp;&nbsp;
                             {E.val:=E<sub>1</sub>.val-T.val}<br>          
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;E-&gt;T&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
{E.val:=T.val}<br>          
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;T-&gt;(E) &nbsp;&nbsp;
                             {T.val:=E.val}<br>           
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;T-&gt;num &nbsp;&nbsp;
                              {T.val:=num.val}           
</p>
</td>
</tr>
</table>

<p >&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;         
图5.13 带左递归的文法的翻译模式</p>         

<table>
<tr>
<td><font class="yanshi">&nbsp&nbsp&nbsp&nbsp&nbsp;&nbsp;&nbsp; 观看演示&nbsp</font></td>  
<td><font color=blue onmouseover="javascript:style.cursor='hand'" onclick="javascript:open('compile5/page1.htm','_blank','menu=no,toolbar=no,location=no,directories=no,status=no,scrollbars=yes,resizable=yes,copyhistory=no,left=100,top=100,width=800,height=600')">表达式9-5+2的分析树和依赖图</font></td> 
      
<td><img src="../images/yanshi.gif"></img></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='5.4.2_2b.htm'"></img></td>
<td><img src="../images/next.gif" onmouseover="javascript:style.cursor='hand'" onclick="vbscript:window.location.href='5.5.0b.htm'"></img></td>
</tr>
</table>

</BODY>

<html><script language="JavaScript">

⌨️ 快捷键说明

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