On Thu, October 8, 2009 14:34, Hans Aberg wrote: > On 8 Oct 2009, at 09:55, Rui Maciel wrote: > >> I'm writing a parser for a document format which has a couple of >> version out. >> The document format basically consists of a header field, where the >> document >> format version is specified and whose format is the same across all >> format >> versions, followed by multiple fields which differ between versions. >> >> Having that case in mind, what is the best strategy to write a bison >> parser >> that is capable of parsing multiple versions of a document format? > it is easy to have multiple generated parsers in one program and switch between them depending on version and possibly also easy to maintain. example how to do this is in gettext package in po-gram-gen.y http://savannah.gnu.org/projects/gettext it is using macros to remap parser variables like this and it works using bison yacc and glr grammars.
/* Remap normal yacc parser interface names (yyparse, yylex, yyerror, etc), as well as gratuitiously global symbol names, so we can have multiple yacc generated parsers in the same program. Note that these are only the variables produced by yacc. If other parser generators (bison, byacc, etc) produce additional global names that conflict at link time, then those parser generators need to be fixed instead of adding those names to this list. */ #define yymaxdepth po_gram_maxdepth #define yyparse po_gram_parse #define yylex po_gram_lex #define yyerror po_gram_error #define yylval po_gram_lval #define yychar po_gram_char #define yydebug po_gram_debug #define yypact po_gram_pact #define yyr1 po_gram_r1 #define yyr2 po_gram_r2 #define yydef po_gram_def #define yychk po_gram_chk #define yypgo po_gram_pgo #define yyact po_gram_act #define yyexca po_gram_exca #define yyerrflag po_gram_errflag #define yynerrs po_gram_nerrs #define yyps po_gram_ps #define yypv po_gram_pv #define yys po_gram_s #define yy_yys po_gram_yys #define yystate po_gram_state #define yytmp po_gram_tmp #define yyv po_gram_v #define yy_yyv po_gram_yyv #define yyval po_gram_val #define yylloc po_gram_lloc #define yyreds po_gram_reds /* With YYDEBUG defined */ #define yytoks po_gram_toks /* With YYDEBUG defined */ #define yylhs po_gram_yylhs #define yylen po_gram_yylen #define yydefred po_gram_yydefred #define yydgoto po_gram_yydgoto #define yysindex po_gram_yysindex #define yyrindex po_gram_yyrindex #define yygindex po_gram_yygindex #define yytable po_gram_yytable #define yycheck po_gram_yycheck _______________________________________________ help-bison@gnu.org http://lists.gnu.org/mailman/listinfo/help-bison