// Statement.h Dave Reed 3/1/05 // // Expression class -- class for storing an expression in the SILLY language // // public member functions: // void Read(Tokenizer & program); // reads & stores the // // expression from program // void Execute(VarTable & variables) const; // evaluates the expression // // given the variable table // void Display() const; // displays the expression // // Statement class -- base class for storing different types of SILLY statements // OutputStatement class -- derived class for storing output statements // AssignStatement class -- derived class for storing assignment statements // IfStatement class -- derived class for storing if statements // // Each class provides the following public member functions: // void Read(Tokenizer & program); // reads & stores the // // statement from program // void Execute(VarTable & variables) const; // executes the statement // // given the variable table // void Display() const; // displays the statement // // Also, the following static member function is provided for reading a stmt // static Statement * GetNext(Tokenizer & program); /////////////////////////////////////////////////////////////////////////////////// #ifndef _STATEMENT_H #define _STATEMENT_H #include #include #include "Token.h" #include "Tokenizer.h" #include "VarTable.h" using namespace std; class Expression { public: Expression() { } void Read(Tokenizer & program); int Evaluate(VarTable & variables) const; void Display() const; private: Token expr; }; enum STATEMENT_TYPE {END, ASSIGN, OUTPUT, IF, ERROR}; class Statement { public: Statement() { } virtual void Read(Tokenizer & program) = 0; virtual void Execute(VarTable & variables) const = 0; virtual STATEMENT_TYPE GetType() const = 0; virtual void Display() const = 0; static Statement * GetNext(Tokenizer & program); }; class OutputStatement : public Statement { public: OutputStatement() { } void Read(Tokenizer & program); void Execute(VarTable & variables) const; STATEMENT_TYPE GetType() const; void Display() const; private: Expression outValue; }; class AssignStatement : public Statement { public: AssignStatement() { } void Read(Tokenizer & program); void Execute(VarTable & variables) const; STATEMENT_TYPE GetType() const; void Display() const; private: string lhs; Expression rhs; }; class IfStatement : public Statement { public: IfStatement() { } void Read(Tokenizer & program); void Execute(VarTable & variables) const; STATEMENT_TYPE GetType() const; void Display() const; private: Expression test; vector< Statement* > stmts; }; #endif