📄 3.6.1a.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 bgColor=lavender>
<table align=right width=300>
<tr>
<td><IMG onmouseover="javascript:style.cursor='hand'" onclick="vbscript:window.location.href='3.5.1c.htm'" src="../images/previous.gif"></IMG></td>
<td><IMG onmouseover="javascript:style.cursor='hand'" onclick="vbscript:window.location.href='3.6.1b.htm'" src="../images/next.gif"></IMG></td>
</tr>
</table>
<br><br>
<table border=0>
<tr>
<td colspan=2>
<font class="title2"><b>3.6 词法分析程序的自动构造工具</b></font>
</td>
</tr>
<tr>
<td width=10></td>
<td>
<br>
<p>根据节3.4的讨论,用正规表达式描述(说明)单词的结构非常方便,而把一个正规式r转换成NFA,进而构造出相应的最小化的DFA M,使得L(M)=L(r)。基于这种方法构造词法分析程序的工具很多,本节介绍广泛使用的工具<font class="emphasize">Lex</font>。 </p>
<div align=left><b>观看演示 </b><font color=blue onmouseover="javascript:style.cursor='hand';" onclick="javascript:open('program/autogen/autogen.html','_blank','left=100,top=100,scrollbars=yes,resizable=yes,width=800,height=600')">根据正规表达式生成NFA、DFA、最简DFA</font><IMG src="../images/yanshi.gif"></div>
<p>Lex已广泛使用于构造各种语言的词法分析程序,这个工具称为<font class="definition3">Lex编译器</font>,它的输入是用Lex语言描述的lex源程序,主要是用正规表达式对某一程序语言单词结构的描述和识别出某类单词后词法分析程序应完成的语义动作。它的输出是用C书写的词法分 析程序。</p>
<p>通常,按图3.15描绘的方式使用Lex。首先,用Lex语言说明的语法分析器构成程序Lex.l,然后Lex.l经过Lex编译器,产生C的程序叫作Lex.yy.c。程序Lex.yy.c包括根据Lex.l中的正规式构造的用表表示的转换图,以及使用这张表识别单词的标准子程序。 </p>
<p>在lex.l中和正规式相联的动作是C的代码,它们被直接搬人lex.yy.c。最后,lex.yy.c通过C编译产生目标程序a.out,它就是把输入串变成记号序列的词法分析器。</p>
<p align="center"><IMG isMap src="img/3.15.gif" > </p>
<p>Lex程序包括三部分:</p>
</td>
</tr>
<tr>
<td width=10></td>
<td>
<table width="100%">
<tr>
<td align=middle>
<font class="emphasize">
声明 <br>
%% <br>
翻译规则 <br>
%% <br>
辅助过程<br><br>
</font>
</td>
<td width=300></td>
</tr>
</table>
</td>
</tr>
<tr>
<td width=10></td>
<td>
<p><font class="definition3">声明</font>节包括变量、显明常量(manifest constant)和正规定义。显明常量是表示常量的标识符。正规定义是和3.4节中类似的表示,在翻译规则中作为正规式。</p>
</td>
</tr>
</table>
<table align=right width=300>
<tr>
<td><IMG onmouseover="javascript:style.cursor='hand'" onclick="vbscript:window.location.href='3.5.1c.htm'" src="../images/previous.gif"></IMG></td>
<td><IMG onmouseover="javascript:style.cursor='hand'" onclick="vbscript:window.location.href='3.6.1b.htm'" src="../images/next.gif"></IMG></td>
</tr>
</table>
</BODY>
</html>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -