YACC(1) | User Commands | YACC(1) |
yacc - yet another compiler-compiler
yacc [-dltVv] [-b file_prefix] [-Q [y | n]]
[-P parser] [-p sym_prefix] file
The yacc command converts a context-free grammar into a set of tables for a simple automaton that executes an LALR(1) parsing algorithm. The grammar can be ambiguous. Specified precedence rules are used to break ambiguities.
The output file, y.tab.c, must be compiled by the C compiler to produce a function yyparse(). This program must be loaded with the lexical analyzer program, yylex(), as well as main() and yyerror(), an error handling routine. These routines must be supplied by the user. The lex(1) command is useful for creating lexical analyzers usable by yacc.
The following options are supported:
-b file_prefix
-d
-l
-p sym_prefix
-P parser
example% yacc -P ~/myparser parser.y
-Q[y|n]
-t
-v
-V
The following operand is required:
file
Example 1 Accessing the yacc Library
Access to the yacc library is obtained with library search operands to cc. To use the yacc library main:
example% cc y.tab.c -ly
Both the lex library and the yacc library contain main. To access the yacc main:
example% cc y.tab.c lex.yy.c -ly -ll
This ensures that the yacc library is searched first, so that its main is used.
The historical yacc libraries have contained two simple functions that are normally coded by the application programmer. These library functions are similar to the following code:
#include <locale.h> int main(void) {
extern int yyparse();
setlocale(LC_ALL, "");
/* If the following parser is one created by lex, the
application must be careful to ensure that LC_CTYPE
and LC_COLLATE are set to the POSIX locale. */
(void) yyparse();
return (0); } #include <stdio.h> int yyerror(const char *msg) {
(void) fprintf(stderr, "%s\n", msg);
return (0); }
See environ(7) for descriptions of the following environment variables that affect the execution of yacc: LANG, LC_ALL, LC_CTYPE, LC_MESSAGES, and NLSPATH.
yacc can handle characters from EUC primary and supplementary codesets as one-token symbols. EUC codes can only be single character quoted terminal symbols. yacc expects yylex() to return a wide character (wchar_t) value for these one-token symbols.
The following exit values are returned:
0
>0
y.output
y.tab.c
y.tab.h
yacc.acts
yacc.debug
yacc.tmp
yaccpar
See attributes(7) for descriptions of the following attributes:
ATTRIBUTE TYPE | ATTRIBUTE VALUE |
Interface Stability | Committed |
Standard | See standards(7). |
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. Similarly, if some rules are not reachable from the start symbol, this instance is also reported.
Because file names are fixed, at most one yacc process can be active in a given directory at a given time.
Users are encouraged to avoid using $ as part of any identifier name.
August 24, 2009 | OmniOS |