From 6ea213ad5dc88ff0e3e200c279aa5a15a17db01f Mon Sep 17 00:00:00 2001 From: Matt Pharr Date: Wed, 6 Jul 2011 09:32:14 +0100 Subject: [PATCH] Added a few error productions to the parser. A few more productions to recover from parse errors (in function parameter lists and in statement lists). These eliminate some of the massive cascading error messages from a single parse error that the previous error recovery strategy would sometimes cause. Fixes issue #44. --- parse.yy | 40 ++++++++++++++++++++++++++++++++++++++-- 1 file changed, 38 insertions(+), 2 deletions(-) diff --git a/parse.yy b/parse.yy index a485ce55..c23dca36 100644 --- a/parse.yy +++ b/parse.yy @@ -103,6 +103,12 @@ static const char *lBuiltinTokens[] = { "static", "struct", "switch", "sync", "task", "true", "typedef", "uniform", "unsigned", "varying", "void", "while", NULL }; + +static const char *lParamListTokens[] = { + "bool", "char", "const", "double", "enum", "false", "float", "int", + "int32", "int64", "reference", "struct", "true", "uniform", "unsigned", + "varying", "void", NULL +}; %} @@ -798,15 +804,33 @@ parameter_list : parameter_declaration { std::vector *dl = new std::vector; - dl->push_back($1); + if ($1 != NULL) + dl->push_back($1); $$ = dl; } | parameter_list ',' parameter_declaration { std::vector *dl = (std::vector *)$1; - dl->push_back($3); + if (dl == NULL) + // dl may be NULL due to an earlier parse error... + dl = new std::vector; + if ($3 != NULL) + dl->push_back($3); $$ = dl; } + | error + { + std::vector builtinTokens; + const char **token = lParamListTokens; + while (*token) { + builtinTokens.push_back(*token); + ++token; + } + std::vector alternates = MatchStrings(yytext, builtinTokens); + std::string alts = lGetAlternates(alternates); + Error(@1, "Syntax error--token \"%s\" unknown.%s", yytext, alts.c_str()); + $$ = NULL; + } ; parameter_declaration @@ -888,6 +912,18 @@ statement | jump_statement | declaration_statement | print_statement + | error + { + std::vector builtinTokens; + const char **token = lBuiltinTokens; + while (*token) { + builtinTokens.push_back(*token); + ++token; + } + std::vector alternates = MatchStrings(yytext, builtinTokens); + std::string alts = lGetAlternates(alternates); + Error(@1, "Syntax error--token \"%s\" unknown.%s", yytext, alts.c_str()); + } ; labeled_statement