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

📄 lex.html

📁 IEEE 1003.1-2003, Single Unix Specification v3
💻 HTML
📖 第 1 页 / 共 3 页
字号:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"><html><head><meta name="generator" content="HTML Tidy, see www.w3.org"><meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"><link type="text/css" rel="stylesheet" href="style.css"><!-- Generated by The Open Group's rhtm tool v1.2.1 --><!-- Copyright (c) 2001-2003 The Open Group, All Rights Reserved --><title>lex</title></head><body bgcolor="white"><script type="text/javascript" language="JavaScript" src="../jscript/codes.js"></script><basefont size="3"> <a name="lex"></a> <a name="tag_04_73"></a><!-- lex --> <!--header start--><center><font size="2">The Open Group Base Specifications Issue 6<br>IEEE Std 1003.1, 2003 Edition<br>Copyright &copy; 2001-2003 The IEEE and The Open Group, All Rights reserved.</font></center><!--header end--><hr size="2" noshade><h4><a name="tag_04_73_01"></a>NAME</h4><blockquote>lex - generate programs for lexical tasks (<b>DEVELOPMENT</b>)</blockquote><h4><a name="tag_04_73_02"></a>SYNOPSIS</h4><blockquote class="synopsis"><div class="box"><code><tt><sup>[<a href="javascript:open_code('CD')">CD</a>]</sup> <img src="../images/opt-start.gif" alt="[Option Start]" border="0"> lex</tt> <b>[</b><tt>-t</tt><b>][</b><tt>-n|-v</tt><b>][</b><i>file</i> <tt>...</tt><b>]</b><tt><imgsrc="../images/opt-end.gif" alt="[Option End]" border="0"></tt></code></div></blockquote><h4><a name="tag_04_73_03"></a>DESCRIPTION</h4><blockquote><p>The <i>lex</i> utility shall generate C programs to be used in lexical processing of character input, and that can be used as aninterface to <a href="../utilities/yacc.html"><i>yacc</i></a>. The C programs shall be generated from <i>lex</i> source code andconform to the ISO&nbsp;C standard. Usually, the <i>lex</i> utility shall write the program it generates to the file<b>lex.yy.c</b>; the state of this file is unspecified if <i>lex</i> exits with a non-zero exit status. See the EXTENDEDDESCRIPTION section for a complete description of the <i>lex</i> input language.</p></blockquote><h4><a name="tag_04_73_04"></a>OPTIONS</h4><blockquote><p>The <i>lex</i> utility shall conform to the Base Definitions volume of IEEE&nbsp;Std&nbsp;1003.1-2001, <a href="../basedefs/xbd_chap12.html#tag_12_02">Section 12.2, Utility Syntax Guidelines</a>.</p><p>The following options shall be supported:</p><dl compact><dt><b>-n</b></dt><dd>Suppress the summary of statistics usually written with the <b>-v</b> option. If no table sizes are specified in the <i>lex</i>source code and the <b>-v</b> option is not specified, then <b>-n</b> is implied.</dd><dt><b>-t</b></dt><dd>Write the resulting program to standard output instead of <b>lex.yy.c</b>.</dd><dt><b>-v</b></dt><dd>Write a summary of <i>lex</i> statistics to the standard output. (See the discussion of <i>lex</i> table sizes in <a href="#tag_04_73_13_01">Definitions in lex</a> .) If the <b>-t</b> option is specified and <b>-n</b> is not specified, this report shallbe written to standard error. If table sizes are specified in the <i>lex</i> source code, and if the <b>-n</b> option is notspecified, the <b>-v</b> option may be enabled.</dd></dl></blockquote><h4><a name="tag_04_73_05"></a>OPERANDS</h4><blockquote><p>The following operand shall be supported:</p><dl compact><dt><i>file</i></dt><dd>A pathname of an input file. If more than one such <i>file</i> is specified, all files shall be concatenated to produce asingle <i>lex</i> program. If no <i>file</i> operands are specified, or if a <i>file</i> operand is <tt>'-'</tt> , the standardinput shall be used.</dd></dl></blockquote><h4><a name="tag_04_73_06"></a>STDIN</h4><blockquote><p>The standard input shall be used if no <i>file</i> operands are specified, or if a <i>file</i> operand is <tt>'-'</tt> . SeeINPUT FILES.</p></blockquote><h4><a name="tag_04_73_07"></a>INPUT FILES</h4><blockquote><p>The input files shall be text files containing <i>lex</i> source code, as described in the EXTENDED DESCRIPTION section.</p></blockquote><h4><a name="tag_04_73_08"></a>ENVIRONMENT VARIABLES</h4><blockquote><p>The following environment variables shall affect the execution of <i>lex</i>:</p><dl compact><dt><i>LANG</i></dt><dd>Provide a default value for the internationalization variables that are unset or null. (See the Base Definitions volume ofIEEE&nbsp;Std&nbsp;1003.1-2001, <a href="../basedefs/xbd_chap08.html#tag_08_02">Section 8.2, Internationalization Variables</a> forthe precedence of internationalization variables used to determine the values of locale categories.)</dd><dt><i>LC_ALL</i></dt><dd>If set to a non-empty string value, override the values of all the other internationalization variables.</dd><dt><i>LC_COLLATE</i></dt><dd><br>Determine the locale for the behavior of ranges, equivalence classes, and multi-character collating elements within regularexpressions. If this variable is not set to the POSIX locale, the results are unspecified.</dd><dt><i>LC_CTYPE</i></dt><dd>Determine the locale for the interpretation of sequences of bytes of text data as characters (for example, single-byte asopposed to multi-byte characters in arguments and input files), and the behavior of character classes within regular expressions.If this variable is not set to the POSIX locale, the results are unspecified.</dd><dt><i>LC_MESSAGES</i></dt><dd>Determine the locale that should be used to affect the format and contents of diagnostic messages written to standarderror.</dd><dt><i>NLSPATH</i></dt><dd><sup>[<a href="javascript:open_code('XSI')">XSI</a>]</sup> <img src="../images/opt-start.gif" alt="[Option Start]" border="0">Determine the location of message catalogs for the processing of <i>LC_MESSAGES .</i> <img src="../images/opt-end.gif" alt="[Option End]" border="0"></dd></dl></blockquote><h4><a name="tag_04_73_09"></a>ASYNCHRONOUS EVENTS</h4><blockquote><p>Default.</p></blockquote><h4><a name="tag_04_73_10"></a>STDOUT</h4><blockquote><p>If the <b>-t</b> option is specified, the text file of C source code output of <i>lex</i> shall be written to standardoutput.</p><p>If the <b>-t</b> option is not specified:</p><ul><li><p>Implementation-defined informational, error, and warning messages concerning the contents of <i>lex</i> source code input shallbe written to either the standard output or standard error.</p></li><li><p>If the <b>-v</b> option is specified and the <b>-n</b> option is not specified, <i>lex</i> statistics shall also be written toeither the standard output or standard error, in an implementation-defined format. These statistics may also be generated if tablesizes are specified with a <tt>'%'</tt> operator in the <i>Definitions</i> section, as long as the <b>-n</b> option is notspecified.</p></li></ul></blockquote><h4><a name="tag_04_73_11"></a>STDERR</h4><blockquote><p>If the <b>-t</b> option is specified, implementation-defined informational, error, and warning messages concerning the contentsof <i>lex</i> source code input shall be written to the standard error.</p><p>If the <b>-t</b> option is not specified:</p><ol><li><p>Implementation-defined informational, error, and warning messages concerning the contents of <i>lex</i> source code input shallbe written to either the standard output or standard error.</p></li><li><p>If the <b>-v</b> option is specified and the <b>-n</b> option is not specified, <i>lex</i> statistics shall also be written toeither the standard output or standard error, in an implementation-defined format. These statistics may also be generated if tablesizes are specified with a <tt>'%'</tt> operator in the <i>Definitions</i> section, as long as the <b>-n</b> option is notspecified.</p></li></ol></blockquote><h4><a name="tag_04_73_12"></a>OUTPUT FILES</h4><blockquote><p>A text file containing C source code shall be written to <b>lex.yy.c</b>, or to the standard output if the <b>-t</b> option ispresent.</p></blockquote><h4><a name="tag_04_73_13"></a>EXTENDED DESCRIPTION</h4><blockquote><p>Each input file shall contain <i>lex</i> source code, which is a table of regular expressions with corresponding actions in theform of C program fragments.</p><p>When <b>lex.yy.c</b> is compiled and linked with the <i>lex</i> library (using the <b>-l&nbsp;l</b> operand with <a href="../utilities/c99.html"><i>c99</i></a>), the resulting program shall read character input from the standard input and shallpartition it into strings that match the given expressions.</p><p>When an expression is matched, these actions shall occur:</p><ul><li><p>The input string that was matched shall be left in <i>yytext</i> as a null-terminated string; <i>yytext</i> shall either be anexternal character array or a pointer to a character string. As explained in <a href="#tag_04_73_13_01">Definitions in lex</a> ,the type can be explicitly selected using the <b>%array</b> or <b>%pointer</b> declarations, but the default isimplementation-defined.</p></li><li><p>The external <b>int</b> <i>yyleng</i> shall be set to the length of the matching string.</p></li><li><p>The expression's corresponding program fragment, or action, shall be executed.</p></li></ul><p>During pattern matching, <i>lex</i> shall search the set of patterns for the single longest possible match. Among rules thatmatch the same number of characters, the rule given first shall be chosen.</p><p>The general format of <i>lex</i> source shall be:</p><blockquote><pre><i>Definitions</i><b>%%</b><i>Rules</i><b>%%</b><i>User</i>Subroutines</pre></blockquote><p>The first <tt>"%%"</tt> is required to mark the beginning of the rules (regular expressions and actions); the second<tt>"%%"</tt> is required only if user subroutines follow.</p><p>Any line in the <i>Definitions</i> section beginning with a &lt;blank&gt; shall be assumed to be a C program fragment and shallbe copied to the external definition area of the <b>lex.yy.c</b> file. Similarly, anything in the <i>Definitions</i> sectionincluded between delimiter lines containing only <tt>"%{"</tt> and <tt>"%}"</tt> shall also be copied unchanged to the externaldefinition area of the <b>lex.yy.c</b> file.</p><p>Any such input (beginning with a &lt;blank&gt; or within <tt>"%{"</tt> and <tt>"%}"</tt> delimiter lines) appearing at thebeginning of the <i>Rules</i> section before any rules are specified shall be written to <b>lex.yy.c</b> after the declarations ofvariables for the <i>yylex</i>() function and before the first line of code in <i>yylex</i>(). Thus, user variables local to<i>yylex</i>() can be declared here, as well as application code to execute upon entry to <i>yylex</i>().</p><p>The action taken by <i>lex</i> when encountering any input beginning with a &lt;blank&gt; or within <tt>"%{"</tt> and<tt>"%}"</tt> delimiter lines appearing in the <i>Rules</i> section but coming after one or more rules is undefined. The presenceof such input may result in an erroneous definition of the <i>yylex</i>() function.</p><h5><a name="tag_04_73_13_01"></a>Definitions in lex</h5><p><i>Definitions</i> appear before the first <tt>"%%"</tt> delimiter. Any line in this section not contained between <tt>"%{"</tt>and <tt>"%}"</tt> lines and not beginning with a &lt;blank&gt; shall be assumed to define a <i>lex</i> substitution string. Theformat of these lines shall be:</p><pre><i>name substitute</i></pre><p>If a <i>name</i> does not meet the requirements for identifiers in the ISO&nbsp;C standard, the result is undefined. The string<i>substitute</i> shall replace the string { <i>name</i>} when it is used in a rule. The <i>name</i> string shall be recognized inthis context only when the braces are provided and when it does not appear within a bracket expression or within double-quotes.</p><p>In the <i>Definitions</i> section, any line beginning with a <tt>'%'</tt> (percent sign) character and followed by analphanumeric word beginning with either <tt>'s'</tt> or <tt>'S'</tt> shall define a set of start conditions. Any line beginningwith a <tt>'%'</tt> followed by a word beginning with either <tt>'x'</tt> or <tt>'X'</tt> shall define a set of exclusive startconditions. When the generated scanner is in a <tt>%s</tt> state, patterns with no state specified shall be also active; in a<tt>%x</tt> state, such patterns shall not be active. The rest of the line, after the first word, shall be considered to be one ormore &lt;blank&gt;-separated names of start conditions. Start condition names shall be constructed in the same way as definitionnames. Start conditions can be used to restrict the matching of regular expressions to one or more states as described in <a href="#tag_04_73_13_04">Regular Expressions in lex</a> .</p><p>Implementations shall accept either of the following two mutually-exclusive declarations in the <i>Definitions</i> section:</p><dl compact><dt><b>%array</b></dt><dd>Declare the type of <i>yytext</i> to be a null-terminated character array.</dd><dt><b>%pointer</b></dt><dd>Declare the type of <i>yytext</i> to be a pointer to a null-terminated character string.</dd></dl><p>The default type of <i>yytext</i> is implementation-defined. If an application refers to <i>yytext</i> outside of the scannersource file (that is, via an <b>extern</b>), the application shall include the appropriate <b>%array</b> or <b>%pointer</b>declaration in the scanner source file.</p><p>Implementations shall accept declarations in the <i>Definitions</i> section for setting certain internal table sizes. Thedeclarations are shown in the following table.</p><center><b>Table: Table Size Declarations in <i>lex</i></b></center><center><table border="1" cellpadding="3" align="center"><tr valign="top"><th align="center"><p class="tent"><b>Declaration</b></p></th><th align="center"><p class="tent"><b>Description</b></p></th><th align="center"><p class="tent"><b>Minimum Value</b></p></th></tr><tr valign="top"><td align="left"><p class="tent">%<b>p</b> <i>n</i></p></td><td align="left"><p class="tent">Number of positions</p></td><td align="left"><p class="tent">2500</p></td></tr><tr valign="top"><td align="left"><p class="tent">%<b>n</b> <i>n</i></p></td><td align="left"><p class="tent">Number of states</p></td><td align="left"><p class="tent">500</p></td></tr><tr valign="top"><td align="left"><p class="tent">%<b>a</b> <i>n</i></p></td><td align="left"><p class="tent">Number of transitions</p></td><td align="left"><p class="tent">2000</p></td></tr>

⌨️ 快捷键说明

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