Related articles |
---|
very simple preprocessor using flex viniciuspetrucci@gmail.com (2005-04-02) |
Re: very simple preprocessor using flex viniciuspetrucci@gmail.com (2005-04-11) |
From: | viniciuspetrucci@gmail.com (vpetrucci) |
Newsgroups: | comp.compilers |
Date: | 11 Apr 2005 00:13:33 -0400 |
Organization: | http://groups.google.com |
References: | 05-04-012 |
Keywords: | macros |
Posted-Date: | 11 Apr 2005 00:13:33 EDT |
> [Macro expansion is tricky. Either you need to build your own pushback
> system, or you have to treat each macro that's being expanded like a
> little nested include file. People have known how to do this since
> the 1960s, but it's not written down in many places. -John]
John,
By "expanded like a little nested include file" Do You mean using
Something like this:
{DEFNAME} {
p_def p = def_find(yytext);
YY_BUFFER_STATE oldbuf;
if (p) {
/* rescan replaced input */
oldbuf = YY_CURRENT_BUFFER;
yy_switch_to_buffer(yy_scan_string(p->s2));
BEGIN INITIAL;
yy_delete_buffer(YY_CURRENT_BUFFER);
yy_switch_to_buffer(oldbuf);
} else {
REJECT;
}
}
The problem is that bison (parser) has already called yylex() and want
back a return of some token matched. when i switch to buffer and call
BEGIN, the lexer continue to scan or wait _another_ call yylex() by
the parser?
thanks,
Vinicius
[That's kind of it except for the minor detail that your code doesn't actually
scan the included text. You need to keep an explicit stack of sources. -John]
Return to the
comp.compilers page.
Search the
comp.compilers archives again.