Interpreter prototype alpha
c++ interpreter for make believe language
 
Loading...
Searching...
No Matches
parser Class Reference

parses the current line of code after receiving from the lexer More...

#include <parser.h>

Public Member Functions

 parser (const std::vector< token > &vect, const std::string &filepath, const int &linenumber)
 accepts a vector of tokens after the current line has been tokenized by the lexer
 
std::shared_ptr< tokenNode__BEGIN__PARSE ()
 begins parsing the tokenized vector
 
std::string getdatatype ()
 returns a string representation of the current lines data type, whether word or number(to prevent collisions and mixing)
 

Private Member Functions

void advance ()
 advances current_index by one in the tokensVect
 
std::shared_ptr< tokenNodefunctions ()
 generates a tree for functions
 
std::shared_ptr< tokenNodecontrolflow ()
 generates a tree for control flow such as if, for and while statements
 
std::shared_ptr< tokenNodevariables ()
 generates a tree for variables
 
std::shared_ptr< tokenNodeOR_logical_operator_expression ()
 generates a tree for the OR logical operator
 
std::shared_ptr< tokenNodeAND_logical_operator_expression ()
 generates a tree for the AND logical operator
 
std::shared_ptr< tokenNoderelational_operator_expression ()
 generates a tree for relations operators such as ==, >, >=, <, <=, !=
 
std::shared_ptr< tokenNodeexpression ()
 generates a tree for expressions for numbers such as +, -
 
std::shared_ptr< tokenNodeterm ()
 generates a tree for expressions for numbers such as *, /, ^, %
 
std::shared_ptr< tokenNodefactor ()
 generates a a basic node for either a word type or a number type
 
std::shared_ptr< tokenNodegetCorrectUnaryType (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>)
 
std::string determineAppendType (const int &tokentypenode)
 determines append type between -=, +=, /=, ^=, %= depending on the enum mapping using the passed in argument tokentypenode
 
std::string continueReadingData ()
 a continuation of the createVariable() function
 
std::shared_ptr< tokenNodegetNUMBERVARIABLE ()
 creates a number variable
 
std::shared_ptr< tokenNodegetWORDVARIABLE ()
 creates a word variable
 
std::shared_ptr< tokenNodecreateVariable (const std::string &var_DT)
 beings creation of a variable and pushes variable onto the stack after creating it
 
std::shared_ptr< tokenNodegetPRINTDATA ()
 a continuation of the createVariable() function
 
std::shared_ptr< tokenNodecreateifstatements ()
 starts creating if, else if and else statements
 
std::shared_ptr< tokenNodecreate__ifstatement ()
 creates an if statement
 
std::shared_ptr< tokenNodecreate__elseifstatements ()
 creates else if statements
 
std::shared_ptr< ifNodecreate__elsestatements ()
 creates an else statement
 
std::shared_ptr< tokenNodecreate_whilestatements ()
 creates a while statement
 
std::shared_ptr< tokenNodecreate__forloops ()
 creates a for loop statement
 
std::shared_ptr< tokenNodecreate__functions ()
 creates a function
 
std::shared_ptr< tokenNodeattachFunctionArguments ()
 attaches function arguments to a function after a function call is made
 
std::shared_ptr< tokenNodecreate_nullVariable (const std::string &variabletype)
 creates a null variable, with no data attached to it
 
std::shared_ptr< tokenNodegetNumberNode (std::shared_ptr< tokenNode > &variablenode_data)
 extracts a number node from a variable node
 

Private Attributes

std::string datatype
 a string representation of the current lines data type, whether word or number(to prevent collisions and mixing)
 
std::vector< tokentokensVect
 a vector of tokens to process
 
int current_index
 current index in the tokensVect vector
 
token currentToken
 current token taken from the tokensVect vector using current_index
 
std::string filePath
 name of the file currently being processed
 
std::string dataType
 used for assigning data types to code blocks
 
std::string current_var_name
 used to keep track of the variable being processed to prevent collisions
 
bool isReassigningVariable
 used to keep track of whether or not a variable is being reassigned
 
bool isAttaching__FuncArg
 used to keep track of whether or not function arguments are being attached
 
int lnNum
 the line number in the file which is currently being processed
 

Static Private Attributes

static const std::array< std::string, STATEMENT_DATATYPE::STATEMENT_DATATYPE_SIZEdatatypeARR = {"number", "word", "null"}
 stores the various supported tokens such as +, - etc
 
static const std::string default_DT = "DEFAULT"
 a string representation of the default data type
 

Detailed Description

parses the current line of code after receiving from the lexer

Author
Michael

The documentation for this class was generated from the following files: