2021-09-08 15:18:24 +02:00
|
|
|
#include <hex/pattern_language/parser.hpp>
|
2020-11-10 15:26:38 +01:00
|
|
|
|
2022-02-27 23:25:39 +01:00
|
|
|
#include <hex/pattern_language/ast/ast_node_array_variable_decl.hpp>
|
|
|
|
#include <hex/pattern_language/ast/ast_node_assignment.hpp>
|
|
|
|
#include <hex/pattern_language/ast/ast_node_attribute.hpp>
|
|
|
|
#include <hex/pattern_language/ast/ast_node_bitfield.hpp>
|
|
|
|
#include <hex/pattern_language/ast/ast_node_builtin_type.hpp>
|
|
|
|
#include <hex/pattern_language/ast/ast_node_cast.hpp>
|
|
|
|
#include <hex/pattern_language/ast/ast_node_compound_statement.hpp>
|
|
|
|
#include <hex/pattern_language/ast/ast_node_conditional_statement.hpp>
|
|
|
|
#include <hex/pattern_language/ast/ast_node_control_flow_statement.hpp>
|
|
|
|
#include <hex/pattern_language/ast/ast_node_enum.hpp>
|
|
|
|
#include <hex/pattern_language/ast/ast_node_function_call.hpp>
|
|
|
|
#include <hex/pattern_language/ast/ast_node_function_definition.hpp>
|
|
|
|
#include <hex/pattern_language/ast/ast_node_literal.hpp>
|
|
|
|
#include <hex/pattern_language/ast/ast_node_mathematical_expression.hpp>
|
|
|
|
#include <hex/pattern_language/ast/ast_node_multi_variable_decl.hpp>
|
|
|
|
#include <hex/pattern_language/ast/ast_node_parameter_pack.hpp>
|
|
|
|
#include <hex/pattern_language/ast/ast_node_pointer_variable_decl.hpp>
|
|
|
|
#include <hex/pattern_language/ast/ast_node_rvalue.hpp>
|
|
|
|
#include <hex/pattern_language/ast/ast_node_scope_resolution.hpp>
|
|
|
|
#include <hex/pattern_language/ast/ast_node_struct.hpp>
|
|
|
|
#include <hex/pattern_language/ast/ast_node_ternary_expression.hpp>
|
|
|
|
#include <hex/pattern_language/ast/ast_node_type_decl.hpp>
|
|
|
|
#include <hex/pattern_language/ast/ast_node_type_operator.hpp>
|
|
|
|
#include <hex/pattern_language/ast/ast_node_union.hpp>
|
|
|
|
#include <hex/pattern_language/ast/ast_node_variable_decl.hpp>
|
|
|
|
#include <hex/pattern_language/ast/ast_node_while_statement.hpp>
|
|
|
|
|
2020-11-10 15:26:38 +01:00
|
|
|
#include <optional>
|
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
|
|
|
|
2022-01-29 04:16:32 +01:00
|
|
|
#define MATCHES(x) (begin() && resetIfFailed(x))
|
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
|
|
|
// Definition syntax:
|
|
|
|
// [A] : Either A or no token
|
|
|
|
// [A|B] : Either A, B or no token
|
|
|
|
// <A|B> : Either A or B
|
|
|
|
// <A...> : One or more of A
|
|
|
|
// A B C : Sequence of tokens A then B then C
|
|
|
|
// (parseXXXX) : Parsing handled by other function
|
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
|
|
|
/* Mathematical expressions */
|
2020-11-10 15:26:38 +01:00
|
|
|
|
2021-01-07 15:37:37 +01:00
|
|
|
// Identifier([(parseMathematicalExpression)|<(parseMathematicalExpression),...>(parseMathematicalExpression)]
|
2022-02-27 23:25:39 +01:00
|
|
|
std::unique_ptr<ASTNode> Parser::parseFunctionCall() {
|
2021-09-03 02:33:45 +02:00
|
|
|
std::string functionName = parseNamespaceResolution();
|
2021-08-25 17:07:01 +02:00
|
|
|
|
|
|
|
if (!MATCHES(sequence(SEPARATOR_ROUNDBRACKETOPEN)))
|
2022-01-31 14:37:12 +01:00
|
|
|
throwParserError("expected '(' after function name");
|
2021-08-25 17:07:01 +02:00
|
|
|
|
2022-02-27 23:25:39 +01:00
|
|
|
std::vector<std::unique_ptr<ASTNode>> params;
|
2021-01-07 15:37:37 +01:00
|
|
|
|
|
|
|
while (!MATCHES(sequence(SEPARATOR_ROUNDBRACKETCLOSE))) {
|
2021-09-21 21:29:18 +02:00
|
|
|
params.push_back(parseMathematicalExpression());
|
2021-01-07 15:37:37 +01:00
|
|
|
|
|
|
|
if (MATCHES(sequence(SEPARATOR_COMMA, SEPARATOR_ROUNDBRACKETCLOSE)))
|
2022-01-31 14:37:12 +01:00
|
|
|
throwParserError("unexpected ',' at end of function parameter list", -1);
|
2021-01-07 15:37:37 +01:00
|
|
|
else if (MATCHES(sequence(SEPARATOR_ROUNDBRACKETCLOSE)))
|
|
|
|
break;
|
|
|
|
else if (!MATCHES(sequence(SEPARATOR_COMMA)))
|
2022-01-31 14:37:12 +01:00
|
|
|
throwParserError("missing ',' between parameters", -1);
|
2021-01-07 15:37:37 +01:00
|
|
|
}
|
|
|
|
|
2022-02-27 23:25:39 +01:00
|
|
|
return create(new ASTNodeFunctionCall(functionName, std::move(params)));
|
2021-01-09 21:47:11 +01:00
|
|
|
}
|
|
|
|
|
2022-02-27 23:25:39 +01:00
|
|
|
std::unique_ptr<ASTNode> Parser::parseStringLiteral() {
|
2021-09-21 21:29:18 +02:00
|
|
|
return create(new ASTNodeLiteral(getValue<Token::Literal>(-1)));
|
2021-01-07 15:37:37 +01:00
|
|
|
}
|
|
|
|
|
2021-09-03 02:33:45 +02:00
|
|
|
std::string Parser::parseNamespaceResolution() {
|
2021-08-25 17:07:01 +02:00
|
|
|
std::string name;
|
|
|
|
|
|
|
|
while (true) {
|
2021-09-21 21:29:18 +02:00
|
|
|
name += getValue<Token::Identifier>(-1).get();
|
2021-01-05 14:42:08 +01:00
|
|
|
|
2021-08-25 17:07:01 +02:00
|
|
|
if (MATCHES(sequence(OPERATOR_SCOPERESOLUTION, IDENTIFIER))) {
|
|
|
|
name += "::";
|
|
|
|
continue;
|
2022-01-24 20:53:17 +01:00
|
|
|
} else
|
2021-08-25 17:07:01 +02:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
return name;
|
2021-01-05 14:42:08 +01:00
|
|
|
}
|
|
|
|
|
2022-02-27 23:25:39 +01:00
|
|
|
std::unique_ptr<ASTNode> Parser::parseScopeResolution() {
|
2021-09-03 02:33:45 +02:00
|
|
|
std::string typeName;
|
|
|
|
|
|
|
|
while (true) {
|
2021-09-21 21:29:18 +02:00
|
|
|
typeName += getValue<Token::Identifier>(-1).get();
|
2021-09-03 02:33:45 +02:00
|
|
|
|
|
|
|
if (MATCHES(sequence(OPERATOR_SCOPERESOLUTION, IDENTIFIER))) {
|
|
|
|
if (peek(OPERATOR_SCOPERESOLUTION, 0) && peek(IDENTIFIER, 1)) {
|
|
|
|
typeName += "::";
|
2022-01-24 20:53:17 +01:00
|
|
|
continue;
|
2021-09-03 02:33:45 +02:00
|
|
|
} else {
|
2021-09-25 14:52:17 +02:00
|
|
|
if (!this->m_types.contains(typeName))
|
2022-01-31 14:37:12 +01:00
|
|
|
throwParserError(hex::format("cannot access scope of invalid type '{}'", typeName), -1);
|
2021-09-25 14:52:17 +02:00
|
|
|
|
|
|
|
return create(new ASTNodeScopeResolution(this->m_types[typeName]->clone(), getValue<Token::Identifier>(-1).get()));
|
2021-09-03 02:33:45 +02:00
|
|
|
}
|
2022-01-24 20:53:17 +01:00
|
|
|
} else
|
2021-09-03 02:33:45 +02:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2022-01-31 14:37:12 +01:00
|
|
|
throwParserError("failed to parse scope resolution. Expected 'TypeName::Identifier'");
|
2021-09-03 02:33:45 +02:00
|
|
|
}
|
|
|
|
|
2022-02-27 23:25:39 +01:00
|
|
|
std::unique_ptr<ASTNode> Parser::parseRValue() {
|
2022-01-29 04:16:32 +01:00
|
|
|
ASTNodeRValue::Path path;
|
|
|
|
return this->parseRValue(path);
|
|
|
|
}
|
|
|
|
|
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
|
|
|
// <Identifier[.]...>
|
2022-02-27 23:25:39 +01:00
|
|
|
std::unique_ptr<ASTNode> Parser::parseRValue(ASTNodeRValue::Path &path) {
|
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 (peek(IDENTIFIER, -1))
|
2021-09-21 21:29:18 +02:00
|
|
|
path.push_back(getValue<Token::Identifier>(-1).get());
|
2021-04-12 20:49:37 +02:00
|
|
|
else if (peek(KEYWORD_PARENT, -1))
|
|
|
|
path.emplace_back("parent");
|
2021-09-21 21:29:18 +02:00
|
|
|
else if (peek(KEYWORD_THIS, -1))
|
|
|
|
path.emplace_back("this");
|
2020-11-10 15:26:38 +01:00
|
|
|
|
2021-04-21 10:17:42 +02:00
|
|
|
if (MATCHES(sequence(SEPARATOR_SQUAREBRACKETOPEN))) {
|
|
|
|
path.push_back(parseMathematicalExpression());
|
|
|
|
if (!MATCHES(sequence(SEPARATOR_SQUAREBRACKETCLOSE)))
|
2022-01-31 14:37:12 +01:00
|
|
|
throwParserError("expected closing ']' at end of array indexing");
|
2021-04-21 10:17:42 +02: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 (MATCHES(sequence(SEPARATOR_DOT))) {
|
2021-04-12 20:49:37 +02:00
|
|
|
if (MATCHES(oneOf(IDENTIFIER, KEYWORD_PARENT)))
|
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
|
|
|
return this->parseRValue(path);
|
|
|
|
else
|
2022-01-31 14:37:12 +01:00
|
|
|
throwParserError("expected member name or 'parent' keyword", -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
|
2022-02-27 23:25:39 +01:00
|
|
|
return create(new ASTNodeRValue(std::move(path)));
|
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
|
|
|
// <Integer|((parseMathematicalExpression))>
|
2022-02-27 23:25:39 +01:00
|
|
|
std::unique_ptr<ASTNode> Parser::parseFactor() {
|
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 (MATCHES(sequence(INTEGER)))
|
2022-02-27 23:25:39 +01:00
|
|
|
return create(new ASTNodeLiteral(getValue<Token::Literal>(-1)));
|
2021-09-24 01:55:00 +02:00
|
|
|
else if (peek(OPERATOR_PLUS) || peek(OPERATOR_MINUS) || peek(OPERATOR_BITNOT) || peek(OPERATOR_BOOLNOT))
|
|
|
|
return this->parseMathematicalExpression();
|
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 (MATCHES(sequence(SEPARATOR_ROUNDBRACKETOPEN))) {
|
|
|
|
auto node = this->parseMathematicalExpression();
|
2022-02-27 23:25:39 +01:00
|
|
|
if (!MATCHES(sequence(SEPARATOR_ROUNDBRACKETCLOSE)))
|
2022-01-31 14:37:12 +01:00
|
|
|
throwParserError("expected closing parenthesis");
|
2022-02-27 23:25:39 +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
|
|
|
return node;
|
2021-08-25 17:07:01 +02:00
|
|
|
} else if (MATCHES(sequence(IDENTIFIER))) {
|
|
|
|
auto originalPos = this->m_curr;
|
2021-09-03 02:33:45 +02:00
|
|
|
parseNamespaceResolution();
|
2021-08-25 17:07:01 +02:00
|
|
|
bool isFunction = peek(SEPARATOR_ROUNDBRACKETOPEN);
|
2022-02-01 22:09:44 +01:00
|
|
|
this->m_curr = originalPos;
|
2021-08-25 17:07:01 +02:00
|
|
|
|
2021-09-03 02:33:45 +02:00
|
|
|
|
2021-08-25 17:07:01 +02:00
|
|
|
if (isFunction) {
|
2021-09-21 21:29:18 +02:00
|
|
|
return this->parseFunctionCall();
|
2021-09-03 02:33:45 +02:00
|
|
|
} else if (peek(OPERATOR_SCOPERESOLUTION, 0)) {
|
2021-09-21 21:29:18 +02:00
|
|
|
return this->parseScopeResolution();
|
2021-09-03 02:33:45 +02:00
|
|
|
} else {
|
2022-01-29 04:16:32 +01:00
|
|
|
return this->parseRValue();
|
2021-08-25 17:07:01 +02:00
|
|
|
}
|
2021-09-21 21:29:18 +02:00
|
|
|
} else if (MATCHES(oneOf(KEYWORD_PARENT, KEYWORD_THIS))) {
|
2022-01-29 04:16:32 +01:00
|
|
|
return this->parseRValue();
|
2021-01-20 22:56:31 +01:00
|
|
|
} else if (MATCHES(sequence(OPERATOR_DOLLAR))) {
|
2022-02-27 23:25:39 +01:00
|
|
|
return create(new ASTNodeRValue(hex::moveToVector<ASTNodeRValue::PathSegment>("$")));
|
2021-04-21 10:17:42 +02:00
|
|
|
} else if (MATCHES(oneOf(OPERATOR_ADDRESSOF, OPERATOR_SIZEOF) && sequence(SEPARATOR_ROUNDBRACKETOPEN))) {
|
|
|
|
auto op = getValue<Token::Operator>(-2);
|
|
|
|
|
2022-02-27 23:25:39 +01:00
|
|
|
std::unique_ptr<ASTNode> result;
|
2022-01-29 04:16:32 +01:00
|
|
|
|
|
|
|
if (MATCHES(oneOf(IDENTIFIER, KEYWORD_PARENT, KEYWORD_THIS))) {
|
|
|
|
result = create(new ASTNodeTypeOperator(op, this->parseRValue()));
|
|
|
|
} else if (MATCHES(sequence(VALUETYPE_ANY))) {
|
|
|
|
auto type = getValue<Token::ValueType>(-1);
|
|
|
|
|
2022-02-27 23:25:39 +01:00
|
|
|
result = create(new ASTNodeLiteral(u128(Token::getTypeSize(type))));
|
2022-01-29 04:16:32 +01:00
|
|
|
} else {
|
2022-01-31 14:37:12 +01:00
|
|
|
throwParserError("expected rvalue identifier or built-in type");
|
2021-04-21 10:17:42 +02:00
|
|
|
}
|
|
|
|
|
2022-02-27 23:25:39 +01:00
|
|
|
if (!MATCHES(sequence(SEPARATOR_ROUNDBRACKETCLOSE)))
|
2022-01-31 14:37:12 +01:00
|
|
|
throwParserError("expected closing parenthesis");
|
2022-01-29 04:16:32 +01:00
|
|
|
|
|
|
|
return result;
|
2021-01-07 15:37:37 +01:00
|
|
|
} else
|
2022-01-31 14:37:12 +01:00
|
|
|
throwParserError("expected value or parenthesis");
|
2021-09-21 21:29:18 +02:00
|
|
|
}
|
|
|
|
|
2022-02-27 23:25:39 +01:00
|
|
|
std::unique_ptr<ASTNode> Parser::parseCastExpression() {
|
2021-09-21 21:29:18 +02:00
|
|
|
if (peek(KEYWORD_BE) || peek(KEYWORD_LE) || peek(VALUETYPE_ANY)) {
|
2022-02-01 22:09:44 +01:00
|
|
|
auto type = parseType(true);
|
2022-02-27 23:25:39 +01:00
|
|
|
auto builtinType = dynamic_cast<ASTNodeBuiltinType *>(type->getType().get());
|
2021-09-21 21:29:18 +02:00
|
|
|
|
|
|
|
if (builtinType == nullptr)
|
2022-01-31 14:37:12 +01:00
|
|
|
throwParserError("invalid type used for pointer size", -1);
|
2021-09-21 21:29:18 +02:00
|
|
|
|
2021-09-24 12:15:50 +02:00
|
|
|
if (!peek(SEPARATOR_ROUNDBRACKETOPEN))
|
2022-01-31 14:37:12 +01:00
|
|
|
throwParserError("expected '(' before cast expression", -1);
|
2021-09-21 21:29:18 +02:00
|
|
|
|
|
|
|
auto node = parseFactor();
|
|
|
|
|
2022-02-27 23:25:39 +01:00
|
|
|
return create(new ASTNodeCast(std::move(node), std::move(type)));
|
2021-09-21 21:29:18 +02:00
|
|
|
} else return parseFactor();
|
2020-11-10 15:26:38 +01:00
|
|
|
}
|
|
|
|
|
2021-01-07 00:41:06 +01:00
|
|
|
// <+|-|!|~> (parseFactor)
|
2022-02-27 23:25:39 +01:00
|
|
|
std::unique_ptr<ASTNode> Parser::parseUnaryExpression() {
|
2021-01-20 22:55:57 +01:00
|
|
|
if (MATCHES(oneOf(OPERATOR_PLUS, OPERATOR_MINUS, OPERATOR_BOOLNOT, OPERATOR_BITNOT))) {
|
2021-01-07 00:41:06 +01:00
|
|
|
auto op = getValue<Token::Operator>(-1);
|
|
|
|
|
2022-02-27 23:25:39 +01:00
|
|
|
return create(new ASTNodeMathematicalExpression(create(new ASTNodeLiteral(0)), this->parseCastExpression(), op));
|
2021-09-21 21:29:18 +02:00
|
|
|
} else if (MATCHES(sequence(STRING))) {
|
|
|
|
return this->parseStringLiteral();
|
2021-01-07 00:41:06 +01:00
|
|
|
}
|
|
|
|
|
2021-09-21 21:29:18 +02:00
|
|
|
return this->parseCastExpression();
|
2021-01-07 00:41:06 +01:00
|
|
|
}
|
|
|
|
|
2021-01-20 22:55:57 +01:00
|
|
|
// (parseUnaryExpression) <*|/|%> (parseUnaryExpression)
|
2022-02-27 23:25:39 +01:00
|
|
|
std::unique_ptr<ASTNode> Parser::parseMultiplicativeExpression() {
|
2021-01-07 00:41:06 +01:00
|
|
|
auto node = this->parseUnaryExpression();
|
2020-12-06 21:40:57 +01:00
|
|
|
|
2021-01-20 22:55:57 +01:00
|
|
|
while (MATCHES(oneOf(OPERATOR_STAR, OPERATOR_SLASH, OPERATOR_PERCENT))) {
|
2021-01-07 00:02:51 +01:00
|
|
|
auto op = getValue<Token::Operator>(-1);
|
2022-02-27 23:25:39 +01:00
|
|
|
node = create(new ASTNodeMathematicalExpression(std::move(node), this->parseUnaryExpression(), op));
|
2020-12-06 21:40:57 +01:00
|
|
|
}
|
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
|
|
|
return node;
|
|
|
|
}
|
2020-11-21 23:00:09 +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
|
|
|
// (parseMultiplicativeExpression) <+|-> (parseMultiplicativeExpression)
|
2022-02-27 23:25:39 +01:00
|
|
|
std::unique_ptr<ASTNode> Parser::parseAdditiveExpression() {
|
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
|
|
|
auto node = this->parseMultiplicativeExpression();
|
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
|
|
|
while (MATCHES(variant(OPERATOR_PLUS, OPERATOR_MINUS))) {
|
2021-01-07 00:02:51 +01:00
|
|
|
auto op = getValue<Token::Operator>(-1);
|
2022-02-27 23:25:39 +01:00
|
|
|
node = create(new ASTNodeMathematicalExpression(std::move(node), this->parseMultiplicativeExpression(), op));
|
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
|
|
|
return node;
|
2020-11-21 23:00:09 +01:00
|
|
|
}
|
|
|
|
|
2021-01-07 00:02:51 +01:00
|
|
|
// (parseAdditiveExpression) < >>|<< > (parseAdditiveExpression)
|
2022-02-27 23:25:39 +01:00
|
|
|
std::unique_ptr<ASTNode> Parser::parseShiftExpression() {
|
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
|
|
|
auto node = this->parseAdditiveExpression();
|
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
|
|
|
while (MATCHES(variant(OPERATOR_SHIFTLEFT, OPERATOR_SHIFTRIGHT))) {
|
2021-01-07 00:02:51 +01:00
|
|
|
auto op = getValue<Token::Operator>(-1);
|
2022-02-27 23:25:39 +01:00
|
|
|
node = create(new ASTNodeMathematicalExpression(std::move(node), this->parseAdditiveExpression(), op));
|
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
|
|
|
return node;
|
2020-11-21 23:00:09 +01:00
|
|
|
}
|
|
|
|
|
2022-02-07 21:37:10 +01:00
|
|
|
// (parseShiftExpression) & (parseShiftExpression)
|
2022-02-27 23:25:39 +01:00
|
|
|
std::unique_ptr<ASTNode> Parser::parseBinaryAndExpression() {
|
2022-02-07 21:37:10 +01:00
|
|
|
auto node = this->parseShiftExpression();
|
2021-01-07 00:02:51 +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 (MATCHES(sequence(OPERATOR_BITAND))) {
|
2022-02-27 23:25:39 +01:00
|
|
|
node = create(new ASTNodeMathematicalExpression(std::move(node), this->parseShiftExpression(), Token::Operator::BitAnd));
|
2020-12-06 21:40:57 +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
|
|
|
return node;
|
2020-11-12 23:57:43 +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
|
|
|
// (parseBinaryAndExpression) ^ (parseBinaryAndExpression)
|
2022-02-27 23:25:39 +01:00
|
|
|
std::unique_ptr<ASTNode> Parser::parseBinaryXorExpression() {
|
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
|
|
|
auto node = this->parseBinaryAndExpression();
|
2020-12-06 21:40:57 +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 (MATCHES(sequence(OPERATOR_BITXOR))) {
|
2022-02-27 23:25:39 +01:00
|
|
|
node = create(new ASTNodeMathematicalExpression(std::move(node), this->parseBinaryAndExpression(), Token::Operator::BitXor));
|
2020-12-06 21:40:57 +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
|
|
|
|
|
|
|
return node;
|
2020-11-21 20:19:33 +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
|
|
|
// (parseBinaryXorExpression) | (parseBinaryXorExpression)
|
2022-02-27 23:25:39 +01:00
|
|
|
std::unique_ptr<ASTNode> Parser::parseBinaryOrExpression() {
|
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
|
|
|
auto node = this->parseBinaryXorExpression();
|
2020-12-06 21:40:57 +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 (MATCHES(sequence(OPERATOR_BITOR))) {
|
2022-02-27 23:25:39 +01:00
|
|
|
node = create(new ASTNodeMathematicalExpression(std::move(node), this->parseBinaryXorExpression(), Token::Operator::BitOr));
|
2020-12-06 21:40:57 +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
|
|
|
|
|
|
|
return node;
|
2020-11-21 20:19:33 +01:00
|
|
|
}
|
|
|
|
|
2022-02-27 23:25:39 +01:00
|
|
|
// (parseBinaryOrExpression) < >=|<=|>|< > (parseBinaryOrExpression)
|
|
|
|
std::unique_ptr<ASTNode> Parser::parseRelationExpression() {
|
2021-01-07 00:02:51 +01:00
|
|
|
auto node = this->parseBinaryOrExpression();
|
|
|
|
|
2022-02-27 23:25:39 +01:00
|
|
|
while (MATCHES(sequence(OPERATOR_BOOLGREATERTHAN) || sequence(OPERATOR_BOOLLESSTHAN) || sequence(OPERATOR_BOOLGREATERTHANOREQUALS) || sequence(OPERATOR_BOOLLESSTHANOREQUALS))) {
|
|
|
|
auto op = getValue<Token::Operator>(-1);
|
|
|
|
node = create(new ASTNodeMathematicalExpression(std::move(node), this->parseBinaryOrExpression(), op));
|
2021-01-07 00:02:51 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
return node;
|
|
|
|
}
|
|
|
|
|
2022-02-27 23:25:39 +01:00
|
|
|
// (parseRelationExpression) <==|!=> (parseRelationExpression)
|
|
|
|
std::unique_ptr<ASTNode> Parser::parseEqualityExpression() {
|
|
|
|
auto node = this->parseRelationExpression();
|
2021-02-22 10:01:58 +01:00
|
|
|
|
2022-02-27 23:25:39 +01:00
|
|
|
while (MATCHES(sequence(OPERATOR_BOOLEQUALS) || sequence(OPERATOR_BOOLNOTEQUALS))) {
|
|
|
|
auto op = getValue<Token::Operator>(-1);
|
|
|
|
node = create(new ASTNodeMathematicalExpression(std::move(node), this->parseRelationExpression(), op));
|
2021-01-07 00:02:51 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
return node;
|
|
|
|
}
|
|
|
|
|
2022-02-27 23:25:39 +01:00
|
|
|
// (parseEqualityExpression) && (parseEqualityExpression)
|
|
|
|
std::unique_ptr<ASTNode> Parser::parseBooleanAnd() {
|
|
|
|
auto node = this->parseEqualityExpression();
|
2021-02-22 10:01:58 +01:00
|
|
|
|
2022-02-27 23:25:39 +01:00
|
|
|
while (MATCHES(sequence(OPERATOR_BOOLAND))) {
|
|
|
|
node = create(new ASTNodeMathematicalExpression(std::move(node), this->parseEqualityExpression(), Token::Operator::BoolAnd));
|
2021-01-07 00:02:51 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
return node;
|
|
|
|
}
|
|
|
|
|
2022-02-27 23:25:39 +01:00
|
|
|
// (parseBooleanAnd) ^^ (parseBooleanAnd)
|
|
|
|
std::unique_ptr<ASTNode> Parser::parseBooleanXor() {
|
|
|
|
auto node = this->parseBooleanAnd();
|
2021-02-22 10:01:58 +01:00
|
|
|
|
2022-02-27 23:25:39 +01:00
|
|
|
while (MATCHES(sequence(OPERATOR_BOOLXOR))) {
|
|
|
|
node = create(new ASTNodeMathematicalExpression(std::move(node), this->parseBooleanAnd(), Token::Operator::BoolXor));
|
2022-02-07 21:37:10 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
return node;
|
|
|
|
}
|
|
|
|
|
2022-02-27 23:25:39 +01:00
|
|
|
// (parseBooleanXor) || (parseBooleanXor)
|
|
|
|
std::unique_ptr<ASTNode> Parser::parseBooleanOr() {
|
|
|
|
auto node = this->parseBooleanXor();
|
2022-02-07 21:37:10 +01:00
|
|
|
|
2022-02-27 23:25:39 +01:00
|
|
|
while (MATCHES(sequence(OPERATOR_BOOLOR))) {
|
|
|
|
node = create(new ASTNodeMathematicalExpression(std::move(node), this->parseBooleanXor(), Token::Operator::BoolOr));
|
2022-02-07 21:37:10 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
return node;
|
|
|
|
}
|
|
|
|
|
2022-02-27 23:25:39 +01:00
|
|
|
// (parseBooleanOr) ? (parseBooleanOr) : (parseBooleanOr)
|
|
|
|
std::unique_ptr<ASTNode> Parser::parseTernaryConditional() {
|
|
|
|
auto node = this->parseBooleanOr();
|
2022-02-07 21:37:10 +01:00
|
|
|
|
2021-01-07 01:19:54 +01:00
|
|
|
while (MATCHES(sequence(OPERATOR_TERNARYCONDITIONAL))) {
|
2022-02-27 23:25:39 +01:00
|
|
|
auto second = this->parseBooleanOr();
|
2021-01-07 01:19:54 +01:00
|
|
|
|
|
|
|
if (!MATCHES(sequence(OPERATOR_INHERIT)))
|
2022-01-31 14:37:12 +01:00
|
|
|
throwParserError("expected ':' in ternary expression");
|
2021-01-07 01:19:54 +01:00
|
|
|
|
2022-02-27 23:25:39 +01:00
|
|
|
auto third = this->parseBooleanOr();
|
|
|
|
node = create(new ASTNodeTernaryExpression(std::move(node), std::move(second), std::move(third), Token::Operator::TernaryConditional));
|
2021-01-07 01:19:54 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
return node;
|
|
|
|
}
|
|
|
|
|
|
|
|
// (parseTernaryConditional)
|
2022-02-27 23:25:39 +01:00
|
|
|
std::unique_ptr<ASTNode> Parser::parseMathematicalExpression() {
|
2021-01-07 01:19:54 +01:00
|
|
|
return this->parseTernaryConditional();
|
2021-01-07 00:02:51 +01:00
|
|
|
}
|
|
|
|
|
2021-01-21 17:49:30 +01:00
|
|
|
// [[ <Identifier[( (parseStringLiteral) )], ...> ]]
|
|
|
|
void Parser::parseAttribute(Attributable *currNode) {
|
|
|
|
if (currNode == nullptr)
|
2022-01-31 14:37:12 +01:00
|
|
|
throwParserError("tried to apply attribute to invalid statement");
|
2021-01-21 17:49:30 +01:00
|
|
|
|
|
|
|
do {
|
|
|
|
if (!MATCHES(sequence(IDENTIFIER)))
|
2022-01-31 14:37:12 +01:00
|
|
|
throwParserError("expected attribute expression");
|
2021-01-21 17:49:30 +01:00
|
|
|
|
2021-09-21 21:29:18 +02:00
|
|
|
auto attribute = getValue<Token::Identifier>(-1).get();
|
2021-01-21 17:49:30 +01:00
|
|
|
|
|
|
|
if (MATCHES(sequence(SEPARATOR_ROUNDBRACKETOPEN, STRING, SEPARATOR_ROUNDBRACKETCLOSE))) {
|
2022-02-01 22:09:44 +01:00
|
|
|
auto value = getValue<Token::Literal>(-2);
|
2021-09-21 21:29:18 +02:00
|
|
|
auto string = std::get_if<std::string>(&value);
|
|
|
|
|
|
|
|
if (string == nullptr)
|
2022-01-31 14:37:12 +01:00
|
|
|
throwParserError("expected string attribute argument");
|
2021-09-21 21:29:18 +02:00
|
|
|
|
|
|
|
currNode->addAttribute(create(new ASTNodeAttribute(attribute, *string)));
|
2022-01-24 20:53:17 +01:00
|
|
|
} else
|
2021-09-21 21:29:18 +02:00
|
|
|
currNode->addAttribute(create(new ASTNodeAttribute(attribute)));
|
2021-01-21 17:49:30 +01:00
|
|
|
|
|
|
|
} while (MATCHES(sequence(SEPARATOR_COMMA)));
|
|
|
|
|
|
|
|
if (!MATCHES(sequence(SEPARATOR_SQUAREBRACKETCLOSE, SEPARATOR_SQUAREBRACKETCLOSE)))
|
2022-01-31 14:37:12 +01:00
|
|
|
throwParserError("unfinished attribute. Expected ']]'");
|
2021-01-21 17:49:30 +01:00
|
|
|
}
|
2021-01-07 00:02:51 +01:00
|
|
|
|
2021-06-20 21:22:31 +02:00
|
|
|
/* Functions */
|
|
|
|
|
2022-02-27 23:25:39 +01:00
|
|
|
std::unique_ptr<ASTNode> Parser::parseFunctionDefinition() {
|
2021-09-21 21:29:18 +02:00
|
|
|
const auto &functionName = getValue<Token::Identifier>(-2).get();
|
2022-02-27 23:25:39 +01:00
|
|
|
std::vector<std::pair<std::string, std::unique_ptr<ASTNode>>> params;
|
2022-01-30 15:18:45 +01:00
|
|
|
std::optional<std::string> parameterPack;
|
2021-06-20 21:22:31 +02:00
|
|
|
|
|
|
|
// Parse parameter list
|
2022-02-01 22:09:44 +01:00
|
|
|
bool hasParams = !peek(SEPARATOR_ROUNDBRACKETCLOSE);
|
2021-09-21 21:29:18 +02:00
|
|
|
u32 unnamedParamCount = 0;
|
2021-06-22 16:04:47 +02:00
|
|
|
while (hasParams) {
|
2022-01-30 15:18:45 +01:00
|
|
|
if (MATCHES(sequence(VALUETYPE_AUTO, SEPARATOR_DOT, SEPARATOR_DOT, SEPARATOR_DOT, IDENTIFIER))) {
|
|
|
|
parameterPack = getValue<Token::Identifier>(-1).get();
|
2021-06-20 21:22:31 +02:00
|
|
|
|
2022-01-30 15:18:45 +01:00
|
|
|
if (MATCHES(sequence(SEPARATOR_COMMA)))
|
2022-01-31 14:37:12 +01:00
|
|
|
throwParserError("parameter pack can only appear at end of parameter list");
|
2022-01-30 15:18:45 +01:00
|
|
|
|
|
|
|
break;
|
|
|
|
} else {
|
|
|
|
auto type = parseType(true);
|
2021-09-21 21:29:18 +02:00
|
|
|
|
2022-01-30 15:18:45 +01:00
|
|
|
if (MATCHES(sequence(IDENTIFIER)))
|
2022-02-27 23:25:39 +01:00
|
|
|
params.emplace_back(getValue<Token::Identifier>(-1).get(), std::move(type));
|
2022-01-30 15:18:45 +01:00
|
|
|
else {
|
2022-02-27 23:25:39 +01:00
|
|
|
params.emplace_back(std::to_string(unnamedParamCount), std::move(type));
|
2022-01-30 15:18:45 +01:00
|
|
|
unnamedParamCount++;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!MATCHES(sequence(SEPARATOR_COMMA))) {
|
2021-06-20 21:22:31 +02:00
|
|
|
break;
|
2022-01-30 15:18:45 +01:00
|
|
|
}
|
2021-06-20 21:22:31 +02:00
|
|
|
}
|
|
|
|
}
|
2022-01-30 15:18:45 +01:00
|
|
|
|
|
|
|
if (!MATCHES(sequence(SEPARATOR_ROUNDBRACKETCLOSE)))
|
2022-01-31 14:37:12 +01:00
|
|
|
throwParserError("expected closing ')' after parameter list");
|
2021-06-20 21:22:31 +02:00
|
|
|
|
|
|
|
if (!MATCHES(sequence(SEPARATOR_CURLYBRACKETOPEN)))
|
2022-01-31 14:37:12 +01:00
|
|
|
throwParserError("expected opening '{' after function definition");
|
2021-06-20 21:22:31 +02:00
|
|
|
|
|
|
|
|
|
|
|
// Parse function body
|
2022-02-27 23:25:39 +01:00
|
|
|
std::vector<std::unique_ptr<ASTNode>> body;
|
2021-06-20 21:22:31 +02:00
|
|
|
|
|
|
|
while (!MATCHES(sequence(SEPARATOR_CURLYBRACKETCLOSE))) {
|
2021-06-20 23:46:13 +02:00
|
|
|
body.push_back(this->parseFunctionStatement());
|
2021-06-20 21:22:31 +02:00
|
|
|
}
|
|
|
|
|
2022-02-27 23:25:39 +01:00
|
|
|
return create(new ASTNodeFunctionDefinition(getNamespacePrefixedName(functionName), std::move(params), std::move(body), parameterPack));
|
2021-06-20 21:22:31 +02:00
|
|
|
}
|
|
|
|
|
2022-02-27 23:25:39 +01:00
|
|
|
std::unique_ptr<ASTNode> Parser::parseFunctionVariableDecl() {
|
|
|
|
std::unique_ptr<ASTNode> statement;
|
2021-10-10 13:47:48 +02:00
|
|
|
auto type = parseType(true);
|
|
|
|
|
|
|
|
if (MATCHES(sequence(IDENTIFIER))) {
|
|
|
|
auto identifier = getValue<Token::Identifier>(-1).get();
|
2022-02-27 23:25:39 +01:00
|
|
|
statement = parseMemberVariable(std::move(type));
|
2021-10-10 13:47:48 +02:00
|
|
|
|
|
|
|
if (MATCHES(sequence(OPERATOR_ASSIGNMENT))) {
|
|
|
|
auto expression = parseMathematicalExpression();
|
|
|
|
|
2022-02-27 23:25:39 +01:00
|
|
|
std::vector<std::unique_ptr<ASTNode>> compoundStatement;
|
|
|
|
{
|
|
|
|
compoundStatement.push_back(std::move(statement));
|
|
|
|
compoundStatement.push_back(create(new ASTNodeAssignment(identifier, std::move(expression))));
|
|
|
|
}
|
|
|
|
|
|
|
|
statement = create(new ASTNodeCompoundStatement(std::move(compoundStatement)));
|
2021-10-10 13:47:48 +02:00
|
|
|
}
|
2022-01-24 20:53:17 +01:00
|
|
|
} else
|
2022-01-31 14:37:12 +01:00
|
|
|
throwParserError("invalid variable declaration");
|
2021-10-10 13:47:48 +02:00
|
|
|
|
|
|
|
return statement;
|
|
|
|
}
|
|
|
|
|
2022-02-27 23:25:39 +01:00
|
|
|
std::unique_ptr<ASTNode> Parser::parseFunctionStatement() {
|
2021-06-20 23:46:13 +02:00
|
|
|
bool needsSemicolon = true;
|
2022-02-27 23:25:39 +01:00
|
|
|
std::unique_ptr<ASTNode> statement;
|
2021-06-20 23:46:13 +02:00
|
|
|
|
2021-08-27 09:54:34 +02:00
|
|
|
if (MATCHES(sequence(IDENTIFIER, OPERATOR_ASSIGNMENT)))
|
2022-01-29 04:16:32 +01:00
|
|
|
statement = parseFunctionVariableAssignment(getValue<Token::Identifier>(-2).get());
|
2022-01-29 03:06:34 +01:00
|
|
|
else if (MATCHES(sequence(OPERATOR_DOLLAR, OPERATOR_ASSIGNMENT)))
|
2022-01-29 04:16:32 +01:00
|
|
|
statement = parseFunctionVariableAssignment("$");
|
|
|
|
else if (MATCHES(oneOf(IDENTIFIER) && oneOf(OPERATOR_PLUS, OPERATOR_MINUS, OPERATOR_STAR, OPERATOR_SLASH, OPERATOR_PERCENT, OPERATOR_SHIFTLEFT, OPERATOR_SHIFTRIGHT, OPERATOR_BITOR, OPERATOR_BITAND, OPERATOR_BITXOR) && sequence(OPERATOR_ASSIGNMENT)))
|
|
|
|
statement = parseFunctionVariableCompoundAssignment(getValue<Token::Identifier>(-3).get());
|
|
|
|
else if (MATCHES(oneOf(OPERATOR_DOLLAR) && oneOf(OPERATOR_PLUS, OPERATOR_MINUS, OPERATOR_STAR, OPERATOR_SLASH, OPERATOR_PERCENT, OPERATOR_SHIFTLEFT, OPERATOR_SHIFTRIGHT, OPERATOR_BITOR, OPERATOR_BITAND, OPERATOR_BITXOR) && sequence(OPERATOR_ASSIGNMENT)))
|
|
|
|
statement = parseFunctionVariableCompoundAssignment("$");
|
2021-12-30 14:44:46 +01:00
|
|
|
else if (MATCHES(oneOf(KEYWORD_RETURN, KEYWORD_BREAK, KEYWORD_CONTINUE)))
|
|
|
|
statement = parseFunctionControlFlowStatement();
|
2021-08-27 09:54:34 +02:00
|
|
|
else if (MATCHES(sequence(KEYWORD_IF, SEPARATOR_ROUNDBRACKETOPEN))) {
|
2022-02-01 22:09:44 +01:00
|
|
|
statement = parseFunctionConditional();
|
2021-08-27 09:54:34 +02:00
|
|
|
needsSemicolon = false;
|
|
|
|
} else if (MATCHES(sequence(KEYWORD_WHILE, SEPARATOR_ROUNDBRACKETOPEN))) {
|
2022-02-01 22:09:44 +01:00
|
|
|
statement = parseFunctionWhileLoop();
|
2021-08-27 09:54:34 +02:00
|
|
|
needsSemicolon = false;
|
2021-10-10 13:47:48 +02:00
|
|
|
} else if (MATCHES(sequence(KEYWORD_FOR, SEPARATOR_ROUNDBRACKETOPEN))) {
|
2022-02-01 22:09:44 +01:00
|
|
|
statement = parseFunctionForLoop();
|
2021-10-10 13:47:48 +02:00
|
|
|
needsSemicolon = false;
|
2021-08-27 09:54:34 +02:00
|
|
|
} else if (MATCHES(sequence(IDENTIFIER))) {
|
2021-08-25 17:07:01 +02:00
|
|
|
auto originalPos = this->m_curr;
|
2021-09-03 02:33:45 +02:00
|
|
|
parseNamespaceResolution();
|
2021-08-25 17:07:01 +02:00
|
|
|
bool isFunction = peek(SEPARATOR_ROUNDBRACKETOPEN);
|
|
|
|
|
|
|
|
if (isFunction) {
|
2021-10-10 15:38:58 +02:00
|
|
|
this->m_curr = originalPos;
|
2022-02-01 22:09:44 +01:00
|
|
|
statement = parseFunctionCall();
|
2022-01-24 20:53:17 +01:00
|
|
|
} else {
|
2021-10-10 15:38:58 +02:00
|
|
|
this->m_curr = originalPos - 1;
|
2022-02-01 22:09:44 +01:00
|
|
|
statement = parseFunctionVariableDecl();
|
2021-10-10 13:05:32 +02:00
|
|
|
}
|
2022-01-24 20:53:17 +01:00
|
|
|
} else if (peek(KEYWORD_BE) || peek(KEYWORD_LE) || peek(VALUETYPE_ANY)) {
|
2021-10-10 13:47:48 +02:00
|
|
|
statement = parseFunctionVariableDecl();
|
2022-01-24 20:53:17 +01:00
|
|
|
} else
|
2022-01-31 14:37:12 +01:00
|
|
|
throwParserError("invalid sequence", 0);
|
2021-06-20 23:46:13 +02:00
|
|
|
|
2022-02-27 23:25:39 +01:00
|
|
|
if (needsSemicolon && !MATCHES(sequence(SEPARATOR_ENDOFEXPRESSION)))
|
2022-01-31 14:37:12 +01:00
|
|
|
throwParserError("missing ';' at end of expression", -1);
|
2021-06-20 23:46:13 +02:00
|
|
|
|
2021-09-13 10:48:45 +02:00
|
|
|
// Consume superfluous semicolons
|
2022-01-24 20:53:17 +01:00
|
|
|
while (needsSemicolon && MATCHES(sequence(SEPARATOR_ENDOFEXPRESSION)))
|
|
|
|
;
|
2021-09-13 10:48:45 +02:00
|
|
|
|
2021-06-20 23:46:13 +02:00
|
|
|
return statement;
|
|
|
|
}
|
|
|
|
|
2022-02-27 23:25:39 +01:00
|
|
|
std::unique_ptr<ASTNode> Parser::parseFunctionVariableAssignment(const std::string &lvalue) {
|
2021-06-20 21:22:31 +02:00
|
|
|
auto rvalue = this->parseMathematicalExpression();
|
|
|
|
|
2022-02-27 23:25:39 +01:00
|
|
|
return create(new ASTNodeAssignment(lvalue, std::move(rvalue)));
|
2021-06-20 21:22:31 +02:00
|
|
|
}
|
|
|
|
|
2022-02-27 23:25:39 +01:00
|
|
|
std::unique_ptr<ASTNode> Parser::parseFunctionVariableCompoundAssignment(const std::string &lvalue) {
|
2022-01-29 04:16:32 +01:00
|
|
|
const auto &op = getValue<Token::Operator>(-2);
|
|
|
|
|
|
|
|
auto rvalue = this->parseMathematicalExpression();
|
|
|
|
|
2022-02-27 23:25:39 +01:00
|
|
|
return create(new ASTNodeAssignment(lvalue, create(new ASTNodeMathematicalExpression(create(new ASTNodeRValue(hex::moveToVector<ASTNodeRValue::PathSegment>(lvalue))), std::move(rvalue), op))));
|
2022-01-29 04:16:32 +01:00
|
|
|
}
|
|
|
|
|
2022-02-27 23:25:39 +01:00
|
|
|
std::unique_ptr<ASTNode> Parser::parseFunctionControlFlowStatement() {
|
2021-12-30 14:44:46 +01:00
|
|
|
ControlFlowStatement type;
|
|
|
|
if (peek(KEYWORD_RETURN, -1))
|
|
|
|
type = ControlFlowStatement::Return;
|
|
|
|
else if (peek(KEYWORD_BREAK, -1))
|
|
|
|
type = ControlFlowStatement::Break;
|
|
|
|
else if (peek(KEYWORD_CONTINUE, -1))
|
|
|
|
type = ControlFlowStatement::Continue;
|
|
|
|
else
|
2022-01-31 14:37:12 +01:00
|
|
|
throwParserError("invalid control flow statement. Expected 'return', 'break' or 'continue'");
|
2021-12-30 14:44:46 +01:00
|
|
|
|
2021-06-20 23:46:13 +02:00
|
|
|
if (peek(SEPARATOR_ENDOFEXPRESSION))
|
2021-12-30 14:44:46 +01:00
|
|
|
return create(new ASTNodeControlFlowStatement(type, nullptr));
|
2021-06-20 23:46:13 +02:00
|
|
|
else
|
2021-12-30 14:44:46 +01:00
|
|
|
return create(new ASTNodeControlFlowStatement(type, this->parseMathematicalExpression()));
|
2021-06-20 23:46:13 +02:00
|
|
|
}
|
|
|
|
|
2022-02-27 23:25:39 +01:00
|
|
|
std::vector<std::unique_ptr<ASTNode>> Parser::parseStatementBody() {
|
|
|
|
std::vector<std::unique_ptr<ASTNode>> body;
|
2021-09-26 18:27:18 +02:00
|
|
|
|
|
|
|
if (MATCHES(sequence(SEPARATOR_CURLYBRACKETOPEN))) {
|
|
|
|
while (!MATCHES(sequence(SEPARATOR_CURLYBRACKETCLOSE))) {
|
|
|
|
body.push_back(parseFunctionStatement());
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
body.push_back(parseFunctionStatement());
|
|
|
|
}
|
|
|
|
|
|
|
|
return body;
|
|
|
|
}
|
|
|
|
|
2022-02-27 23:25:39 +01:00
|
|
|
std::unique_ptr<ASTNode> Parser::parseFunctionConditional() {
|
2021-06-20 23:46:13 +02:00
|
|
|
auto condition = parseMathematicalExpression();
|
2022-02-27 23:25:39 +01:00
|
|
|
std::vector<std::unique_ptr<ASTNode>> trueBody, falseBody;
|
2021-06-20 23:46:13 +02:00
|
|
|
|
2021-09-26 18:27:18 +02:00
|
|
|
if (!MATCHES(sequence(SEPARATOR_ROUNDBRACKETCLOSE)))
|
2022-01-31 14:37:12 +01:00
|
|
|
throwParserError("expected closing ')' after statement head");
|
2021-06-20 23:46:13 +02:00
|
|
|
|
2021-09-26 18:27:18 +02:00
|
|
|
trueBody = parseStatementBody();
|
|
|
|
|
|
|
|
if (MATCHES(sequence(KEYWORD_ELSE)))
|
|
|
|
falseBody = parseStatementBody();
|
2021-06-20 23:46:13 +02:00
|
|
|
|
2022-02-27 23:25:39 +01:00
|
|
|
return create(new ASTNodeConditionalStatement(std::move(condition), std::move(trueBody), std::move(falseBody)));
|
2021-06-20 21:22:31 +02:00
|
|
|
}
|
|
|
|
|
2022-02-27 23:25:39 +01:00
|
|
|
std::unique_ptr<ASTNode> Parser::parseFunctionWhileLoop() {
|
2021-06-21 00:21:38 +02:00
|
|
|
auto condition = parseMathematicalExpression();
|
2022-02-27 23:25:39 +01:00
|
|
|
std::vector<std::unique_ptr<ASTNode>> body;
|
2021-06-21 00:21:38 +02:00
|
|
|
|
2021-09-26 18:27:18 +02:00
|
|
|
if (!MATCHES(sequence(SEPARATOR_ROUNDBRACKETCLOSE)))
|
2022-01-31 14:37:12 +01:00
|
|
|
throwParserError("expected closing ')' after statement head");
|
2021-09-26 18:27:18 +02:00
|
|
|
|
|
|
|
body = parseStatementBody();
|
2021-06-21 00:21:38 +02:00
|
|
|
|
2022-02-27 23:25:39 +01:00
|
|
|
return create(new ASTNodeWhileStatement(std::move(condition), std::move(body)));
|
2021-06-21 00:21:38 +02:00
|
|
|
}
|
|
|
|
|
2022-02-27 23:25:39 +01:00
|
|
|
std::unique_ptr<ASTNode> Parser::parseFunctionForLoop() {
|
|
|
|
auto variable = parseFunctionVariableDecl();
|
2021-10-10 13:47:48 +02:00
|
|
|
|
|
|
|
if (!MATCHES(sequence(SEPARATOR_COMMA)))
|
2022-01-31 14:37:12 +01:00
|
|
|
throwParserError("expected ',' after for loop variable declaration");
|
2021-10-10 13:47:48 +02:00
|
|
|
|
2022-02-27 23:25:39 +01:00
|
|
|
auto condition = parseMathematicalExpression();
|
2021-10-10 13:47:48 +02:00
|
|
|
|
|
|
|
if (!MATCHES(sequence(SEPARATOR_COMMA)))
|
2022-01-31 14:37:12 +01:00
|
|
|
throwParserError("expected ',' after for loop condition");
|
2021-10-10 13:47:48 +02:00
|
|
|
|
2022-02-27 23:25:39 +01:00
|
|
|
std::unique_ptr<ASTNode> postExpression = nullptr;
|
2022-02-01 18:09:40 +01:00
|
|
|
if (MATCHES(sequence(IDENTIFIER, OPERATOR_ASSIGNMENT)))
|
|
|
|
postExpression = parseFunctionVariableAssignment(getValue<Token::Identifier>(-2).get());
|
|
|
|
else if (MATCHES(sequence(OPERATOR_DOLLAR, OPERATOR_ASSIGNMENT)))
|
|
|
|
postExpression = parseFunctionVariableAssignment("$");
|
|
|
|
else if (MATCHES(oneOf(IDENTIFIER) && oneOf(OPERATOR_PLUS, OPERATOR_MINUS, OPERATOR_STAR, OPERATOR_SLASH, OPERATOR_PERCENT, OPERATOR_SHIFTLEFT, OPERATOR_SHIFTRIGHT, OPERATOR_BITOR, OPERATOR_BITAND, OPERATOR_BITXOR) && sequence(OPERATOR_ASSIGNMENT)))
|
|
|
|
postExpression = parseFunctionVariableCompoundAssignment(getValue<Token::Identifier>(-3).get());
|
|
|
|
else if (MATCHES(oneOf(OPERATOR_DOLLAR) && oneOf(OPERATOR_PLUS, OPERATOR_MINUS, OPERATOR_STAR, OPERATOR_SLASH, OPERATOR_PERCENT, OPERATOR_SHIFTLEFT, OPERATOR_SHIFTRIGHT, OPERATOR_BITOR, OPERATOR_BITAND, OPERATOR_BITXOR) && sequence(OPERATOR_ASSIGNMENT)))
|
|
|
|
postExpression = parseFunctionVariableCompoundAssignment("$");
|
|
|
|
else
|
|
|
|
throwParserError("expected variable assignment in for loop post expression");
|
2021-10-10 13:47:48 +02:00
|
|
|
|
2022-02-27 23:25:39 +01:00
|
|
|
std::vector<std::unique_ptr<ASTNode>> body;
|
2021-10-10 13:47:48 +02:00
|
|
|
|
|
|
|
|
|
|
|
if (!MATCHES(sequence(SEPARATOR_ROUNDBRACKETCLOSE)))
|
2022-01-31 14:37:12 +01:00
|
|
|
throwParserError("expected closing ')' after statement head");
|
2021-10-10 13:47:48 +02:00
|
|
|
|
|
|
|
body = parseStatementBody();
|
|
|
|
|
2022-02-27 23:25:39 +01:00
|
|
|
std::vector<std::unique_ptr<ASTNode>> compoundStatement;
|
|
|
|
{
|
|
|
|
compoundStatement.push_back(std::move(variable));
|
|
|
|
compoundStatement.push_back(create(new ASTNodeWhileStatement(std::move(condition), std::move(body), std::move(postExpression))));
|
|
|
|
}
|
2021-10-10 13:47:48 +02:00
|
|
|
|
2022-02-27 23:25:39 +01:00
|
|
|
return create(new ASTNodeCompoundStatement(std::move(compoundStatement), true));
|
2021-10-10 13:47:48 +02:00
|
|
|
}
|
|
|
|
|
2021-01-07 00:02:51 +01:00
|
|
|
/* Control flow */
|
|
|
|
|
|
|
|
// if ((parseMathematicalExpression)) { (parseMember) }
|
2022-02-27 23:25:39 +01:00
|
|
|
std::unique_ptr<ASTNode> Parser::parseConditional() {
|
2021-01-07 00:02:51 +01:00
|
|
|
auto condition = parseMathematicalExpression();
|
2022-02-27 23:25:39 +01:00
|
|
|
std::vector<std::unique_ptr<ASTNode>> trueBody, falseBody;
|
2021-01-07 00:02:51 +01:00
|
|
|
|
|
|
|
if (MATCHES(sequence(SEPARATOR_ROUNDBRACKETCLOSE, SEPARATOR_CURLYBRACKETOPEN))) {
|
|
|
|
while (!MATCHES(sequence(SEPARATOR_CURLYBRACKETCLOSE))) {
|
|
|
|
trueBody.push_back(parseMember());
|
|
|
|
}
|
|
|
|
} else if (MATCHES(sequence(SEPARATOR_ROUNDBRACKETCLOSE))) {
|
|
|
|
trueBody.push_back(parseMember());
|
|
|
|
} else
|
2022-01-31 14:37:12 +01:00
|
|
|
throwParserError("expected body of conditional statement");
|
2021-01-07 00:02:51 +01:00
|
|
|
|
|
|
|
if (MATCHES(sequence(KEYWORD_ELSE, SEPARATOR_CURLYBRACKETOPEN))) {
|
|
|
|
while (!MATCHES(sequence(SEPARATOR_CURLYBRACKETCLOSE))) {
|
|
|
|
falseBody.push_back(parseMember());
|
|
|
|
}
|
|
|
|
} else if (MATCHES(sequence(KEYWORD_ELSE))) {
|
|
|
|
falseBody.push_back(parseMember());
|
|
|
|
}
|
|
|
|
|
2022-02-27 23:25:39 +01:00
|
|
|
return create(new ASTNodeConditionalStatement(std::move(condition), std::move(trueBody), std::move(falseBody)));
|
2020-11-21 20:19:33 +01:00
|
|
|
}
|
|
|
|
|
2021-06-17 23:13:58 +02:00
|
|
|
// while ((parseMathematicalExpression))
|
2022-02-27 23:25:39 +01:00
|
|
|
std::unique_ptr<ASTNode> Parser::parseWhileStatement() {
|
2021-06-17 23:13:58 +02:00
|
|
|
auto condition = parseMathematicalExpression();
|
|
|
|
|
|
|
|
if (!MATCHES(sequence(SEPARATOR_ROUNDBRACKETCLOSE)))
|
2022-01-31 14:37:12 +01:00
|
|
|
throwParserError("expected closing ')' after while head");
|
2021-06-17 23:13:58 +02:00
|
|
|
|
2022-02-27 23:25:39 +01:00
|
|
|
return create(new ASTNodeWhileStatement(std::move(condition), {}));
|
2021-06-17 23:13:58 +02: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
|
|
|
/* Type declarations */
|
2020-12-06 21:40:57 +01:00
|
|
|
|
2021-09-21 21:29:18 +02:00
|
|
|
// [be|le] <Identifier|u8|u16|u32|u64|u128|s8|s16|s32|s64|s128|float|double|str>
|
2022-02-27 23:25:39 +01:00
|
|
|
std::unique_ptr<ASTNodeTypeDecl> Parser::parseType(bool allowFunctionTypes) {
|
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::optional<std::endian> endian;
|
2020-11-10 16:24:48 +01:00
|
|
|
|
2021-08-25 17:07:01 +02:00
|
|
|
if (MATCHES(sequence(KEYWORD_LE)))
|
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
|
|
|
endian = std::endian::little;
|
2021-08-25 17:07:01 +02:00
|
|
|
else if (MATCHES(sequence(KEYWORD_BE)))
|
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
|
|
|
endian = std::endian::big;
|
2020-12-06 21:40:57 +01:00
|
|
|
|
2022-01-24 20:53:17 +01:00
|
|
|
if (MATCHES(sequence(IDENTIFIER))) { // Custom type
|
2021-09-03 02:33:45 +02:00
|
|
|
std::string typeName = parseNamespaceResolution();
|
2020-11-10 16:24:48 +01:00
|
|
|
|
2021-08-25 17:07:01 +02:00
|
|
|
if (this->m_types.contains(typeName))
|
2022-03-17 00:10:16 +01:00
|
|
|
return create(new ASTNodeTypeDecl({}, this->m_types[typeName], endian));
|
2021-08-25 17:07:01 +02:00
|
|
|
else if (this->m_types.contains(getNamespacePrefixedName(typeName)))
|
2022-03-17 00:10:16 +01:00
|
|
|
return create(new ASTNodeTypeDecl({}, this->m_types[getNamespacePrefixedName(typeName)], endian));
|
2021-08-25 17:07:01 +02:00
|
|
|
else
|
2022-01-31 14:37:12 +01:00
|
|
|
throwParserError(hex::format("unknown type '{}'", typeName));
|
2022-01-24 20:53:17 +01:00
|
|
|
} else if (MATCHES(sequence(VALUETYPE_ANY))) { // Builtin type
|
2021-09-21 21:29:18 +02:00
|
|
|
auto type = getValue<Token::ValueType>(-1);
|
2021-09-23 23:43:16 +02:00
|
|
|
if (!allowFunctionTypes) {
|
|
|
|
if (type == Token::ValueType::String)
|
2022-01-31 14:37:12 +01:00
|
|
|
throwParserError("cannot use 'str' in this context. Use a character array instead");
|
2021-09-23 23:43:16 +02:00
|
|
|
else if (type == Token::ValueType::Auto)
|
2022-01-31 14:37:12 +01:00
|
|
|
throwParserError("cannot use 'auto' in this context");
|
2021-09-23 23:43:16 +02:00
|
|
|
}
|
2021-09-21 21:29:18 +02:00
|
|
|
|
2022-02-27 23:25:39 +01:00
|
|
|
return create(new ASTNodeTypeDecl({}, create(new ASTNodeBuiltinType(type)), endian));
|
2022-01-31 14:37:12 +01:00
|
|
|
} else throwParserError("failed to parse type. Expected identifier or builtin type");
|
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
|
|
|
// using Identifier = (parseType)
|
2022-02-27 23:25:39 +01:00
|
|
|
std::shared_ptr<ASTNodeTypeDecl> Parser::parseUsingDeclaration() {
|
2021-10-10 15:38:58 +02:00
|
|
|
auto name = parseNamespaceResolution();
|
|
|
|
|
|
|
|
if (!MATCHES(sequence(OPERATOR_ASSIGNMENT)))
|
2022-01-31 14:37:12 +01:00
|
|
|
throwParserError("expected '=' after type name of using declaration");
|
2021-10-10 15:38:58 +02:00
|
|
|
|
2022-02-27 23:25:39 +01:00
|
|
|
auto type = parseType();
|
2020-11-20 21:29:28 +01:00
|
|
|
|
2022-02-27 23:25:39 +01:00
|
|
|
auto endian = type->getEndian();
|
|
|
|
return addType(name, std::move(type), endian);
|
2020-11-20 21:29:28 +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
|
|
|
// padding[(parseMathematicalExpression)]
|
2022-02-27 23:25:39 +01:00
|
|
|
std::unique_ptr<ASTNode> Parser::parsePadding() {
|
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
|
|
|
auto size = parseMathematicalExpression();
|
2020-11-14 14:40:21 +01:00
|
|
|
|
2022-02-27 23:25:39 +01:00
|
|
|
if (!MATCHES(sequence(SEPARATOR_SQUAREBRACKETCLOSE)))
|
2022-01-31 14:37:12 +01:00
|
|
|
throwParserError("expected closing ']' at end of array declaration", -1);
|
2020-11-14 14:40:21 +01:00
|
|
|
|
2022-02-27 23:25:39 +01:00
|
|
|
return create(new ASTNodeArrayVariableDecl({}, create(new ASTNodeTypeDecl({}, create(new ASTNodeBuiltinType(Token::ValueType::Padding)))), std::move(size)));
|
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
|
|
|
}
|
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
|
|
|
// (parseType) Identifier
|
2022-03-17 00:10:16 +01:00
|
|
|
std::unique_ptr<ASTNode> Parser::parseMemberVariable(const std::shared_ptr<ASTNodeTypeDecl> &type) {
|
2021-08-25 17:54:47 +02:00
|
|
|
if (peek(SEPARATOR_COMMA)) {
|
|
|
|
|
2022-02-27 23:25:39 +01:00
|
|
|
std::vector<std::unique_ptr<ASTNode>> variables;
|
2021-08-25 17:54:47 +02:00
|
|
|
|
|
|
|
do {
|
2022-03-17 00:10:16 +01:00
|
|
|
variables.push_back(create(new ASTNodeVariableDecl(getValue<Token::Identifier>(-1).get(), type)));
|
2021-08-25 17:54:47 +02:00
|
|
|
} while (MATCHES(sequence(SEPARATOR_COMMA, IDENTIFIER)));
|
|
|
|
|
2022-02-27 23:25:39 +01:00
|
|
|
return create(new ASTNodeMultiVariableDecl(std::move(variables)));
|
2022-02-05 23:34:52 +01:00
|
|
|
} else if (MATCHES(sequence(OPERATOR_AT)))
|
2022-03-17 00:10:16 +01:00
|
|
|
return create(new ASTNodeVariableDecl(getValue<Token::Identifier>(-2).get(), type, parseMathematicalExpression()));
|
2022-02-05 23:34:52 +01:00
|
|
|
else
|
2022-03-17 00:10:16 +01:00
|
|
|
return create(new ASTNodeVariableDecl(getValue<Token::Identifier>(-1).get(), type));
|
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
|
|
|
}
|
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
|
|
|
// (parseType) Identifier[(parseMathematicalExpression)]
|
2022-03-17 00:10:16 +01:00
|
|
|
std::unique_ptr<ASTNode> Parser::parseMemberArrayVariable(const std::shared_ptr<ASTNodeTypeDecl> &type) {
|
2021-09-21 21:29:18 +02:00
|
|
|
auto name = getValue<Token::Identifier>(-2).get();
|
2020-11-14 14:40:21 +01:00
|
|
|
|
2022-02-27 23:25:39 +01:00
|
|
|
std::unique_ptr<ASTNode> size;
|
2021-01-07 21:16:34 +01:00
|
|
|
|
|
|
|
if (!MATCHES(sequence(SEPARATOR_SQUAREBRACKETCLOSE))) {
|
2021-06-17 23:13:58 +02:00
|
|
|
if (MATCHES(sequence(KEYWORD_WHILE, SEPARATOR_ROUNDBRACKETOPEN)))
|
|
|
|
size = parseWhileStatement();
|
|
|
|
else
|
|
|
|
size = parseMathematicalExpression();
|
2021-01-07 21:16:34 +01:00
|
|
|
|
|
|
|
if (!MATCHES(sequence(SEPARATOR_SQUAREBRACKETCLOSE)))
|
2022-01-31 14:37:12 +01:00
|
|
|
throwParserError("expected closing ']' at end of array declaration", -1);
|
2021-01-07 21:16:34 +01:00
|
|
|
}
|
|
|
|
|
2022-02-05 23:34:52 +01:00
|
|
|
if (MATCHES(sequence(OPERATOR_AT)))
|
2022-03-17 00:10:16 +01:00
|
|
|
return create(new ASTNodeArrayVariableDecl(name, type, std::move(size), parseMathematicalExpression()));
|
2022-02-05 23:34:52 +01:00
|
|
|
else
|
2022-03-17 00:10:16 +01:00
|
|
|
return create(new ASTNodeArrayVariableDecl(name, type, std::move(size)));
|
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
|
|
|
// (parseType) *Identifier : (parseType)
|
2022-03-17 00:10:16 +01:00
|
|
|
std::unique_ptr<ASTNode> Parser::parseMemberPointerVariable(const std::shared_ptr<ASTNodeTypeDecl> &type) {
|
2021-09-21 21:29:18 +02:00
|
|
|
auto name = getValue<Token::Identifier>(-2).get();
|
2020-11-20 20:26:19 +01:00
|
|
|
|
2021-08-25 17:07:01 +02:00
|
|
|
auto sizeType = parseType();
|
2020-11-27 21:20:23 +01:00
|
|
|
|
2021-08-25 17:07:01 +02:00
|
|
|
{
|
2022-02-27 23:25:39 +01:00
|
|
|
auto builtinType = dynamic_cast<ASTNodeBuiltinType *>(sizeType->getType().get());
|
2020-11-20 20:26:19 +01:00
|
|
|
|
2021-08-25 17:07:01 +02:00
|
|
|
if (builtinType == nullptr || !Token::isUnsigned(builtinType->getType()))
|
2022-01-31 14:37:12 +01:00
|
|
|
throwParserError("invalid type used for pointer size", -1);
|
2021-08-25 17:07:01 +02:00
|
|
|
}
|
2020-11-20 20:26:19 +01:00
|
|
|
|
2022-02-05 23:34:52 +01:00
|
|
|
if (MATCHES(sequence(OPERATOR_AT)))
|
2022-03-17 00:10:16 +01:00
|
|
|
return create(new ASTNodePointerVariableDecl(name, type, std::move(sizeType), parseMathematicalExpression()));
|
2022-02-05 23:34:52 +01:00
|
|
|
else
|
2022-03-17 00:10:16 +01:00
|
|
|
return create(new ASTNodePointerVariableDecl(name, type, std::move(sizeType)));
|
2020-11-20 20:26:19 +01:00
|
|
|
}
|
|
|
|
|
2021-01-07 00:02:51 +01:00
|
|
|
// [(parsePadding)|(parseMemberVariable)|(parseMemberArrayVariable)|(parseMemberPointerVariable)]
|
2022-02-27 23:25:39 +01:00
|
|
|
std::unique_ptr<ASTNode> Parser::parseMember() {
|
|
|
|
std::unique_ptr<ASTNode> member;
|
2021-01-07 00:02:51 +01:00
|
|
|
|
2022-02-05 23:20:44 +01:00
|
|
|
if (MATCHES(sequence(OPERATOR_DOLLAR, OPERATOR_ASSIGNMENT)))
|
|
|
|
member = parseFunctionVariableAssignment("$");
|
|
|
|
else if (MATCHES(sequence(OPERATOR_DOLLAR) && oneOf(OPERATOR_PLUS, OPERATOR_MINUS, OPERATOR_STAR, OPERATOR_SLASH, OPERATOR_PERCENT, OPERATOR_SHIFTLEFT, OPERATOR_SHIFTRIGHT, OPERATOR_BITOR, OPERATOR_BITAND, OPERATOR_BITXOR) && sequence(OPERATOR_ASSIGNMENT)))
|
|
|
|
member = parseFunctionVariableCompoundAssignment("$");
|
|
|
|
else if (MATCHES(sequence(IDENTIFIER, OPERATOR_ASSIGNMENT)))
|
|
|
|
member = parseFunctionVariableAssignment(getValue<Token::Identifier>(-2).get());
|
|
|
|
else if (MATCHES(sequence(IDENTIFIER) && oneOf(OPERATOR_PLUS, OPERATOR_MINUS, OPERATOR_STAR, OPERATOR_SLASH, OPERATOR_PERCENT, OPERATOR_SHIFTLEFT, OPERATOR_SHIFTRIGHT, OPERATOR_BITOR, OPERATOR_BITAND, OPERATOR_BITXOR) && sequence(OPERATOR_ASSIGNMENT)))
|
|
|
|
member = parseFunctionVariableCompoundAssignment(getValue<Token::Identifier>(-3).get());
|
|
|
|
else if (peek(KEYWORD_BE) || peek(KEYWORD_LE) || peek(VALUETYPE_ANY) || peek(IDENTIFIER)) {
|
2021-08-25 17:07:01 +02:00
|
|
|
// Some kind of variable definition
|
|
|
|
|
2021-11-27 12:57:59 +01:00
|
|
|
bool isFunction = false;
|
|
|
|
|
|
|
|
if (peek(IDENTIFIER)) {
|
|
|
|
auto originalPos = this->m_curr;
|
|
|
|
this->m_curr++;
|
|
|
|
parseNamespaceResolution();
|
2022-02-01 22:09:44 +01:00
|
|
|
isFunction = peek(SEPARATOR_ROUNDBRACKETOPEN);
|
2021-11-27 12:57:59 +01:00
|
|
|
this->m_curr = originalPos;
|
|
|
|
|
|
|
|
if (isFunction) {
|
|
|
|
this->m_curr++;
|
|
|
|
member = parseFunctionCall();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if (!isFunction) {
|
|
|
|
auto type = parseType();
|
|
|
|
|
2022-01-29 22:17:51 +01:00
|
|
|
if (MATCHES(sequence(IDENTIFIER, SEPARATOR_SQUAREBRACKETOPEN) && sequence<Not>(SEPARATOR_SQUAREBRACKETOPEN)))
|
2022-02-27 23:25:39 +01:00
|
|
|
member = parseMemberArrayVariable(std::move(type));
|
2021-11-27 12:57:59 +01:00
|
|
|
else if (MATCHES(sequence(IDENTIFIER)))
|
2022-02-27 23:25:39 +01:00
|
|
|
member = parseMemberVariable(std::move(type));
|
2021-11-27 12:57:59 +01:00
|
|
|
else if (MATCHES(sequence(OPERATOR_STAR, IDENTIFIER, OPERATOR_INHERIT)))
|
2022-02-27 23:25:39 +01:00
|
|
|
member = parseMemberPointerVariable(std::move(type));
|
2021-11-27 12:57:59 +01:00
|
|
|
else
|
2022-01-31 14:37:12 +01:00
|
|
|
throwParserError("invalid variable declaration");
|
2021-11-27 12:57:59 +01:00
|
|
|
}
|
2022-01-24 20:53:17 +01:00
|
|
|
} else if (MATCHES(sequence(VALUETYPE_PADDING, SEPARATOR_SQUAREBRACKETOPEN)))
|
2021-01-07 00:02:51 +01:00
|
|
|
member = parsePadding();
|
|
|
|
else if (MATCHES(sequence(KEYWORD_IF, SEPARATOR_ROUNDBRACKETOPEN)))
|
|
|
|
return parseConditional();
|
|
|
|
else if (MATCHES(sequence(SEPARATOR_ENDOFPROGRAM)))
|
2022-01-31 14:37:12 +01:00
|
|
|
throwParserError("unexpected end of program", -2);
|
2021-12-30 18:31:24 +01:00
|
|
|
else if (MATCHES(sequence(KEYWORD_BREAK)))
|
2022-02-27 23:25:39 +01:00
|
|
|
member = create(new ASTNodeControlFlowStatement(ControlFlowStatement::Break, nullptr));
|
2021-12-30 18:31:24 +01:00
|
|
|
else if (MATCHES(sequence(KEYWORD_CONTINUE)))
|
2022-02-27 23:25:39 +01:00
|
|
|
member = create(new ASTNodeControlFlowStatement(ControlFlowStatement::Continue, nullptr));
|
2021-01-07 00:02:51 +01:00
|
|
|
else
|
2022-01-31 14:37:12 +01:00
|
|
|
throwParserError("invalid struct member", 0);
|
2021-01-07 00:02:51 +01:00
|
|
|
|
2021-01-21 17:49:30 +01:00
|
|
|
if (MATCHES(sequence(SEPARATOR_SQUAREBRACKETOPEN, SEPARATOR_SQUAREBRACKETOPEN)))
|
2022-02-27 23:25:39 +01:00
|
|
|
parseAttribute(dynamic_cast<Attributable *>(member.get()));
|
2021-01-21 17:49:30 +01:00
|
|
|
|
2021-01-07 00:02:51 +01:00
|
|
|
if (!MATCHES(sequence(SEPARATOR_ENDOFEXPRESSION)))
|
2022-01-31 14:37:12 +01:00
|
|
|
throwParserError("missing ';' at end of expression", -1);
|
2021-01-07 00:02:51 +01:00
|
|
|
|
2021-09-13 10:48:45 +02:00
|
|
|
// Consume superfluous semicolons
|
2022-01-24 20:53:17 +01:00
|
|
|
while (MATCHES(sequence(SEPARATOR_ENDOFEXPRESSION)))
|
|
|
|
;
|
2021-09-13 10:48:45 +02:00
|
|
|
|
2021-01-07 00:02:51 +01:00
|
|
|
return member;
|
|
|
|
}
|
|
|
|
|
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
|
|
|
// struct Identifier { <(parseMember)...> }
|
2022-02-27 23:25:39 +01:00
|
|
|
std::shared_ptr<ASTNodeTypeDecl> Parser::parseStruct() {
|
2021-09-24 00:47:34 +02:00
|
|
|
const auto &typeName = getValue<Token::Identifier>(-1).get();
|
2021-09-25 22:03:55 +02:00
|
|
|
|
2022-02-27 23:25:39 +01:00
|
|
|
auto typeDecl = addType(typeName, create(new ASTNodeStruct()));
|
|
|
|
auto structNode = static_cast<ASTNodeStruct *>(typeDecl->getType().get());
|
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-24 00:47:34 +02:00
|
|
|
if (MATCHES(sequence(OPERATOR_INHERIT, IDENTIFIER))) {
|
|
|
|
// Inheritance
|
|
|
|
|
|
|
|
do {
|
|
|
|
auto inheritedTypeName = getValue<Token::Identifier>(-1).get();
|
|
|
|
if (!this->m_types.contains(inheritedTypeName))
|
2022-01-31 14:37:12 +01:00
|
|
|
throwParserError(hex::format("cannot inherit from unknown type '{}'", inheritedTypeName), -1);
|
2021-09-24 00:47:34 +02:00
|
|
|
|
|
|
|
structNode->addInheritance(this->m_types[inheritedTypeName]->clone());
|
|
|
|
} while (MATCHES(sequence(SEPARATOR_COMMA, IDENTIFIER)));
|
|
|
|
|
|
|
|
} else if (MATCHES(sequence(OPERATOR_INHERIT, VALUETYPE_ANY))) {
|
2022-01-31 14:37:12 +01:00
|
|
|
throwParserError("cannot inherit from builtin type");
|
2021-09-24 00:47:34 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
if (!MATCHES(sequence(SEPARATOR_CURLYBRACKETOPEN)))
|
2022-01-31 14:37:12 +01:00
|
|
|
throwParserError("expected '{' after struct definition", -1);
|
2021-09-24 00:47:34 +02: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 (!MATCHES(sequence(SEPARATOR_CURLYBRACKETCLOSE))) {
|
2021-01-07 00:02:51 +01:00
|
|
|
structNode->addMember(parseMember());
|
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-25 22:03:55 +02:00
|
|
|
return typeDecl;
|
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
|
|
|
// union Identifier { <(parseMember)...> }
|
2022-02-27 23:25:39 +01:00
|
|
|
std::shared_ptr<ASTNodeTypeDecl> Parser::parseUnion() {
|
2021-09-21 21:29:18 +02:00
|
|
|
const auto &typeName = getValue<Token::Identifier>(-2).get();
|
2021-09-25 22:03:55 +02:00
|
|
|
|
2022-02-27 23:25:39 +01:00
|
|
|
auto typeDecl = addType(typeName, create(new ASTNodeUnion()));
|
|
|
|
auto unionNode = static_cast<ASTNodeStruct *>(typeDecl->getType().get());
|
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
|
|
|
while (!MATCHES(sequence(SEPARATOR_CURLYBRACKETCLOSE))) {
|
2021-01-07 00:02:51 +01:00
|
|
|
unionNode->addMember(parseMember());
|
2020-11-27 21:20:23 +01:00
|
|
|
}
|
2020-11-10 15:26:38 +01:00
|
|
|
|
2021-09-25 22:03:55 +02:00
|
|
|
return typeDecl;
|
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
|
|
|
// enum Identifier : (parseType) { <<Identifier|Identifier = (parseMathematicalExpression)[,]>...> }
|
2022-02-27 23:25:39 +01:00
|
|
|
std::shared_ptr<ASTNodeTypeDecl> Parser::parseEnum() {
|
2021-09-21 21:29:18 +02:00
|
|
|
auto typeName = getValue<Token::Identifier>(-2).get();
|
2020-11-20 21:29:28 +01:00
|
|
|
|
2021-08-25 17:07:01 +02:00
|
|
|
auto underlyingType = parseType();
|
2022-01-31 14:37:12 +01:00
|
|
|
if (underlyingType->getEndian().has_value()) throwParserError("underlying type may not have an endian specification", -2);
|
2020-11-20 20:26:19 +01:00
|
|
|
|
2022-02-27 23:25:39 +01:00
|
|
|
auto typeDecl = addType(typeName, create(new ASTNodeEnum(std::move(underlyingType))));
|
|
|
|
auto enumNode = static_cast<ASTNodeEnum *>(typeDecl->getType().get());
|
2020-11-20 20:26:19 +01:00
|
|
|
|
2021-09-03 02:33:45 +02:00
|
|
|
if (!MATCHES(sequence(SEPARATOR_CURLYBRACKETOPEN)))
|
2022-01-31 14:37:12 +01:00
|
|
|
throwParserError("expected '{' after enum definition", -1);
|
2021-09-03 02:33:45 +02:00
|
|
|
|
2022-02-27 23:25:39 +01:00
|
|
|
std::unique_ptr<ASTNode> lastEntry;
|
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 (!MATCHES(sequence(SEPARATOR_CURLYBRACKETCLOSE))) {
|
|
|
|
if (MATCHES(sequence(IDENTIFIER, OPERATOR_ASSIGNMENT))) {
|
2022-02-01 22:09:44 +01:00
|
|
|
auto name = getValue<Token::Identifier>(-2).get();
|
2021-01-08 11:58:07 +01:00
|
|
|
auto value = parseMathematicalExpression();
|
|
|
|
|
2022-02-27 23:25:39 +01:00
|
|
|
lastEntry = value->clone();
|
|
|
|
enumNode->addEntry(name, std::move(value));
|
2022-01-24 20:53:17 +01:00
|
|
|
} else if (MATCHES(sequence(IDENTIFIER))) {
|
2022-02-27 23:25:39 +01:00
|
|
|
std::unique_ptr<ASTNode> valueExpr;
|
2021-09-21 21:29:18 +02:00
|
|
|
auto name = getValue<Token::Identifier>(-1).get();
|
2021-01-08 11:58:07 +01:00
|
|
|
if (enumNode->getEntries().empty())
|
2022-02-27 23:25:39 +01:00
|
|
|
valueExpr = create(new ASTNodeLiteral(u128(0)));
|
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
|
2022-02-27 23:25:39 +01:00
|
|
|
valueExpr = create(new ASTNodeMathematicalExpression(lastEntry->clone(), create(new ASTNodeLiteral(u128(1))), Token::Operator::Plus));
|
2020-11-14 14:40:21 +01:00
|
|
|
|
2022-02-27 23:25:39 +01:00
|
|
|
lastEntry = valueExpr->clone();
|
|
|
|
enumNode->addEntry(name, std::move(valueExpr));
|
2022-01-24 20:53:17 +01:00
|
|
|
} else if (MATCHES(sequence(SEPARATOR_ENDOFPROGRAM)))
|
2022-01-31 14:37:12 +01:00
|
|
|
throwParserError("unexpected end of program", -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
|
2022-01-31 14:37:12 +01:00
|
|
|
throwParserError("invalid enum entry", -1);
|
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
|
|
|
if (!MATCHES(sequence(SEPARATOR_COMMA))) {
|
|
|
|
if (MATCHES(sequence(SEPARATOR_CURLYBRACKETCLOSE)))
|
|
|
|
break;
|
|
|
|
else
|
2022-01-31 14:37:12 +01:00
|
|
|
throwParserError("missing ',' between enum entries", -1);
|
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
|
|
|
}
|
2020-11-10 15:26:38 +01:00
|
|
|
|
2021-09-25 22:03:55 +02:00
|
|
|
return typeDecl;
|
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
|
|
|
}
|
2020-11-10 16:24:48 +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
|
|
|
// bitfield Identifier { <Identifier : (parseMathematicalExpression)[;]...> }
|
2022-02-27 23:25:39 +01:00
|
|
|
std::shared_ptr<ASTNodeTypeDecl> Parser::parseBitfield() {
|
2021-09-21 21:29:18 +02:00
|
|
|
std::string typeName = getValue<Token::Identifier>(-2).get();
|
2020-11-10 15:26:38 +01:00
|
|
|
|
2022-02-27 23:25:39 +01:00
|
|
|
auto typeDecl = addType(typeName, create(new ASTNodeBitfield()));
|
|
|
|
auto bitfieldNode = static_cast<ASTNodeBitfield *>(typeDecl->getType().get());
|
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
|
|
|
while (!MATCHES(sequence(SEPARATOR_CURLYBRACKETCLOSE))) {
|
|
|
|
if (MATCHES(sequence(IDENTIFIER, OPERATOR_INHERIT))) {
|
2021-09-21 21:29:18 +02:00
|
|
|
auto name = getValue<Token::Identifier>(-2).get();
|
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
|
|
|
bitfieldNode->addEntry(name, parseMathematicalExpression());
|
2021-10-14 20:28:13 +02:00
|
|
|
} else if (MATCHES(sequence(VALUETYPE_PADDING, OPERATOR_INHERIT))) {
|
2022-01-24 20:53:17 +01:00
|
|
|
bitfieldNode->addEntry("padding", parseMathematicalExpression());
|
2021-10-14 20:28:13 +02:00
|
|
|
} else if (MATCHES(sequence(SEPARATOR_ENDOFPROGRAM)))
|
2022-01-31 14:37:12 +01:00
|
|
|
throwParserError("unexpected end of program", -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
|
2022-01-31 14:37:12 +01:00
|
|
|
throwParserError("invalid bitfield member", 0);
|
2020-11-10 15:26:38 +01:00
|
|
|
|
2021-09-13 10:48:45 +02:00
|
|
|
if (!MATCHES(sequence(SEPARATOR_ENDOFEXPRESSION)))
|
2022-01-31 14:37:12 +01:00
|
|
|
throwParserError("missing ';' at end of expression", -1);
|
2021-09-13 10:48:45 +02:00
|
|
|
|
|
|
|
// Consume superfluous semicolons
|
2022-01-24 20:53:17 +01:00
|
|
|
while (MATCHES(sequence(SEPARATOR_ENDOFEXPRESSION)))
|
|
|
|
;
|
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
|
|
|
}
|
2020-11-27 21:20:23 +01:00
|
|
|
|
2021-09-25 22:03:55 +02:00
|
|
|
return typeDecl;
|
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
|
|
|
}
|
2020-11-10 16:24:48 +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
|
|
|
// (parseType) Identifier @ Integer
|
2022-03-17 00:10:16 +01:00
|
|
|
std::unique_ptr<ASTNode> Parser::parseVariablePlacement(const std::shared_ptr<ASTNodeTypeDecl> &type) {
|
2022-02-01 22:09:44 +01:00
|
|
|
bool inVariable = false;
|
2021-12-18 22:56:36 +01:00
|
|
|
bool outVariable = false;
|
|
|
|
|
2021-09-21 21:29:18 +02:00
|
|
|
auto name = getValue<Token::Identifier>(-1).get();
|
2021-08-25 17:07:01 +02:00
|
|
|
|
2022-02-27 23:25:39 +01:00
|
|
|
std::unique_ptr<ASTNode> placementOffset;
|
2021-10-18 22:04:54 +02:00
|
|
|
if (MATCHES(sequence(OPERATOR_AT))) {
|
|
|
|
placementOffset = parseMathematicalExpression();
|
2021-12-18 22:56:36 +01:00
|
|
|
} else if (MATCHES(sequence(KEYWORD_IN))) {
|
|
|
|
inVariable = true;
|
2022-01-24 20:53:17 +01:00
|
|
|
} else if (MATCHES(sequence(KEYWORD_OUT))) {
|
2021-12-18 22:56:36 +01:00
|
|
|
outVariable = true;
|
2021-10-18 22:04:54 +02:00
|
|
|
}
|
2020-11-10 16:24:48 +01:00
|
|
|
|
2022-03-17 00:10:16 +01:00
|
|
|
return create(new ASTNodeVariableDecl(name, type, std::move(placementOffset), inVariable, outVariable));
|
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
|
|
|
}
|
2020-11-27 21:20:23 +01:00
|
|
|
|
2021-01-07 21:16:34 +01:00
|
|
|
// (parseType) Identifier[[(parseMathematicalExpression)]] @ Integer
|
2022-03-17 00:10:16 +01:00
|
|
|
std::unique_ptr<ASTNode> Parser::parseArrayVariablePlacement(const std::shared_ptr<ASTNodeTypeDecl> &type) {
|
2021-09-21 21:29:18 +02:00
|
|
|
auto name = getValue<Token::Identifier>(-2).get();
|
2020-12-06 21:40:57 +01:00
|
|
|
|
2022-02-27 23:25:39 +01:00
|
|
|
std::unique_ptr<ASTNode> size;
|
2021-01-07 21:16:34 +01:00
|
|
|
|
|
|
|
if (!MATCHES(sequence(SEPARATOR_SQUAREBRACKETCLOSE))) {
|
2021-06-17 23:13:58 +02:00
|
|
|
if (MATCHES(sequence(KEYWORD_WHILE, SEPARATOR_ROUNDBRACKETOPEN)))
|
|
|
|
size = parseWhileStatement();
|
|
|
|
else
|
|
|
|
size = parseMathematicalExpression();
|
2021-01-07 21:16:34 +01:00
|
|
|
|
|
|
|
if (!MATCHES(sequence(SEPARATOR_SQUAREBRACKETCLOSE)))
|
2022-01-31 14:37:12 +01:00
|
|
|
throwParserError("expected closing ']' at end of array declaration", -1);
|
2021-01-07 21:16:34 +01:00
|
|
|
}
|
2020-12-06 21:40:57 +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 (!MATCHES(sequence(OPERATOR_AT)))
|
2022-01-31 14:37:12 +01:00
|
|
|
throwParserError("expected placement instruction", -1);
|
2020-12-06 21:40:57 +01:00
|
|
|
|
2021-08-25 17:07:01 +02:00
|
|
|
auto placementOffset = parseMathematicalExpression();
|
|
|
|
|
2022-03-17 00:10:16 +01:00
|
|
|
return create(new ASTNodeArrayVariableDecl(name, type, std::move(size), std::move(placementOffset)));
|
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
|
|
|
}
|
2020-12-07 23:49:19 +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
|
|
|
// (parseType) *Identifier : (parseType) @ Integer
|
2022-03-17 00:10:16 +01:00
|
|
|
std::unique_ptr<ASTNode> Parser::parsePointerVariablePlacement(const std::shared_ptr<ASTNodeTypeDecl> &type) {
|
2021-09-21 21:29:18 +02:00
|
|
|
auto name = getValue<Token::Identifier>(-2).get();
|
2020-12-06 21:40:57 +01:00
|
|
|
|
2022-02-27 23:25:39 +01:00
|
|
|
auto sizeType = parseType();
|
2020-12-06 21:40:57 +01:00
|
|
|
|
2021-08-25 17:07:01 +02:00
|
|
|
{
|
2022-02-27 23:25:39 +01:00
|
|
|
auto builtinType = dynamic_cast<ASTNodeBuiltinType *>(sizeType->getType().get());
|
2020-12-06 21:40:57 +01:00
|
|
|
|
2021-08-25 17:07:01 +02:00
|
|
|
if (builtinType == nullptr || !Token::isUnsigned(builtinType->getType()))
|
2022-01-31 14:37:12 +01:00
|
|
|
throwParserError("invalid type used for pointer size", -1);
|
2021-08-25 17:07:01 +02:00
|
|
|
}
|
2020-12-06 21:40:57 +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 (!MATCHES(sequence(OPERATOR_AT)))
|
2022-01-31 14:37:12 +01:00
|
|
|
throwParserError("expected placement instruction", -1);
|
2020-12-07 23:49:19 +01:00
|
|
|
|
2021-08-25 17:07:01 +02:00
|
|
|
auto placementOffset = parseMathematicalExpression();
|
|
|
|
|
2022-03-17 00:10:16 +01:00
|
|
|
return create(new ASTNodePointerVariableDecl(name, type, std::move(sizeType), std::move(placementOffset)));
|
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
|
|
|
}
|
2020-11-10 16:24:48 +01:00
|
|
|
|
2022-02-27 23:25:39 +01:00
|
|
|
std::vector<std::shared_ptr<ASTNode>> Parser::parseNamespace() {
|
|
|
|
std::vector<std::shared_ptr<ASTNode>> statements;
|
2021-08-25 17:07:01 +02:00
|
|
|
|
|
|
|
if (!MATCHES(sequence(IDENTIFIER)))
|
2022-01-31 14:37:12 +01:00
|
|
|
throwParserError("expected namespace identifier");
|
2021-08-25 17:07:01 +02:00
|
|
|
|
|
|
|
this->m_currNamespace.push_back(this->m_currNamespace.back());
|
2020-11-10 16:24:48 +01:00
|
|
|
|
2021-08-25 17:07:01 +02:00
|
|
|
while (true) {
|
2021-09-21 21:29:18 +02:00
|
|
|
this->m_currNamespace.back().push_back(getValue<Token::Identifier>(-1).get());
|
2021-08-25 17:07:01 +02:00
|
|
|
|
|
|
|
if (MATCHES(sequence(OPERATOR_SCOPERESOLUTION, IDENTIFIER)))
|
|
|
|
continue;
|
|
|
|
else
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!MATCHES(sequence(SEPARATOR_CURLYBRACKETOPEN)))
|
2022-01-31 14:37:12 +01:00
|
|
|
throwParserError("expected '{' at start of namespace");
|
2021-08-25 17:07:01 +02:00
|
|
|
|
|
|
|
while (!MATCHES(sequence(SEPARATOR_CURLYBRACKETCLOSE))) {
|
|
|
|
auto newStatements = parseStatements();
|
2022-02-27 23:25:39 +01:00
|
|
|
std::move(newStatements.begin(), newStatements.end(), std::back_inserter(statements));
|
2021-08-25 17:07:01 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
this->m_currNamespace.pop_back();
|
|
|
|
|
|
|
|
return statements;
|
|
|
|
}
|
|
|
|
|
2022-02-27 23:25:39 +01:00
|
|
|
std::unique_ptr<ASTNode> Parser::parsePlacement() {
|
2021-08-25 17:07:01 +02:00
|
|
|
auto type = parseType();
|
|
|
|
|
|
|
|
if (MATCHES(sequence(IDENTIFIER, SEPARATOR_SQUAREBRACKETOPEN)))
|
2022-02-27 23:25:39 +01:00
|
|
|
return parseArrayVariablePlacement(std::move(type));
|
2021-08-25 17:07:01 +02:00
|
|
|
else if (MATCHES(sequence(IDENTIFIER)))
|
2022-02-27 23:25:39 +01:00
|
|
|
return parseVariablePlacement(std::move(type));
|
2021-08-25 17:07:01 +02:00
|
|
|
else if (MATCHES(sequence(OPERATOR_STAR, IDENTIFIER, OPERATOR_INHERIT)))
|
2022-02-27 23:25:39 +01:00
|
|
|
return parsePointerVariablePlacement(std::move(type));
|
2022-01-31 14:37:12 +01:00
|
|
|
else throwParserError("invalid sequence", 0);
|
2021-08-25 17:07:01 +02:00
|
|
|
}
|
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
|
|
|
/* Program */
|
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
|
|
|
// <(parseUsingDeclaration)|(parseVariablePlacement)|(parseStruct)>
|
2022-02-27 23:25:39 +01:00
|
|
|
std::vector<std::shared_ptr<ASTNode>> Parser::parseStatements() {
|
|
|
|
std::shared_ptr<ASTNode> statement;
|
2020-11-10 15:26:38 +01:00
|
|
|
|
2021-10-10 15:38:58 +02:00
|
|
|
if (MATCHES(sequence(KEYWORD_USING, IDENTIFIER)))
|
2021-08-25 17:07:01 +02:00
|
|
|
statement = parseUsingDeclaration();
|
|
|
|
else if (peek(IDENTIFIER)) {
|
|
|
|
auto originalPos = this->m_curr;
|
|
|
|
this->m_curr++;
|
2021-09-03 02:33:45 +02:00
|
|
|
parseNamespaceResolution();
|
2021-08-25 17:07:01 +02:00
|
|
|
bool isFunction = peek(SEPARATOR_ROUNDBRACKETOPEN);
|
2022-02-01 22:09:44 +01:00
|
|
|
this->m_curr = originalPos;
|
2021-08-25 17:07:01 +02:00
|
|
|
|
|
|
|
if (isFunction) {
|
|
|
|
this->m_curr++;
|
|
|
|
statement = parseFunctionCall();
|
2022-01-24 20:53:17 +01:00
|
|
|
} else
|
2021-08-25 17:07:01 +02:00
|
|
|
statement = parsePlacement();
|
2022-01-24 20:53:17 +01:00
|
|
|
} else if (peek(KEYWORD_BE) || peek(KEYWORD_LE) || peek(VALUETYPE_ANY))
|
2021-08-25 17:07:01 +02:00
|
|
|
statement = parsePlacement();
|
2021-09-24 00:47:34 +02:00
|
|
|
else if (MATCHES(sequence(KEYWORD_STRUCT, 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
|
|
|
statement = parseStruct();
|
|
|
|
else if (MATCHES(sequence(KEYWORD_UNION, IDENTIFIER, SEPARATOR_CURLYBRACKETOPEN)))
|
|
|
|
statement = parseUnion();
|
2021-08-25 17:07:01 +02:00
|
|
|
else if (MATCHES(sequence(KEYWORD_ENUM, IDENTIFIER, OPERATOR_INHERIT)))
|
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
|
|
|
statement = parseEnum();
|
|
|
|
else if (MATCHES(sequence(KEYWORD_BITFIELD, IDENTIFIER, SEPARATOR_CURLYBRACKETOPEN)))
|
|
|
|
statement = parseBitfield();
|
2021-06-20 21:22:31 +02:00
|
|
|
else if (MATCHES(sequence(KEYWORD_FUNCTION, IDENTIFIER, SEPARATOR_ROUNDBRACKETOPEN)))
|
2021-09-21 21:29:18 +02:00
|
|
|
statement = parseFunctionDefinition();
|
2021-08-25 17:07:01 +02:00
|
|
|
else if (MATCHES(sequence(KEYWORD_NAMESPACE)))
|
|
|
|
return parseNamespace();
|
2022-01-31 14:37:12 +01:00
|
|
|
else throwParserError("invalid sequence", 0);
|
2020-11-10 15:26:38 +01:00
|
|
|
|
2021-01-21 17:49:30 +01:00
|
|
|
if (MATCHES(sequence(SEPARATOR_SQUAREBRACKETOPEN, SEPARATOR_SQUAREBRACKETOPEN)))
|
2022-02-27 23:25:39 +01:00
|
|
|
parseAttribute(dynamic_cast<Attributable *>(statement.get()));
|
2021-01-21 17:49:30 +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 (!MATCHES(sequence(SEPARATOR_ENDOFEXPRESSION)))
|
2022-01-31 14:37:12 +01:00
|
|
|
throwParserError("missing ';' at end of expression", -1);
|
2020-11-10 15:26:38 +01:00
|
|
|
|
2021-09-13 10:48:45 +02:00
|
|
|
// Consume superfluous semicolons
|
2022-01-24 20:53:17 +01:00
|
|
|
while (MATCHES(sequence(SEPARATOR_ENDOFEXPRESSION)))
|
|
|
|
;
|
2021-09-13 10:48:45 +02:00
|
|
|
|
2022-02-27 23:25:39 +01:00
|
|
|
return hex::moveToVector(std::move(statement));
|
2021-09-25 22:03:55 +02:00
|
|
|
}
|
2020-11-10 15:26:38 +01:00
|
|
|
|
2022-02-27 23:25:39 +01:00
|
|
|
std::shared_ptr<ASTNodeTypeDecl> Parser::addType(const std::string &name, std::unique_ptr<ASTNode> &&node, std::optional<std::endian> endian) {
|
2021-09-25 22:03:55 +02:00
|
|
|
auto typeName = getNamespacePrefixedName(name);
|
2021-09-03 10:30:40 +02:00
|
|
|
|
2021-09-25 22:03:55 +02:00
|
|
|
if (this->m_types.contains(typeName))
|
2022-01-31 14:37:12 +01:00
|
|
|
throwParserError(hex::format("redefinition of type '{}'", typeName));
|
2021-08-25 17:07:01 +02:00
|
|
|
|
2022-02-27 23:25:39 +01:00
|
|
|
std::shared_ptr typeDecl = create(new ASTNodeTypeDecl(typeName, std::move(node), endian));
|
2022-01-24 20:53:17 +01:00
|
|
|
this->m_types.insert({ typeName, typeDecl });
|
2021-09-25 22:03:55 +02:00
|
|
|
|
|
|
|
return typeDecl;
|
2020-11-10 15:26:38 +01:00
|
|
|
}
|
|
|
|
|
2021-08-25 17:07:01 +02:00
|
|
|
// <(parseNamespace)...> EndOfProgram
|
2022-02-27 23:25:39 +01:00
|
|
|
std::optional<std::vector<std::shared_ptr<ASTNode>>> Parser::parse(const std::vector<Token> &tokens) {
|
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
|
|
|
this->m_curr = tokens.begin();
|
|
|
|
|
|
|
|
this->m_types.clear();
|
2020-11-10 15:26:38 +01:00
|
|
|
|
2021-08-25 17:07:01 +02:00
|
|
|
this->m_currNamespace.clear();
|
|
|
|
this->m_currNamespace.emplace_back();
|
|
|
|
|
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 {
|
|
|
|
auto program = parseTillToken(SEPARATOR_ENDOFPROGRAM);
|
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
|
|
|
if (program.empty() || this->m_curr != tokens.end())
|
2022-01-31 14:37:12 +01:00
|
|
|
throwParserError("program is empty!", -1);
|
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
|
|
|
return program;
|
2022-01-31 14:37:12 +01:00
|
|
|
} catch (PatternLanguageError &e) {
|
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
|
|
|
this->m_error = e;
|
|
|
|
|
2022-01-31 14:37:12 +01:00
|
|
|
return std::nullopt;
|
|
|
|
}
|
2020-11-10 15:26:38 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|