Dear All, I write a .l file and a .y file to parse the struct: somebody=age, and the result is to print somebody's age is .... But the parser can work at the first time, at the second time it reports wrong although input is right. I don't know why, and here is the code: 3.l
%{ #include "3.tab.h" #include<string.h> extern void yyerror( char*); %} %% [a-zA-Z]+ {yylval.str=strdup(yytext); return NAME;} [0-9]+ {yylval.num = atoi(yytext); return AGE;} [ \t\n] {;} [=;] {return yytext[0];} . {ECHO; yyerror ("unexpected character");} %% int yywrap (void) {return 1;} ############################### 3.y %{ #include<stdio.h> extern int yylex(); void yyerror(const char*); %} %union{ char* str; int num; } %token <str> NAME //%token '=' %token <num> AGE %% exp: | NAME '=' AGE {printf("the man %s's age is%d\n",$1,$3 );} ; %% void yyerror(const char*s) { fprintf(stderr, "%s\n", s); } int main() { return yyparse(); } _______________________________________________ help-bison@gnu.org http://lists.gnu.org/mailman/listinfo/help-bison