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

📄 yacc.html

📁 IEEE 1003.1-2003, Single Unix Specification v3
💻 HTML
📖 第 1 页 / 共 4 页
字号:
<!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>yacc</title></head><body bgcolor="white"><script type="text/javascript" language="JavaScript" src="../jscript/codes.js"></script><basefont size="3"> <a name="yacc"></a> <a name="tag_04_174"></a><!-- yacc --> <!--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_174_01"></a>NAME</h4><blockquote>yacc - yet another compiler compiler (<b>DEVELOPMENT</b>)</blockquote><h4><a name="tag_04_174_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"> yacc</tt> <b>[</b><tt>-dltv</tt><b>][</b><tt>-b</tt> <i>file_prefix</i><b>][</b><tt>-p</tt><i>sym_prefix</i><b>]</b> <i>grammar</i><tt><img src="../images/opt-end.gif" alt="[Option End]" border="0"></tt></code></div></blockquote><h4><a name="tag_04_174_03"></a>DESCRIPTION</h4><blockquote><p>The <i>yacc</i> utility shall read a description of a context-free grammar in <i>grammar</i> and write C source code, conformingto the ISO&nbsp;C standard, to a code file, and optionally header information into a header file, in the current directory. The Ccode shall define a function and related routines and macros for an automaton that executes a parsing algorithm meeting therequirements in <a href="#tag_04_174_13_13">Algorithms</a> .</p><p>The form and meaning of the grammar are described in the EXTENDED DESCRIPTION section.</p><p>The C source code and header file shall be produced in a form suitable as input for the C compiler (see <a href="c99.html"><i>c99</i></a> ).</p></blockquote><h4><a name="tag_04_174_04"></a>OPTIONS</h4><blockquote><p>The <i>yacc</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>-b&nbsp;</b> <i>file_prefix</i></dt><dd>Use <i>file_prefix</i> instead of <b>y</b> as the prefix for all output filenames. The code file <b>y.tab.c</b>, the headerfile <b>y.tab.h</b> (created when <b>-d</b> is specified), and the description file <b>y.output</b> (created when <b>-v</b> isspecified), shall be changed to <i>file_prefix</i> <b>.tab.c</b>, <i>file_prefix</i> <b>.tab.h</b>, and <i>file_prefix</i><b>.output</b>, respectively.</dd><dt><b>-d</b></dt><dd>Write the header file; by default only the code file is written. The <b>#define</b> statements associate the token codesassigned by <i>yacc</i> with the user-declared token names. This allows source files other than <b>y.tab.c</b> to access the tokencodes.</dd><dt><b>-l</b></dt><dd>Produce a code file that does not contain any <b>#line</b> constructs. If this option is not present, it is unspecified whetherthe code file or header file contains <b>#line</b> directives. This should only be used after the grammar and the associatedactions are fully debugged.</dd><dt><b>-p&nbsp;</b> <i>sym_prefix</i></dt><dd><br>Use <i>sym_prefix</i> instead of <b>yy</b> as the prefix for all external names produced by <i>yacc</i>. The names affected shallinclude the functions <i>yyparse</i>(), <i>yylex</i>(), and <i>yyerror</i>(), and the variables <i>yylval</i>, <i>yychar</i>, and<i>yydebug</i>. (In the remainder of this section, the six symbols cited are referenced using their default names only as anotational convenience.) Local names may also be affected by the <b>-p</b> option; however, the <b>-p</b> option shall not affect<b>#define</b> symbols generated by <i>yacc</i>.</dd><dt><b>-t</b></dt><dd>Modify conditional compilation directives to permit compilation of debugging code in the code file. Runtime debuggingstatements shall always be contained in the code file, but by default conditional compilation directives prevent theircompilation.</dd><dt><b>-v</b></dt><dd>Write a file containing a description of the parser and a report of conflicts generated by ambiguities in the grammar.</dd></dl></blockquote><h4><a name="tag_04_174_05"></a>OPERANDS</h4><blockquote><p>The following operand is required:</p><dl compact><dt><i>grammar</i></dt><dd>A pathname of a file containing instructions, hereafter called <i>grammar</i>, for which a parser is to be created. The formatfor the grammar is described in the EXTENDED DESCRIPTION section.</dd></dl></blockquote><h4><a name="tag_04_174_06"></a>STDIN</h4><blockquote><p>Not used.</p></blockquote><h4><a name="tag_04_174_07"></a>INPUT FILES</h4><blockquote><p>The file <i>grammar</i> shall be a text file formatted as specified in the EXTENDED DESCRIPTION section.</p></blockquote><h4><a name="tag_04_174_08"></a>ENVIRONMENT VARIABLES</h4><blockquote><p>The following environment variables shall affect the execution of <i>yacc</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_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).</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><p>The <i>LANG</i> and <i>LC_*</i> variables affect the execution of the <i>yacc</i> utility as stated. The <i>main</i>() functiondefined in <a href="#tag_04_174_13_11">Yacc Library</a> shall call:</p><pre><tt>setlocale(LC_ALL, "")</tt></pre><p>and thus the program generated by <i>yacc</i> shall also be affected by the contents of these variables at runtime.</p></blockquote><h4><a name="tag_04_174_09"></a>ASYNCHRONOUS EVENTS</h4><blockquote><p>Default.</p></blockquote><h4><a name="tag_04_174_10"></a>STDOUT</h4><blockquote><p>Not used.</p></blockquote><h4><a name="tag_04_174_11"></a>STDERR</h4><blockquote><p>If shift/reduce or reduce/reduce conflicts are detected in <i>grammar</i>, <i>yacc</i> shall write a report of those conflictsto the standard error in an unspecified format.</p><p>Standard error shall also be used for diagnostic messages.</p></blockquote><h4><a name="tag_04_174_12"></a>OUTPUT FILES</h4><blockquote><p>The code file, the header file, and the description file shall be text files. All are described in the following sections.</p><h5><a name="tag_04_174_12_01"></a>Code File</h5><p>This file shall contain the C source code for the <i>yyparse</i>() function. It shall contain code for the various semanticactions with macro substitution performed on them as described in the EXTENDED DESCRIPTION section. It also shall contain a copy ofthe <b>#define</b> statements in the header file. If a <b>%union</b> declaration is used, the declaration for YYSTYPE shall also beincluded in this file.</p><h5><a name="tag_04_174_12_02"></a>Header File</h5><p>The header file shall contain <b>#define</b> statements that associate the token numbers with the token names. This allowssource files other than the code file to access the token codes. If a <b>%union</b> declaration is used, the declaration forYYSTYPE and an <i>extern YYSTYPE yylval</i> declaration shall also be included in this file.</p><h5><a name="tag_04_174_12_03"></a>Description File</h5><p>The description file shall be a text file containing a description of the state machine corresponding to the parser, using anunspecified format. Limits for internal tables (see <a href="#tag_04_174_13_14">Limits</a> ) shall also be reported, in animplementation-defined manner. (Some implementations may use dynamic allocation techniques and have no specific limit values toreport.)</p></blockquote><h4><a name="tag_04_174_13"></a>EXTENDED DESCRIPTION</h4><blockquote><p>The <i>yacc</i> command accepts a language that is used to define a grammar for a target language to be parsed by the tables andcode generated by <i>yacc</i>. The language accepted by <i>yacc</i> as a grammar for the target language is described below usingthe <i>yacc</i> input language itself.</p><p>The input <i>grammar</i> includes rules describing the input structure of the target language and code to be invoked when theserules are recognized to provide the associated semantic action. The code to be executed shall appear as bodies of text that areintended to be C-language code. The C-language inclusions are presumed to form a correct function when processed by <i>yacc</i>into its output files. The code included in this way shall be executed during the recognition of the target language.</p><p>Given a grammar, the <i>yacc</i> utility generates the files described in the OUTPUT FILES section. The code file can becompiled and linked using <a href="../utilities/c99.html"><i>c99</i></a>. If the declaration and programs sections of the grammarfile did not include definitions of <i>main</i>(), <i>yylex</i>(), and <i>yyerror</i>(), the compiled output requires linking withexternally supplied versions of those functions. Default versions of <i>main</i>() and <i>yyerror</i>() are supplied in the<i>yacc</i> library and can be linked in by using the <b>-l&nbsp;y</b> operand to <a href="../utilities/c99.html"><i>c99</i></a>.The <i>yacc</i> library interfaces need not support interfaces with other than the default <b>yy</b> symbol prefix. The applicationprovides the lexical analyzer function, <i>yylex</i>(); the <a href="../utilities/lex.html"><i>lex</i></a> utility is specificallydesigned to generate such a routine.</p><h5><a name="tag_04_174_13_01"></a>Input Language</h5><p>The application shall ensure that every specification file consists of three sections in order: <i>declarations</i>, <i>grammarrules</i>, and <i>programs</i>, separated by double percent signs ( <tt>"%%"</tt> ). The declarations and programs sections can beempty. If the latter is empty, the preceding <tt>"%%"</tt> mark separating it from the rules section can be omitted.</p><p>The input is free form text following the structure of the grammar defined below.</p><h5><a name="tag_04_174_13_02"></a>Lexical Structure of the Grammar</h5><p>The &lt;blank&gt;s, &lt;newline&gt;s, and &lt;form-feed&gt;s shall be ignored, except that the application shall ensure thatthey do not appear in names or multi-character reserved symbols. Comments shall be enclosed in <tt>"/*&nbsp;...&nbsp;*/"</tt> , andcan appear wherever a name is valid.</p><p>Names are of arbitrary length, made up of letters, periods ( <tt>'.'</tt> ), underscores ( <tt>'_'</tt> ), and non-initialdigits. Uppercase and lowercase letters are distinct. Conforming applications shall not use names beginning in <b>yy</b> or<b>YY</b> since the <i>yacc</i> parser uses such names. Many of the names appear in the final output of <i>yacc</i>, and thus theyshould be chosen to conform with any additional rules created by the C compiler to be used. In particular they appear in<b>#define</b> statements.</p><p>A literal shall consist of a single character enclosed in single-quotes ( <tt>'&quot;</tt> ). All of the escape sequences supportedfor character constants by the ISO&nbsp;C standard shall be supported by <i>yacc</i>.</p><p>The relationship with the lexical analyzer is discussed in detail below.</p><p>The application shall ensure that the NUL character is not used in grammar rules or literals.</p><h5><a name="tag_04_174_13_03"></a>Declarations Section</h5><p>The declarations section is used to define the symbols used to define the target language and their relationship with eachother. In particular, much of the additional information required to resolve ambiguities in the context-free grammar for the targetlanguage is provided here.</p><p>Usually <i>yacc</i> assigns the relationship between the symbolic names it generates and their underlying numeric value. Thedeclarations section makes it possible to control the assignment of these values.</p><p>It is also possible to keep semantic information associated with the tokens currently on the parse stack in a user-definedC-language <b>union</b>, if the members of the union are associated with the various names in the grammar. The declarations sectionprovides for this as well.</p><p>The first group of declarators below all take a list of names as arguments. That list can optionally be preceded by the name ofa C union member (called a <i>tag</i> below) appearing within <tt>'&lt;'</tt> and <tt>'&gt;'</tt> . (As an exception to thetypographical conventions of the rest of this volume of IEEE&nbsp;Std&nbsp;1003.1-2001, in this case &lt;<i>tag</i>&gt; does notrepresent a metavariable, but the literal angle bracket characters surrounding a symbol.) The use of <i>tag</i> specifies that thetokens named on this line shall be of the same C type as the union member referenced by <i>tag</i>. This is discussed in moredetail below.</p><p>For lists used to define tokens, the first appearance of a given token can be followed by a positive integer (as a string ofdecimal digits). If this is done, the underlying value assigned to it for lexical purposes shall be taken to be that number.</p><p>The following declares <i>name</i> to be a token:</p>

⌨️ 快捷键说明

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