You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Farkle fails to build this grammar because the expr <op> expr productions don't have any P&A1, and that's because the operator terminals are indirectly specified. The current workaround is to inline or_op and and_op. There are two ways to solve this:
Recognize nonterminals in associativity groups. The constructors of associativity groups accept an array of objects, which can be DesigntimeFarkles for terminals, strings for literals, or arbitrary objects for contextual precedence tokens, ignoring everything else. We should also recognize DesigntimeFarkles for nonterminals.
With this change the P&A of productions without contextual precedence would become the P&A of the last terminal or nonterminal of the production that has P&A. This would be the equivalent of writing %left <op>.
Infer the P&A of nonterminals whose all productions have the same P&A. This would make the above grammar work with no modifications to the P&A rules. If we go down this way we have to watch out for recursive nonterminals.
Judging from Bison's documentation, it doesn't do the things proposed above; I wonder why. Should we even do such comparisons? In any case I don't see any downsides; it won't affect those that don't use them.
Update: item 2 is not as simple as it sounds when considering more complex cases like recursive nonterminals. Improving Farkle's conflict resolution mechanism is an interesting area to explore, but it must be done carefully.
Consider this grammar represented in Bison syntax:
Farkle fails to build this grammar because the
expr <op> expr
productions don't have any P&A1, and that's because the operator terminals are indirectly specified. The current workaround is to inlineor_op
andand_op
. There are two ways to solve this:Recognize nonterminals in associativity groups. The constructors of associativity groups accept an array of objects, which can be
DesigntimeFarkle
s for terminals, strings for literals, or arbitrary objects for contextual precedence tokens, ignoring everything else. We should also recognizeDesigntimeFarkle
s for nonterminals.With this change the P&A of productions without contextual precedence would become the P&A of the last terminal or nonterminal of the production that has P&A. This would be the equivalent of writing
%left <op>
.Infer the P&A of nonterminals whose all productions have the same P&A. This would make the above grammar work with no modifications to the P&A rules. If we go down this way we have to watch out for recursive nonterminals.
Judging from Bison's documentation, it doesn't do the things proposed above; I wonder why. Should we even do such comparisons? In any case I don't see any downsides; it won't affect those that don't use them.
Footnotes
Precedence & Associativity ↩
The text was updated successfully, but these errors were encountered: