(flex.info)How can I expand macros in the input?


Next: How can I build a two-pass scanner? Prev: How can I change the matching pattern at run time? Up: FAQ
Enter node , (file) or (file)node

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.


automatically generated by info2www version 1.2.2.9