help-bison
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

bison2.4.1 perhaps has a bug under winxp platform.


From: Supervisor Root
Subject: bison2.4.1 perhaps has a bug under winxp platform.
Date: Mon, 8 Feb 2010 22:40:34 +0800


Through my testing, I found there was a bug in bison2.5.4.

 

I used bison2.4.1, yacc1.9.1 and flex2.5.4 to create a simple parser under 
windows XP platform and Linux platform.
 
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], "rb");
 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] ;
[\r] ;
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;
}

 

////////////////////////////////////////////////////////////////////////// 
The test file is as follows:
/* 1.st */
if true
  if true
  {
 if a
  print 123;
 }
 else
 print 456;

The running result is as follows:

yytext = a, syntax error
a error!
a error!
number = 123
single if statement.
compound statement.
number = 456
if else statement.
single if statement.
This is a corrent program!


////////////////////////////////////////////////////////



Who can explain the cause?
 
Best regards,
 
2009-02-08









Hotmail: Powerful Free email with security by Microsoft. Get it now.
                                          
_________________________________________________________________
Hotmail: Trusted email with Microsoft’s powerful SPAM protection.
https://signup.live.com/signup.aspx?id=60969


reply via email to

[Prev in Thread] Current Thread [Next in Thread]