| [ << ] | [ < ] | [ Up ] | [ > ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
How can I expand macros in the input?
The best way to approach this problem is at a higher level, e.g., in the parser.
However, you can do this using multiple input buffers.
%%
macro/[a-z]+ {
/* Saw the macro "macro" followed by extra stuff. */
main_buffer = YY_CURRENT_BUFFER;
expansion_buffer = yy_scan_string(expand(yytext));
yy_switch_to_buffer(expansion_buffer);
}
<<EOF>> {
if ( expansion_buffer )
{
// We were doing an expansion, return to where
// we were.
yy_switch_to_buffer(main_buffer);
yy_delete_buffer(expansion_buffer);
expansion_buffer = 0;
}
else
yyterminate();
}
You probably will want a stack of expansion buffers to allow nested macros. From the above though hopefully the idea is clear.
This document was generated on August 12, 2012 using texi2html 5.0.
