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

Support nonterminals participating in P&A. #41

Open
teo-tsirpanis opened this issue Feb 9, 2023 · 1 comment
Open

Support nonterminals participating in P&A. #41

teo-tsirpanis opened this issue Feb 9, 2023 · 1 comment

Comments

@teo-tsirpanis
Copy link
Owner

teo-tsirpanis commented Feb 9, 2023

Consider this grammar represented in Bison syntax:

%left '|' "or"
%left '&' "and"
%precedence '!' "not"

%start expr

or_op: '|' | "or";
and_op: '&' | "and";

expr:
  expr or_op expr
  | expr and_op expr
  | "x";

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.

Footnotes

  1. Precedence & Associativity

@teo-tsirpanis
Copy link
Owner Author

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant