/
thomas-king
/
SyntacticAnalyzer
Обзор
Документация
Войти
/
thomas-king
/
SyntacticAnalyzer
Код
Запросы
0
Задачи
Вики
Пакеты
0
Релизы
0
CI/CD
Аналитика
Безопасность
main
include/Models/Token.h
77 строк
1 KB
Ace Rodstin
Implement SyntacticAnalyzer.
06 апр 2023, 09:52
06 апр 2023, 09:52
2d58f4b
Код
Авторство
О чём код?
// // Token.h // TokensParser // // Created by Ace Rodstin on 3/6/23. // Copyright © 2023 Ace Rodstin. All rights reserved. // #ifndef TOKEN_HEADER_FILE #define TOKEN_HEADER_FILE #include <optional> #include <string> #include "Keyword.h" #include "Operator.h" #include "Punctuator.h" #include "Literal.h" using namespace std; namespace ace { class Token { public: enum class Kind { keyword, identifier, punctuator, _operator, literal, endOfInput, unknown }; Token(Kind kind); Token(string identifier); Token(Keyword keyword); Token(Punctuator punctuator); Token(Operator op); Token(Literal literal); Kind getKind() const; string getIdentifier() const; Keyword getKeyword() const; Punctuator getPunctuator() const; Operator getOperator() const; Literal getLiteral() const; string toString() const; bool operator ==(const Token& other) const; private: Kind kind; optional<string> identifier; optional<Keyword> keyword; optional<Punctuator> punctuator; optional<Operator> _operator; optional<Literal> literal; string description(Kind kind) const; string description(optional<string> identifier) const; string description(optional<Literal> literal) const; template<class T> string description(optional<T> property) const { string description; if (property.has_value()) { return ace::description(property.value()); } else { return "null"; } } }; } #endif