Hello,
I'm new to Bison and tried to write my first bison Parser.
Unfortunately, the Parser only gives my a Syntaxerror.
It should parse Dates in the Form 'DD.MM.[YY]YY
hh:mm[:ss[.sss]]' (without the '').
I use bison version 2.4.3 and gcc version 4.2.4 under Ubuntu 8.04 or
Fedora 14.
The Output of Bison and my parser file are attached.
I'm not sure what other Information you could need, so please help me
out if you miss something.
Kind regards
icehawk
gerold@gerold-desktop:/media/A-DATA UFD/c/bison$ bison zeit.y && echo "" && gcc -o zeit zeit.tab.c && echo "12.12.2009 12:14:12" |./zeit
Starting parse
Entering state 0
Reading a token: Next token is token $undefined ()
Reducing stack by rule 1 (line 18):
-> $$ = nterm input ()
Stack now 0
Entering state 3
Next token is token $undefined ()
syntax error
Error: popping nterm input ()
Stack now 0
Cleanup: discarding lookahead token $undefined ()
Stack now 0
/* Parst eine Zeitangabe der Form: DD.MM.[YY]YY hh:mm[:ss[.sss]] */
%{
#include <stdio.h>
#include <ctype.h>
int yylex();
void yyerror();
%}
%debug
%language "c"
%token TWONUM
%token WHITESPACE
%token THREENUM
%%
input : /* Nichts */
| zeile '\n'
;
zeile : datum WHITESPACE zeit
| WHITESPACE datum WHITESPACE zeit WHITESPACE
// | error {yyerrok;}
;
/* Datum */
datum : TWONUM '.' TWONUM '.' jahr
// | error {yyerrok;}
;
jahr : TWONUM
| TWONUM TWONUM
;
/* Zeit */
zeit : TWONUM ':' TWONUM ':'
| TWONUM ':' TWONUM ':' TWONUM
| TWONUM ':' TWONUM ':' TWONUM '.' THREENUM
;
%%
int main()
{
yydebug = 1;
yyparse();
return 0;
}
int yylex()
{
int zeichen = 0;
int zeichenold = 0;
/* WHITESPACE */
if( (zeichen = getchar()) == ' ' || zeichen == '\t' )
{
while( (zeichen = getchar()) == ' ' || zeichen == '\t') /* überspringe */ ;
printf("return WHITESPACE;");
return WHITESPACE;
}
if(isdigit(zeichen = getchar()))
{
zeichenold = zeichen;
if( isdigit(zeichen = getchar()) )
{
if( isdigit(zeichen = getchar()) ) return THREENUM;
else
{
ungetc(zeichen,stdin);
printf("return TWONUM;");
return TWONUM;
}
}
else
{
ungetc(zeichen,stdin);
printf("return %d;",zeichenold);
return zeichenold;
}
}
if( (zeichen = getchar()) != EOF )
{
printf("return %d;",zeichen);
return zeichen;
}
else
{
printf("return 0;");
return 0;
}
}
/* Called by yyparse on error. */
void yyerror (char const *s)
{
fprintf (stderr, "%s\n", s);
}
_______________________________________________
[email protected] https://lists.gnu.org/mailman/listinfo/help-bison