[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: simple parsing problem
From: |
Steve Fernandez |
Subject: |
Re: simple parsing problem |
Date: |
Mon, 28 Oct 2002 18:21:24 +0530 |
User-agent: |
Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.0.0) Gecko/20020623 Debian/1.0.0-0.woody.1 |
anton wilson wrote:
>The following is a simple test grammer I wrote to recognize token
sequences
>composed of an optional INDENT or DEDENT token followed by an ID and
then a
>NEWLINE.
>
>When the lexer sends it the token sequence:
>
>ID
>NEWLINE
>INDENT
>ID
>NEWLINE
>DEDENT
>ID
>NEWLINE
>
>there is a syntax error called between the DEDENT and the ID.
>Is there something wrong with my grammer? Thanks.
>
>
>%token NEWLINE INDENT DEDENT ID
>
>
>%%
>
>lines: {printf("lines\n");}
>| lines line {printf("lines\n");}
>;
>line: id newline {printf("line\n");}
>| dedent id newline {printf("line\n");}
>| indent id newline {printf("line\n");}
>;
>newline: NEWLINE {printf("newline token\n");}
>;
>indent: INDENT {printf("indent token\n");}
>;
>dedent: DEDENT {printf("dedent token\n");}
>;
>id: ID {printf("id token\n");}
>
>%%
>
>
>
>_______________________________________________
>address@hidden http://mail.gnu.org/mailman/listinfo/help-bison
>
>
>
Hi Anton,
Is this the output you expected? Seems correct to me :-)
address@hidden:~# lex test.l
address@hidden:~# yacc -d test.y -o test.tab.c
address@hidden:~# ./test < input
lines
id token
newline token
line
lines
indent token
id token
newline token
line
lines
dedent token
id token
newline token
line
lines
I think the error was caused because of the extra spaces that
were in your grammar between dedent and id. The source files that I used
are attached. Let me know if this was the problem
Regards,
Steve Fernandez.
--
Registered Linux User #211615
Registered Linux Machine #98619
"I am not young enough to know everything."
%{
#include "lex.yy.c"
int yylex ( void );
int yyerror ( char * );
int main ( void );
%}
%token NEWLINE INDENT DEDENT ID
%%
lines : { printf ( "lines\n" ); }
| lines line { printf ( "lines\n" ); }
;
line : id newline {printf("line\n");}
| dedent id newline {printf("line\n");}
| indent id newline {printf("line\n");}
;
newline : NEWLINE { printf ( "newline token\n" ); }
;
indent : INDENT { printf ( "indent token\n" ); }
;
dedent : DEDENT { printf ( "dedent token\n" ); }
;
id : ID { printf ( "id token\n" ); }
;
%%
int main ( void )
{
yyparse ( );
return ( 0 );
}
int yyerror ( char *error )
{
printf ( "%s\n", error );
return ( 0 );
}
%option noyywrap
%{
#include "test.tab.h"
%}
%%
NEWLINE return ( NEWLINE );
INDENT return ( INDENT );
DEDENT return ( DEDENT );
ID return ( ID );
ID
NEWLINE
INDENT
ID
NEWLINE
DEDENT
ID
NEWLINE
smime.p7s
Description: S/MIME Cryptographic Signature