Problem when running a lex/yacc parser
All,
I am currently seeing a problem when using lex/yacc to generate my parser (I suspect that gcc is the problem), I do not have the same result than the same one I use on my linux box. I am currently using XCode 2.4.
I have attached below the lexer and yacc file. I use the command line below to generate the C sources from the lex and yacc file, same ones on my Mac and on my linux box:
yacc -d problem.y
lex problem.l
gcc -o problem y.tab.c lex.yy.c
Normaly, when executing the binary and typing 1minutes, I should have the output below (working on the linux machine) :
1 seconds (0)
60 seconds (0)
,but on the Mac I have the output shown below with inverted values :
0 seconds (1)
0 seconds (60)
Could someone try to compile the sources on their Mac (I am quite currious to see the result with XCode 2.3).
---------------------- problem.l ------------------------
%{
#include <stdlib.h>
#include <time.h>
#include "y.tab.h"
extern YYSTYPE yylval;
%}
%%
minutes? { return MINUTE; }
weeks? { return WEEK; }
hours? { return HOUR; }
days? { return DAY; }
[0-9]+ { yylval.number=strtoull(yytext, NULL, 10); return NUMBER; }
[ \t\n\r]+ { }
%%
---------------------------------------------------------
---------------------- problem.y ------------------------
%{
#include <stdio.h>
#include <string.h>
#include <time.h>
int yyparse(void);
%}
%union
{
unsigned long long number;
}
%token MINUTE HOUR DAY WEEK MONTH YEAR
%token <number> NUMBER
%type <number> time_duration
%start time_duration
%%
time_duration:
NUMBER MINUTE
{
/* Convert from minutes to seconds */
printf("%d seconds (%d)\n\r", $$, $1);
$$ = $1 * 60;
printf("%d seconds (%d)\n\r", $$, $1);
}
|
NUMBER HOUR
{
/* Convert from hours to seconds */
$$ = $1 * 60 * 60;
printf("%d seconds\n\r", $$);
}
|
NUMBER DAY
{
/* Convert from days to seconds */
$$ = $1 * 60 * 60 * 24;
printf("%d seconds\n\r", $$);
}
|
NUMBER WEEK
{
/* Convert from weeks to seconds */
$$ = $1 * 60 * 60 * 24 * 7;
printf("%d seconds\n\r", $$);
}
;
%%
void yyerror(const char *str)
{
fprintf(stderr, "Error: %s\n", str);
}
int yywrap()
{
return 1;
}
main()
{
yyparse();
}
---------------------------------------------------------
PowerBook G4 Mac OS X (10.4.7) Affected with the faulty lower SODIMM (and not in the serial range of the ones recognized with a fau
I am currently seeing a problem when using lex/yacc to generate my parser (I suspect that gcc is the problem), I do not have the same result than the same one I use on my linux box. I am currently using XCode 2.4.
I have attached below the lexer and yacc file. I use the command line below to generate the C sources from the lex and yacc file, same ones on my Mac and on my linux box:
yacc -d problem.y
lex problem.l
gcc -o problem y.tab.c lex.yy.c
Normaly, when executing the binary and typing 1minutes, I should have the output below (working on the linux machine) :
1 seconds (0)
60 seconds (0)
,but on the Mac I have the output shown below with inverted values :
0 seconds (1)
0 seconds (60)
Could someone try to compile the sources on their Mac (I am quite currious to see the result with XCode 2.3).
---------------------- problem.l ------------------------
%{
#include <stdlib.h>
#include <time.h>
#include "y.tab.h"
extern YYSTYPE yylval;
%}
%%
minutes? { return MINUTE; }
weeks? { return WEEK; }
hours? { return HOUR; }
days? { return DAY; }
[0-9]+ { yylval.number=strtoull(yytext, NULL, 10); return NUMBER; }
[ \t\n\r]+ { }
%%
---------------------------------------------------------
---------------------- problem.y ------------------------
%{
#include <stdio.h>
#include <string.h>
#include <time.h>
int yyparse(void);
%}
%union
{
unsigned long long number;
}
%token MINUTE HOUR DAY WEEK MONTH YEAR
%token <number> NUMBER
%type <number> time_duration
%start time_duration
%%
time_duration:
NUMBER MINUTE
{
/* Convert from minutes to seconds */
printf("%d seconds (%d)\n\r", $$, $1);
$$ = $1 * 60;
printf("%d seconds (%d)\n\r", $$, $1);
}
|
NUMBER HOUR
{
/* Convert from hours to seconds */
$$ = $1 * 60 * 60;
printf("%d seconds\n\r", $$);
}
|
NUMBER DAY
{
/* Convert from days to seconds */
$$ = $1 * 60 * 60 * 24;
printf("%d seconds\n\r", $$);
}
|
NUMBER WEEK
{
/* Convert from weeks to seconds */
$$ = $1 * 60 * 60 * 24 * 7;
printf("%d seconds\n\r", $$);
}
;
%%
void yyerror(const char *str)
{
fprintf(stderr, "Error: %s\n", str);
}
int yywrap()
{
return 1;
}
main()
{
yyparse();
}
---------------------------------------------------------
PowerBook G4 Mac OS X (10.4.7) Affected with the faulty lower SODIMM (and not in the serial range of the ones recognized with a fau
PowerBook G4, Mac OS X (10.4.7)