help-flex
[Top][All Lists]
Advanced

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

Re: A Beginner's (probably stupid) Question


From: arief_mulya
Subject: Re: A Beginner's (probably stupid) Question
Date: Wed, 09 Apr 2003 12:05:03 +0700
User-agent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.0.0) Gecko/20020623 Debian/1.0.0-0.woody.1

John wrote:
How do exactly one do interconnection between flex and
bison? I mean, how do the two interconnect with each other?


In two ways:

1. Bison calls the function yylex(), which should return an integer
   token. Flex's job is to generate yylex. Certain flex actions
   (section 2 of flex input) should return the current token value. In
   this way, flex actions communicate the current token value to
   bison.

2. Bison provides the global variables yylval, and yylloc. Flex
   actions may set the values of yylval and yylloc before returning a
   token. In this way, flex actions communicate additional information
   about the current token to bison.

Notice that the communication is one-way, from flex to bison.  Rarely
does it flow the other way.


Dear John,
Thanks for the enlightment.


I currently face a quite of heavy misguide here.

Let say I have this kind of line:
ABCDE=1231ABC,BCDEF=123414; <the ';' can also be a '!' a ',' or a space>

I want to take only the values after the '=' sign.

So in my first (rather stupid) tries I do this in my scanner:
---------------------------------------------------------
%%
.        /* skips */
[ \t]+$  /* garbage */

ABCDE=[0-9]*[A-Z]*/[,! ;]                {
                        yylval = (char *) strndup(
strchr(yytext, '=') + 1, yyleng - 1);
                        return ABCDE;
                        }
BCDEF=[0-9]*[A-Z]*/[,! ;]     {
                        yylval = (char *) strndup(
strchr(yytext, '=') + 1, yyleng - 1);
                        return BCDEF;
                        }
----------------------------------------------------------


and in my parser I do this:
----------------------------------------------------------
%token ABCDE
%token BCDEF

%%
exp:      ABCDE {printf("%s\t", $1); free($1);}
        | BCDEF {printf("%s\t", $1); free($1);}
;

----------------------------------------------------------

But it keep getting me blanks output, or syntax error.

I already do #define YYSTYPE char *
(which I learn, has also re-defined in the parser.h file manually, if it wants to be recognized in the scanner file)

Should I use my own variable(s)? to transfer data?

Any clues are very much appreciated.
Mean while I'm going to google on this matter. See if I can find some working examples.


Best Regards,
arief_mulya
--






reply via email to

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