My language have unary +, binary +, and haskell style application notation that concatenates callee and argument directly, so a+b is ambiguous that it can be a+b(binary +) or a +b(a applied to +b). My expectation is to prefer binary + over application when such expression occurs. I didn’t figure out how to do it.
It parses a+b as Program(Application(Identifier,AddUnary("+",Identifier))). I’ve tried @dynamicPrecedence with no luck, but I’m not sure I’ve understood this feature so I didn’t show it in code above. Can you show me what’s the correct way to make it parse a+b as binary + expression?
Thanks.
What I want is not making add take precedence over add-unary. What I want is to parse a+b as binary +, not a applied to +b. The problem is between Application and Add, not AddUnary and Add.
After the change a+b is parsed as binary +, which is what I want, but as a result -a+b is parsed as -(a+b), which is not what I want. That’s why I put add below add-unary in the first place. I want -a+b be parsed as (-a)+b like in most languages.
I don’t expect unary minus and unary plus to have different precedences because they will be both categorized as additive unary operators and have same precedence. That is, -a+b will be parsed as (-a)+b, while +a+b will be parsed as (+a)+b similarly.
However, if we need different precedences for them for technical reason, that is acceptable.
To summarize, my requirement is to define an expression grammar that contains unary +/-, binary +/-, and application, where:
+/- operations will be parsed as in most popular languages like c or js
application will be direct concatenation like in haskell, and have higher precedence than any +/- expressions
Disambiguation: for expressions like a+b, parse it as a+b(binary +), not a (+b)(a applied to +b)