Interpreter prototype alpha
c++ interpreter for make believe language
 
Loading...
Searching...
No Matches
parser.h
Go to the documentation of this file.
1
7#ifndef PARSER_h
8#define PARSER_H
9#include "../tokens/tokens.h"
10#include "../tokenNode/tokenNode.h"
11#include "../tokenNode/NumberNode/NumberNode.h"
12#include "../tokenNode/OperatorNode/OperatorNode.h"
13#include "../tokenNode/StringNode/StringNode.h"
14#include "../tokenNode/VariableNode/VariableNode.h"
15#include "../tokenNode/builtinNode/builtinNode.h"
16#include "../tokenNode/ifNode/ifNode.h"
17#include "../tokenNode/whileNode/whileNode.h"
18#include "../tokenNode/forNode/forNode.h"
19#include "../tokenNode/functionNode/functionNode.h"
20
29};
30
34class parser{
35public:
36
43 parser(const std::vector<token>& vect, const std::string& filepath, const int& linenumber);
44
50 std::shared_ptr<tokenNode> __BEGIN__PARSE();
51
57 std::string getdatatype();
58
59private:
63 const static std::array<std::string, STATEMENT_DATATYPE::STATEMENT_DATATYPE_SIZE> datatypeARR;
64
68 const static std::string default_DT;
69
73 std::string datatype;
74
78 std::vector<token> tokensVect;
79
84
89
93 std::string filePath;
94
98 std::string dataType;
99
103 std::string current_var_name;
104
109
114
118 int lnNum;
119
125 void advance();
126
132 std::shared_ptr<tokenNode> functions();
133
139 std::shared_ptr<tokenNode> controlflow();
140
146 std::shared_ptr<tokenNode> variables();
147
153 std::shared_ptr<tokenNode> OR_logical_operator_expression();
154
160 std::shared_ptr<tokenNode> AND_logical_operator_expression();
161
167 std::shared_ptr<tokenNode> relational_operator_expression();
168
174 std::shared_ptr<tokenNode> expression();
175
181 std::shared_ptr<tokenNode> term();
182
188 std::shared_ptr<tokenNode> factor();
189
190 //helper functions
191
200 std::shared_ptr<tokenNode> getCorrectUnaryType(std::shared_ptr<NumberNode>& numbernode, const std::shared_ptr<OperatorNode>& operatornode, const std::string& operationtype, const std::string& nodetype);
201
207 std::string determineAppendType(const int& tokentypenode);
208
214 std::string continueReadingData();
215
221 std::shared_ptr<tokenNode> getNUMBERVARIABLE();
222
228 std::shared_ptr<tokenNode> getWORDVARIABLE();
229
235 std::shared_ptr<tokenNode> createVariable(const std::string& var_DT);
236
242 std::shared_ptr<tokenNode> getPRINTDATA();
243
244 //control flow
245
251 std::shared_ptr<tokenNode> createifstatements();
252
258 std::shared_ptr<tokenNode> create__ifstatement();
259
265 std::shared_ptr<tokenNode> create__elseifstatements();
266
272 std::shared_ptr<ifNode> create__elsestatements();
273
279 std::shared_ptr<tokenNode> create_whilestatements();
280
286 std::shared_ptr<tokenNode> create__forloops();
287
288 //functions
289
295 std::shared_ptr<tokenNode> create__functions();
296
302 std::shared_ptr<tokenNode> attachFunctionArguments();
303
309 std::shared_ptr<tokenNode> create_nullVariable(const std::string& variabletype);
310
316 std::shared_ptr<tokenNode> getNumberNode(std::shared_ptr<tokenNode>& variablenode_data);
317};
318
319#endif
STATEMENT_DATATYPE
mapping of different data types
Definition parser.h:24
@ NULL_STATEMENT_DATATYPE
Definition parser.h:27
@ STATEMENT_DATATYPE_SIZE
Definition parser.h:28
@ NUMBER_DT
Definition parser.h:25
@ WORD_DT
Definition parser.h:26
token currentToken
current token taken from the tokensVect vector using current_index
Definition parser.h:88
std::shared_ptr< tokenNode > getPRINTDATA()
a continuation of the createVariable() function
Definition parser.cpp:557
bool isReassigningVariable
used to keep track of whether or not a variable is being reassigned
Definition parser.h:108
std::shared_ptr< tokenNode > AND_logical_operator_expression()
generates a tree for the AND logical operator
Definition parser.cpp:107
std::shared_ptr< tokenNode > getNUMBERVARIABLE()
creates a number variable
Definition parser.cpp:547
std::shared_ptr< tokenNode > attachFunctionArguments()
attaches function arguments to a function after a function call is made
Definition parser.cpp:1055
std::shared_ptr< tokenNode > create__elseifstatements()
creates else if statements
Definition parser.cpp:644
std::shared_ptr< tokenNode > create__functions()
creates a function
Definition parser.cpp:949
std::shared_ptr< tokenNode > functions()
generates a tree for functions
Definition parser.cpp:31
std::shared_ptr< tokenNode > getCorrectUnaryType(std::shared_ptr< NumberNode > &numbernode, const std::shared_ptr< OperatorNode > &operatornode, const std::string &operationtype, const std::string &nodetype)
creates a unary for a factor eg: -(<factor>) or +(<factor>)
Definition parser.cpp:463
static const std::string default_DT
a string representation of the default data type
Definition parser.h:68
std::shared_ptr< tokenNode > getNumberNode(std::shared_ptr< tokenNode > &variablenode_data)
extracts a number node from a variable node
Definition parser.cpp:929
std::string determineAppendType(const int &tokentypenode)
determines append type between -=, +=, /=, ^=, %= depending on the enum mapping using the passed in a...
Definition parser.cpp:489
std::string current_var_name
used to keep track of the variable being processed to prevent collisions
Definition parser.h:103
void advance()
advances current_index by one in the tokensVect
Definition parser.cpp:19
std::shared_ptr< tokenNode > __BEGIN__PARSE()
begins parsing the tokenized vector
Definition parser.cpp:29
bool isAttaching__FuncArg
used to keep track of whether or not function arguments are being attached
Definition parser.h:113
std::string continueReadingData()
a continuation of the createVariable() function
Definition parser.cpp:511
std::shared_ptr< tokenNode > OR_logical_operator_expression()
generates a tree for the OR logical operator
Definition parser.cpp:88
int lnNum
the line number in the file which is currently being processed
Definition parser.h:118
std::vector< token > tokensVect
a vector of tokens to process
Definition parser.h:78
static const std::array< std::string, STATEMENT_DATATYPE::STATEMENT_DATATYPE_SIZE > datatypeARR
stores the various supported tokens such as +, - etc
Definition parser.h:63
std::string getdatatype()
returns a string representation of the current lines data type, whether word or number(to prevent col...
Definition parser.cpp:27
std::shared_ptr< ifNode > create__elsestatements()
creates an else statement
Definition parser.cpp:740
std::shared_ptr< tokenNode > controlflow()
generates a tree for control flow such as if, for and while statements
Definition parser.cpp:41
std::shared_ptr< tokenNode > term()
generates a tree for expressions for numbers such as *, /, ^, %
Definition parser.cpp:225
std::string filePath
name of the file currently being processed
Definition parser.h:93
std::shared_ptr< tokenNode > create_nullVariable(const std::string &variabletype)
creates a null variable, with no data attached to it
Definition parser.cpp:1099
std::string datatype
a string representation of the current lines data type, whether word or number(to prevent collisions ...
Definition parser.h:73
std::shared_ptr< tokenNode > variables()
generates a tree for variables
Definition parser.cpp:65
std::shared_ptr< tokenNode > create_whilestatements()
creates a while statement
Definition parser.cpp:785
std::shared_ptr< tokenNode > createifstatements()
starts creating if, else if and else statements
Definition parser.cpp:581
std::shared_ptr< tokenNode > create__forloops()
creates a for loop statement
Definition parser.cpp:833
std::shared_ptr< tokenNode > getWORDVARIABLE()
creates a word variable
Definition parser.cpp:552
std::shared_ptr< tokenNode > relational_operator_expression()
generates a tree for relations operators such as ==, >, >=, <, <=, !=
Definition parser.cpp:126
int current_index
current index in the tokensVect vector
Definition parser.h:83
std::shared_ptr< tokenNode > expression()
generates a tree for expressions for numbers such as +, -
Definition parser.cpp:195
std::shared_ptr< tokenNode > createVariable(const std::string &var_DT)
beings creation of a variable and pushes variable onto the stack after creating it
Definition parser.cpp:536
std::string dataType
used for assigning data types to code blocks
Definition parser.h:98
std::shared_ptr< tokenNode > create__ifstatement()
creates an if statement
std::shared_ptr< tokenNode > factor()
generates a a basic node for either a word type or a number type
Definition parser.cpp:275
parses the current line of code after receiving from the lexer
Definition parser.h:34
creates an object with the mapping of a token that was assigned to it from the 'tokens' class
Definition tokens.h:200