help-flex
[Top][All Lists]
Advanced

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

Re: scaning from memory


From: Moretti, Luciano (MED)
Subject: Re: scaning from memory
Date: Wed, 4 Aug 2004 15:16:46 -0500

In the original post from 2001/04/25 
From:   John W. Millaway         
Subject:        Re: scaning from memory  
Date:   Wed, 25 Apr 2001 10:50:36 -0700 (PDT)    
  _____  

> I am trying to write a parser with flex/bison scaning strings
> in memory, but I can't make it work. I am pretty sure it's a
> common way of using flex, but I didn't find any example on the
> web. (I have read the manual, of course). I have found several
> times this question, but no answer.
> I don't know where to put the yy_scan_string() statement. I
> use the <<EOF>> rule as last rule. And I have also modified
> the prototype of the yylex function with
> #define YY_DECL int yylex(YYSTYPE *lvalp,char *name)
> where name is the string I want to parse.

You should call yy_scan_string before calling yylex. Here are two examples:

1. In general:

  YY_BUFFER_STATE buf_state = yy_scan_string( str );
  while( yylex() != 0 )
      ;
  yy_delete_buffer(buf_state);


2. Your particular scanner:

%{
#define YY_USER_INIT  buf_state = yy_scan_string( name );
%}
%%
    static YY_BUFFER_STATE buf_state;

<<EOF>>   { yy_buffer_delete( buf_state ); yyterminate(); }
%%

-John
-------------------------------------------------

Ok, I know this was a while ago, but I can't seem to find a solution to my
problem.
I'm trying to use the basic code from 1, but GCC complains that 

main.c:36: error: `YY_BUFFER_STATE' undeclared (first use in this function)

I can't seem to find out where YY_BUFFER_STATE is declared.  The only other
references I can seem to find are in my generated .c file, and I don't see
where it's declared there either.

any help would be appreciated,

Luciano Moretti





reply via email to

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