Linux yacc command

Updated: 05/04/2019 by Computer Hope
yacc command

On Unix-like operating systems, the yacc command is a compiler that generates a Look-Ahead, Left-to-right, Rightmost-derivation (LALR) parser. It is a compiler-compiler: a compiler which creates a compiler. Yacc takes as input a formal description of a programming language, and its output is a parser which executes certain actions, specific to a target architecture, when compiling a program written in the language.


The name "yacc" is an acronym for "Yet Another Compiler-Compiler." It was extremely popular and was once standard on all Unix systems. It has since been supplanted by more recent compiler-compilers, which are mostly backward compatible with yacc.


yacc [-d] [-l] [-t] [-V] [-v] [ -b file_prefix ] [ -Q [y | n ] ] 
     [ -P parser ] [ -p sym_prefix ] file
-d Generates the file with the #define statements that associate the yacc user-assigned "token codes" with the user-declared "token names." This association allows source files other than to access the token codes.
-l Specifies that the code produced in will not contain any #line constructs. This option should only be used after the grammar and the associated actions are fully debugged.
-t Compiles runtime debugging code by default. Runtime debugging code is always generated in under conditional compilation control. By default, this code is not included when is compiled. Whether or not 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 included. If its value is 0, then the code will not be included. The size and execution time of a program produced without the runtime debugging code will be smaller and slightly faster.
-v Prepares the file y.output, which contains a description of the parsing tables and a report on conflicts generated by ambiguities in the grammar.
-V Prints on the standard error output the version information for yacc.
-b file_prefix Use file_prefix instead of y as the prefix for all output files. The code file, the header file (created when -d is specified), and the description file y.output (created when -v is specified), will be changed to,, and file_prefix.output, respectively.
-Q [y|n] The -Qy option puts the version stamping information in This allows you to know what version of yacc built the file. The -Qn option (the default) writes no version information.
-P parser Allows you to specify the parser of your choice instead of /usr/ccs/bin/yaccpar. For example, you can specify:

yacc -P ~/myparser parser.y
-p sym_prefix Use sym_prefix instead of yy as the prefix for all external names produced by yacc. The names affected include the functions yyparse(), yylex() and yyerror(), and the variables yylval, yychar and yydebug. (In the remainder of this section, the six symbols cited are referenced using their default names only as a notational convenience.) Local names may also be affected by the -p option; however, the -p option does not affect #define symbols generated by yacc.
file A path name of a file containing instructions for which a parser is to be created.

cc — Compiler of the C programming language.
lex — Generate programs for performing lexical tasks.