You get Bison to create a list of tokens; your lexer uses the list created by Bison.
bison -d grammar.y # Generates grammar.tab.c and grammar.tab.h
Then your lexer uses grammar.tab.h
:
$ cat grammar.y %token ID %% program: /* Nothing */ | program ID ; %% $ cat lexer.l %{ #include "grammar.tab.h" %} %% [a-zA-Z][A-Za-z_0-9]+ { return ID; } [ \t\n] { /* Nothing */ } . { return *yytext; } %% $ bison -d grammar.y $ flex lexer.l $ gcc -o testgrammar grammar.tab.c lex.yy.c -ly -lfl $ ./testgrammar id est quod erat demonstrandum $
Bison 2.4.3 on MacOS X 10.7.2 generates token numbers as enum
, not as a series of #define
values βββ to get the names of tokens in the symbol table for debuggers (a very good idea!).
source share