Expected Token Using Lemon Parser Generator

Is there a known way to generate the list of "Expected Token" when a syntax error occurs? I use Lemon as a parser generator.

+5
source share
2 answers

It works:

%syntax_error { 
        int n = sizeof(yyTokenName) / sizeof(yyTokenName[0]);
        for (int i = 0; i < n; ++i) {
                int a = yy_find_shift_action(yypParser, (YYCODETYPE)i);
                if (a < YYNSTATE + YYNRULE) {
                        printf("possible token: %s\n", yyTokenName[i]);
                }
        }
}

It tries all possible markers and prints those that are applicable in the current state of the parser.

, , synax_error, , , . , , _error. , , , . .

+9

. , Lemon . ParseTrace Shift Reduces . . *.out .

+1

All Articles