| 2049 | |
| 2050 | |
| 2051 | static int |
| 2052 | yy_syntax_error_arguments (const yypcontext_t *yyctx, |
| 2053 | yysymbol_kind_t yyarg[], int yyargn) |
| 2054 | { |
| 2055 | /* Actual size of YYARG. */ |
| 2056 | int yycount = 0; |
| 2057 | /* There are many possibilities here to consider: |
| 2058 | - If this state is a consistent state with a default action, then |
| 2059 | the only way this function was invoked is if the default action |
| 2060 | is an error action. In that case, don't check for expected |
| 2061 | tokens because there are none. |
| 2062 | - The only way there can be no lookahead present (in yychar) is if |
| 2063 | this state is a consistent state with a default action. Thus, |
| 2064 | detecting the absence of a lookahead is sufficient to determine |
| 2065 | that there is no unexpected or expected token to report. In that |
| 2066 | case, just report a simple "syntax error". |
| 2067 | - Don't assume there isn't a lookahead just because this state is a |
| 2068 | consistent state with a default action. There might have been a |
| 2069 | previous inconsistent state, consistent state with a non-default |
| 2070 | action, or user semantic action that manipulated yychar. |
| 2071 | - Of course, the expected token list depends on states to have |
| 2072 | correct lookahead information, and it depends on the parser not |
| 2073 | to perform extra reductions after fetching a lookahead from the |
| 2074 | scanner and before detecting a syntax error. Thus, state merging |
| 2075 | (from LALR or IELR) and default reductions corrupt the expected |
| 2076 | token list. However, the list is correct for canonical LR with |
| 2077 | one exception: it will still contain any token that will not be |
| 2078 | accepted due to an error action in a later state. |
| 2079 | */ |
| 2080 | if (yyctx->yytoken != YYSYMBOL_YYEMPTY) |
| 2081 | { |
| 2082 | int yyn; |
| 2083 | if (yyarg) |
| 2084 | yyarg[yycount] = yyctx->yytoken; |
| 2085 | ++yycount; |
| 2086 | yyn = yypcontext_expected_tokens (yyctx, |
| 2087 | yyarg ? yyarg + 1 : yyarg, yyargn - 1); |
| 2088 | if (yyn == YYENOMEM) |
| 2089 | return YYENOMEM; |
| 2090 | else |
| 2091 | yycount += yyn; |
| 2092 | } |
| 2093 | return yycount; |
| 2094 | } |
| 2095 | |
| 2096 | /* Copy into *YYMSG, which is of size *YYMSG_ALLOC, an error message |
| 2097 | about the unexpected token YYTOKEN for the state stack whose top is |
no test coverage detected
searching dependent graphs…