mirror of
https://git.savannah.gnu.org/git/bison.git
synced 2026-03-09 12:23:04 +00:00
For associating token numbers with token names for "yacc.c", don't use
#define statements unless `--yacc' is specified; always use enum yytokentype. Most important discussions start at: <http://lists.gnu.org/archive/html/bison-patches/2005-09/msg00053.html>, <http://lists.gnu.org/archive/html/bison-patches/2005-12/msg00052.html>, and <http://lists.gnu.org/archive/html/bison-patches/2006-06/msg00043.html>. * NEWS (2.3+): Mention. * data/c.m4 (b4_yacc_if): New. (b4_token_enums_defines): Use b4_yacc_if to decide whether to add the token #define's. * doc/bison.texinfo (Bison Options): Describe the effect of `--yacc' on token name definitions. * src/getargs.c (usage): Capitalize `Yacc' in English. * src/output.c (prepare): Define b4_yacc_flag. * tests/regression.at (Early token definitions): Test that tokens names are defined before the pre-prologue not just before the post-prologue. Remove this test case and copy to... (Early token definitions with --yacc): ... this to test #define's. (Early token definitions without --yacc): ... and this to test enums.
This commit is contained in:
@@ -49,12 +49,12 @@ AT_CLEANUP
|
||||
|
||||
|
||||
|
||||
## ------------------------- ##
|
||||
## Early token definitions. ##
|
||||
## ------------------------- ##
|
||||
## ------------------------------------- ##
|
||||
## Early token definitions with --yacc. ##
|
||||
## ------------------------------------- ##
|
||||
|
||||
|
||||
AT_SETUP([Early token definitions])
|
||||
AT_SETUP([Early token definitions with --yacc])
|
||||
|
||||
# Found in GCJ: they expect the tokens to be defined before the user
|
||||
# prologue, so that they can use the token definitions in it.
|
||||
@@ -63,17 +63,56 @@ AT_DATA_GRAMMAR([input.y],
|
||||
[[%{
|
||||
void yyerror (const char *s);
|
||||
int yylex (void);
|
||||
#ifndef MY_TOKEN
|
||||
# error "MY_TOKEN not defined."
|
||||
#endif
|
||||
%}
|
||||
|
||||
%union
|
||||
{
|
||||
int val;
|
||||
};
|
||||
%{
|
||||
#ifndef MY_TOKEN
|
||||
# error "MY_TOKEN not defined."
|
||||
#endif
|
||||
%token MY_TOKEN
|
||||
%%
|
||||
exp: MY_TOKEN;
|
||||
%%
|
||||
]])
|
||||
|
||||
AT_CHECK([bison -y -o input.c input.y])
|
||||
AT_COMPILE([input.o], [-c input.c])
|
||||
|
||||
AT_CLEANUP
|
||||
|
||||
|
||||
|
||||
## ---------------------------------------- ##
|
||||
## Early token definitions without --yacc. ##
|
||||
## ---------------------------------------- ##
|
||||
|
||||
|
||||
AT_SETUP([Early token definitions without --yacc])
|
||||
|
||||
# Found in GCJ: they expect the tokens to be defined before the user
|
||||
# prologue, so that they can use the token definitions in it.
|
||||
|
||||
AT_DATA_GRAMMAR([input.y],
|
||||
[[%{
|
||||
#include <stdio.h>
|
||||
void yyerror (const char *s);
|
||||
int yylex (void);
|
||||
void print_my_token (void);
|
||||
void
|
||||
print_my_token (void)
|
||||
{
|
||||
enum yytokentype my_token = MY_TOKEN;
|
||||
printf ("%d\n", my_token);
|
||||
}
|
||||
%}
|
||||
|
||||
%union
|
||||
{
|
||||
int val;
|
||||
};
|
||||
%token MY_TOKEN
|
||||
%%
|
||||
exp: MY_TOKEN;
|
||||
|
||||
Reference in New Issue
Block a user