Piethon  1.0
A Python-like interpreter using flex and bison.
program.cpp
Go to the documentation of this file.
1 #include <iostream>
2 #include <cstdlib>
3 #include "exception.h"
4 #include "statement.h"
5 #include "function.h"
6 #include "program.h"
7 
8 using std::cerr;
9 using std::endl;
10 
12  delete statementList;
13 }
14 
16  try {
17  // execute all statements in program
18  statementList->eval(st, ft);
19 
20  // call the main function, if defined
21  Function* main = ft["main"];
22  if (main != NULL) {
23  main->apply(st, ft);
24  }
25  } catch (ParseException e) {
26  cerr << "error (line " << e.getLineNumber() << "): " << e.what() << endl;
27  return 2;
28  } catch (ReturnValue e) {
29  cerr << "error (line " << e.getLineNumber() << "): " << "return statement outside of function" << endl;
30  return 2;
31  }
32  return 0;
33 }
34 
int main(int argc, char **argv)
Definition: main.cpp:11
int eval()
Definition: program.cpp:15
virtual int getLineNumber() const
Definition: exception.cpp:7
void eval(SymbolTable &, FunctionTable &) const
Definition: statement.cpp:103
Number apply(const SymbolTable &, const FunctionTable &, ExpressionList *) const
Definition: function.cpp:39
~Program()
Definition: program.cpp:11
virtual const char * what() const
Definition: exception.cpp:3
int getLineNumber() const
Definition: exception.cpp:19