MXVM 1.8.1
Virtual Machine, Compiler, and Pascal Frontend
Loading...
Searching...
No Matches
types.cpp
Go to the documentation of this file.
1
6#include "scanner/types.hpp"
7
8namespace types {
9
10 std::vector<std::string> strTokenType{"Identifier", "Argument", "Symbols", "String", "Numeric", "Hex", "NULL"};
11 std::vector<std::string> strCharType{"Characters", "Digits", "Symbols", "String", "Quote", "Space", "NULL"};
12
13 void print_type_TokenType(std::ostream &out, const TokenType &tt) {
14 unsigned int t_type = static_cast<unsigned int>(tt);
15 if (t_type < strTokenType.size())
16 out << strTokenType[t_type];
17 }
18
19 void print_type_CharType(std::ostream &out, const CharType &c) {
20 unsigned int t_type = static_cast<unsigned int>(c);
21 if (t_type < strCharType.size())
22 out << strCharType[t_type];
23 }
24
25 std::optional<OperatorType> lookUp(const std::string &op) {
26 for (size_t i = 0; i < opStrings.size(); ++i) {
27 if (opStrings[i] == op)
28 return static_cast<OperatorType>(i);
29 }
30 return std::nullopt;
31 }
32
33 std::optional<KeywordType> lookUp_Keyword(const std::string &op) {
34 for (size_t i = 0; i < kwStr.size(); ++i) {
35 if (kwStr[i] == op)
36 return static_cast<KeywordType>(i);
37 }
38 return std::nullopt;
39 }
40
41} // namespace types
std::optional< OperatorType > lookUp(const std::string &op)
Look up an operator string and return its OperatorType.
Definition types.cpp:25
KeywordType
Keyword type enumeration.
Definition types.hpp:196
std::vector< std::string > strTokenType
string names of TokenType values
Definition types.cpp:10
TokenType
Classification of scanned tokens.
Definition types.hpp:16
std::vector< std::string > kwStr
Keyword string representations indexed by KeywordType.
Definition types.hpp:210
std::vector< std::string > opStrings
Operator string representations indexed by OperatorType.
Definition types.hpp:142
std::optional< KeywordType > lookUp_Keyword(const std::string &op)
Look up a keyword string and return its KeywordType.
Definition types.cpp:33
OperatorType
Enumeration of all recognised operator symbols.
Definition types.hpp:36
void print_type_CharType(std::ostream &out, const CharType &c)
Print a CharType name to a stream.
Definition types.cpp:19
std::vector< std::string > strCharType
Definition types.cpp:11
void print_type_TokenType(std::ostream &out, const TokenType &tt)
Print a TokenType name to a stream.
Definition types.cpp:13
CharType
Classification of individual characters during lexing.
Definition types.hpp:26
Token, character, and operator type enumerations for the scanner.