[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: scaning from memory
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
__________________________________________________
Do You Yahoo!?
Yahoo! Auctions - buy the things you want at great prices
http://auctions.yahoo.com/
- scaning from memory, alexandre.gouraud, 2001/04/25
- Re: scaning from memory,
John W. Millaway <=