[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Error recovery doesn't work correctly when LAC is on
From: |
Piotr Siupa |
Subject: |
Error recovery doesn't work correctly when LAC is on |
Date: |
Tue, 28 Mar 2023 18:42:59 +0200 |
Hello!
I've encountered a problem that I have no idea how to solve and it
doesn't seem that anyone on Stack Overflow knows anything either
(https://stackoverflow.com/q/75809021/3052438) so I came here, to the
source.
I've found that I can write a very simple grammar with error recovery
which works perfectly as long as I don't use `%define parse.lac full`.
If I do, error recovery stops working in certain cases.
Here is an example that just expects each line to be a single
character 'x' with optionally the first line being '!'. The error
recovery is supposed to resume from an EOL.
```
%{
#include <stdio.h>
int yylex();
void yyerror(const char *);
%}
%define parse.lac full
%define parse.error detailed
%%
prog:
init statements { printf("program finished successfully!\n"); }
;
init:
%empty
| '!' '\n' { printf("an optional \"special\" first line\n"); }
;
statements:
%empty
| statements 'x' '\n' { printf("correct line\n"); }
| statements error '\n' { yyerrok; printf("error line\n"); }
;
%%
int yylex()
{
char c;
if (scanf("%c", &c) != EOF)
return c;
else
return YYEOF;
}
void yyerror(const char *s) {
fprintf(stderr, "%s\n", s);
}
int main() {
return yyparse();
}
```
Here is what it print when I pass 2 illegal lines without LAC turned on:
```
syntax error, unexpected invalid token, expecting end of file or 'x'
error line
syntax error, unexpected invalid token, expecting end of file or 'x'
error line
program finished successfully!
```
This is what I'm expecting but the error message misses the character
`!`. LAC is supposed to fix such problems. However, if I turn it on,
the output is just:
```
syntax error, unexpected invalid token, expecting end of file or '!' or 'x'
```
So, it generates the correct message now but it doesn't enter error
recovery at all.
I have no idea if this is some kind of a bug or if I'm doing it wrong.
Any help will be appreciated.
the-example.y
Description: Binary data
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- Error recovery doesn't work correctly when LAC is on,
Piotr Siupa <=