[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
tokens?
From: |
Maarten Marien |
Subject: |
tokens? |
Date: |
Mon, 10 Nov 2003 14:26:14 +0100 |
Hello,
I have a question regarding the header-generating option of bison++ (-d). Do
I need to specify any other options to be able to read the definitions of
tokens in the header file? I thought just including "parse.h" ought to do the
trick? The definitions of the tokens NAME and NUMBER are in the header file,
but there's a whole bunch of #ifdef and #ifndefs in front...
Source files are below, flex version is 2.5.4 and g++ version is 2.95.4.
Thanks a lot for your help,
Maarten.
==== parse.yy: =====
%token NAME NUMBER
%%
statement: NAME '=' expression
| expression { printf("= %d\n", $1); }
;
expression: expression '+' NUMBER { $$ = $1 + $3; }
| expression '-' NUMBER { $$ = $1 - $3; }
| NUMBER { $$ = $1; }
;
==== lex.ll: =====
%{
#include "parse.h"
extern int yylval;
%}
%%
[0-9]+ { yylval = atoi(yytext); return NUMBER; }
[ \t] ; /* ignore white space */
\n return 0; /* logical EOF */
. return yytext[0];
%%
==== bash: ====
$ bison++ -d --output=parse.tab.cc parse.yy
parse.yy:11 parser name defined to default :"parse"
$ ls
lex.ll main.cc parse.h parse.tab.cc parse.yy
$ flex -+ lex.ll
$ g++ -c -o lex.yy.o lex.yy.cc
lex.ll: In method `int yyFlexLexer::yylex()':
lex.ll:7: `NUMBER' undeclared (first use this function)
lex.ll:7: (Each undeclared identifier is reported only once
lex.ll:7: for each function it appears in.)
$
- tokens?,
Maarten Marien <=