diff options
-rw-r--r-- | grammer.cpp | 3 | ||||
-rw-r--r-- | test-lexer.cpp | 4 |
2 files changed, 5 insertions, 2 deletions
diff --git a/grammer.cpp b/grammer.cpp index 55e31c8..22b874e 100644 --- a/grammer.cpp +++ b/grammer.cpp @@ -426,6 +426,9 @@ bool Compiler::FillTree() index_t to_fill{}; while (!subTreeIsComplete(root_node_id, to_fill)) { + if (tokens_used >= tokens.size()) + return false; // Unexpected end of program? + auto& node {nodes[to_fill]}; std::string next_child {bnf[node.type][node.variant][node.child_ids.size()]}; if (next_child == tokens[tokens_used].type) { // add token directly diff --git a/test-lexer.cpp b/test-lexer.cpp index 0449af9..2eeaef8 100644 --- a/test-lexer.cpp +++ b/test-lexer.cpp @@ -61,7 +61,7 @@ TEST_F(Test, BNF) { // implicit? //std::set<std::string> Terminals{"identifier", "=", ";"}; - std::string Code{"a = bc ; c = 123 ; esd = Ff ; 1 = XYZ ;"}; + std::string Code{"a = bc ; c = 123 ; esd = Ff ; 1 = XYZ ; "}; std::vector<Token> tokens_reference{ {"identifier", "a", { 1, 1} }, {"preprocessing-op-or-punc", "=", { 1, 3}}, @@ -78,7 +78,7 @@ TEST_F(Test, BNF) { {"pp-number", "1", { 1, 31}}, {"preprocessing-op-or-punc", "=", { 1, 33}}, {"identifier", "XYZ", { 1, 35}}, - {"preprocessing-op-or-punc", ";", { 1, 38}}, + {"preprocessing-op-or-punc", ";", { 1, 39}}, }; Lex::Lexer lexer(LexBNF, LexTop); |