# Flat operators

**URL:** <https://discuss.codemirror.net/t/flat-operators/2267>\
**Category:** Lezer\
**Created:** [January 12, 2020, 10:27am UTC](https://discuss.codemirror.net/t/flat-operators/2267 "2020-01-12T10:27:19Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![poeschko](https://discuss.codemirror.net/user_avatar/discuss.codemirror.net/poeschko/32/697_2.png) [@poeschko](https://discuss.codemirror.net/u/poeschko)\
**Post date:** [January 12, 2020, 10:27am UTC](https://discuss.codemirror.net/t/flat-operators/2267/1 "2020-01-12T10:27:19Z")

</div>

What’s a good way to implement “flat” operators, where I want all the operands as direct children of a single parse node, as opposed to left/right-associative operators that force a particular (binary) grouping?

Naïve attempt:

```auto
@top[name=top] { expr }

@tokens {
    pl { "+" }
    int { std.digit+ }
}

expr { PlusExpr | int }

PlusExpr { expr (pl expr)+ }

```

(which results in a shift/reduce conflict)

I would like it to generate a parse tree of the form

```auto
PlusExpr(1, 2, 3, 4, 5)

```

when parsing

```auto
1+2+3+4+5

```

I could use

```auto
@precedence { plus @left }

PlusExpr { expr !plus expr }

```

and then flatten out the parse tree after parsing, but that seems a bit wasteful (?). Is there any better way?

P.S. Thanks for creating this library, it’s awesome!

---

<div class="post-metadata">

**Author:** ![marijn](https://discuss.codemirror.net/user_avatar/discuss.codemirror.net/marijn/32/136_2.png) [@marijn](https://discuss.codemirror.net/u/marijn)\
**Post date:** [January 12, 2020, 10:43am UTC](https://discuss.codemirror.net/t/flat-operators/2267/2 "2020-01-12T10:43:06Z")

</div>

If you put the `!plus` marker in your `PlusExpr { expr (pl !plus expr)+ }` rule, this seems to work.
