📄 7.3.3.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.3.2c.htm'" ></td>
<td><img src="../images/next.gif" onmouseover="javascript:style.cursor='hand'"
onclick="vbscript:window.location.href='7.3.3b.htm'" ></td>
</tr>
</table>
<p><br>
<br>
<font class="title2">7.3.3 访问数组元素的翻译模式</font> </p>
<table>
<tr>
<td> </td>
<td class="content">给定文法如下: <br>
(1)S→L:=E <br>
(2)E→E+E <br>
(3)E→(E) <br>
(4)E→L <br>
(5) L→Elist] <br>
(6)L→-<b>id</b> <br>
(7)Elist→Elist,E <br>
(8)ELzst→<b>id</b>[ E <br>
我们将给出它的语义动作。 <br>
若L是一个简单的名字,将生成一般的赋值;否则,若L为数组元素引用,则生成对L所指示地址的索引赋值:
<br>
1.S→L:=E <br>
{<b>if</b> L. offset=<b>null then</b>/*L
is a simple <b>id</b> */ <br>
emit(L.place':=' E.place); <b>else</b>
<br>
emit(L.place'['L.offset']' ':= '
E. Place)} <br>
对于算术表达式的代码完全与图7.8相同: <br>
2.E→E<span class="down"><sub>1</sub></span>+E<span class="down"><sub>2</sub></span>
<br>
{E.place:=newtemp; <br>
emit(E.place':=' E<span
class="down"><sub>1</sub></span>.place'+' E<span class="down"><sub>2</sub></span>.place)}
<br>
3.E→(E<span class="down"><sub>1</sub></span>) <br>
{ E.place :=E<span class="down"><sub>1</sub></span>.place}
<br>
当一个数组引用L归约到E时,我们需要L的右-值。因此我们使用索引来获得地址L.place[L.offset]
的内容: <br>
</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.3.2c.htm'" ></td>
<td><img src="../images/next.gif" onmouseover="javascript:style.cursor='hand'"
onclick="vbscript:window.location.href='7.3.3b.htm'" ></td>
</tr>
</table>
</body>
</html>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -