# parser: Use an operator precedence table · gitcafe/zig

[View on GitCafe](https://git.cafe/gitcafe/zig/commit/01aa74a93fa7c18f8a2f27a4c5f76333935c3502)

Repository: [gitcafe/zig](https://git.cafe/gitcafe/zig)

Visibility: public

Requested revision: 01aa74a93fa7c18f8a2f27a4c5f76333935c3502

Requested commit: 01aa74a93fa7c18f8a2f27a4c5f76333935c3502

Commit: 01aa74a93fa7c18f8a2f27a4c5f76333935c3502

Tree: de2602e3e0da264135be942426f50460c44952cc

Author: Shachaf Ben-Kiki

Committer: Shachaf Ben-Kiki

## Message

```
parser: Use an operator precedence table

Instead of having one function per precedence level, mirroring the BNF grammar,
this uses the "precedence climbing" algorithm with a table of operator
precedences (and a few special cases that don't fit into the table as it is).

This is a first pass -- it's probably possible to put more of the parser
into this form, e.g. to support prefix/suffix operators with precedence, if
necessary, or just to simplify the code more.

It may also be possible to speed this up by putting more useful information
into the tokens during tokenization, to avoid the extra branch on the token in
operInfo.

```

## Parents

- [37b05742ff1544bccf7c8ae9b12c6707a5a54df2](https://git.cafe/gitcafe/zig/commit/37b05742ff1544bccf7c8ae9b12c6707a5a54df2?format=markdown)

[Source at this commit](https://git.cafe/gitcafe/zig/tree/01aa74a93fa7c18f8a2f27a4c5f76333935c3502?format=markdown)
