Left associative operators with high precedence

I would like an operator that has higher precedence than :*, but is left associative. I found there is no pre-defined symbol has these two properties at the same time. Since I’m working with strings coming from user input, I guess I can define a macro or something to change the precedence before parsing. But I’m not sure how.
For example, I would like "a⊗ b*c⊗ d" to be parsed to (a⊗ b)*(c⊗ d).

Since you are working on strings, you don’t need a macro, you need a parser.

You can make your from scratch or use tools like

https://lcsb-biocore.github.io/PikaParser.jl/stable/

https://gkappler.github.io/CombinedParsers.jl/dev/man/user/

I don’t think you can use Julia’s parser for this because it can’t distinguish between

julia> Meta.parse("(a⊗b*c)⊗d")
:(((a ⊗ b) * c) ⊗ d)

julia> Meta.parse("a⊗b*c⊗d")
:(((a ⊗ b) * c) ⊗ d)

Though maybe you can modify the output of the JuliaSyntax parser using the fancy parenthesis-tracking stuff — probably not worthwhile.

1 Like

Thank you, I’m trying to write expression parser myself.