mdaines / grammophone

A tool for analyzing and transforming context-free grammars.
https://mdaines.github.io/grammophone
MIT License
200 stars 23 forks source link

Is the approach to propagating the EOF lookahead that Grammophone takes a nonstandard extension? #51

Open modulovalue opened 2 months ago

modulovalue commented 2 months ago

Hello @mdaines,

Consider the following fragment of an LALR(1) automaton as produced by Grammophone:

Screenshot 2024-04-27 at 12 01 30

I was wondering, do you know if this approach to introducing the EOF $ lookahead/follow symbol is the standard approach for doing that, or is this an extension that Grammophone decided to introduce?

What I'm doing in my implementation is to simply give the starting production with the dot on the rightmost side (e.g. S -> A B C •) a $ starting lookahead which should then be propagated to wherever it is expected. One benefit of this approach is that there's no special casing needed for the constituents of a DFA node, that is, all constituents are a real production with a dot. In your case, the constituents of a DFA node can be a production with a dot, or a synthetic production with a dot (e.g. Start •, • Start).

Just wanted to hear your thoughts on that. Do you know which approach is more common?