2021-09-08 15:18:24 +02:00
|
|
|
#include <hex/pattern_language/lexer.hpp>
|
2020-11-10 15:26:38 +01:00
|
|
|
|
2021-01-05 14:42:08 +01:00
|
|
|
#include <algorithm>
|
2020-11-10 15:26:38 +01:00
|
|
|
#include <functional>
|
2020-12-18 21:44:13 +01:00
|
|
|
#include <optional>
|
2021-01-05 14:42:08 +01:00
|
|
|
#include <vector>
|
2020-11-10 15:26:38 +01:00
|
|
|
|
2021-09-08 15:18:24 +02:00
|
|
|
namespace hex::pl {
|
2020-11-10 15:26:38 +01:00
|
|
|
|
Pattern Language rewrite (#111)
* Initial parser rewrite effort
Lexer and Token cleanup, Parser started over
* Greatly improved parser syntax
* Reimplemented using declarations and variable placement parsing
* Added back unions and structs
* Added enums as well as mathematical expressions (+, -, *, /, <<, >>, &, |, ^)
* Code style improvement
* Implemented arrays and fixed memory issues
* Fixed more memory issues in parser, reimplemented validator, evaluator and patterns
* Fixed builtin types, arrays and reimplemented strings
* Improved error messages
* Made character a distinct type, used for chars and strings
* Implemented padding, fixed arrays
* Added bitfields
* Added rvalue parsing, no evaluating yet
* Added .idea folder to gitignore
* Fixed build on MacOS
* Added custom implementation of integral concept if not available
* Rebased onto master
* Fixed array variable decl crash
* Added rvalues and dot syntax
* Lower case all pattern language error messages
* Fixed typo in variable name
* Fixed bug where preprocessor would not ignore commented out directives
* Reimplemented pointers
* Fixed rebase issues
2021-01-02 20:27:11 +01:00
|
|
|
#define TOKEN(type, value) Token::Type::type, Token::type::value, lineNumber
|
|
|
|
#define VALUE_TOKEN(type, value) Token::Type::type, value, lineNumber
|
|
|
|
|
2020-11-10 15:26:38 +01:00
|
|
|
std::string matchTillInvalid(const char* characters, std::function<bool(char)> predicate) {
|
|
|
|
std::string ret;
|
|
|
|
|
|
|
|
while (*characters != 0x00) {
|
|
|
|
ret += *characters;
|
|
|
|
characters++;
|
|
|
|
|
|
|
|
if (!predicate(*characters))
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2021-09-08 15:18:24 +02:00
|
|
|
size_t getIntegerLiteralLength(const std::string &string) {
|
2021-01-05 14:42:08 +01:00
|
|
|
return string.find_first_not_of("0123456789ABCDEFabcdef.xUL");
|
|
|
|
}
|
|
|
|
|
2021-09-21 21:29:18 +02:00
|
|
|
std::optional<Token::Literal> parseIntegerLiteral(const std::string &string) {
|
2021-01-05 14:42:08 +01:00
|
|
|
Token::ValueType type = Token::ValueType::Any;
|
2021-09-21 21:29:18 +02:00
|
|
|
Token::Literal result;
|
2021-01-05 14:42:08 +01:00
|
|
|
|
2020-11-11 10:47:02 +01:00
|
|
|
u8 base;
|
2020-11-10 15:26:38 +01:00
|
|
|
|
2021-01-05 14:42:08 +01:00
|
|
|
auto endPos = getIntegerLiteralLength(string);
|
2021-09-08 15:18:24 +02:00
|
|
|
auto numberData = std::string_view(string).substr(0, endPos);
|
2021-01-05 14:42:08 +01:00
|
|
|
|
|
|
|
if (numberData.ends_with('U')) {
|
|
|
|
type = Token::ValueType::Unsigned128Bit;
|
|
|
|
numberData.remove_suffix(1);
|
2021-01-07 15:37:37 +01:00
|
|
|
} else if (!numberData.starts_with("0x") && !numberData.starts_with("0b")) {
|
|
|
|
if (numberData.ends_with('F')) {
|
|
|
|
type = Token::ValueType::Float;
|
|
|
|
numberData.remove_suffix(1);
|
|
|
|
} else if (numberData.ends_with('D')) {
|
|
|
|
type = Token::ValueType::Double;
|
|
|
|
numberData.remove_suffix(1);
|
|
|
|
}
|
2021-01-05 14:42:08 +01:00
|
|
|
}
|
2020-11-10 15:26:38 +01:00
|
|
|
|
2021-01-05 14:42:08 +01:00
|
|
|
if (numberData.starts_with("0x")) {
|
|
|
|
numberData = numberData.substr(2);
|
2020-11-10 15:26:38 +01:00
|
|
|
base = 16;
|
|
|
|
|
2021-01-05 14:42:08 +01:00
|
|
|
if (Token::isFloatingPoint(type))
|
|
|
|
return { };
|
|
|
|
|
2020-11-10 15:26:38 +01:00
|
|
|
if (numberData.find_first_not_of("0123456789ABCDEFabcdef") != std::string_view::npos)
|
|
|
|
return { };
|
2021-01-05 14:42:08 +01:00
|
|
|
} else if (numberData.starts_with("0b")) {
|
|
|
|
numberData = numberData.substr(2);
|
2020-11-10 15:26:38 +01:00
|
|
|
base = 2;
|
|
|
|
|
2021-01-05 14:42:08 +01:00
|
|
|
if (Token::isFloatingPoint(type))
|
|
|
|
return { };
|
|
|
|
|
2020-11-10 15:26:38 +01:00
|
|
|
if (numberData.find_first_not_of("01") != std::string_view::npos)
|
|
|
|
return { };
|
2021-01-05 14:42:08 +01:00
|
|
|
} else if (numberData.find('.') != std::string_view::npos || Token::isFloatingPoint(type)) {
|
|
|
|
base = 10;
|
|
|
|
if (type == Token::ValueType::Any)
|
|
|
|
type = Token::ValueType::Double;
|
|
|
|
|
|
|
|
if (std::count(numberData.begin(), numberData.end(), '.') > 1 || numberData.find_first_not_of("0123456789.") != std::string_view::npos)
|
|
|
|
return { };
|
|
|
|
|
|
|
|
if (numberData.ends_with('.'))
|
|
|
|
return { };
|
|
|
|
} else if (isdigit(numberData[0])) {
|
2020-11-10 15:26:38 +01:00
|
|
|
base = 10;
|
|
|
|
|
|
|
|
if (numberData.find_first_not_of("0123456789") != std::string_view::npos)
|
|
|
|
return { };
|
|
|
|
} else return { };
|
|
|
|
|
2021-01-05 14:42:08 +01:00
|
|
|
if (type == Token::ValueType::Any)
|
2021-09-21 21:29:18 +02:00
|
|
|
type = Token::ValueType::Signed128Bit;
|
2021-01-05 14:42:08 +01:00
|
|
|
|
|
|
|
|
2020-11-10 15:26:38 +01:00
|
|
|
if (numberData.length() == 0)
|
|
|
|
return { };
|
|
|
|
|
2021-01-05 14:42:08 +01:00
|
|
|
if (Token::isUnsigned(type) || Token::isSigned(type)) {
|
|
|
|
u128 integer = 0;
|
|
|
|
for (const char& c : numberData) {
|
2020-11-10 15:26:38 +01:00
|
|
|
integer *= base;
|
|
|
|
|
2021-01-05 14:42:08 +01:00
|
|
|
if (isdigit(c))
|
|
|
|
integer += (c - '0');
|
|
|
|
else if (c >= 'A' && c <= 'F')
|
|
|
|
integer += 10 + (c - 'A');
|
|
|
|
else if (c >= 'a' && c <= 'f')
|
|
|
|
integer += 10 + (c - 'a');
|
|
|
|
else return { };
|
|
|
|
}
|
|
|
|
|
|
|
|
switch (type) {
|
2021-06-20 21:22:31 +02:00
|
|
|
case Token::ValueType::Unsigned128Bit: return { u128(integer) };
|
|
|
|
case Token::ValueType::Signed128Bit: return { s128(integer) };
|
2021-01-05 14:42:08 +01:00
|
|
|
default: return { };
|
|
|
|
}
|
|
|
|
} else if (Token::isFloatingPoint(type)) {
|
|
|
|
double floatingPoint = strtod(numberData.data(), nullptr);
|
|
|
|
|
|
|
|
switch (type) {
|
2021-06-20 21:22:31 +02:00
|
|
|
case Token::ValueType::Float: return { float(floatingPoint) };
|
|
|
|
case Token::ValueType::Double: return { double(floatingPoint) };
|
2021-01-05 14:42:08 +01:00
|
|
|
default: return { };
|
|
|
|
}
|
2020-11-10 15:26:38 +01:00
|
|
|
}
|
|
|
|
|
2021-01-05 14:42:08 +01:00
|
|
|
|
|
|
|
return { };
|
2020-11-10 15:26:38 +01:00
|
|
|
}
|
|
|
|
|
2021-09-08 15:18:24 +02:00
|
|
|
std::optional<std::pair<char, size_t>> getCharacter(const std::string &string) {
|
2021-01-09 21:45:48 +01:00
|
|
|
|
|
|
|
if (string.length() < 1)
|
|
|
|
return { };
|
|
|
|
|
|
|
|
// Escape sequences
|
|
|
|
if (string[0] == '\\') {
|
|
|
|
|
|
|
|
if (string.length() < 2)
|
|
|
|
return { };
|
|
|
|
|
|
|
|
// Handle simple escape sequences
|
|
|
|
switch (string[1]) {
|
|
|
|
case 'a': return {{ '\a', 2 }};
|
|
|
|
case 'b': return {{ '\b', 2 }};
|
|
|
|
case 'f': return {{ '\f', 2 }};
|
|
|
|
case 'n': return {{ '\n', 2 }};
|
|
|
|
case 'r': return {{ '\r', 2 }};
|
|
|
|
case 't': return {{ '\t', 2 }};
|
|
|
|
case 'v': return {{ '\v', 2 }};
|
|
|
|
case '\\': return {{ '\\', 2 }};
|
|
|
|
case '\'': return {{ '\'', 2 }};
|
|
|
|
case '\"': return {{ '\"', 2 }};
|
|
|
|
}
|
|
|
|
|
|
|
|
// Hexadecimal number
|
|
|
|
if (string[1] == 'x') {
|
|
|
|
if (string.length() != 4)
|
|
|
|
return { };
|
|
|
|
|
|
|
|
if (!isxdigit(string[2]) || !isxdigit(string[3]))
|
|
|
|
return { };
|
|
|
|
|
|
|
|
return {{ std::strtoul(&string[2], nullptr, 16), 4 }};
|
|
|
|
}
|
|
|
|
|
|
|
|
// Octal number
|
|
|
|
if (string[1] == 'o') {
|
|
|
|
if (string.length() != 5)
|
|
|
|
return { };
|
|
|
|
|
|
|
|
if (string[2] < '0' || string[2] > '7' || string[3] < '0' || string[3] > '7' || string[4] < '0' || string[4] > '7')
|
|
|
|
return { };
|
|
|
|
|
|
|
|
return {{ std::strtoul(&string[2], nullptr, 8), 5 }};
|
|
|
|
}
|
|
|
|
|
|
|
|
return { };
|
|
|
|
} else return {{ string[0], 1 }};
|
|
|
|
}
|
|
|
|
|
2021-09-08 15:18:24 +02:00
|
|
|
std::optional<std::pair<std::string, size_t>> getStringLiteral(const std::string &string) {
|
2021-01-09 21:45:48 +01:00
|
|
|
if (!string.starts_with('\"'))
|
|
|
|
return { };
|
|
|
|
|
|
|
|
size_t size = 1;
|
|
|
|
|
|
|
|
std::string result;
|
|
|
|
while (string[size] != '\"') {
|
|
|
|
auto character = getCharacter(string.substr(size));
|
|
|
|
|
|
|
|
if (!character.has_value())
|
|
|
|
return { };
|
|
|
|
|
|
|
|
auto &[c, charSize] = character.value();
|
|
|
|
|
|
|
|
result += c;
|
|
|
|
size += charSize;
|
|
|
|
|
|
|
|
if (size >= string.length())
|
|
|
|
return { };
|
|
|
|
}
|
|
|
|
|
|
|
|
return {{ result, size + 1 }};
|
|
|
|
}
|
|
|
|
|
2021-09-08 15:18:24 +02:00
|
|
|
std::optional<std::pair<char, size_t>> getCharacterLiteral(const std::string &string) {
|
2021-01-09 21:45:48 +01:00
|
|
|
if (string.empty())
|
|
|
|
return { };
|
|
|
|
|
2021-06-17 23:13:58 +02:00
|
|
|
if (string[0] != '\'')
|
2021-01-09 21:45:48 +01:00
|
|
|
return { };
|
|
|
|
|
|
|
|
|
|
|
|
auto character = getCharacter(string.substr(1));
|
|
|
|
|
|
|
|
if (!character.has_value())
|
|
|
|
return { };
|
|
|
|
|
|
|
|
auto &[c, charSize] = character.value();
|
|
|
|
|
2021-06-17 23:13:58 +02:00
|
|
|
if (string.length() >= charSize + 2 && string[charSize + 1] != '\'')
|
2021-01-09 21:45:48 +01:00
|
|
|
return { };
|
|
|
|
|
|
|
|
return {{ c, charSize + 2 }};
|
|
|
|
}
|
|
|
|
|
2020-12-22 18:10:01 +01:00
|
|
|
std::optional<std::vector<Token>> Lexer::lex(const std::string& code) {
|
2020-11-10 15:26:38 +01:00
|
|
|
std::vector<Token> tokens;
|
|
|
|
u32 offset = 0;
|
|
|
|
|
2020-11-27 21:20:23 +01:00
|
|
|
u32 lineNumber = 1;
|
|
|
|
|
Pattern Language rewrite (#111)
* Initial parser rewrite effort
Lexer and Token cleanup, Parser started over
* Greatly improved parser syntax
* Reimplemented using declarations and variable placement parsing
* Added back unions and structs
* Added enums as well as mathematical expressions (+, -, *, /, <<, >>, &, |, ^)
* Code style improvement
* Implemented arrays and fixed memory issues
* Fixed more memory issues in parser, reimplemented validator, evaluator and patterns
* Fixed builtin types, arrays and reimplemented strings
* Improved error messages
* Made character a distinct type, used for chars and strings
* Implemented padding, fixed arrays
* Added bitfields
* Added rvalue parsing, no evaluating yet
* Added .idea folder to gitignore
* Fixed build on MacOS
* Added custom implementation of integral concept if not available
* Rebased onto master
* Fixed array variable decl crash
* Added rvalues and dot syntax
* Lower case all pattern language error messages
* Fixed typo in variable name
* Fixed bug where preprocessor would not ignore commented out directives
* Reimplemented pointers
* Fixed rebase issues
2021-01-02 20:27:11 +01:00
|
|
|
try {
|
2020-11-14 14:40:21 +01:00
|
|
|
|
Pattern Language rewrite (#111)
* Initial parser rewrite effort
Lexer and Token cleanup, Parser started over
* Greatly improved parser syntax
* Reimplemented using declarations and variable placement parsing
* Added back unions and structs
* Added enums as well as mathematical expressions (+, -, *, /, <<, >>, &, |, ^)
* Code style improvement
* Implemented arrays and fixed memory issues
* Fixed more memory issues in parser, reimplemented validator, evaluator and patterns
* Fixed builtin types, arrays and reimplemented strings
* Improved error messages
* Made character a distinct type, used for chars and strings
* Implemented padding, fixed arrays
* Added bitfields
* Added rvalue parsing, no evaluating yet
* Added .idea folder to gitignore
* Fixed build on MacOS
* Added custom implementation of integral concept if not available
* Rebased onto master
* Fixed array variable decl crash
* Added rvalues and dot syntax
* Lower case all pattern language error messages
* Fixed typo in variable name
* Fixed bug where preprocessor would not ignore commented out directives
* Reimplemented pointers
* Fixed rebase issues
2021-01-02 20:27:11 +01:00
|
|
|
while (offset < code.length()) {
|
|
|
|
const char& c = code[offset];
|
2020-11-13 14:35:52 +01:00
|
|
|
|
Pattern Language rewrite (#111)
* Initial parser rewrite effort
Lexer and Token cleanup, Parser started over
* Greatly improved parser syntax
* Reimplemented using declarations and variable placement parsing
* Added back unions and structs
* Added enums as well as mathematical expressions (+, -, *, /, <<, >>, &, |, ^)
* Code style improvement
* Implemented arrays and fixed memory issues
* Fixed more memory issues in parser, reimplemented validator, evaluator and patterns
* Fixed builtin types, arrays and reimplemented strings
* Improved error messages
* Made character a distinct type, used for chars and strings
* Implemented padding, fixed arrays
* Added bitfields
* Added rvalue parsing, no evaluating yet
* Added .idea folder to gitignore
* Fixed build on MacOS
* Added custom implementation of integral concept if not available
* Rebased onto master
* Fixed array variable decl crash
* Added rvalues and dot syntax
* Lower case all pattern language error messages
* Fixed typo in variable name
* Fixed bug where preprocessor would not ignore commented out directives
* Reimplemented pointers
* Fixed rebase issues
2021-01-02 20:27:11 +01:00
|
|
|
if (c == 0x00)
|
|
|
|
break;
|
2020-11-13 14:35:52 +01:00
|
|
|
|
Pattern Language rewrite (#111)
* Initial parser rewrite effort
Lexer and Token cleanup, Parser started over
* Greatly improved parser syntax
* Reimplemented using declarations and variable placement parsing
* Added back unions and structs
* Added enums as well as mathematical expressions (+, -, *, /, <<, >>, &, |, ^)
* Code style improvement
* Implemented arrays and fixed memory issues
* Fixed more memory issues in parser, reimplemented validator, evaluator and patterns
* Fixed builtin types, arrays and reimplemented strings
* Improved error messages
* Made character a distinct type, used for chars and strings
* Implemented padding, fixed arrays
* Added bitfields
* Added rvalue parsing, no evaluating yet
* Added .idea folder to gitignore
* Fixed build on MacOS
* Added custom implementation of integral concept if not available
* Rebased onto master
* Fixed array variable decl crash
* Added rvalues and dot syntax
* Lower case all pattern language error messages
* Fixed typo in variable name
* Fixed bug where preprocessor would not ignore commented out directives
* Reimplemented pointers
* Fixed rebase issues
2021-01-02 20:27:11 +01:00
|
|
|
if (std::isblank(c) || std::isspace(c)) {
|
|
|
|
if (code[offset] == '\n') lineNumber++;
|
|
|
|
offset += 1;
|
|
|
|
} else if (c == ';') {
|
|
|
|
tokens.emplace_back(TOKEN(Separator, EndOfExpression));
|
|
|
|
offset += 1;
|
|
|
|
} else if (c == '(') {
|
|
|
|
tokens.emplace_back(TOKEN(Separator, RoundBracketOpen));
|
|
|
|
offset += 1;
|
|
|
|
} else if (c == ')') {
|
|
|
|
tokens.emplace_back(TOKEN(Separator, RoundBracketClose));
|
|
|
|
offset += 1;
|
|
|
|
} else if (c == '{') {
|
|
|
|
tokens.emplace_back(TOKEN(Separator, CurlyBracketOpen));
|
|
|
|
offset += 1;
|
|
|
|
} else if (c == '}') {
|
|
|
|
tokens.emplace_back(TOKEN(Separator, CurlyBracketClose));
|
|
|
|
offset += 1;
|
|
|
|
} else if (c == '[') {
|
|
|
|
tokens.emplace_back(TOKEN(Separator, SquareBracketOpen));
|
|
|
|
offset += 1;
|
|
|
|
} else if (c == ']') {
|
|
|
|
tokens.emplace_back(TOKEN(Separator, SquareBracketClose));
|
|
|
|
offset += 1;
|
|
|
|
} else if (c == ',') {
|
|
|
|
tokens.emplace_back(TOKEN(Separator, Comma));
|
|
|
|
offset += 1;
|
|
|
|
} else if (c == '.') {
|
|
|
|
tokens.emplace_back(TOKEN(Separator, Dot));
|
|
|
|
offset += 1;
|
2021-08-25 17:07:01 +02:00
|
|
|
} else if (code.substr(offset, 2) == "::") {
|
|
|
|
tokens.emplace_back(TOKEN(Operator, ScopeResolution));
|
|
|
|
offset += 2;
|
Pattern Language rewrite (#111)
* Initial parser rewrite effort
Lexer and Token cleanup, Parser started over
* Greatly improved parser syntax
* Reimplemented using declarations and variable placement parsing
* Added back unions and structs
* Added enums as well as mathematical expressions (+, -, *, /, <<, >>, &, |, ^)
* Code style improvement
* Implemented arrays and fixed memory issues
* Fixed more memory issues in parser, reimplemented validator, evaluator and patterns
* Fixed builtin types, arrays and reimplemented strings
* Improved error messages
* Made character a distinct type, used for chars and strings
* Implemented padding, fixed arrays
* Added bitfields
* Added rvalue parsing, no evaluating yet
* Added .idea folder to gitignore
* Fixed build on MacOS
* Added custom implementation of integral concept if not available
* Rebased onto master
* Fixed array variable decl crash
* Added rvalues and dot syntax
* Lower case all pattern language error messages
* Fixed typo in variable name
* Fixed bug where preprocessor would not ignore commented out directives
* Reimplemented pointers
* Fixed rebase issues
2021-01-02 20:27:11 +01:00
|
|
|
} else if (c == '@') {
|
|
|
|
tokens.emplace_back(TOKEN(Operator, AtDeclaration));
|
|
|
|
offset += 1;
|
2021-01-07 00:02:51 +01:00
|
|
|
} else if (code.substr(offset, 2) == "==") {
|
|
|
|
tokens.emplace_back(TOKEN(Operator, BoolEquals));
|
|
|
|
offset += 2;
|
|
|
|
} else if (code.substr(offset, 2) == "!=") {
|
|
|
|
tokens.emplace_back(TOKEN(Operator, BoolNotEquals));
|
|
|
|
offset += 2;
|
|
|
|
} else if (code.substr(offset, 2) == ">=") {
|
|
|
|
tokens.emplace_back(TOKEN(Operator, BoolGreaterThanOrEquals));
|
|
|
|
offset += 2;
|
|
|
|
} else if (code.substr(offset, 2) == "<=") {
|
|
|
|
tokens.emplace_back(TOKEN(Operator, BoolLessThanOrEquals));
|
|
|
|
offset += 2;
|
|
|
|
} else if (code.substr(offset, 2) == "&&") {
|
|
|
|
tokens.emplace_back(TOKEN(Operator, BoolAnd));
|
|
|
|
offset += 2;
|
|
|
|
} else if (code.substr(offset, 2) == "||") {
|
|
|
|
tokens.emplace_back(TOKEN(Operator, BoolOr));
|
|
|
|
offset += 2;
|
|
|
|
} else if (code.substr(offset, 2) == "^^") {
|
|
|
|
tokens.emplace_back(TOKEN(Operator, BoolXor));
|
|
|
|
offset += 2;
|
Pattern Language rewrite (#111)
* Initial parser rewrite effort
Lexer and Token cleanup, Parser started over
* Greatly improved parser syntax
* Reimplemented using declarations and variable placement parsing
* Added back unions and structs
* Added enums as well as mathematical expressions (+, -, *, /, <<, >>, &, |, ^)
* Code style improvement
* Implemented arrays and fixed memory issues
* Fixed more memory issues in parser, reimplemented validator, evaluator and patterns
* Fixed builtin types, arrays and reimplemented strings
* Improved error messages
* Made character a distinct type, used for chars and strings
* Implemented padding, fixed arrays
* Added bitfields
* Added rvalue parsing, no evaluating yet
* Added .idea folder to gitignore
* Fixed build on MacOS
* Added custom implementation of integral concept if not available
* Rebased onto master
* Fixed array variable decl crash
* Added rvalues and dot syntax
* Lower case all pattern language error messages
* Fixed typo in variable name
* Fixed bug where preprocessor would not ignore commented out directives
* Reimplemented pointers
* Fixed rebase issues
2021-01-02 20:27:11 +01:00
|
|
|
} else if (c == '=') {
|
|
|
|
tokens.emplace_back(TOKEN(Operator, Assignment));
|
|
|
|
offset += 1;
|
|
|
|
} else if (c == ':') {
|
|
|
|
tokens.emplace_back(TOKEN(Operator, Inherit));
|
|
|
|
offset += 1;
|
|
|
|
} else if (c == '+') {
|
|
|
|
tokens.emplace_back(TOKEN(Operator, Plus));
|
|
|
|
offset += 1;
|
|
|
|
} else if (c == '-') {
|
|
|
|
tokens.emplace_back(TOKEN(Operator, Minus));
|
|
|
|
offset += 1;
|
|
|
|
} else if (c == '*') {
|
|
|
|
tokens.emplace_back(TOKEN(Operator, Star));
|
|
|
|
offset += 1;
|
|
|
|
} else if (c == '/') {
|
|
|
|
tokens.emplace_back(TOKEN(Operator, Slash));
|
|
|
|
offset += 1;
|
2021-01-20 22:55:57 +01:00
|
|
|
} else if (c == '%') {
|
|
|
|
tokens.emplace_back(TOKEN(Operator, Percent));
|
|
|
|
offset += 1;
|
2021-01-05 14:42:08 +01:00
|
|
|
} else if (code.substr(offset, 2) == "<<") {
|
Pattern Language rewrite (#111)
* Initial parser rewrite effort
Lexer and Token cleanup, Parser started over
* Greatly improved parser syntax
* Reimplemented using declarations and variable placement parsing
* Added back unions and structs
* Added enums as well as mathematical expressions (+, -, *, /, <<, >>, &, |, ^)
* Code style improvement
* Implemented arrays and fixed memory issues
* Fixed more memory issues in parser, reimplemented validator, evaluator and patterns
* Fixed builtin types, arrays and reimplemented strings
* Improved error messages
* Made character a distinct type, used for chars and strings
* Implemented padding, fixed arrays
* Added bitfields
* Added rvalue parsing, no evaluating yet
* Added .idea folder to gitignore
* Fixed build on MacOS
* Added custom implementation of integral concept if not available
* Rebased onto master
* Fixed array variable decl crash
* Added rvalues and dot syntax
* Lower case all pattern language error messages
* Fixed typo in variable name
* Fixed bug where preprocessor would not ignore commented out directives
* Reimplemented pointers
* Fixed rebase issues
2021-01-02 20:27:11 +01:00
|
|
|
tokens.emplace_back(TOKEN(Operator, ShiftLeft));
|
2020-11-13 14:35:52 +01:00
|
|
|
offset += 2;
|
2021-01-05 14:42:08 +01:00
|
|
|
} else if (code.substr(offset, 2) == ">>") {
|
Pattern Language rewrite (#111)
* Initial parser rewrite effort
Lexer and Token cleanup, Parser started over
* Greatly improved parser syntax
* Reimplemented using declarations and variable placement parsing
* Added back unions and structs
* Added enums as well as mathematical expressions (+, -, *, /, <<, >>, &, |, ^)
* Code style improvement
* Implemented arrays and fixed memory issues
* Fixed more memory issues in parser, reimplemented validator, evaluator and patterns
* Fixed builtin types, arrays and reimplemented strings
* Improved error messages
* Made character a distinct type, used for chars and strings
* Implemented padding, fixed arrays
* Added bitfields
* Added rvalue parsing, no evaluating yet
* Added .idea folder to gitignore
* Fixed build on MacOS
* Added custom implementation of integral concept if not available
* Rebased onto master
* Fixed array variable decl crash
* Added rvalues and dot syntax
* Lower case all pattern language error messages
* Fixed typo in variable name
* Fixed bug where preprocessor would not ignore commented out directives
* Reimplemented pointers
* Fixed rebase issues
2021-01-02 20:27:11 +01:00
|
|
|
tokens.emplace_back(TOKEN(Operator, ShiftRight));
|
|
|
|
offset += 2;
|
2021-01-07 00:02:51 +01:00
|
|
|
} else if (c == '>') {
|
|
|
|
tokens.emplace_back(TOKEN(Operator, BoolGreaterThan));
|
|
|
|
offset += 1;
|
|
|
|
} else if (c == '<') {
|
|
|
|
tokens.emplace_back(TOKEN(Operator, BoolLessThan));
|
|
|
|
offset += 1;
|
2021-01-07 00:41:06 +01:00
|
|
|
} else if (c == '!') {
|
|
|
|
tokens.emplace_back(TOKEN(Operator, BoolNot));
|
|
|
|
offset += 1;
|
Pattern Language rewrite (#111)
* Initial parser rewrite effort
Lexer and Token cleanup, Parser started over
* Greatly improved parser syntax
* Reimplemented using declarations and variable placement parsing
* Added back unions and structs
* Added enums as well as mathematical expressions (+, -, *, /, <<, >>, &, |, ^)
* Code style improvement
* Implemented arrays and fixed memory issues
* Fixed more memory issues in parser, reimplemented validator, evaluator and patterns
* Fixed builtin types, arrays and reimplemented strings
* Improved error messages
* Made character a distinct type, used for chars and strings
* Implemented padding, fixed arrays
* Added bitfields
* Added rvalue parsing, no evaluating yet
* Added .idea folder to gitignore
* Fixed build on MacOS
* Added custom implementation of integral concept if not available
* Rebased onto master
* Fixed array variable decl crash
* Added rvalues and dot syntax
* Lower case all pattern language error messages
* Fixed typo in variable name
* Fixed bug where preprocessor would not ignore commented out directives
* Reimplemented pointers
* Fixed rebase issues
2021-01-02 20:27:11 +01:00
|
|
|
} else if (c == '|') {
|
|
|
|
tokens.emplace_back(TOKEN(Operator, BitOr));
|
|
|
|
offset += 1;
|
|
|
|
} else if (c == '&') {
|
|
|
|
tokens.emplace_back(TOKEN(Operator, BitAnd));
|
|
|
|
offset += 1;
|
|
|
|
} else if (c == '^') {
|
|
|
|
tokens.emplace_back(TOKEN(Operator, BitXor));
|
|
|
|
offset += 1;
|
2021-01-07 00:41:06 +01:00
|
|
|
} else if (c == '~') {
|
|
|
|
tokens.emplace_back(TOKEN(Operator, BitNot));
|
|
|
|
offset += 1;
|
2021-01-07 01:19:54 +01:00
|
|
|
} else if (c == '?') {
|
|
|
|
tokens.emplace_back(TOKEN(Operator, TernaryConditional));
|
|
|
|
offset += 1;
|
2021-01-20 22:56:31 +01:00
|
|
|
} else if (c == '$') {
|
|
|
|
tokens.emplace_back(TOKEN(Operator, Dollar));
|
|
|
|
offset += 1;
|
2021-04-21 10:17:42 +02:00
|
|
|
} else if (code.substr(offset, 9) == "addressof") {
|
|
|
|
tokens.emplace_back(TOKEN(Operator, AddressOf));
|
|
|
|
offset += 9;
|
|
|
|
}
|
|
|
|
else if (code.substr(offset, 6) == "sizeof") {
|
|
|
|
tokens.emplace_back(TOKEN(Operator, SizeOf));
|
|
|
|
offset += 6;
|
|
|
|
}
|
|
|
|
else if (c == '\'') {
|
2021-01-09 21:45:48 +01:00
|
|
|
auto character = getCharacterLiteral(code.substr(offset));
|
2020-11-13 14:35:52 +01:00
|
|
|
|
2021-01-09 21:45:48 +01:00
|
|
|
if (!character.has_value())
|
Pattern Language rewrite (#111)
* Initial parser rewrite effort
Lexer and Token cleanup, Parser started over
* Greatly improved parser syntax
* Reimplemented using declarations and variable placement parsing
* Added back unions and structs
* Added enums as well as mathematical expressions (+, -, *, /, <<, >>, &, |, ^)
* Code style improvement
* Implemented arrays and fixed memory issues
* Fixed more memory issues in parser, reimplemented validator, evaluator and patterns
* Fixed builtin types, arrays and reimplemented strings
* Improved error messages
* Made character a distinct type, used for chars and strings
* Implemented padding, fixed arrays
* Added bitfields
* Added rvalue parsing, no evaluating yet
* Added .idea folder to gitignore
* Fixed build on MacOS
* Added custom implementation of integral concept if not available
* Rebased onto master
* Fixed array variable decl crash
* Added rvalues and dot syntax
* Lower case all pattern language error messages
* Fixed typo in variable name
* Fixed bug where preprocessor would not ignore commented out directives
* Reimplemented pointers
* Fixed rebase issues
2021-01-02 20:27:11 +01:00
|
|
|
throwLexerError("invalid character literal", lineNumber);
|
2020-11-10 15:26:38 +01:00
|
|
|
|
2021-01-09 21:45:48 +01:00
|
|
|
auto [c, charSize] = character.value();
|
2020-11-27 14:18:28 +01:00
|
|
|
|
2021-09-21 21:29:18 +02:00
|
|
|
tokens.emplace_back(VALUE_TOKEN(Integer, Token::Literal(c)));
|
2021-01-09 21:45:48 +01:00
|
|
|
offset += charSize;
|
|
|
|
} else if (c == '\"') {
|
|
|
|
auto string = getStringLiteral(code.substr(offset));
|
Pattern Language rewrite (#111)
* Initial parser rewrite effort
Lexer and Token cleanup, Parser started over
* Greatly improved parser syntax
* Reimplemented using declarations and variable placement parsing
* Added back unions and structs
* Added enums as well as mathematical expressions (+, -, *, /, <<, >>, &, |, ^)
* Code style improvement
* Implemented arrays and fixed memory issues
* Fixed more memory issues in parser, reimplemented validator, evaluator and patterns
* Fixed builtin types, arrays and reimplemented strings
* Improved error messages
* Made character a distinct type, used for chars and strings
* Implemented padding, fixed arrays
* Added bitfields
* Added rvalue parsing, no evaluating yet
* Added .idea folder to gitignore
* Fixed build on MacOS
* Added custom implementation of integral concept if not available
* Rebased onto master
* Fixed array variable decl crash
* Added rvalues and dot syntax
* Lower case all pattern language error messages
* Fixed typo in variable name
* Fixed bug where preprocessor would not ignore commented out directives
* Reimplemented pointers
* Fixed rebase issues
2021-01-02 20:27:11 +01:00
|
|
|
|
2021-01-09 21:45:48 +01:00
|
|
|
if (!string.has_value())
|
|
|
|
throwLexerError("invalid string literal", lineNumber);
|
Pattern Language rewrite (#111)
* Initial parser rewrite effort
Lexer and Token cleanup, Parser started over
* Greatly improved parser syntax
* Reimplemented using declarations and variable placement parsing
* Added back unions and structs
* Added enums as well as mathematical expressions (+, -, *, /, <<, >>, &, |, ^)
* Code style improvement
* Implemented arrays and fixed memory issues
* Fixed more memory issues in parser, reimplemented validator, evaluator and patterns
* Fixed builtin types, arrays and reimplemented strings
* Improved error messages
* Made character a distinct type, used for chars and strings
* Implemented padding, fixed arrays
* Added bitfields
* Added rvalue parsing, no evaluating yet
* Added .idea folder to gitignore
* Fixed build on MacOS
* Added custom implementation of integral concept if not available
* Rebased onto master
* Fixed array variable decl crash
* Added rvalues and dot syntax
* Lower case all pattern language error messages
* Fixed typo in variable name
* Fixed bug where preprocessor would not ignore commented out directives
* Reimplemented pointers
* Fixed rebase issues
2021-01-02 20:27:11 +01:00
|
|
|
|
2021-01-09 21:45:48 +01:00
|
|
|
auto [s, stringSize] = string.value();
|
Pattern Language rewrite (#111)
* Initial parser rewrite effort
Lexer and Token cleanup, Parser started over
* Greatly improved parser syntax
* Reimplemented using declarations and variable placement parsing
* Added back unions and structs
* Added enums as well as mathematical expressions (+, -, *, /, <<, >>, &, |, ^)
* Code style improvement
* Implemented arrays and fixed memory issues
* Fixed more memory issues in parser, reimplemented validator, evaluator and patterns
* Fixed builtin types, arrays and reimplemented strings
* Improved error messages
* Made character a distinct type, used for chars and strings
* Implemented padding, fixed arrays
* Added bitfields
* Added rvalue parsing, no evaluating yet
* Added .idea folder to gitignore
* Fixed build on MacOS
* Added custom implementation of integral concept if not available
* Rebased onto master
* Fixed array variable decl crash
* Added rvalues and dot syntax
* Lower case all pattern language error messages
* Fixed typo in variable name
* Fixed bug where preprocessor would not ignore commented out directives
* Reimplemented pointers
* Fixed rebase issues
2021-01-02 20:27:11 +01:00
|
|
|
|
2021-09-21 21:29:18 +02:00
|
|
|
tokens.emplace_back(VALUE_TOKEN(String, Token::Literal(s)));
|
2021-01-09 21:45:48 +01:00
|
|
|
offset += stringSize;
|
2021-09-25 14:52:17 +02:00
|
|
|
} else if (std::isalpha(c) || c == '_') {
|
Pattern Language rewrite (#111)
* Initial parser rewrite effort
Lexer and Token cleanup, Parser started over
* Greatly improved parser syntax
* Reimplemented using declarations and variable placement parsing
* Added back unions and structs
* Added enums as well as mathematical expressions (+, -, *, /, <<, >>, &, |, ^)
* Code style improvement
* Implemented arrays and fixed memory issues
* Fixed more memory issues in parser, reimplemented validator, evaluator and patterns
* Fixed builtin types, arrays and reimplemented strings
* Improved error messages
* Made character a distinct type, used for chars and strings
* Implemented padding, fixed arrays
* Added bitfields
* Added rvalue parsing, no evaluating yet
* Added .idea folder to gitignore
* Fixed build on MacOS
* Added custom implementation of integral concept if not available
* Rebased onto master
* Fixed array variable decl crash
* Added rvalues and dot syntax
* Lower case all pattern language error messages
* Fixed typo in variable name
* Fixed bug where preprocessor would not ignore commented out directives
* Reimplemented pointers
* Fixed rebase issues
2021-01-02 20:27:11 +01:00
|
|
|
std::string identifier = matchTillInvalid(&code[offset], [](char c) -> bool { return std::isalnum(c) || c == '_'; });
|
|
|
|
|
|
|
|
// Check for reserved keywords
|
|
|
|
|
|
|
|
if (identifier == "struct")
|
|
|
|
tokens.emplace_back(TOKEN(Keyword, Struct));
|
|
|
|
else if (identifier == "union")
|
|
|
|
tokens.emplace_back(TOKEN(Keyword, Union));
|
|
|
|
else if (identifier == "using")
|
|
|
|
tokens.emplace_back(TOKEN(Keyword, Using));
|
|
|
|
else if (identifier == "enum")
|
|
|
|
tokens.emplace_back(TOKEN(Keyword, Enum));
|
|
|
|
else if (identifier == "bitfield")
|
|
|
|
tokens.emplace_back(TOKEN(Keyword, Bitfield));
|
|
|
|
else if (identifier == "be")
|
|
|
|
tokens.emplace_back(TOKEN(Keyword, BigEndian));
|
|
|
|
else if (identifier == "le")
|
|
|
|
tokens.emplace_back(TOKEN(Keyword, LittleEndian));
|
2021-01-07 00:02:51 +01:00
|
|
|
else if (identifier == "if")
|
|
|
|
tokens.emplace_back(TOKEN(Keyword, If));
|
|
|
|
else if (identifier == "else")
|
|
|
|
tokens.emplace_back(TOKEN(Keyword, Else));
|
2021-01-07 17:34:50 +01:00
|
|
|
else if (identifier == "false")
|
2021-09-21 21:29:18 +02:00
|
|
|
tokens.emplace_back(VALUE_TOKEN(Integer, Token::Literal(false)));
|
2021-01-07 17:34:50 +01:00
|
|
|
else if (identifier == "true")
|
2021-09-21 21:29:18 +02:00
|
|
|
tokens.emplace_back(VALUE_TOKEN(Integer, Token::Literal(true)));
|
2021-04-12 20:49:37 +02:00
|
|
|
else if (identifier == "parent")
|
|
|
|
tokens.emplace_back(TOKEN(Keyword, Parent));
|
2021-09-21 21:29:18 +02:00
|
|
|
else if (identifier == "this")
|
|
|
|
tokens.emplace_back(TOKEN(Keyword, This));
|
2021-06-17 23:13:58 +02:00
|
|
|
else if (identifier == "while")
|
|
|
|
tokens.emplace_back(TOKEN(Keyword, While));
|
2021-06-20 21:22:31 +02:00
|
|
|
else if (identifier == "fn")
|
|
|
|
tokens.emplace_back(TOKEN(Keyword, Function));
|
|
|
|
else if (identifier == "return")
|
|
|
|
tokens.emplace_back(TOKEN(Keyword, Return));
|
2021-08-25 17:07:01 +02:00
|
|
|
else if (identifier == "namespace")
|
|
|
|
tokens.emplace_back(TOKEN(Keyword, Namespace));
|
Pattern Language rewrite (#111)
* Initial parser rewrite effort
Lexer and Token cleanup, Parser started over
* Greatly improved parser syntax
* Reimplemented using declarations and variable placement parsing
* Added back unions and structs
* Added enums as well as mathematical expressions (+, -, *, /, <<, >>, &, |, ^)
* Code style improvement
* Implemented arrays and fixed memory issues
* Fixed more memory issues in parser, reimplemented validator, evaluator and patterns
* Fixed builtin types, arrays and reimplemented strings
* Improved error messages
* Made character a distinct type, used for chars and strings
* Implemented padding, fixed arrays
* Added bitfields
* Added rvalue parsing, no evaluating yet
* Added .idea folder to gitignore
* Fixed build on MacOS
* Added custom implementation of integral concept if not available
* Rebased onto master
* Fixed array variable decl crash
* Added rvalues and dot syntax
* Lower case all pattern language error messages
* Fixed typo in variable name
* Fixed bug where preprocessor would not ignore commented out directives
* Reimplemented pointers
* Fixed rebase issues
2021-01-02 20:27:11 +01:00
|
|
|
|
|
|
|
// Check for built-in types
|
|
|
|
else if (identifier == "u8")
|
|
|
|
tokens.emplace_back(TOKEN(ValueType, Unsigned8Bit));
|
|
|
|
else if (identifier == "s8")
|
|
|
|
tokens.emplace_back(TOKEN(ValueType, Signed8Bit));
|
|
|
|
else if (identifier == "u16")
|
|
|
|
tokens.emplace_back(TOKEN(ValueType, Unsigned16Bit));
|
|
|
|
else if (identifier == "s16")
|
|
|
|
tokens.emplace_back(TOKEN(ValueType, Signed16Bit));
|
|
|
|
else if (identifier == "u32")
|
|
|
|
tokens.emplace_back(TOKEN(ValueType, Unsigned32Bit));
|
|
|
|
else if (identifier == "s32")
|
|
|
|
tokens.emplace_back(TOKEN(ValueType, Signed32Bit));
|
|
|
|
else if (identifier == "u64")
|
|
|
|
tokens.emplace_back(TOKEN(ValueType, Unsigned64Bit));
|
|
|
|
else if (identifier == "s64")
|
|
|
|
tokens.emplace_back(TOKEN(ValueType, Signed64Bit));
|
|
|
|
else if (identifier == "u128")
|
|
|
|
tokens.emplace_back(TOKEN(ValueType, Unsigned128Bit));
|
|
|
|
else if (identifier == "s128")
|
|
|
|
tokens.emplace_back(TOKEN(ValueType, Signed128Bit));
|
|
|
|
else if (identifier == "float")
|
|
|
|
tokens.emplace_back(TOKEN(ValueType, Float));
|
|
|
|
else if (identifier == "double")
|
|
|
|
tokens.emplace_back(TOKEN(ValueType, Double));
|
|
|
|
else if (identifier == "char")
|
|
|
|
tokens.emplace_back(TOKEN(ValueType, Character));
|
2021-05-02 20:13:37 +02:00
|
|
|
else if (identifier == "char16")
|
|
|
|
tokens.emplace_back(TOKEN(ValueType, Character16));
|
2021-01-07 17:34:50 +01:00
|
|
|
else if (identifier == "bool")
|
|
|
|
tokens.emplace_back(TOKEN(ValueType, Boolean));
|
2021-09-21 21:29:18 +02:00
|
|
|
else if (identifier == "str")
|
|
|
|
tokens.emplace_back(TOKEN(ValueType, String));
|
Pattern Language rewrite (#111)
* Initial parser rewrite effort
Lexer and Token cleanup, Parser started over
* Greatly improved parser syntax
* Reimplemented using declarations and variable placement parsing
* Added back unions and structs
* Added enums as well as mathematical expressions (+, -, *, /, <<, >>, &, |, ^)
* Code style improvement
* Implemented arrays and fixed memory issues
* Fixed more memory issues in parser, reimplemented validator, evaluator and patterns
* Fixed builtin types, arrays and reimplemented strings
* Improved error messages
* Made character a distinct type, used for chars and strings
* Implemented padding, fixed arrays
* Added bitfields
* Added rvalue parsing, no evaluating yet
* Added .idea folder to gitignore
* Fixed build on MacOS
* Added custom implementation of integral concept if not available
* Rebased onto master
* Fixed array variable decl crash
* Added rvalues and dot syntax
* Lower case all pattern language error messages
* Fixed typo in variable name
* Fixed bug where preprocessor would not ignore commented out directives
* Reimplemented pointers
* Fixed rebase issues
2021-01-02 20:27:11 +01:00
|
|
|
else if (identifier == "padding")
|
|
|
|
tokens.emplace_back(TOKEN(ValueType, Padding));
|
2021-09-23 23:43:16 +02:00
|
|
|
else if (identifier == "auto")
|
|
|
|
tokens.emplace_back(TOKEN(ValueType, Auto));
|
Pattern Language rewrite (#111)
* Initial parser rewrite effort
Lexer and Token cleanup, Parser started over
* Greatly improved parser syntax
* Reimplemented using declarations and variable placement parsing
* Added back unions and structs
* Added enums as well as mathematical expressions (+, -, *, /, <<, >>, &, |, ^)
* Code style improvement
* Implemented arrays and fixed memory issues
* Fixed more memory issues in parser, reimplemented validator, evaluator and patterns
* Fixed builtin types, arrays and reimplemented strings
* Improved error messages
* Made character a distinct type, used for chars and strings
* Implemented padding, fixed arrays
* Added bitfields
* Added rvalue parsing, no evaluating yet
* Added .idea folder to gitignore
* Fixed build on MacOS
* Added custom implementation of integral concept if not available
* Rebased onto master
* Fixed array variable decl crash
* Added rvalues and dot syntax
* Lower case all pattern language error messages
* Fixed typo in variable name
* Fixed bug where preprocessor would not ignore commented out directives
* Reimplemented pointers
* Fixed rebase issues
2021-01-02 20:27:11 +01:00
|
|
|
|
|
|
|
// If it's not a keyword and a builtin type, it has to be an identifier
|
|
|
|
|
|
|
|
else
|
2021-09-21 21:29:18 +02:00
|
|
|
tokens.emplace_back(VALUE_TOKEN(Identifier, Token::Identifier(identifier)));
|
Pattern Language rewrite (#111)
* Initial parser rewrite effort
Lexer and Token cleanup, Parser started over
* Greatly improved parser syntax
* Reimplemented using declarations and variable placement parsing
* Added back unions and structs
* Added enums as well as mathematical expressions (+, -, *, /, <<, >>, &, |, ^)
* Code style improvement
* Implemented arrays and fixed memory issues
* Fixed more memory issues in parser, reimplemented validator, evaluator and patterns
* Fixed builtin types, arrays and reimplemented strings
* Improved error messages
* Made character a distinct type, used for chars and strings
* Implemented padding, fixed arrays
* Added bitfields
* Added rvalue parsing, no evaluating yet
* Added .idea folder to gitignore
* Fixed build on MacOS
* Added custom implementation of integral concept if not available
* Rebased onto master
* Fixed array variable decl crash
* Added rvalues and dot syntax
* Lower case all pattern language error messages
* Fixed typo in variable name
* Fixed bug where preprocessor would not ignore commented out directives
* Reimplemented pointers
* Fixed rebase issues
2021-01-02 20:27:11 +01:00
|
|
|
|
|
|
|
offset += identifier.length();
|
|
|
|
} else if (std::isdigit(c)) {
|
2021-01-05 14:42:08 +01:00
|
|
|
auto integer = parseIntegerLiteral(&code[offset]);
|
Pattern Language rewrite (#111)
* Initial parser rewrite effort
Lexer and Token cleanup, Parser started over
* Greatly improved parser syntax
* Reimplemented using declarations and variable placement parsing
* Added back unions and structs
* Added enums as well as mathematical expressions (+, -, *, /, <<, >>, &, |, ^)
* Code style improvement
* Implemented arrays and fixed memory issues
* Fixed more memory issues in parser, reimplemented validator, evaluator and patterns
* Fixed builtin types, arrays and reimplemented strings
* Improved error messages
* Made character a distinct type, used for chars and strings
* Implemented padding, fixed arrays
* Added bitfields
* Added rvalue parsing, no evaluating yet
* Added .idea folder to gitignore
* Fixed build on MacOS
* Added custom implementation of integral concept if not available
* Rebased onto master
* Fixed array variable decl crash
* Added rvalues and dot syntax
* Lower case all pattern language error messages
* Fixed typo in variable name
* Fixed bug where preprocessor would not ignore commented out directives
* Reimplemented pointers
* Fixed rebase issues
2021-01-02 20:27:11 +01:00
|
|
|
|
|
|
|
if (!integer.has_value())
|
|
|
|
throwLexerError("invalid integer literal", lineNumber);
|
|
|
|
|
|
|
|
|
2021-09-21 21:29:18 +02:00
|
|
|
tokens.emplace_back(VALUE_TOKEN(Integer, Token::Literal(integer.value())));
|
2021-01-05 14:42:08 +01:00
|
|
|
offset += getIntegerLiteralLength(&code[offset]);
|
Pattern Language rewrite (#111)
* Initial parser rewrite effort
Lexer and Token cleanup, Parser started over
* Greatly improved parser syntax
* Reimplemented using declarations and variable placement parsing
* Added back unions and structs
* Added enums as well as mathematical expressions (+, -, *, /, <<, >>, &, |, ^)
* Code style improvement
* Implemented arrays and fixed memory issues
* Fixed more memory issues in parser, reimplemented validator, evaluator and patterns
* Fixed builtin types, arrays and reimplemented strings
* Improved error messages
* Made character a distinct type, used for chars and strings
* Implemented padding, fixed arrays
* Added bitfields
* Added rvalue parsing, no evaluating yet
* Added .idea folder to gitignore
* Fixed build on MacOS
* Added custom implementation of integral concept if not available
* Rebased onto master
* Fixed array variable decl crash
* Added rvalues and dot syntax
* Lower case all pattern language error messages
* Fixed typo in variable name
* Fixed bug where preprocessor would not ignore commented out directives
* Reimplemented pointers
* Fixed rebase issues
2021-01-02 20:27:11 +01:00
|
|
|
} else
|
|
|
|
throwLexerError("unknown token", lineNumber);
|
|
|
|
|
2020-11-27 21:20:23 +01:00
|
|
|
}
|
Pattern Language rewrite (#111)
* Initial parser rewrite effort
Lexer and Token cleanup, Parser started over
* Greatly improved parser syntax
* Reimplemented using declarations and variable placement parsing
* Added back unions and structs
* Added enums as well as mathematical expressions (+, -, *, /, <<, >>, &, |, ^)
* Code style improvement
* Implemented arrays and fixed memory issues
* Fixed more memory issues in parser, reimplemented validator, evaluator and patterns
* Fixed builtin types, arrays and reimplemented strings
* Improved error messages
* Made character a distinct type, used for chars and strings
* Implemented padding, fixed arrays
* Added bitfields
* Added rvalue parsing, no evaluating yet
* Added .idea folder to gitignore
* Fixed build on MacOS
* Added custom implementation of integral concept if not available
* Rebased onto master
* Fixed array variable decl crash
* Added rvalues and dot syntax
* Lower case all pattern language error messages
* Fixed typo in variable name
* Fixed bug where preprocessor would not ignore commented out directives
* Reimplemented pointers
* Fixed rebase issues
2021-01-02 20:27:11 +01:00
|
|
|
|
|
|
|
tokens.emplace_back(TOKEN(Separator, EndOfProgram));
|
|
|
|
} catch (LexerError &e) {
|
|
|
|
this->m_error = e;
|
|
|
|
return { };
|
2020-11-10 15:26:38 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2020-12-22 18:10:01 +01:00
|
|
|
return tokens;
|
2020-11-10 15:26:38 +01:00
|
|
|
}
|
|
|
|
}
|