Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #pragma once
- #include <iostream>
- #include <string>
- #include <vector>
- #include <cctype>
- #include <cmath>
- #include "Token.hpp"
- class Parser {
- private:
- void throwSyntaxError(const std::string& message);
- void skipWhitespace(std::size_t& selection);
- std::string readWord(const std::size_t selection);
- bool isKeyword(const std::string& identifier);
- bool isValid(const char symbol);
- bool skipComment(std::size_t& selection);
- std::string readCharacterLiteral(std::size_t& selection);
- std::string readStringLiteral(std::size_t& selection);
- void readNumberLiteral(std::size_t& selection, std::vector<Token>& tokens, bool& foundToken);
- std::string readIdentifier(std::size_t& selection);
- public:
- std::string Code;
- std::vector<Token> Tokenize();
- std::string Stringify(const TokenType type);
- void Log(const std::vector<Token> tokens);
- Parser() = default;
- static const std::string ENTRY;
- static const std::string IMPORT;
- static const std::string MODULE;
- static const std::string UNIFORM;
- static const std::string FUNCTION;
- static const std::string RETURNS;
- static const std::string RETURN;
- static const std::string CONTINUE;
- static const std::string BREAK;
- static const std::string CONSTRUCT;
- static const std::string INHERITS;
- static const std::string SHARED;
- static const std::string PUBLIC;
- static const std::string PROTECTED;
- static const std::string READONLY;
- static const std::string GETTER;
- static const std::string MUTABLE;
- static const std::string VAR;
- static const std::string TRY;
- static const std::string CATCH;
- static const std::string THROW;
- static const std::string IF;
- static const std::string ELSE;
- static const std::string WHILE;
- static const std::string FOR;
- static const std::string IN;
- static const std::string EQUALS;
- static const std::string AND;
- static const std::string OR;
- static const std::string REF;
- static const std::string VAL;
- static const std::string AS;
- static const std::string PUSH;
- static const std::string POP;
- static const std::string INCREMENT;
- static const std::string DECREMENT;
- static const std::string MULTIPLY;
- static const std::string DIVIDE;
- static const std::string BY;
- static constexpr std::size_t TOTAL_KEYWORDS = 39;
- static const std::string KEYWORDS[TOTAL_KEYWORDS];
- static constexpr char HASH = '#';
- static constexpr char APOSTROPHE = '\'';
- static constexpr char QUOTATIONS = '"';
- static constexpr char UNDERSCORE = '_';
- static constexpr char DOT = '.';
- static constexpr char COMMA = ',';
- static constexpr char QUESTION_MARK = '?';
- static constexpr char EXCLIMATION_MARK = '!';
- static constexpr char COLON = ':';
- static constexpr char SEMICOLON = ';';
- static constexpr char EQUAL = '=';
- static constexpr char MODULO = '%';
- static constexpr char RAISE = '^';
- static constexpr char PLUS = '+';
- static constexpr char DASH = '-';
- static constexpr char ASTERISK = '*';
- static constexpr char AMPERSAND = '&';
- static constexpr char DOLLAR = '$';
- static constexpr char AT = '@';
- static constexpr char SLASH = '/';
- static constexpr char BACKSLASH = '\\';
- static constexpr char VERTICAL_BAR = '|';
- static constexpr char OPEN_PARENTHESIS = '(';
- static constexpr char CLOSED_PARENTHESIS = ')';
- static constexpr char OPEN_CURLY_BRACKET = '{';
- static constexpr char CLOSED_CURLY_BRACKET = '}';
- static constexpr char OPEN_BRACKET = '[';
- static constexpr char CLOSED_BRACKET = ']';
- static constexpr char OPEN_ANGLE_BRACKET = '<';
- static constexpr char CLOSED_ANGLE_BRACKET = '>';
- static constexpr std::size_t TOTAL_SYMBOLS = 30 - 4; // excluding HASH, APOSTROPHE, QUOTATIONS, UNDERSCORE
- // symbols that exclude HASH, APOSTROPHE, QUOTATIONS, UNDERSCORE because:
- // HASH is used for comments # this is a comment #
- // APOSTROPHE is used for character literals 'this is a character'
- // QUOTATIONS is used for string literals "this is a string"
- // UNDERSCORE can be used in an identifier name _variable_name
- static const char SYMBOLS[TOTAL_SYMBOLS];
- };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement