# Left associative operators with high precedence

**URL:** <https://discourse.julialang.org/t/left-associative-operators-with-high-precedence/110995>\
**Category:** General Usage\
**Created:** [March 1, 2024, 5:49am UTC](https://discourse.julialang.org/t/left-associative-operators-with-high-precedence/110995 "2024-03-01T05:49:22Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![phyxmeow](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/phyxmeow/32/36373_2.png) [@phyxmeow](https://discourse.julialang.org/u/phyxmeow)\
**Post date:** [March 1, 2024, 5:49am UTC](https://discourse.julialang.org/t/left-associative-operators-with-high-precedence/110995/1 "2024-03-01T05:49:22Z")

</div>

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)`.

---

<div class="post-metadata">

**Author:** ![jar1](https://avatars.discourse-cdn.com/v4/letter/j/c0e974/32.png) [@jar1](https://discourse.julialang.org/u/jar1)\
**Post date:** [March 1, 2024, 5:55am UTC](https://discourse.julialang.org/t/left-associative-operators-with-high-precedence/110995/2 "2024-03-01T05:55:40Z")

</div>

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

You can [make your from scratch](https://en.wikipedia.org/wiki/Shunting_yard_algorithm) or use tools like

[https://lcsb-biocore.github.io/PikaParser.jl/stable/](https://lcsb-biocore.github.io/PikaParser.jl/stable/)

[https://gkappler.github.io/CombinedParsers.jl/dev/man/user/](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
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.

---

<div class="post-metadata">

**Author:** ![phyxmeow](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/phyxmeow/32/36373_2.png) [@phyxmeow](https://discourse.julialang.org/u/phyxmeow)\
**Post date:** [March 7, 2024, 12:29pm UTC](https://discourse.julialang.org/t/left-associative-operators-with-high-precedence/110995/3 "2024-03-07T12:29:35Z")

</div>

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