Interpreter prototype alpha
c++ interpreter for make believe language
 
Loading...
Searching...
No Matches
Interpreter.h
Go to the documentation of this file.
1
8#ifndef INTERPRETER_H
9#define INTERPRETER_H
10#include "../tokens/tokens.h"
11#include "../tokenNode/tokenNode.h"
12#include "../tokenNode/NumberNode/NumberNode.h"
13#include "../tokenNode/OperatorNode/OperatorNode.h"
14#include "../tokenNode/StringNode/StringNode.h"
15#include "../tokenNode/VariableNode/VariableNode.h"
16#include "../tokenNode/builtinNode/builtinNode.h"
17#include "../tokenNode/ifNode/ifNode.h"
18#include "../tokenNode/whileNode/whileNode.h"
19#include "../tokenNode/forNode/forNode.h"
20
22
23};
24
29 bool isbooleanstatement = false;
30 bool result = false;
31 double value = 0.0;
32};
33
38 bool isbooleanstatement = false;
39 bool result = false;
40 std::string value = "";
41};
42
47 bool isbooleanval = false;
48 bool booleanval = false;
49 bool isnumberval = false;
50 bool iswordval = false;
51 double numberval = 0.0;
52 std::string wordval = "";
53};
54
59public:
65 Interpreter(const std::string& filepath, const int& linenumber);
66
73 void run__CODE(std::shared_ptr<tokenNode>& TKNode, const std::string& datatype);
74
75private:
79 std::string filePath;
80
84 int lnNum;
85
90
97 void visit_controlflow(std::shared_ptr<tokenNode>& TKNode, const std::string& datatype);
98
105 void visit_built_in_func(std::shared_ptr<tokenNode>& TKNode, const std::string& datatype);
106
113 bool checkCondition(std::shared_ptr<tokenNode>& TKNode, const std::string& datatype);
114
121 void visit_Variables(std::shared_ptr<tokenNode>& TKNode, const std::string& datatype);
122
128 returnStringValues visitWORDS(std::shared_ptr<tokenNode>& TKNode);
129
135 std::string visit__StringNode(std::shared_ptr<StringNode>& TKNode);
136
143 std::string visit__StringAppendNode(std::shared_ptr<VariableNode>& nodeToAppendTo, const std::string& passedvalue);
144
150 returnNumberValues visitNUMBERS(std::shared_ptr<tokenNode>& TKNode);
151
157 double visit__unaryNumberNode(std::shared_ptr<NumberNode>& TKNode);
158
164 double visit__unaryNumberNodeExpr(std::shared_ptr<NumberNode>& TKNode);
165
171 double visit__NumberNode(std::shared_ptr<NumberNode>& TKNode);
172
179 double visit__NumberAppendNode(std::shared_ptr<VariableNode>& nodeToAppendTo, const double& passedvalue);
180
186 returnNumberValues visit__numberOPNODE(std::shared_ptr<OperatorNode>& TKNode);
187
193 returnStringValues visit__stringOPNODE(std::shared_ptr<OperatorNode>& TKNode);
194
200 void resetVariableValue(std::shared_ptr<forNode>& forobj);
201};
202
203#endif
DATATYPES
Definition Interpreter.h:21
double value
Definition Interpreter.h:31
bool result
Definition Interpreter.h:30
bool isbooleanstatement
Definition Interpreter.h:29
returns a struct containing number values from calculations
Definition Interpreter.h:28
bool result
Definition Interpreter.h:39
bool isbooleanstatement
Definition Interpreter.h:38
std::string value
Definition Interpreter.h:40
returns a struct containing string values from calculations
Definition Interpreter.h:37
double numberval
Definition Interpreter.h:51
bool booleanval
Definition Interpreter.h:48
bool isbooleanval
Definition Interpreter.h:47
bool isnumberval
Definition Interpreter.h:49
bool iswordval
Definition Interpreter.h:50
std::string wordval
Definition Interpreter.h:52
specifies the type of the return value and carries the return value
Definition Interpreter.h:46
void run__CODE(std::shared_ptr< tokenNode > &TKNode, const std::string &datatype)
runs the interpreter
Definition Interpreter.cpp:9
std::string visit__StringNode(std::shared_ptr< StringNode > &TKNode)
visits a string and extracts it's value eg "value"
Definition Interpreter.cpp:323
void resetVariableValue(std::shared_ptr< forNode > &forobj)
reset a variable in a for loop back to it's original value after the for loop has finished executing
Definition Interpreter.cpp:616
std::string filePath
name of the file currently being processed
Definition Interpreter.h:79
double visit__unaryNumberNode(std::shared_ptr< NumberNode > &TKNode)
extracts the number value from this node which is of type unary, eg -5 or +5
Definition Interpreter.cpp:327
void visit_controlflow(std::shared_ptr< tokenNode > &TKNode, const std::string &datatype)
visits control flow on the syntax tree
Definition Interpreter.cpp:13
void visit_built_in_func(std::shared_ptr< tokenNode > &TKNode, const std::string &datatype)
visits built in function
Definition Interpreter.cpp:105
returnStringValues visitWORDS(std::shared_ptr< tokenNode > &TKNode)
attempts to figure out if the passed in argument is a StringNode, OperatorNode or VariableNode
Definition Interpreter.cpp:239
double visit__unaryNumberNodeExpr(std::shared_ptr< NumberNode > &TKNode)
visits a number node contained within an expression such as and multiplies it by it's unary,...
Definition Interpreter.cpp:336
bool checkCondition(std::shared_ptr< tokenNode > &TKNode, const std::string &datatype)
checks if the condition of a control flow is true from visit_controlflow() on for-loop,...
Definition Interpreter.cpp:593
double visit__NumberAppendNode(std::shared_ptr< VariableNode > &nodeToAppendTo, const double &passedvalue)
appends/adds or any other operator, a value to the end of a variable
Definition Interpreter.cpp:533
returnNumberValues visit__numberOPNODE(std::shared_ptr< OperatorNode > &TKNode)
attempts to figure out which operator is being used between two number nodes
Definition Interpreter.cpp:345
double visit__NumberNode(std::shared_ptr< NumberNode > &TKNode)
extracts the number value from this node , eg 5
Definition Interpreter.cpp:325
std::string visit__StringAppendNode(std::shared_ptr< VariableNode > &nodeToAppendTo, const std::string &passedvalue)
appends a value to the end of a variable
Definition Interpreter.cpp:575
returnStringValues visit__stringOPNODE(std::shared_ptr< OperatorNode > &TKNode)
attempts to figure out which operator is being used between two word nodes
Definition Interpreter.cpp:457
bool isInLoop
specifies whether or not what is currently being processed is a loop or not
Definition Interpreter.h:89
int lnNum
the line number in the file which is currently being processed
Definition Interpreter.h:84
void visit_Variables(std::shared_ptr< tokenNode > &TKNode, const std::string &datatype)
visits variable nodes and extracts their values
Definition Interpreter.cpp:157
returnNumberValues visitNUMBERS(std::shared_ptr< tokenNode > &TKNode)
attempts to figure out if the passed in argument is a NumberNode, OperatorNode or VariableNode
Definition Interpreter.cpp:277
Interprets and executes code from the abstract syntax tree.
Definition Interpreter.h:58