Piethon  1.0
A Python-like interpreter using flex and bison.
statement.h
Go to the documentation of this file.
1 #ifndef STATEMENT_H
2 #define STATEMENT_H
3 
4 #include <string>
5 #include <list>
6 
7 using std::string;
8 using std::list;
9 
10 extern int yylineno;
11 
12 class SymbolTable;
13 class FunctionTable;
14 class Function;
15 class Expression;
16 class ExpressionList;
17 
18 class Statement {
19 public:
20  virtual ~Statement() {};
21 
22  virtual void eval(SymbolTable&, FunctionTable&) const = 0;
23  virtual int getLineNumber() const;
24 
25 protected:
27  Statement(int i) : lineNumber(i) { }
29 };
30 
31 
32 class Assignment: public Statement {
33 public:
34  Assignment(const string& n, Expression *e) : name(n), exp(e) { }
35  ~Assignment();
36 
37  void eval(SymbolTable&, FunctionTable&) const;
38 
39 private:
40  string name;
41  Expression* exp;
42 };
43 
44 
46 public:
47  ~StatementList();
48 
49  void eval(SymbolTable&, FunctionTable&) const;
50  void add(Statement*);
51 
52 private:
53  list<Statement*> stmtList;
54 };
55 
56 
57 class FunctionCall : public Statement {
58 public:
59  FunctionCall(const string& n, ExpressionList* el) : Statement(yylineno), name(n), expList(el) { }
60  ~FunctionCall();
61 
62  void eval(SymbolTable&, FunctionTable&) const;
63 
64 private:
65  string name;
66  ExpressionList* expList;
67 };
68 
69 
70 class FunctionDef : public Statement {
71 public:
72  FunctionDef(const string& n, Function* fun) : name(n), function(fun) { }
73  ~FunctionDef();
74 
75  void eval(SymbolTable&, FunctionTable&) const;
76 
77 private:
78  string name;
79  Function* function;
80 };
81 
82 
83 class IfElse : public Statement {
84 public:
85  IfElse(Expression *cond, StatementList* tList, StatementList* fList) : condition(cond), trueList(tList), falseList(fList) { }
86  IfElse(Expression *cond, StatementList* tList) : condition(cond), trueList(tList), falseList(new StatementList()) { }
87  ~IfElse();
88 
89  void eval(SymbolTable&, FunctionTable&) const;
90 
91 private:
92  Expression* condition;
93  StatementList* trueList;
94  StatementList* falseList;
95 };
96 
97 
98 class While : public Statement {
99 public:
100  While(Expression* cond, StatementList* sList) : condition(cond), stmtList(sList) { }
101  ~While();
102 
103  void eval(SymbolTable&, FunctionTable&) const;
104 
105 private:
106  Expression* condition;
107  StatementList* stmtList;
108 };
109 
110 
111 class Print : public Statement {
112 public:
113  Print(Expression* e) : exp(e) { }
114  ~Print();
115 
116  void eval(SymbolTable&, FunctionTable&) const;
117 
118 private:
119  Expression* exp;
120 };
121 
122 
123 class Return: public Statement {
124 public:
125  Return(Expression* e) : exp(e) { }
126  ~Return();
127 
128  void eval(SymbolTable&, FunctionTable&) const;
129 
130 private:
131  Expression* exp;
132 };
133 
134 #endif
Statement()
Definition: statement.h:26
Return(Expression *e)
Definition: statement.h:125
virtual ~Statement()
Definition: statement.h:20
Assignment(const string &n, Expression *e)
Definition: statement.h:34
FunctionDef(const string &n, Function *fun)
Definition: statement.h:72
Statement(int i)
Definition: statement.h:27
IfElse(Expression *cond, StatementList *tList, StatementList *fList)
Definition: statement.h:85
While(Expression *cond, StatementList *sList)
Definition: statement.h:100
virtual void eval(SymbolTable &, FunctionTable &) const =0
Print(Expression *e)
Definition: statement.h:113
int yylineno
FunctionCall(const string &n, ExpressionList *el)
Definition: statement.h:59
virtual int getLineNumber() const
Definition: statement.cpp:16
int lineNumber
Definition: statement.h:28
IfElse(Expression *cond, StatementList *tList)
Definition: statement.h:86