Question in Flex (parser)

Posted by shkk on Stack Overflow See other posts from Stack Overflow or by shkk
Published on 2010-12-10T14:48:39Z Indexed on 2010/12/22 10:54 UTC
Read the original article Hit count: 143

Filed under:

Hello... I want to ask you a question about Flex, the program for parsing code. Supposing I have an instruction like this one, in the rules part:

"=" BEGIN(attribution);

<attribution>{var_name} { fprintf(yyout, "="); ECHO; }

<attribution>";" BEGIN(INITIAL);

{var_name} is a regular expression that matches a variable's name, and all I want to do is to copy at the output all the attribution instructions, such as a = 3; or b = a;

My rule though cannot write with fprintf the left member of the attribution, but only = 3; or =a;

One solution for that might be that, after I make the match "=" and I am in the attribution state, to go 2 positions back as to get the left operand as well. How can I do that in Flex?

© Stack Overflow or respective owner

Related posts about gnu-flex