DOC HOME SITE MAP MAN PAGES GNU INFO SEARCH
 

(bison) Multiple Parsers

Info Catalog (bison) Declarations (bison) Grammar File
 
 Multiple Parsers in the Same Program
 ====================================
 
    Most programs that use Bison parse only one language and therefore
 contain only one Bison parser.  But what if you want to parse more than
 one language with the same program?  Then you need to avoid a name
 conflict between different definitions of `yyparse', `yylval', and so
 on.
 
    The easy way to do this is to use the option `-p PREFIX' (
 Invoking Bison Invocation.).  This renames the interface functions and
 variables of the Bison parser to start with PREFIX instead of `yy'.
 You can use this to give each parser distinct names that do not
 conflict.
 
    The precise list of symbols renamed is `yyparse', `yylex',
 `yyerror', `yynerrs', `yylval', `yychar' and `yydebug'.  For example,
 if you use `-p c', the names become `cparse', `clex', and so on.
 
    *All the other variables and macros associated with Bison are not
 renamed.* These others are not global; there is no conflict if the same
 name is used in different parsers.  For example, `YYSTYPE' is not
 renamed, but defining this in different ways in different parsers causes
 no trouble ( Data Types of Semantic Values Value Type.).
 
    The `-p' option works by adding macro definitions to the beginning
 of the parser source file, defining `yyparse' as `PREFIXparse', and so
 on.  This effectively substitutes one name for the other in the entire
 parser file.
 
Info Catalog (bison) Declarations (bison) Grammar File
automatically generated byinfo2html