help-bison
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Newbie question - yyval problems


From: Hans Aberg
Subject: Re: Newbie question - yyval problems
Date: Mon, 20 May 2002 12:44:27 +0200

At 20:21 +0200 2002/05/19, Boris Köster wrote:
>I have a problem with bison, and I don´t know what I am doing
>wrong.
>%%
>
><INITIAL,paramscan>Tante|Geschlecht|Sexy  {
>                        yyval=strdup(yytext);

I figure it should be yylval here, and other similar places. Also define
YYSTYPE properly, say to char*.

As a matter of style, you seem to overuse the Flex start conditions; if you
put the parsing onto the Bison parser, it might be easier to generate
errors: from the parser instead of the lexer. For example:

Flex:

%{
#define get_text yylval(pos, red) \
  = strndup(yytext + (pos), yyleng - (pos + red))
  /* Starting at pos, taking away red from the end,
     I got strndup right -- I use C++! */
%}

%x string_scan

%%

"="               { get_text(0, 0); return ASSOP; }
{identifier}      { get_text(0, 0); return KEYWORD; }

\"                { BEGIN(string_scan); }
<string_scan>{string} { ... BEGIN(INITIAL); get_text(1, 1);
                        return STRING; }

...


Bison:

%%
...

ausdruck: KEYWORD ASSOP STRING EOL { ... };

For questions about Flex, use:
  Help-flex mailing list
  address@hidden
  http://mail.gnu.org/mailman/listinfo/help-flex

  Hans Aberg





reply via email to

[Prev in Thread] Current Thread [Next in Thread]