|
Home > Archive > Unix Programming > April 2005 > Flex/Bison Question (lex & yacc example question)
You are viewing an archived Text-only version of the thread.
To view this thread in it's original format and/or if you want to reply to
this thread please [click here]
| Author |
Flex/Bison Question (lex & yacc example question)
|
|
| pmatos 2005-04-20, 8:48 pm |
| Hi all,
I've just been having this bison/flex question and well, though this
would be a good place to ask.
Just reading lex & yacc book and trying example ch3-01.
I have calc.l:
%{
#include "calc.tab.h"
extern int yylval;
%}
%%
[0-9]+ { yylval = atoi{yytext}; return NUMBER; }
[ \t] ;
\n return 0;
.. return yytext[0];
%%
and calc.y:
%token NAME NUMBER
%%
statement: NAME '=' expression
| expression { printf("= %d\n", $1); }
;
expression: NUMBER '+' NUMBER {$$ = $1 + $3; }
| NUMBER '-' NUMBER {$$ = $1 - $3; }
| NUMBER {$$ = $1; }
;
When I try to compile... no matter gcc version (tried 2.95 and 3.3.5) I
get:
pmatos@euler calc $ gcc lex.yy.c calc.tab.c -o calc
calc.l: In function `yylex':
calc.l:8: warning: assignment makes integer from pointer without a cast
calc.l:8: parse error before `{'
calc.l:10: case label not within a switch statement
calc.l:11: case label not within a switch statement
calc.l:12: case label not within a switch statement
calc.l:13: case label not within a switch statement
lex.yy.c:630: case label not within a switch statement
lex.yy.c:633: case label not within a switch statement
lex.yy.c:755: default label not within a switch statement
lex.yy.c: At top level:
lex.yy.c:760: parse error before `}'
In the book everything seems to work fine. Any suggestions? (using
bison 2.0 and flex 2.5.4a)
Cheers,
Paulo Matos
| |
| pmatos 2005-04-20, 8:48 pm |
| LOL
I'm sorry...
I'm doing atoi{yytext} instead of atoi(yytext) above... ;)
| |
| T.M. Sommers 2005-04-21, 2:54 am |
| pmatos wrote:
>
> I've just been having this bison/flex question and well, though this
> would be a good place to ask.
> Just reading lex & yacc book and trying example ch3-01.
comp.compilers is a good place to ask about the lex and yacc
book; the author is the moderator.
--
Thomas M. Sommers -- tms@nj.net -- AB2SB
| |
| pmatos 2005-04-21, 2:54 am |
| Ah, that's a very nice suggestion... ;) Thanks a lot...
|
|
|
|
|