* 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.
This commit is contained in:
Akim Demaille
2006-03-10 13:30:19 +00:00
parent 6e0f828781
commit c095d689c3
5 changed files with 24 additions and 9 deletions

View File

@@ -1,3 +1,10 @@
2006-03-10 Akim Demaille <akim@lrde.epita.fr>
* 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.
2006-03-09 Paul Eggert <eggert@cs.ucla.edu> 2006-03-09 Paul Eggert <eggert@cs.ucla.edu>
Fix two nits reported by twlevo, plus one more that I discovered. Fix two nits reported by twlevo, plus one more that I discovered.

View File

@@ -34,16 +34,15 @@ m4_define_default([b4_filename_type], [std::string])
# b4_token_enums(LIST-OF-PAIRS-TOKEN-NAME-TOKEN-NUMBER) # 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_define([b4_token_enums],
[m4_if([$@], [[]], [],
[/* Tokens. */ [/* Tokens. */
enum yytokentype { enum yytokentype {
m4_map_sep([ b4_token_enum], [, m4_map_sep([ b4_token_enum], [,
], ],
[$@]) [$@])
}; };
])]) ])
## ----------------- ## ## ----------------- ##

View File

@@ -312,6 +312,8 @@ b4_syncline([@oline@], [@ofile@])
{ {
]b4_token_enums(b4_tokens)[ ]b4_token_enums(b4_tokens)[
}; };
/// Token type.
typedef token::yytokentype token_type;
/// Build a parser object. /// Build a parser object.
]b4_parser_class_name[ (]b4_parse_param_decl[); ]b4_parser_class_name[ (]b4_parse_param_decl[);

View File

@@ -120,6 +120,8 @@ b4_syncline([@oline@], [@ofile@])
{ {
]b4_token_enums(b4_tokens)[ ]b4_token_enums(b4_tokens)[
}; };
/// Token type.
typedef token::yytokentype token_type;
/// Build a parser object. /// Build a parser object.
]b4_parser_class_name[ (]b4_parse_param_decl[); ]b4_parser_class_name[ (]b4_parse_param_decl[);

View File

@@ -7326,10 +7326,11 @@ factor both as follows.
@comment file: calc++-driver.hh @comment file: calc++-driver.hh
@example @example
// Announce to Flex the prototype we want for lexing function, ... // Announce to Flex the prototype we want for lexing function, ...
# define YY_DECL \ # define YY_DECL \
int yylex (yy::calcxx_parser::semantic_type* yylval, \ yy::calcxx_parser::token_type \
yy::calcxx_parser::location_type* yylloc, \ yylex (yy::calcxx_parser::semantic_type* yylval, \
calcxx_driver& driver) yy::calcxx_parser::location_type* yylloc, \
calcxx_driver& driver)
// ... and declare it for the parser's sake. // ... and declare it for the parser's sake.
YY_DECL; YY_DECL;
@end example @end example
@@ -7621,6 +7622,10 @@ parser's to get the set of defined tokens.
<http://bugs.debian.org/cgi-bin/bugreport.cgi?bug=333231>. */ <http://bugs.debian.org/cgi-bin/bugreport.cgi?bug=333231>. */
# undef yywrap # undef yywrap
# define yywrap() 1 # 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
%@} %@}
@end example @end example
@@ -7678,8 +7683,8 @@ It is convenient to use a typedef to shorten
%@{ %@{
typedef yy::calcxx_parser::token token; typedef yy::calcxx_parser::token token;
%@} %@}
/* Convert ints to the actual type of tokens. */
[-+*/] return yytext[0]; [-+*/] return yy::calcxx_parser::token_type (yytext[0]);
":=" return token::ASSIGN; ":=" return token::ASSIGN;
@{int@} @{ @{int@} @{
errno = 0; errno = 0;