| 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
|