Interpreter prototype alpha
c++ interpreter for make believe language
 
Loading...
Searching...
No Matches
tokens.h
Go to the documentation of this file.
1
8#ifndef TOKEN_H
9#define TOKEN_H
10#include "../Exceptions/Exceptions.h"
11
15enum TOKENS{
16 NUMBER,//=0
17 PLUS,//=1
18 MINUS,//=2
20 DIVIDE,//=4
21 LPAREN,//=5
22 RPAREN,//=6
23 POWER,//=7
26 EQUALS,//=10
27 STRING,//=11
28 AND,//=12
29 NOT,//=13
30 OR,//=14
31 MODULUS,//=15
46 FORLOOPSEP,//=30 meaning ":" eg for(number val = 0 : val < 3 : val+= 1)
47 FUNCARGSEP,//=31 meaning "," eg func(1, 2);
48 NULLNODE//=32
49};
50
89 NULLPTRNODE//=34
90};
91
102 IF,//=6
104 ELSE,//=8
105 THEN,//=9
106 WHILE,//=10
107 FOR,//=11
109 FUNCTION__CALL//=13
111
115class tokens{
116private:
120 const static int tokensArrSIZE = 33, ignoreCharArrSIZE = 3, DIGITSSIZE = 11, KEYWORDSSIZE = 14,
122
123public:
127 const static std::array<std::string, tokens::tokensArrSIZE> tokensArr;
128
132 const static std::array<char, tokens::ignoreCharArrSIZE> ignoreCharArr;
133
137 const static std::array<char, tokens::DIGITSSIZE> DIGITS;
138
142 const static std::array<std::string, tokens::KEYWORDSSIZE> KEYWORDS;
143
147 const static std::array<char, tokens::LETTERSSIZE> LETTERS;
148
152 const static std::array<std::string, tokens::visitNodesArrSIZE> visitNodesArr;
153
159 static bool isInIgnoreCharArr(const std::string& toCheck);
160
166 static bool isInDIGITSarr(const std::string& toCheck);
167
173 static bool isInLETTERSarr(const std::string& toCheck);
174
180 static bool isInKEYWORDSarr(const std::string& toCheck);
181
187 static std::string tokentype(const int& index);
188
194 static bool isOperatorNode(const std::string& nodeType);
195};
196
200class token{
201public:
205 int type = tokens::tokensArr.size() - 1;
206
210 std::string value = "";
211
217 std::string __represent__ () const;
218};
219
220#endif
KEYWRODSTYPE
mapping of supported keywords
Definition tokens.h:95
@ DISPLAYLINE
Definition tokens.h:100
@ PRINTNEWLINE
Definition tokens.h:99
@ IF
Definition tokens.h:102
@ WHILE
Definition tokens.h:106
@ FUNCTION__DECL
Definition tokens.h:108
@ STRINGKEY
Definition tokens.h:97
@ ELSEIF
Definition tokens.h:103
@ ELSE
Definition tokens.h:104
@ FUNCTION__CALL
Definition tokens.h:109
@ FOR
Definition tokens.h:107
@ THEN
Definition tokens.h:105
@ PRINTLINE
Definition tokens.h:98
@ DISPLAYNEWLINE
Definition tokens.h:101
@ NUMBERKEY
Definition tokens.h:96
VISITNODES
mapping of different types nodes(interpreterr.cpp uses this)
Definition tokens.h:54
@ IFSTATEMENTNODE
Definition tokens.h:77
@ OPNODELESSTHANOREQUALTO
Definition tokens.h:74
@ OPNODEMINUS
Definition tokens.h:56
@ OPNODEEQUALSEQUALS
Definition tokens.h:70
@ FUNCTIONDECLARATION
Definition tokens.h:88
@ OPNODELESSTHAN
Definition tokens.h:72
@ OPNODEDIVIDE
Definition tokens.h:58
@ OPNODENOT
Definition tokens.h:67
@ OPNODEPLUS
Definition tokens.h:55
@ OPNODEMULTIPLY
Definition tokens.h:57
@ OPNODEMODULUS
Definition tokens.h:69
@ FORSTATEMENT
Definition tokens.h:87
@ OPNODEMINUSEQUALS
Definition tokens.h:82
@ STRINGNODE
Definition tokens.h:65
@ OPNODEMULTIPLYEQUALS
Definition tokens.h:83
@ OPNODENOTEQUALTO
Definition tokens.h:75
@ NULLPTRNODE
Definition tokens.h:89
@ WHILESTATEMENT
Definition tokens.h:80
@ NUMBERVARNODE
Definition tokens.h:63
@ BUITINFUNCTION
Definition tokens.h:76
@ POWEROPNODE
Definition tokens.h:62
@ OPNODEPLUSEQUALS
Definition tokens.h:81
@ STRINGVARNODE
Definition tokens.h:64
@ PLUSUNARYOPNODE
Definition tokens.h:60
@ OPNODEDIVIDEEQUALS
Definition tokens.h:84
@ ELSESTATEMENT
Definition tokens.h:79
@ ELSEIFSTATEMENTNODE
Definition tokens.h:78
@ OPNODEGREATERTHANOREQUALTO
Definition tokens.h:73
@ MINUSUNARYOPNODE
Definition tokens.h:61
@ OPNODEAND
Definition tokens.h:66
@ NUMBERNODE
Definition tokens.h:59
@ OPNODEGREATERTHAN
Definition tokens.h:71
@ OPNODEOR
Definition tokens.h:68
@ OPNODEMODULUSEQUALS
Definition tokens.h:85
@ OPNODEPOWEREQUALS
Definition tokens.h:86
TOKENS
mapping of different types of supported tokens
Definition tokens.h:15
@ NOT
Definition tokens.h:29
@ DIVIDE
Definition tokens.h:20
@ ENDLOCALSCOPE
Definition tokens.h:39
@ FORLOOPSEP
Definition tokens.h:46
@ KEYWORD
Definition tokens.h:25
@ NUMBER
Definition tokens.h:16
@ MODULUS
Definition tokens.h:31
@ RPAREN
Definition tokens.h:22
@ POWER
Definition tokens.h:23
@ LPAREN
Definition tokens.h:21
@ FUNCARGSEP
Definition tokens.h:47
@ MINUSEQUALS
Definition tokens.h:41
@ GREATERTHAN
Definition tokens.h:33
@ POWEREQUALS
Definition tokens.h:45
@ BEGINLOCALSCOPE
Definition tokens.h:38
@ LESSTHANOREQUALTO
Definition tokens.h:36
@ PLUSEQUALS
Definition tokens.h:40
@ GREATERTHANOREQUALTO
Definition tokens.h:35
@ EQUALSEQUALS
Definition tokens.h:32
@ IDENTIFIER
Definition tokens.h:24
@ AND
Definition tokens.h:28
@ PLUS
Definition tokens.h:17
@ LESSTHAN
Definition tokens.h:34
@ DIVIDEEQUALS
Definition tokens.h:43
@ EQUALS
Definition tokens.h:26
@ OR
Definition tokens.h:30
@ NOTEQUALTO
Definition tokens.h:37
@ MULTIPLYEQUALS
Definition tokens.h:42
@ MODULUSEQUALS
Definition tokens.h:44
@ NULLNODE
Definition tokens.h:48
@ MULTIPLY
Definition tokens.h:19
@ STRING
Definition tokens.h:27
@ MINUS
Definition tokens.h:18
static bool isInDIGITSarr(const std::string &toCheck)
checks if the passed in toCheck arg is a digit
Definition tokens.cpp:40
static const int LETTERSSIZE
Definition tokens.h:121
static const std::array< std::string, tokens::tokensArrSIZE > tokensArr
stores the various supported tokens such as +, - etc
Definition tokens.h:127
static bool isInKEYWORDSarr(const std::string &toCheck)
checks if the passed in toCheck arg is a keyword in the language
Definition tokens.cpp:54
static const std::array< char, tokens::DIGITSSIZE > DIGITS
stores range of all digits from 0 - 9
Definition tokens.h:137
static const int KEYWORDSSIZE
Definition tokens.h:120
static const int tokensArrSIZE
the sizes of the arrays which store all of the languages tokens and keywords
Definition tokens.h:120
static const int ignoreCharArrSIZE
Definition tokens.h:120
static const std::array< std::string, tokens::visitNodesArrSIZE > visitNodesArr
stores which node type should be visited for the currently selected node(only used in parser....
Definition tokens.h:152
static std::string tokentype(const int &index)
gets the token which maps to the passed in index arg in std::string format
Definition tokens.cpp:74
static const std::array< std::string, tokens::KEYWORDSSIZE > KEYWORDS
stores the various keywords such number, for, while
Definition tokens.h:142
static bool isInLETTERSarr(const std::string &toCheck)
checks if the passed in toCheck arg is a letter
Definition tokens.cpp:47
static const std::array< char, tokens::LETTERSSIZE > LETTERS
stores all letters in the alphabet in upper and lower case and the underscore symbol '_'
Definition tokens.h:147
static const std::array< char, tokens::ignoreCharArrSIZE > ignoreCharArr
stores ignorable characters such as ' ', \n etc
Definition tokens.h:132
static bool isInIgnoreCharArr(const std::string &toCheck)
checks if the passed in toCheck arg is an ignorable character
Definition tokens.cpp:33
static const int DIGITSSIZE
Definition tokens.h:120
static bool isOperatorNode(const std::string &nodeType)
checks if the passed in nodeType arg is an operator node
Definition tokens.cpp:61
static const int visitNodesArrSIZE
Definition tokens.h:121
stores the mapping of different keywords and types
Definition tokens.h:115
int type
number used to represent token type in enums
Definition tokens.h:205
std::string __represent__() const
returns a string representation of the the type and value class member variables
Definition tokens.cpp:79
std::string value
can be none if the no value is assigned, eg plus or minus operations
Definition tokens.h:210
creates an object with the mapping of a token that was assigned to it from the 'tokens' class
Definition tokens.h:200