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

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

<font class="title2"><b>5.8.2 类型分析</b></font>        

<br><br>
<font class="title2"><b>5.8.2.1 变量标识符和类型表达式的绑定</b></font>        

<table><tr><td>&nbsp&nbsp&nbsp&nbsp</td>
<td class="content">
<P>
程序是由说明和语句序列组成的,且说明在前,语句序列在后。语句序列是计算,而说明部分建立计算环境,其中说明了每个变量标识符以及与之绑定的类型。语法(5.10)是一个简单的程序语言语法,假设数组的下标从1开始。 
</p>
</td></tr></table>

<table><tr><td>&nbsp&nbsp&nbsp&nbsp</td>
<td class="content">
<P>
文法G[P],产生式如下: 
</p>
</td></tr></table>

<table><tr><td>&nbsp&nbsp&nbsp&nbsp</td>
<td class="content">
<P>
 &nbsp;&nbsp;&nbsp;P→D;E <br>
        &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;D→D;D|id:T <br>
        &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;T→char|integer|ARRAY[num] OF 
        T|↑T &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;(5.10) <br>
        &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;E→num|id|E MOD E| E[E] |E↑ 
</p>
</td></tr></table>


<table><tr><td>&nbsp&nbsp&nbsp&nbsp</td>
<td class="content">
<P>
语义分析程序首先处理类型说明,建立类型表达式,然后处理变量说明,建立变量和类型表达式的绑定。具体实现是把变量标识符的类型信息记录在其在符号表的表项中,过程addtype(id.enery,T.type)完成这个任务,其翻译模式由图5.32给出。 
</p>
</td></tr></table>
    

<table><tr><td>&nbsp&nbsp&nbsp&nbsp</td>
<td class="content">
<P>
&nbsp;&nbsp;&nbsp;P→D;E <br>
        &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;D→D;D <br>
        &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;D→id:T&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{addtype(id.enery,T.TYPE)} 
        <br>
        &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;T→char&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{T.type:=char} 
        <br>
        &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;T→integer&nbsp;  &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{T.type:=integer} 
        <br>
        &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;T→↑T<sub>1</sub> &nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{T.type:=POINTER(T<sub>1</sub>.type)} 
        <br>
        &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;T→ARRAY[num] OF T<sub>1</sub> 
        &nbsp; &nbsp;{T.type:=ARRAY(num.val,T<sub>1</sub>.type)} <br><br>
        &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<b>图5.32 </b>  建立变量标识符和类型属性绑定的翻译模式
<p>
</p>
</td></tr></table>
    
<table><tr><td>&nbsp&nbsp&nbsp&nbsp</td>
<td class="content">
<P>
待语义分析程序处理语句序列时,借助于符号表中变量和类型属性的绑定信息,分析确定每个语言结构的类型表达式,从而完成类型检查及有关语义分析的任务。 
</p>
</td></tr></table>


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

</BODY>

⌨️ 快捷键说明

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