Back Next

Method

If the technique is carried to its logical extreme, the production bodies all call...

 %%

expression
  : IDENTIFIER
     { $$ = parse_expression_identifier($1); }
  | expression PLUS expression
     { $$ = parse_expression_addition($1, $3); }
  | expression ASSIGN expression
     { $$ = parse_expression_assignment($1, $3); }
  | etc etc
  ; 
 %{ translator *context;
%}

%%

expression
  : IDENTIFIER
     { $$ = context->expression_identifier($1); }
  | expression PLUS expression
     { $$ = context->expression_addition($1, $3); }
  | expression ASSIGN expression
     { $$ = context->expression_assignment($1, $3); }
  | etc etc
  ; 

Aha! What if the methods were virtual?

/* vim: set ts=8 sw=4 et : */