Unix Programming - Re: Writing a Parser

This is Interesting: Free IT Magazines  
Home > Archive > Unix Programming > July 2004 > Re: Writing a Parser





You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

Author Re: Writing a Parser
Jens.Toerring@physik.fu-berlin.de

2004-07-01, 5:58 pm

Cesar A. K. Grossmann <cakgguard-usenet2004@yahoo.com.br> wrote:
> Jens.Toerring@physik.fu-berlin.de wrote:
[vbcol=seagreen]
> How you write rules for (f)lex to identify correctly identifiers from
> strings?


> I had:


> [[:alpha:]][[:alnum:]_]* return IDENTIFIER;
> \"[^\"]+\" return STRING;


> It didn't worked (but the error can be in the bison rules, as the error
> is a "parse error").


If it's "parse error" it definitely sounds like something from the
parser and not the lexer. As far as I can see your (f)lex rule for
strings looks ok and a short test program like

%option noyywrap
%{
#include <stdio.h>
#include <stdlib.h>
%}
%%
\"[^\"]+\" printf( "Got a string: %s\n", yytext );
..
<<EOF>> return 0;
%%
int main( void )
{
yyin = stdin;
yylex( );
return EXIT_SUCCESS;
}

seems to work properly. So I guess it must be something parser related.
Perhaps you should simply print out in yyerror() the last token which
made the parser complain. Perhaps that helps to pinpoint where things
go wrong.
Regards, Jens
--
\ Jens Thoms Toerring ___ Jens.Toerring@physik.fu-berlin.de
\__________________________ http://www.toerring.de
Sponsored Links






Free braindumps | Software forum | Database administration forum

Copyright 2003 - 2008 webservertalk.com