From 1574ec62498ed1ae51d4bf9500d89e63422ce567 Mon Sep 17 00:00:00 2001 From: omicron Date: Wed, 16 Apr 2025 12:13:02 +0200 Subject: [PATCH 1/4] Fix parse_consecutive behavior when the token stream runs out --- src/parser/combinators.c | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/parser/combinators.c b/src/parser/combinators.c index 1c6cba7..7f6637d 100644 --- a/src/parser/combinators.c +++ b/src/parser/combinators.c @@ -1,4 +1,5 @@ #include "combinators.h" +#include "util.h" // Parse a list of the given parser delimited by the given token id. Does not // store the delimiters in the parent node @@ -122,5 +123,12 @@ parse_result_t parse_consecutive(tokenlist_entry_t *current, node_id_t id, } current = result.next; } + + // token stream ended before we matched all parsers + if (parser != nullptr) { + ast_node_free(all); + return parse_no_match(); + } + return parse_success(all, current); } -- 2.47.2 From 242fd9baa58e3c6d2043d68b7deddcbfb68fb4a9 Mon Sep 17 00:00:00 2001 From: omicron Date: Wed, 16 Apr 2025 12:34:44 +0200 Subject: [PATCH 2/4] Fix grammar not being able to disambiguate some instructions When two identifiers follow eachother it could be two instruction mnemonics or one instruction mnemonic and one operand. To fix this TOKEN_NEWLINE has been reintroduced as a semantic token. The grammar has been changed to allow empty statements and every instruction and directive has to end in a newline. Labels do not have to end in a newline. In addition to updating the grammar, the implementation of tokenlist, ast and parser has been updated to reflect these changes. --- doc/parser_grammar.txt | 6 +++--- src/ast.c | 5 ++++- src/ast.h | 1 + src/parser/parser.c | 8 +++++--- src/parser/primitives.c | 4 ++++ src/parser/primitives.h | 1 + src/tokenlist.c | 1 - 7 files changed, 18 insertions(+), 8 deletions(-) diff --git a/doc/parser_grammar.txt b/doc/parser_grammar.txt index e7e9315..9a651b9 100644 --- a/doc/parser_grammar.txt +++ b/doc/parser_grammar.txt @@ -1,13 +1,13 @@ ::= * - ::=