diff --git a/src/parser.lemon b/src/parser.lemon index 3fc54a7..5904893 100644 --- a/src/parser.lemon +++ b/src/parser.lemon @@ -54,8 +54,10 @@ // Mostly based on the following SO post, but we instead put it in a std::vector // https://stackoverflow.com/questions/11705737/expected-token-using-lemon-parser-generator/13010096#13010096 std::vector expectedTokens; - int n = sizeof(yyTokenName) / sizeof(yyTokenName[0]); - for (int i = 0; i < n; ++i) { + + // we loop over all known tokens, if we exceed our defined tokens we exit + // our last defined token is TOKEN_STRING, so we halt when we go past it + for (int i = 0; i <= TOKEN_STRING; ++i) { int a = yy_find_shift_action(yypParser, (YYCODETYPE)i); if (a < YYNSTATE + YYNRULE) expectedTokens.emplace_back(yyTokenName[i]); }