Re: yypcontext_expected_tokens does not list optional components in grammar

Hans Ã…berg <[email protected]> Fri, 5 Dec 2025 10:37:36 +0100
Newsgroups gmane.comp.parsers.bison.general
Message-ID <[email protected]>
> On 4 Dec 2025, at 21:28, Jan Ko=C5=84czak =
<[email protected]> wrote:
>=20
>> It could be that using a parser based on IELR or LR fixes it. The =
default
>> is LALR, which does not always see the error tokens immediately, but =
may
>> perform some reductions first.
>=20
> Thanks for the pointers, it really did help me to find the right =
solution.
> While switching to LR parser indeed yielded expected results in the =
example,
> I believe the thing that I was missing was enabling 'Lookahead =
Correction'
> by the '%define parse.lac full' directive, which is in the manual =
section
> that you mentioned. Having that, yypcontext_expected_tokens provides =
me with=20
> complete list of expected tokens regardless of 'lr.type'.

Actually, I already had it in my own grammar. =F0=9F=99=82 Its addition =
was discussed on the Bison lists and added at some point. The precedence =
rules, including %nonaasoc, look at the tokens immediately before and =
after the parser position in a state and make decisions based on that, =
so it depends on the parser algorithm used. I made a different method =
that prohibits grammar expansions instead, which possibly might do =
better here if implemented.