I am calling yyparse from a member function. How to access the member variables/function from the bison action.
I am currently doing as
%{
#include "myclass.h"
#include "parse.tab.hh"
MyClass *ptr=NULL;
void MyClass::evaluate(string expression)
    {
    开发者_如何学Pythonptr=this;
    yy_scan_string(expression.c_str());               
    yyparse();
    }
%}
%%
EXPR :  EXPR PLUS EXPR {
       $$ = ptr->memberFunction("+",$1,$3);
        }
You can set up bison to accept parameters:
%parse-param {MyClass* self}
%lex-param   {MyClass* self}
%{
    void MyClass::evaluate(string expression)
    {
        yy_scan_string(expression.c_str());               
        yyparse(this);   /* %parse-param allows a parameter to yyparse */
    }
%}
%%
    EXPR :  EXPR PLUS EXPR         {$$ = self->memberFunction("+",$1,$3);}
%%
   int yylex(MyClass* self) /* Controlled by %lex-param */
   {
       return self->lex();
   }
 
         
                                         
                                         
                                         
                                        ![Interactive visualization of a graph in python [closed]](https://www.devze.com/res/2023/04-10/09/92d32fe8c0d22fb96bd6f6e8b7d1f457.gif) 
                                         
                                         
                                         
                                         加载中,请稍侯......
 加载中,请稍侯......
      
精彩评论