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

📄 yacc.html

📁 unix 下的C开发手册,还用详细的例程。
💻 HTML
📖 第 1 页 / 共 4 页
字号:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2 Final//EN"><html><head><!-- Copyright 1997 The Open Group, All Rights Reserved --><title>yacc</title></head><body bgcolor=white><center><font size=2>The Single UNIX &reg; Specification, Version 2<br>Copyright &copy; 1997 The Open Group</font></center><hr size=2 noshade><h4><a name = "tag_001_014_2942">&nbsp;</a>NAME</h4><blockquote>yacc - yet another compiler compiler (<b>DEVELOPMENT</b>)</blockquote><h4><a name = "tag_001_014_2943">&nbsp;</a>SYNOPSIS</h4><blockquote><pre><code>yacc <b>[</b>-dltv<b>][</b>-b <i>file_prefix</i><b>][</b>-p <i>sym_prefix</i><b>]</b><i> grammar</i></code></pre></blockquote><h4><a name = "tag_001_014_2944">&nbsp;</a>DESCRIPTION</h4><blockquote><p>The<i>yacc</i>utility reads a description of a context-free grammar in<i>file</i>and writesC source code, conforming to the ISO&nbsp;C standard,to a code file, and optionallyheader information into a header file,in the current directory.The C code defines a function and related routines and macrosfor an automaton that executes a parsing algorithm meeting the requirements in<xref href=yaccalg><a href="#tag_001_014_2954_013">Algorithms</a></xref>.<p>The form and meaning of the grammar are described in theEXTENDED DESCRIPTION section.<p>The C source code and header file are produced in a formsuitable as input for the C compiler (see<i><a href="c89.html">c89</a></i>).</blockquote><h4><a name = "tag_001_014_2945">&nbsp;</a>OPTIONS</h4><blockquote>The<i>yacc</i>utility supports the <b>XBD</b> specification, <a href="../xbd/utilconv.html#usg"><b>Utility Syntax Guidelines</b>&nbsp;</a> .<p>The following options are supported:<dl compact><dt><b>-b&nbsp;</b><i>file_prefix</i><dd>Use<i>file_prefix</i>instead ofyas the prefix for all output filenames.The code file<b>y.tab.c</b>,the header file<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>is specified),will 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.<dt><b>-d</b><dd>Write the header file;by default only the code file is written.The<b>#define</b>statements that associate thetoken codes assigned by<i>yacc</i>with the user-declared token names.This allows source files other than<b>y.tab.c</b>to access the token codes.<dt><b>-l</b><dd>Produce a code file that does not contain any<b>#line</b>constructs.If this option is not present, it is unspecified whether thecode file or header file contains<b>#line</b>directives.This should only be used after thegrammar and the associated actions are fully debugged.<dt><b>-p&nbsp;</b><i>sym_prefix</i><dd>Use<i>sym_prefix</i>instead ofyyas the prefix for all external names produced by<i>yacc</i>.The names affected include 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 citedare referenced using their default names only as a notational convenience.)Local names may also be affected by the<b>-p</b>option;however, the<b>-p</b>option does not affect<b>#define</b>symbols generated by<i>yacc</i>.<dt><b>-t</b><dd>Modify conditional compilation directives to permit compilationof debugging code in the code file.Run-time debugging statementswill be always contained in the code file,but by default conditionalcompilation directives prevent their compilation.<dt><b>-v</b><dd>Write a file containing a description of the parser and a reportof conflicts generated by ambiguities in the grammar.</dl><br></blockquote><h4><a name = "tag_001_014_2946">&nbsp;</a>OPERANDS</h4><blockquote>The following operand is required:<dl compact><dt><i>grammar</i><dd>A pathname of a file containing instructions, hereafter called<i>grammar ,</i>for which a parser is to be created.The format for the grammar is described in theEXTENDED DESCRIPTION section.</dl></blockquote><h4><a name = "tag_001_014_2947">&nbsp;</a>STDIN</h4><blockquote>Not used.</blockquote><h4><a name = "tag_001_014_2948">&nbsp;</a>INPUT FILES</h4><blockquote>The file<i>grammar</i>must be a text file formatted as specified in theEXTENDED DESCRIPTION section.</blockquote><h4><a name = "tag_001_014_2949">&nbsp;</a>ENVIRONMENT VARIABLES</h4><blockquote>The following environment variables affect the execution of<i>yacc</i>:<dl compact><dt><i>LANG</i><dd>Provide a default value for the internationalisation variablesthat are unset or null.If<i>LANG</i>is unset or null, the corresponding value from theimplementation-dependent default locale will be used.If any of the internationalisation variables contains an invalid setting, theutility will behave as if none of the variables had been defined.<dt><i>LC_ALL</i><dd>If set to a non-empty string value,override the values of all the other internationalisation variables.<dt><i>LC_CTYPE</i><dd>Determine thelocale for the interpretation of sequences of bytes of text data ascharacters (for example, single- as opposed to multi-byte charactersin arguments and input files).<dt><i>LC_MESSAGES</i><dd>Determine the locale that should be used to affectthe format and contents of diagnosticmessages written to standard error.<dt><i>NLSPATH</i><dd>Determine the location of message cataloguesfor the processing of<i>LC_MESSAGES .</i></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>function defined in<xref href=yacclib><a href="#tag_001_014_2954_011">Yacc Library</a></xref>calls:<pre><code>setlocale(LC_ALL, "")</code></pre>and thus, the program generated by<i>yacc</i>will also be affected by thecontents of these variables at runtime.</blockquote><h4><a name = "tag_001_014_2950">&nbsp;</a>ASYNCHRONOUS EVENTS</h4><blockquote>Default.</blockquote><h4><a name = "tag_001_014_2951">&nbsp;</a>STDOUT</h4><blockquote>Not used.</blockquote><h4><a name = "tag_001_014_2952">&nbsp;</a>STDERR</h4><blockquote>If shift/reduce or reduce/reduce conflictsare detected in<i>grammar</i>,<i>yacc</i>writes a report of those conflicts to the standard errorin an unspecified format.<p>Standard error is also used for diagnostic messages.</blockquote><h4><a name = "tag_001_014_2953">&nbsp;</a>OUTPUT FILES</h4><blockquote>The code file, the header file andthe description file are text files.All are described in the following sections.<h5><a name = "tag_001_014_2953_001">&nbsp;</a>Code file</h5>This file will contain the C source code for the<i>yyparse()</i>routine.It will contain code for the various semantic actions with macrosubstitution performed on them as described in theEXTENDED DESCRIPTION section.It will also contain a copy of the<b>#define</b>statements in the header file.If a<b>%union</b>declaration is used, the declaration for YYSTYPEalso will be included in this file.<p>The contents of the Program Section (see<xref href=yaccprog><a href="#tag_001_014_2954_005">Programs Section</a></xref>)of the input file will then be included.<h5><a name = "tag_001_014_2953_002">&nbsp;</a>Header file</h5>The header file will contain<b>#define</b>statements that associate thetoken numbers with the token names.This allows source files other thanthe code fileto access the token codes.If a<b>%union</b>declaration is used, the declaration forYYSTYPEand anextern YYSTYPE yylvaldeclaration also will be included in this file.<h5><a name = "tag_001_014_2953_003">&nbsp;</a>Description file</h5>The description filewill be a text file containing a description of the state machinecorresponding to the parser, using an unspecified format.Limits for internal tables (see<b>Limits</b>in the EXTENDED DESCRIPTION section)will also be reported, in an implementation-dependent manner.(Some implementations may use dynamic allocation techniquesand have no specific limit values to report.)</blockquote><h4><a name = "tag_001_014_2954">&nbsp;</a>EXTENDED DESCRIPTION</h4><blockquote>The<i>yacc</i>command accepts a language that is used to define a grammar for a targetlanguage to be parsed by the tables and code generated by<i>yacc</i>.The languageaccepted by<i>yacc</i>as a grammar for the target language is described below using the<i>yacc</i>input language itself.<p>The input<i>grammar</i>includes rules describing the input structure of the target languageand code to be invoked when these rules are recognised to providethe associated semantic action.The code to be executed will appear as bodies of textthat are intended to be C-language code.The C-language inclusions are presumed to form a correct functionwhen processed by<i>yacc</i>into its output files.The code included in this way will be executedduring the recognition of the target language.<p>Given a grammar, the<i>yacc</i>utility generates the files described in the OUTPUT FILES section.The code file can be compiled and linked using<i><a href="cc.html">cc</a></i>or<i><a href="c89.html">c89</a></i>.If the declarationand programs sections of the grammar file did not includedefinitions of<i>main()</i>,<i>yylex()</i>and<i>yyerror()</i>,the compiled output requires linking with externally suppliedversion 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<i><a href="cc.html">cc</a></i>or<i><a href="c89.html">c89</a></i>.The<i>yacc</i>library interfaces need not supportinterfaces with other than the default<b>yy</b>symbol prefix.The application provides the lexical analyser function,<i>yylex()</i>;the<i><a href="lex.html">lex</a></i>utilityis specifically designed to generate such a routine.<h5><a name = "tag_001_014_2954_001">&nbsp;</a>Input Language</h5>Every specification file must consist of three sectionsin order:<i>declarations ,</i><i>grammar rules</i>and<i>programs ,</i>separated by double percent signs(<b>%%</b>).The declarations and programs sections can be empty.If the latter is empty, the preceding<b>%%</b>mark separating it from the rules section can be omitted.<p>The input is free form text following the structure of thegrammar defined below.<h5><a name = "tag_001_014_2954_002">&nbsp;</a>Lexical Structure of the Grammar</h5><xref type="5" name="yacclex"></xref>The charactersblank,newlineandform-feedare ignored, except that they must not appearin names or multi-character reserved symbols.Comments must be enclosed in/*&nbsp;...\ */,and can appear wherever a name is valid.<p>Names are of arbitrary length, made up of letters, periods(.),underscores(_)and non-initial digits.Upper- and lower-case letters are distinct.Portable applications must not usenames beginning in

⌨️ 快捷键说明

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