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
11
Program::~Program
() {
12
delete
statementList;
13
}
14
15
int
Program::eval
() {
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
statement.h
function.h
Function
Definition:
function.h:29
main
int main(int argc, char **argv)
Definition:
main.cpp:11
Program::eval
int eval()
Definition:
program.cpp:15
ReturnValue
Definition:
exception.h:68
ParseException::getLineNumber
virtual int getLineNumber() const
Definition:
exception.cpp:7
exception.h
StatementList::eval
void eval(SymbolTable &, FunctionTable &) const
Definition:
statement.cpp:103
program.h
ParseException
Definition:
exception.h:8
Function::apply
Number apply(const SymbolTable &, const FunctionTable &, ExpressionList *) const
Definition:
function.cpp:39
Program::~Program
~Program()
Definition:
program.cpp:11
ParseException::what
virtual const char * what() const
Definition:
exception.cpp:3
ReturnValue::getLineNumber
int getLineNumber() const
Definition:
exception.cpp:19
Generated on Tue Jan 19 2021 23:43:11 for Piethon by
1.8.13