Re: Writing a Parser
Web Server forum
Back To The Forum Home!Search!Private Messaging System

Web Server Talk Web Server Talk > Unix and Linux reviews > Free Unix support > Unix Programming > Re: Writing a Parser




  Last Thread   Next Thread Next
  Show Printable Version Email this Page Subscribe to this Thread      Post New Thread    Post A Reply      

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


View Ip Address Report This Message To A Moderator Edit/Delete Message


 
07-01-04 10: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





[ Post a follow-up to this message ]



    Sponsored Links  




 





   All times are GMT. The time now is 09:26 AM.      Post New Thread    Post A Reply      
  Last Thread   Next Thread Next


Most Popular forums 

Forum Jump:
Rate This Thread:

Forum Rules:
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is OFF
vB code is ON
Smilies are ON
[IMG] code is OFF
 
Medical and Health forum | Computer Games Reviews | Graphics design forum

Back To The Top
Home | Usercp | Faq | Register