Push all code
This commit is contained in:
parent
347987bb66
commit
ba2bf4b404
10 changed files with 1671 additions and 0 deletions
48
include/lexer.hpp
Normal file
48
include/lexer.hpp
Normal file
|
@ -0,0 +1,48 @@
|
|||
#pragma once
|
||||
#include <string>
|
||||
#include <list>
|
||||
|
||||
class Lexer {
|
||||
public:
|
||||
struct LexerToken {
|
||||
enum class Type {
|
||||
None, Word, Semicolon, CurlyOpenBracket, CurlyCloseBracket,
|
||||
RoundOpenBracket, RoundCloseBracket, Period, Commo, Plus, Minus, Star,
|
||||
Slash, Equal, ExclamationMark, PlusEqual, MinusEqual, StarEqual,
|
||||
SlashEqual, EqualEqual, ExclamationMarkEqual, PlusPlus, MinusMinus,
|
||||
LAngle, RAngle, LAngleEqual, RAngleEqual, LArrow, RArrow, FOR, IF, ELSE,
|
||||
WHILE, StringLiteral
|
||||
};
|
||||
LexerToken() = default;
|
||||
LexerToken(const LexerToken&) = default;
|
||||
LexerToken(LexerToken&&) = default;
|
||||
LexerToken(const Type& type, const std::string& info) : type(type), info(info) {}
|
||||
LexerToken(const Type& type, std::string&& info) : type(type), info(info) {}
|
||||
LexerToken(Type&& type, const std::string& info) : type(type), info(info) {}
|
||||
LexerToken(Type&& type, std::string&& info) : type(type), info(info) {}
|
||||
|
||||
LexerToken& operator=(LexerToken&&) = default;
|
||||
LexerToken& operator=(const LexerToken&) = default;
|
||||
|
||||
Type type;
|
||||
std::string info;
|
||||
};
|
||||
using LexerTokenList = std::list<LexerToken>;
|
||||
|
||||
void ParseText(std::string&&);
|
||||
void ParseText(const std::string&);
|
||||
|
||||
LexerTokenList GetTokens() const;
|
||||
private:
|
||||
void PushToken();
|
||||
LexerTokenList tokens;
|
||||
|
||||
LexerToken::Type current_state = LexerToken::Type::None;
|
||||
std::string current_info;
|
||||
};
|
||||
|
||||
using LexerTokenList = Lexer::LexerTokenList;
|
||||
|
||||
namespace std {
|
||||
std::string to_string(Lexer::LexerToken::Type);
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue