BISON++(1)
β¨ BISON++ β¨
okay bestie, gather round π this is BISON++(1) from the COMMANDS section of the manual, and it's a whole vibe. it's a parser generator, it's giving main character energy, and yes we're gonna read the entire thing together. no skimming. periodt.
π NAME π
bison++ β generate a parser in c or c++.
πΈ SYNOPSIS πΈ
bison++ [-dltvyVu] [-b file-prefix] [-p name-prefix] [-o outfile] [-h
headerfile] [-S skeleton] [-H header-skeleton] [--debug] [--defines]
[--fixed-output-files] [--no-lines] [--verbose] [--version] [--yacc]
[--usage] [--help] [--file-prefix=prefix] [--name-prefix=prefix]
[--skeleton=skeletonfile] [--headerskeleton=headerskeletonfile]
[--output=outfile] [--header-name=header] grammar-file
π¦ DESCRIPTION π¦
so like. it generates a parser. that's the whole job π
it's based on bison version 1.19, and for the details of the main functionality you should go look at bison(1). only the changes get reported here β that's the whole point of this page.
okay so here's the tea: if you're compiling with a C++ compiler, you now generate a C++ class. the generated header is far more rich than before, and it's made from a skeleton-header. the code skeleton is also richer, and the generated code matters less compared to the skeletons themselves. which means β iconic behaviour β you can modify a whole bunch of stuff just by changing the two skeletons. obsessed.
and in plain C? bison++ is compatible with standard bison. no notes. π«Ά
π OPTIONS π
--name-prefix=prefix,-p prefixβ sets the prefix of the names ofyylexandyyerror. it's kept for compatibility, but honestly you should prefer%define LEX newname, and similar. iykyk.--skeleton=skeleton,-S skeletonβ sets the filename of the code skeleton. default isbison.cc.--headerskeleton=header-skeleton,-H header-skeletonβ sets the filename of the header skeleton. default isbison.h.--header-name=header,-h headerβ sets the filename of the header skeleton. default isy.tab.h, orprefix.hif option-bis used, orc_basename.hif-ois used. the.c,.cc,.C,.cpp,.cxxoptions for output files get replaced by.hfor the header name.
π DECLARATIONS π
these are the new declarations you can put in the declaration section:
%name parser_nameβ declares the name of this parser. used for the C++ class name, and to render many names unique. default isparse. must be given before%unionand%define, or never.%define define_name content...β declares a macro symbol in the header and in the code. the name of the symbol isYY_'parser_name'_'define_name'. the content goes after it, just like with#define. newlines can be escaped the same way as with#define. lots of symbols are proposed for customisation. β¨%unionβ as with bison, generates a union for the semantic type. the difference is that the union is namedyy_'parser_name'_stype.%pure_parserβ as with bison in C. in C++ it generates a parser whereyylval, andyylloc(if needed) are passed as parameters toyylex, and where some instance variables are local toyyparse(likeyydebug...). not very useful, honestly, since you can just create multiple instances for reentering another parser. π%header{β like%{, but it includes this text both in the header and in the code. end it with%}. when you put it in the declaration section, the text is added before the definitions. it can be put in the last section so that the text is added after all definitions in the header, and in the last section at the current position in the code.
β οΈ heads up bestie: the order of these declarations matters, because they get translated into preprocessor symbols, typedefs or code depending on their type. for example, use%namebefore any%define, since the name is needed to compose the name of the define symbols. and the order of%headerand%unionmatters too, since the type may be undefined.
π DECLARATION DEFINE SYMBOLS π
these are the symbols you can define with %define in the declaration section, or that are already defined. remember: they get replaced by a preprocessor #define YY_'parser_name'_'name'.
BISONβ defined to1in the code. used for conditional code. don't redefine it.h_includedβ defined in the code, and in the header. used for include anti-reload. don't redefine it.COMPATIBILITYβ indicates whether obsoleted defines are to be used and produced. if defined to0, it means no compatibility is needed; otherwise, if defined to non-0, it generates it. if it's undefined, the default is to be compatible if classes are not used.USE_GOTOβ indicates (if defined as1) thatgotois to be used (for backward compatibility) in the parser function. by defaultgotois replaced with a switch construction, to avoid problems with some compilers that don't supportgotoand destructor in the same function block. ifCOMPATIBILITYis1, andUSE_GOTOis not defined, thenUSE_GOTOis defined to1, to be compatible with older bison.USE_CONST_TOKENβ indicates (if defined as1) thatstatic const intis to be used in C++, for token IDs. by default anenumis used to define the token IDs instead ofconst.ENUM_TOKENβ when enums are used instead ofstatic const intfor token IDs, this symbol defines the name of the enum type. defined toyy_'parser_name'_enum_tokenby default.PUREβ indicates that%pure_parseris asked... don't redefine it.LSP_NEEDEDβ if defined, indicates that the@construct is used, so the LLOC stack is needed. can be defined to force use of the location stack.DEBUGβ if defined to non-0, activates debugging code. seeYYDEBUGin bison.ERROR_VERBOSEβ if defined, activates dumping the parser stack when an error happens.STYPEβ the type of the semantic value of a token. defined by%union. default isint. seeYYSTYPEin bison. don't redefine it, if you use a%union.LTYPEβ the token location type. if needed, default isyyltype. seeYYLTYPEin bison. the defaultyyltypeis a typedef and struct defined as in old bison.LLOCβ the token location variable name. if needed, default isyylloc. seeyyllocin bison.LVALβ the token semantic value variable name. default isyylval. seeyylvalin bison.CHARβ the lookahead token value variable name. default isyychar. seeyycharin bison.LEXβ the scanner function name. default isyylex. seeyylexin bison.PARSEβ the parser function name. default isyyparse. seeyyparsein bison.PARSE_PARAMβ the parser function parameters declaration. default isvoidin C++ or ANSIC, and nothing if old C. in ANSIC and C++ it contains the prototype. in old-C it contains just the list of parameter names. doesn't allow default value.PARSE_PARAM_DEFβ the parser function parameters definition, for old style C. default is nothing. for example, to use anintparameter calledx,PARSE_PARAMisx, andPARSE_PARAM_DEFisint x;. in ANSIC or C++ it is unuseful and ignored.ERRORβ the error function name. default isyyerror. seeyyerrorin bison.NERRSβ the error count name. default isyynerrs. seeyynerrsin bison.DEBUG_FLAGβ the runtime debug flag. default isyydebug. seeyydebugin bison.
and these ones? only used if a class is generated. π
CLASSβ the class name. default is the parser name.INHERITβ the inheritance list. don't forget the:before it, if the list is not empty.MEMBERSβ list of members to add to the class definition, before ending it.LEX_BODYβ the scanner member function body. may be defined to=0for a pure function, or to an inline body.ERROR_BODYβ the error member function body. may be defined to=0for a pure function, or to an inline body.CONSTRUCTOR_PARAMβ list of parameters of the constructor. doesn't allow default value.CONSTRUCTOR_INITβ list of initialisation before the constructor call. if it's not empty, don't forget the:before the list of initialisation.CONSTRUCTOR_CODEβ code added after internal initialisation in the constructor.
π OBSOLETED PREPROCESSOR SYMBOLS π
if you use the new features, the following symbols should not be used, even though they are still proposed. the symbol COMPATIBILITY controls their disponibility. incoherence may arise if they are defined simultaneously with the new symbol. π
YYLTYPEβ prefer%define LTYPE.YYSTYPEβ prefer%define STYPE.YYDEBUGβ prefer%define DEBUG.YYERROR_VERBOSEβ prefer%define ERROR_VERBOSE.YYLSP_NEEDEDβ prefer%define LSP_NEEDED.yystypeβ now a preprocessor symbol instead of a typedef. preferyy_'parser_name'_stype.
π§ CONSERVED PREPROCESSOR SYMBOLS π§
these symbols are kept, and cannot be defined elsewhere, since they control private parameters of the generated parser, or are actually unused. you can #define them to the value you need, or indirectly to the name of a %define generated symbol if you want to be clean. β¨
YYINITDEPTHβ initial stack depth.YYMAXDEPTHβ stack overflow limit depth.yyoverflowβ instead of expanding withalloca, realloc manually or raise an error.
β OTHER ADDED PREPROCESSOR SYMBOLS β
YY_USE_CLASSβ indicates that a class will be produced. default if C++.
π C++ CLASS GENERATED π
okay so to keep the notation from being a whole mess, we write %SYMBOLNAME for the preprocessor symbol that gets generated by a %define of that name. fr fr, go look at how %define works to see its actual real name, that's where the truth lives.
And heads up bestie: sometimes two symbols differ by literally just one underscore, like yywrap and yy_wrap, and they are NOT the same thing at all. Not even close. In that case yy_wrap() is a virtual member function, and yywrap() is a macro. iykyk. π
π General Class declaration
class %CLASS %INHERIT
{
public:
#if %USE_CONST_TOKEN != 0
static const TOKEN_NEXT;
static const AND_SO_ON;
// ...
#else
enum %ENUM_TOKEN { %NULL_TOKEN
,TOKEN_FIRST=256
,TOKEN_NEXT=257
,AND_SO_ON=258
} ;
// ...
#endif
public:
int %PARSE (%PARSE_PARAM);
virtual void %ERROR(char *msg) %ERROR_BODY;
#ifdef %PURE
// if %PURE , we must pass the value and (eventually) the
location explicitely
#ifdef %LSP_NEEDED
// if and only if %LSP_NEEDED , we must pass the location
explicitely
virtual int %LEX (%STYPE *%LVAL,%LTYPE *%LLOC) %LEX_BODY;
#else
virtual int %LEX (%STYPE *%LVAL) %LEX_BODY;
#endif
#else
// if not %PURE , we must declare member to store the value and
(eventually) the location explicitely
// if not %PURE ,%NERRS and %CHAR are not local variable to
%PARSE, so must be member
virtual int %LEX() %LEX_BODY;
%STYPE %LVAL;
#ifdef %LSP_NEEDED
%LTYPE %LLOC;
#endif
int %NERRS;
int %CHAR;
#endif
#if %DEBUG != 0
int %DEBUG_FLAG; /* nonzero means print parse trace */
#endif
public:
%CLASS(%CONSTRUCTOR_PARAM);
public:
%MEMBERS
};
// here are defined the token constants
// for example:
#if %USE_CONST_TOKEN != 0
const %CLASS::TOKEN_FIRST=1;
#endif
// here is the construcor
%CLASS::%CLASS(%CONSTRUCTOR_PARAM) %CONSTRUCTOR_INIT
{
#if %DEBUG != 0
%DEBUG_FLAG=0;
#endif
%CONSTRUCTOR_CODE;
};
π¦ Default Class declaration
this is the whole vibe when you %define absolutely nothing β the header just makes this for you:
// Here is the default declaration made in the header when you %define
nothing
// typical yyltype
typedef struct yyltype
{
int timestamp;
int first_line;
int first_column;
int last_line;
int last_column;
char *text;
} yyltype;
// class definition
class parser
{
public:
enum yy_parser_enum_token { YY_parser_NULL_TOKEN
,TOKEN_FIRST=256
,TOKEN_NEXT=257
,AND_SO_ON=258
} ;
// ...
public:
int yyparse (yyparse_PARAM);
virtual void yyerror(char *msg) ;
#ifdef YY_parser_PURE
#ifdef YY_parser_LSP_NEEDED
virtual int yylex (int *yylval,yyltype *yylloc) ;
#else
virtual int yylex (int *yylval) ;
#endif
#else
virtual int yylex() %LEX_BODY;
int yylval;
#ifdef YY_parser_LSP_NEEDED
yyltype yylloc;
#endif
int yynerrs;
int yychar;
#endif
#if YY_parser_DEBUG != 0
int yydebug;
#endif
public:
parser();
public:
};
// here is the constructor code
parser::parser()
{
#if YY_parser_DEBUG != 0
yydebug=0;
#endif
};
β¨ USAGE β¨
Should replace bison, because it generate a far more customisable parser, still beeing compatible. like, it does everything bison does but cuter and with more knobs. π
You should always use the header facility. no cap.
Use it with flex++ (same author). they're a matching set, a little duo, iconic. π«Ά
π EXEMPLES π
This man page has been produced through a parser made in C++ with this version of bison and our version of flex++ (same author). yes bestie it's self-referential, it's giving meta, we love that for us. β¨
πΈ FILES πΈ
bison.ccβ main skeleton. the whole main character of skeletons.bison.hβ header skeleton.bison.hairyβ old main skeleton for semantic parser. Not adapted to this version. Kept for future works. (it's in the archive, bestie, do not touch it for now π₯²)
π ENVIRONNEMENT π
nothing here. empty. silence. the calmest section on the whole page. π§ββοΈ
π DIAGNOSTICS π
also nothing! we simply do not have diagnostics content. moving on, gorgeous. π
β SEE ALSO β
π¦ DOCUMENTATION π¦
yeah so this one is empty too. no thoughts, head empty, just vibes. π
π BUGS π
Tell us more ! fr fr, we want to know.
The %semantic_parser is no more supported. If you want to use it, adapt the skeletons, and maybe bison++ generator itself. The reason is that it seems unused, unuseful, not documented, and too complex for us to support. tell us if you use, need, or understand it. π
Header is not included in the parser code. Change made in the generated header are not used in the parser code, even if you include it volontarily, since it is guarded against re-include. So don't modify it. periodt.
For the same reasons, if you modify the header skeleton, or the code skeleton, report the changes in the other skeleton if applicable. If not done, incoherent declarations may lead to unpredictable result. π (and not the fun kind of unpredictable, the scary kind)
Use of defines for YYLTYPE, YYSTYPE, YYDEBUG is supported for backward compatibility in C, but should not be used with new features, as %defines or C++ classes. You can define them, and use them as with old bison in C only.
Parameters are richer than before, and nothing is removed. POSIX compliance can be enforced by not using extensions. If you want to forbide them, there is a good job ! π
π₯ FUTUR WORKS π₯
tell us !
- Support semantic parser. Is it really used ?
- POSIX compliance. is'nt it good now ?
- Use lex and yacc (flex/bison) to generate the scanner/parser. It would be comfortable for futur works, though very complicated. Who feel it good ?
- iostream : this is a great demand. this work will be done as soon as possible. The virtual members permit such work still easily.
π INSTALLATION π
With this install the executable is named bison++. rename it bison if you want, because it could replace bison. your call bestie, both are valid. π
π TESTS π
empty! nothing to report! we're just chilling! π
π AUTHORS π
Alain Coetmeur (coetmeur@icdc.fr), R&D department (RDT), Informatique-CDC, France. iconic. π«Ά
π RESTRICTIONS π
The words 'author', and 'us' mean the author and colleages, not GNU. We don't have contacted GNU about this, nowaday. If you're in GNU, we are ready to propose it to you, and you may tell us what you think about. no hard feelings, we're just saying. π
Based on GNU version 1.21 of bison. Modified by the author.
and that's the whole page, bestie β courtesy of GNU and RDT, dated 3/3/93, filed under BISON++(1). go forth and generate parsers, you absolute legend π
β¨
π¦ where this page comes from
- debian bookworm: bison++ 1.21.11-5+b1 Β· GPL-2.0-or-later
- debian trixie: bison++ 1.21.11-5+b1 Β· GPL-2.0-or-later
- ubuntu jammy: bison++ 1.21.11-5 Β· GPL-2.0-or-later
- ubuntu noble: bison++ 1.21.11-5 Β· GPL-2.0-or-later
- ubuntu resolute: bison++ 1.21.11-5build1 Β· GPL-2.0-or-later
- ubuntu stonking: bison++ 1.21.11-5build1 Β· GPL-2.0-or-later
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms