Next: , Previous: Type Decl, Up: Declarations


3.7.5 Performing Actions before Parsing

Sometimes your parser needs to perform some initializations before parsing. The %initial-action directive allows for such arbitrary code.

— Directive: %initial-action { code }

Declare that the braced code must be invoked before parsing each time yyparse is called. The code may use $$ (or $<tag>$) and @$ — initial value and location of the lookahead — and the %parse-param.

For instance, if your locations use a file name, you may use

     %parse-param { char const *file_name };
     %initial-action
     {
       @$.initialize (file_name);
     };