bisonpp version 0.3

Bisonpp is a simple script that simplifies writing parsers using C++. Bisonpp calls bison, it has been tested with bison v.1.25. The commandline is

bisonpp [--help] [--class class-name] [bison-option].. file

Bisonpp uses a slightly modified version of bison.simple, called bisonpp.simple. The main differences are that the definitions of the following ``global'' variables have been removed

int             yynerrs;
int             yychar;
YYSTYPE         yylval;
void    	yyerror(const char* msg);
and that the declaration of yyparse() now reads
int @CLASS@::yyparse()
where @CLASS@ will be replaced by the class-name argument of bisonpp.

All this implies that the user must include a declaration of a class class-name in the first section of the bison input file. Typically, this will be done by an include directive, like

#include parser.h

where parser.h might look like this (in the example, the
class-name is ExpParser:
#ifndef	EXPPARSER_H
#define	EXPPARSER_H

#include	
#include	"explexer.h"
#include	"y.tab.h"

class ExpParser {
public:
private:
	ExpLexer	_lexer;

	// yynerrs, yychar, yylval, yyerror *must* be defined
	// because they are used by the bison-generated yyparse()
	// function

	int		yynerrs;
	int		yychar;
	YYSTYPE		yylval;

	void	yyerror(const char* msg) { 
		cerr << "yyerror: " << msg << endl; }

	int	yylex() { return _lexer.yylex(yylval); }

public:
	ExpParser(istream& is): _lexer(&is) {}
	
	int	yyparse();
};

#endif

Example

Here is complete example using flex and bisonpp to build a small program that evaluates the command line arguments as a simple arithmetic expression.

Download

Bisonpp is available from tinf2.vub.ac.be