Museum

Home

Lab Overview

Retrotechnology Articles

Online Manuals

⇒ yacc(CP) — OpenDesktop Software Development System 3.0.0

Media Vault

Software Library

Restoration Projects

Artifacts Sought

Related Articles

lex(CP)


 yacc(CP)                       6 January 1993                       yacc(CP)


 Name

    yacc - yet another compiler-compiler--a parser generator

 Syntax

    yacc [-vdlt] [-S[ailmnrsw[num]]] filename

 Description

    The yacc command is used to generate C code that implements a parser. The
    program that yacc generates is based on an input file consisting of a
    grammar and possibly some C code fragments and internal declarations.
    yacc converts a context-free grammar into a set of tables for a simple
    automaton which executes a parsing algorithm.  Code that is executed
    whenever a grammar production is recognized may be supplied. The grammar
    may be ambiguous; precedence rules are used to resolve ambiguities.

    The output file containing the parser code is called y.tab.c. This pro-
    gram must be compiled by the C compiler; the parsing routine is called
    yyparse.  This program must be linked with a lexical analyzer routine
    with the name yylex, as well as main and yyerror, an error-handling rou-
    tine.  lex(CP) will generate a lexical analyzer routine called yylex; if
    the program is linked with the yacc library, main and yyerror will be
    supplied.

 Options


    -d A file called y.tab.h will be generated.  This file contains #define
       statements associating yacc-assigned token codes with the
       user-declared token names.  This file may be included in other pro-
       grams which need to access the token codes.

    -l The code produced in y.tab.c will not contain any #line constructs.
       This option should only be used after the grammar and the associated
       actions are fully debugged.

    -S This flag is used to increase the allocation of various resources.  It
       allows you to set the following parameters:

       Key letter   Name       Meaning                         Default

       a            ACTSIZE    action table storage size       10,000
       m            MEMSIZE    production storage size         20,000
       s            NSTATES    state table size                1,250
       r            NPROD      number of grammar rules         600
       n            NONTERM    number of non-terminals         600
       i            CNAMSZ     number of idents and literals   4,000
       l            LSETSIZE   number of look-ahead sets       700
       w            WSETSIZE   number of working sets          250

       For example:

          yacc -Sw600 yacc.y

       The number following the key letter is an integer increasing the allo-
       cation of the corresponding resource.  -S can appear several times on
       the command line.

    -t Runtime debugging code is always generated in y.tab.c.  By default,
       this code is not compiled.  However, when yacc's -t option is used,
       this debugging code will be compiled. Independent of whether the -t
       option is used, the runtime debugging code is under the control of
       YYDEBUG, a preprocessor symbol.  If YYDEBUG has a non-zero value, then
       the debugging code is compiled.  If its value is zero, then the code
       will not be compiled.  A program compiled without the runtime debug-
       ging code will be smaller and slightly faster.

    -v A file called y.output will be generated.  This file contains a
       description of the parsing tables and a report on conflicts generated
       by ambiguities in the grammar.

 Files

    y.output
    y.tab.c
    y.tab.h                 Defines for token names.
    yacc.tmp, yacc.debug, yacc.acts Temporary files.
    /usr/lib/yaccpar        Parser prototype for C programs.

 Diagnostics

    The number of reduce-reduce and shift-reduce conflicts is reported on the
    standard error output; a more detailed report is found in the y.output
    file.  If some rules are not reachable from the start symbol, this is
    reported.

 Caveat

    Because file names are fixed, only one yacc process can be active in a
    given directory.

 See also

    lex(CP)

 Standards conformance

    yacc is conformant with:
    AT&T SVID Issue 2;
    and X/Open Portability Guide, Issue 3, 1989.


Typewritten Software • bear@typewritten.org • Edmonds, WA 98026