Index: ChangeLog from Akim Demaille * data/c.m4 (b4_token_enum): Always define the enum of tokens, even if empty. * data/lalrl1.cc, data/glr.cc (parser::token_type): New. * doc/bison.texinfo (Calc++ Scanner): Use it. Index: data/c++.m4 =================================================================== RCS file: /cvsroot/bison/bison/data/c++.m4,v retrieving revision 1.4 diff -u -r1.4 c++.m4 --- data/c++.m4 2 Jan 2006 16:06:11 -0000 1.4 +++ data/c++.m4 10 Mar 2006 13:29:34 -0000 @@ -34,16 +34,15 @@ # b4_token_enums(LIST-OF-PAIRS-TOKEN-NAME-TOKEN-NUMBER) # ----------------------------------------------------- -# Output the definition of the tokens (if there are) as enums. +# Output the definition of the tokens as enums. m4_define([b4_token_enums], -[m4_if(address@hidden, [[]], [], [/* Tokens. */ enum yytokentype { m4_map_sep([ b4_token_enum], [, ], address@hidden) }; -])]) +]) ## ----------------- ## Index: data/glr.cc =================================================================== RCS file: /cvsroot/bison/bison/data/glr.cc,v retrieving revision 1.12 diff -u -r1.12 glr.cc --- data/glr.cc 22 Jan 2006 07:38:49 -0000 1.12 +++ data/glr.cc 10 Mar 2006 13:29:34 -0000 @@ -312,6 +312,8 @@ { ]b4_token_enums(b4_tokens)[ }; + /// Token type. + typedef token::yytokentype token_type; /// Build a parser object. ]b4_parser_class_name[ (]b4_parse_param_decl[); Index: data/lalr1.cc =================================================================== RCS file: /cvsroot/bison/bison/data/lalr1.cc,v retrieving revision 1.123 diff -u -r1.123 lalr1.cc --- data/lalr1.cc 2 Feb 2006 05:27:35 -0000 1.123 +++ data/lalr1.cc 10 Mar 2006 13:29:34 -0000 @@ -120,6 +120,8 @@ { ]b4_token_enums(b4_tokens)[ }; + /// Token type. + typedef token::yytokentype token_type; /// Build a parser object. ]b4_parser_class_name[ (]b4_parse_param_decl[); Index: doc/bison.texinfo =================================================================== RCS file: /cvsroot/bison/bison/doc/bison.texinfo,v retrieving revision 1.179 diff -u -r1.179 bison.texinfo --- doc/bison.texinfo 8 Mar 2006 19:34:56 -0000 1.179 +++ doc/bison.texinfo 10 Mar 2006 13:29:35 -0000 @@ -7326,10 +7326,11 @@ @comment file: calc++-driver.hh @example // Announce to Flex the prototype we want for lexing function, ... -# define YY_DECL \ - int yylex (yy::calcxx_parser::semantic_type* yylval, \ - yy::calcxx_parser::location_type* yylloc, \ - calcxx_driver& driver) +# define YY_DECL \ + yy::calcxx_parser::token_type \ + yylex (yy::calcxx_parser::semantic_type* yylval, \ + yy::calcxx_parser::location_type* yylloc, \ + calcxx_driver& driver) // ... and declare it for the parser's sake. YY_DECL; @end example @@ -7621,6 +7622,10 @@ . */ # undef yywrap # define yywrap() 1 +/* By default yylex returns int, we use token_type. + Unfortunately yyterminate by default returns 0, which is + not of token_type. */ +#define yyterminate() return token::END address@hidden @end example @@ -7678,8 +7683,8 @@ address@hidden typedef yy::calcxx_parser::token token; address@hidden - -[-+*/] return yytext[0]; + /* Convert ints to the actual type of tokens. */ +[-+*/] return yy::calcxx_parser::token_type (yytext[0]); ":=" return token::ASSIGN; @address@hidden @{ errno = 0;