📄 7.1.4.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.1.3.htm'" width="24" height="24" ></td>
<td>
<img src="../images/next.gif" onmouseover="javascript:style.cursor='hand'"
onclick="vbscript:window.location.href='7.1.5.htm'" width="26" height="24" ></td>
</tr>
</table>
<p><br>
<br>
<font class="title2"><b>7.1.4 语法制导翻译生成三地址代码</b></font> </p>
<table>
<tr>
<td> </td>
<td class="content">
<p>生成三地址代码时,临时变量的名字用来补充语法树的内部结点。例如,对于产生式E→E<sub>1</sub>+E<sub>2</sub>的左端的非终结符号E而言,它的经过计算得出的值往往放到一个新的临时变量t中。一般说来,赋值语句id:=E的三地址代码包括:对表达式E 求值并置于变量t中,然后进行赋值id.place :=t。如果一个表达式仅有一单个标识符,例如y,则由y自身保留表达式的值。 </p>
</td>
</tr>
</table>
<table>
<tr>
<td> </td>
<td class="content">
<p>表7.2是为赋值语句生成三地址代码的S-属性定义。表中的算符||表示符号串连接。如给定输入a:= b*-c+b*-c,便可产生如图7.3(a)的代码。非终结符号S有综合属性S.code,它代表赋值语句S的三地址代码。非终结符号E有如下两个属性: </p>
</td>
</tr>
</table>
<center>
<br>
<b>表7.2 产生赋值语句三地址代码的语法制导定义</b><br>
<img src="images/t7_2.gif" alt="t7_2.gif (6064 bytes)" width="567" height="273"><br>
</center>
<table>
<tr>
<td> </td>
<td class="content">(1)E.place表示存放E值的名字。 </td>
</tr>
</table>
<table>
<tr>
<td> </td>
<td class="content">(2)E.code表示对E求值的三地址语句序列。 </td>
</tr>
</table>
<table>
<tr>
<td> </td>
<td class="content">在对函数newtemp的相继的调用中,将返回一个不同的名字的序列如t<span
class="down">1</sub>,t<sub>2</sub>...即在每次调用中,返回一个新的临时变量名字。为了方便,我们在表7.2中使用gen(x'
:='y'+'z)表示生成三地址语句x:=y+z
。此外,在实际实现中,三地址语句序列往往是被存放到一个输出文件中,而不是将三地址语句序列置入code属性之中。这将在7.3节中谈到。至于其它一些语句的三地址代码的生成将在以后各节分别介绍。
</td>
</tr>
</table>
<p><br>
</p>
<table align="right" width="300">
<tr>
<td>
<img src="../images/previous.gif" onmouseover="javascript:style.cursor='hand'"
onclick="vbscript:window.location.href='7.1.3.htm'" width="24" height="24" ></td>
<td>
<img src="../images/next.gif" onmouseover="javascript:style.cursor='hand'"
onclick="vbscript:window.location.href='7.1.5.htm'" width="26" height="24" ></td>
</tr>
</table>
</body>
</html>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -