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

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

<font class="title2"><b>练习</b></font>
<table><tr><td>&nbsp&nbsp&nbsp&nbsp</td>
<td class="content">
<a name="6.3"></a>

* 6.3                               
&nbsp;&nbsp;在一个嵌套过程被作为参数传递时,也同样可以使用词法作用域规则。在下面的pascal程序中第(6)—(7)行上的函数f有一个非局部名字m;这里m的所有出现都以黑体显示;在第(8)行上,过程c给m赋值为0,然后把f作为实在参数传递给b。                                       
        试问: <br>
        &nbsp;&nbsp; (a)在第(5)行上的m的说明的作用域是否包括第(2)—(3)行上的b的过程体? <br>                                      
        &nbsp;&nbsp;(b)在b的过程体中,因为形式参数将被实在参数f所替代,语句wriieln(h(2))激活f,那么,这时打印出的结果是什么?                                       <br>
        &nbsp;&nbsp;进一步要问,我们如何为f的活动记录建立存取链呢?回答是,作为一个参数被传递的嵌套过程必须携带它自己的存取链,如程序下面的图所示。当过程c传递f时,f的一个存取链和c调用f时确定的f存取链一样。这个链和f一起传递给b。以后,当f从b中被激活时,这个链被用来建立f的活动记录中的存取链。                                      
        <br>
        &nbsp;&nbsp;&nbsp; (c)试模拟整个程序的执行,在执行过程中注意各种变量的存取。<br>                                     
&nbsp;&nbsp;&nbsp; (d)图示出进入过程f时DISPLAY表显示的活动记录。&nbsp;<p> (1) <b><font color="#0000FF">program</font></b> param(input,output); <br>                            
        &nbsp;&nbsp;&nbsp; (2) <b>&nbsp;&nbsp;&nbsp;<font color="#0000FF">procedure</font></b> b(function h(n:<font color="#0000FF"><b>integer</b></font>)<br>                             
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;  &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;  &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;  
   : <b><font color="#0000FF">integer</font></b>); <br>                           
        &nbsp;&nbsp;&nbsp; (3) <b>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<font color="#0000FF">begin</font></b>                            
        writeln(h(2))<b><font color="#0000FF">end</font></b>  <font color="#008000"> { b }</font> ; <br>                            
        &nbsp;&nbsp;&nbsp; (4) <b>&nbsp;&nbsp;&nbsp;<font color="#0000FF">procedure</font></b> c; <br>                            
        &nbsp;&nbsp;&nbsp; (5)<b> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<font color="#0000FF">var</font></b>                            
 <b>                            
        m</b>: integer; <br>                            
        &nbsp;&nbsp;&nbsp; (6) <b>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<font color="#0000FF">function</font></b>                            
        f(n:integer ): <font color="#0000FF"><b> integer</b></font> : <br>                            
        &nbsp;&nbsp;&nbsp; (7) <b>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<font color="#0000FF">begin</font></b>                            
        f:=<b>m</b><!--[if supportFields]><span lang=EN-US
style='font-size:10.5pt;mso-bidi-font-size:12.0pt;font-family:"Times New Roman";
mso-fareast-font-family:宋体;mso-font-kerning:1.0pt;mso-ansi-language:EN-US;
mso-fareast-language:ZH-CN;mso-bidi-language:AR-SA'><span style='mso-element:
field-begin'></span><span style="mso-spacerun: yes">&nbsp;</span>eq \o\ac(</span><span
style='font-size:15.5pt;mso-bidi-font-size:12.0pt;font-family:宋体;mso-hansi-font-family:
"Times New Roman";mso-bidi-font-family:"Times New Roman";mso-text-raise:-2.0pt;
mso-font-kerning:1.0pt;mso-ansi-language:EN-US;mso-fareast-language:ZH-CN;
mso-bidi-language:AR-SA'>○</span><span lang=EN-US style='font-size:10.5pt;
mso-bidi-font-size:12.0pt;font-family:"Times New Roman";mso-fareast-font-family:
宋体;mso-font-kerning:1.0pt;mso-ansi-language:EN-US;mso-fareast-language:ZH-CN;
mso-bidi-language:AR-SA'>,m)</span><![endif]-->
<!--[if supportFields]><span
lang=EN-US style='font-size:10.5pt;mso-bidi-font-size:12.0pt;font-family:"Times New Roman";
mso-fareast-font-family:宋体;mso-font-kerning:1.0pt;mso-ansi-language:EN-US;
mso-fareast-language:ZH-CN;mso-bidi-language:AR-SA'><span style='mso-element:
field-end'></span></span><![endif]-->
<!--[if supportFields]><span
lang=EN-US style='font-size:10.5pt;mso-bidi-font-size:12.0pt;font-family:"Times New Roman";
mso-fareast-font-family:宋体;mso-font-kerning:1.0pt;mso-ansi-language:EN-US;
mso-fareast-language:ZH-CN;mso-bidi-language:AR-SA'><span style='mso-element:
field-end'></span></span><![endif]-->
 +n <b><font color="#0000FF">end</font></b>  <font color="#008000">{f}</font>; <br>                           
        &nbsp;&nbsp;&nbsp; (8) <b>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<font color="#0000FF">begin</font></b> 
<b>                            
        m</b> :=0; b(f) <b><font color="#0000FF">end</font></b>  <font color="#008000"> {c}</font> ; <br>                            
        &nbsp;&nbsp;&nbsp; (9) <b>&nbsp;&nbsp;&nbsp;<font color="#0000FF">begin</font></b> <br>                           
        &nbsp;&nbsp;&nbsp; (10)&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;c <br>                            
        &nbsp;&nbsp;&nbsp; (11)&nbsp;&nbsp; <b><font color="#0000FF">end</font></b>.</p>                           
<p>
        &nbsp;&nbsp;&nbsp;  
        <p align="center"><img src="6_34.gif" width="334" height="342"> </p>
<table align=center width=70%>
<tr><td align=right>
<img src="../images/key.gif" onmouseover="javascript:style.cursor='hand'" onclick="javascript:window.open('key/a_6.3.htm','','left=100,top=100,toolbar=no,scrollbars=yes,width=600,height=600')"></img>
</td></tr>
</table>
<hr size=2 align=center color=red><br>               
<br>
<table align=right width=300>
<tr>
<td><img src="../images/previous.gif" onmouseover="javascript:style.cursor='hand'" onclick="vbscript:window.location.href='6.6.5.htm'" ></td>
<td><img src="../images/next.gif" onmouseover="javascript:style.cursor='hand'" onclick="vbscript:window.location.href='6.6.5c.htm'"></img></td>
</tr>
</table>

</BODY>

⌨️ 快捷键说明

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