I used bison2.4.1, yacc1.9.1 and flex2.5.4 to create a simple parser under windows XP platform, but I found that yyparse return zero when syntax is error, this is or not a bug?
The parser's yacc grammar is as follows: /*statement.flex*/ /* */ %{ #include <stdio.h> #include "y.tab.h" %} %% [ \t]+ ; [\n]+ ; if return IF; else return ELSE; print return PRINT; true {yylval.value = 1; return TRUE;} false {yylval.value = 1; return FALSE;} [1-9][0-9]+ {yylval.value = atoi(yytext); return NUMBER;} . return yytext[0]; %% int yywrap(void) { return 1; } /* statement */ %{ #include <stdio.h> %} %union { int value; } %token IF ELSE PRINT %token <value> NUMBER TRUE FALSE %type <value> condition %% program: statement_list ; statement_list: statement_list statement | statement statement: IF condition statement { printf("single if statement.\n"); } | IF condition statement ELSE statement { printf("if else statement.\n"); } | PRINT NUMBER ';' { printf("number = %d\n", $2); } | '{' statement_list '}' { printf("compound statement.\n"); } ; condition: TRUE | FALSE | error {} ; %% extern FILE *yyin; extern char *yytext; int main(int argc, char *argv[]) { int nRet; if (argc < 2) return 1; yyin = fopen(argv[1], "r"); nRet = yyparse(); if (nRet == 0) { printf("This is a corrent program!\n"); } else { printf("This is a incorrent program!\n"); } return 0; } int yyerror(const char *str) { fprintf(stdout, "yytext = %s, %s\n", yytext, str); return 0; } The parser's flex grammar is as follows: /* */ %{ #include <stdio.h> #include "y.tab.h" %} %% [ \t]+ ; [\n]+ ; if return IF; else return ELSE; print return PRINT; true {yylval.value = 1; return TRUE;} false {yylval.value = 1; return FALSE;} [1-9][0-9]+ {yylval.value = atoi(yytext); return NUMBER;} . return yytext[0]; %% int yywrap(void) { return 1; } In addition, the parser runs normal under linux platform. (yyparse returns non-zero under linux platform, but yyparse return zero in windows xp platform, why? It it a bug? Who can explain the cause? Best regards, 2009-02-08 _________________________________________________________________ Hotmail: Trusted email with Microsoft’s powerful SPAM protection. https://signup.live.com/signup.aspx?id=60969 _______________________________________________ help-bison@gnu.org http://lists.gnu.org/mailman/listinfo/help-bison