Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

"Lookahead exceeds token buffer length" with simple grammar #54

Closed
Leandros opened this issue Jan 5, 2023 · 3 comments
Closed

"Lookahead exceeds token buffer length" with simple grammar #54

Leandros opened this issue Jan 5, 2023 · 3 comments
Assignees
Labels
bug Something isn't working

Comments

@Leandros
Copy link

Leandros commented Jan 5, 2023

Trying to parse anything with a parser generated from this elementary grammar:

%start Foo
%title "Foo grammar"
%comment "Empty grammar generated by `parol`"
%line_comment "//"

%%

Rjs: 'Hello' 'world';

Trying to parse

Hello world

results in the following errors:

  × Failed parsing file ./test.txt
  ├─▶ Failed accessing lookahead token!
  ╰─▶ Lookahead exceeds token buffer length

The error can be fixed by adding the empty case to the production:

Rjs: 'Hello' 'world' | ;

Is this intended behavior?

@jsinger67
Copy link
Owner

jsinger67 commented Jan 6, 2023

@Leandros Thank you for reporting this.
I know about this behavior but it is not good documented and actually easy to fix.
The cause of this is that your first grammar is actually k0. This results in a lookahead buffer of size 0.
I think I will fix this simply by setting the lower size limit of the lookahead buffer to 1.

Edit: I think I should elaborate a bit on this weird k0 thingy.
From the perspective of the parser there is no need to choose between different productions for a non-terminal when there's only one production. So it doesn't need no lookahead at all to solve this decision problem. This is the reason for taking a zero value as lookahead size (k0) for this simple grammar.
In the real world the scanner must be able to deliver consumable tokens for the parser. So buffer size 0 won't work here.
That's the point here. An edge case but valid.

@jsinger67 jsinger67 self-assigned this Jan 6, 2023
@jsinger67 jsinger67 added the bug Something isn't working label Jan 6, 2023
@jsinger67
Copy link
Owner

Fixed with commit c302ba2.

@Leandros
Copy link
Author

Wonderful. Thank you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants