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

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

<font class="title2"><b>6.4.3 含有嵌套过程的词法作用域</b></font>         

<table><tr><td>&nbsp&nbsp&nbsp&nbsp</td>
<td class="content">
<P>
在Pascal过程中的一个名字a的非局部出现是在静态程序正文中的a的最近嵌套说明的作用域之内。图6.18的Pascal程序中 
</p>
</td></tr></table>

     
<table><tr><td>&nbsp&nbsp&nbsp&nbsp</td>
<td class="content">
<P>
<br> 
        &nbsp;&nbsp;&nbsp;  (1) <b><font color="#0000FF">program</font></b> sort(input,output); <br>  
        &nbsp;&nbsp;&nbsp;  (2) <b>&nbsp;&nbsp;&nbsp;<font color="#0000FF">var</font></b> a:array[0..10] of   
        integer; <br> 
        &nbsp;&nbsp;&nbsp;  (3) &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;x: integer;   
        <br> 
        &nbsp;&nbsp;&nbsp;  (4) <b>&nbsp;&nbsp;&nbsp;<font color="#0000FF">procedure</font></b> readarray; <br>  
        &nbsp;&nbsp;&nbsp;  (5) <b>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<font color="#0000FF">var</font></b>  
        i: integer; <br>  
        &nbsp;&nbsp;&nbsp;  (6) <b>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<font color="#0000FF">begin</font></b>...a...   
        <b><font color="#0000FF">end</font></b> {readarray}; <br>  
        &nbsp;&nbsp;&nbsp;  (7) <b>&nbsp;&nbsp;&nbsp;<font color="#0000FF">procedure</font></b> exchange(i,j:integer) <br> 
        &nbsp;&nbsp;&nbsp;  (8) <b>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<font color="#0000FF">begin</font></b>  
        <br> 
        &nbsp;&nbsp;&nbsp;  (9) &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;x:=   
        a[i] ;a[i]:=a[j];a[j]:=x <br>  
        &nbsp;&nbsp;&nbsp;  (10)&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <b><font color="#0000FF">end</font></b> {exchange}; <br>  
        &nbsp;&nbsp;&nbsp;  (11)&nbsp;&nbsp; <b><font color="#0000FF">procedure</font></b> quicksort(m,n: integer);   
        <br> 
        &nbsp;&nbsp;&nbsp;  (12)&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <b><font color="#0000FF">var</font></b> k,v:integer; <br>   
        &nbsp;&nbsp;&nbsp;  (13)&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <b><font color="#0000FF">function</font></b> 
        partition(y,z: integer): integer; <br> 
        &nbsp;&nbsp;&nbsp;  (14)&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 
<b><font color="#0000FF">var</font></b> i,j: integer; <br>  
        &nbsp;&nbsp;&nbsp;  (15)&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 
<b><font color="#0000FF">begin</font></b> ...a...<br>  
        &nbsp;&nbsp;&nbsp; (16)&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;...v... 
        <br>
        &nbsp;&nbsp;&nbsp;  (17)&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;...exchange(i,j);...  
        <br> 
        &nbsp;&nbsp;&nbsp;  (18)&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 
<b><font color="#0000FF">end</font></b> {partition}; <br>  
        &nbsp;&nbsp;&nbsp;  (19)&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <b><font color="#0000FF">begin</font></b>...<b><font color="#0000FF">end</font></b>  
        { quicksort}; <br>  
        &nbsp;&nbsp;&nbsp;  (20)&nbsp;&nbsp; <b><font color="#0000FF">begin</font></b>…<b><font color="#0000FF">end</font></b> {sort}。 <br>  
        &nbsp;&nbsp;&nbsp; </p> 
      <p align="left">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 
      <b>图6.18</b>带有嵌套过程的一个Pascal程序<br>
<br><br>
</p>
</td></tr></table>

<table><tr><td></td>
<td class="content">
<p>
的嵌套的过程定义由下面的锯齿状的排列指出: 
</td></tr></table>

<table><tr><td>&nbsp&nbsp&nbsp&nbsp</td>
<td class="content">
<p>
sort <br> 
        &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; readarray <br>
        &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; exchange <br>
        &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; quicksort <br>
        &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; partition <br><br>
</td></tr></table>

<table><tr><td>&nbsp&nbsp&nbsp&nbsp</td>
<td class="content">
<p>
在图6.18的第(15)行上的a的出现是在函数partition之中,它嵌套在过程quicksort之内。a的最近嵌套说明是在第(2)行,位于包括整个程序的过程中。最近嵌套规则也同样用于过程名字。如第(17)行的由partition 调用的过程exchange对于partition而言是非局部的。应用这个规则我们首先检查exchange是否在quicksort之内被定义,由于它不是,我们在主程序sort中找到了它。 
</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='6.4.2.htm'"></img></td>
<td><img src="../images/next.gif" onmouseover="javascript:style.cursor='hand'" onclick="vbscript:window.location.href='6.4.3_1.htm'"></img></td>
</tr>
</table>

</BODY>

<html><script language="JavaScript">

⌨️ 快捷键说明

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