#include #include using namespace std; class Context{ }; class AbstractExpression{ public: virtual Context& Interpret(Context& context)=0; }; class TerminalExpression: public AbstractExpression{ public: Context& Interpret(Context& context){ cout<<"Called Terminal.Interpret()"< subexpressions; public: Context& Interpret(Context& context){ cout<<"Called Nonterminal.Interpret()"<Interpret(context); return context; } void AddSubexpression(AbstractExpression* ex){ subexpressions.push_back(ex); } }; main(){ Context context; TerminalExpression tex1; TerminalExpression tex2; NonterminalExpression ntex; ntex.AddSubexpression(&tex1); ntex.AddSubexpression(&tex2); TerminalExpression tex3; NonterminalExpression root; root.AddSubexpression(&tex3); root.AddSubexpression(&ntex); root.Interpret(context); return 0; }