📄 5.8.1b.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.htm'"></td>
<td><img src="../images/next.gif" onmouseover="javascript:style.cursor='hand'" onclick="vbscript:window.location.href='5.8.1_1.htm'"></img></td>
</tr>
</table>
<br><br>
<table><tr><td>    </td>
<td class="content">
<P>
<b>例5.23</b> 设有Pascal 程序片段:
</p>
</td></tr></table>
<table><tr><td>        </td>
<td class="content">
<P>
<b> <font color="#0000FF">TYPE</font> </b><br>
stype=<b><font color="#0000FF">RECORD</font> </b><br>
name:<b><font color="#0000FF">ARRAY</font></b> [1..8] OF char; <br>
score:integer
<br>
<b> <font color="#0000FF">END</font></b>;
<br>
<b> <font color="#0000FF">VAR</font> </b><br>
table:<b><font color="#0000FF">ARRAY</font></b> [1..50]
OF stype; <br>
p: ↑stype;
</p>
</td></tr></table>
<table><tr><td>    </td>
<td class="content">
<P>
则stype代表的类型表达式
</p>
</td></tr></table>
<table><tr><td>    </td>
<td class="content">
<P>
<b> <font color="#0000FF">RECORD</font></b>((nameX<b><font color="#0000FF">ARRAY</font></b>(1..8,char))X(scoreXinteger))
</p>
</td></tr></table>
<table width="470"><tr><td width="16">    </td>
<td class="content" width="440">
<P>
和table绑定的类型表达式 <font color="#0000FF">ARRAY</font>(1..50,stype)
</p>
</td></tr></table>
<table width="468"><tr><td width="16">    </td>
<td class="content" width="438">
<P>
和P绑定的类型表达式 <font color="#0000FF">POINTER</font>(stype)
</p>
</td></tr></table>
<table><tr><td>    </td>
<td class="content">
<P>
<b>例5.24</b> 设有下面的函数定义
</p>
</td></tr></table>
<table><tr><td>    </td>
<td class="content">
<P>
<b><font color="#0000FF">FUNCTION</font></b> f(P1:T1;P2:T2;…,Pn:Tn):T;
<br> <b><font color="#0000FF">BEGIN</font></b> ……<b><font color="#0000FF">END</font></b>;
<br>
</p>
</td></tr></table>
<table><tr><td>    </td>
<td class="content">
<P>和f绑定的类型表达式 T<sub>1</sub>XT<sub>2</sub>X…XT<sub>n</sub>→T
</p>
</td></tr></table>
<table><tr><td>    </td>
<td class="content">
<P>
具体说来,
<br> <b><font color="#0000FF">FUNCTION</font></b>
f(a,b:<font color="#0000FF">char</font>):↑<font color="#0000FF">integer</font>;
<br> <b><font color="#0000FF">BEGIN</font></b> …<b><font color="#0000FF">END</font></b>;
<br> 和f绑定的类型表达式为
<br> char X char→POINTER(integer)
</p>
</td></tr></table>
<table><tr><td>    </td>
<td class="content">
<P>
<b>例5.25</b> 在函数式语言中可如下定义恒等函数
</p>
</td></tr></table>
<table><tr><td>    </td>
<td class="content">
<P>
fun f(x)=x x可以是任何类型的语言结构。
</p>
</td></tr></table>
<table><tr><td>    </td>
<td class="content">
<P>
因此x可以是任何类型f的类型表达式为
<br> α→α α为类型变量,其值是任何类型表达式。
<p>
</p>
</td></tr></table>
<table><tr><td>    </td>
<td class="content">
<P>
多态类型语言结构的类型表达式中含类型变量,这种语言的类型分析和类型检查应在专门论题中讨论。
</p>
</td></tr></table>
<br>
<hr size=2 color=red width=90%>
<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.8.1.htm'"></td>
<td><img src="../images/next.gif" onmouseover="javascript:style.cursor='hand'" onclick="vbscript:window.location.href='5.8.1_1.htm'"></img></td>
</tr>
</table>
</BODY>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -