lace-language / lace

4 stars 0 forks source link

Re-implement expression parsing #21

Closed bal-e closed 1 year ago

bal-e commented 1 year ago

Rather than relying on a separate function for each set of binary operators, I've introduced a single set of functions for parsing arbitrary binary operators, using precedence and associativity computations to decide the how to structure the operators. I've also rewritten how unary expressions are parsed; they're now entirely handled by a single unary_expr() function, which checks for all prefix and postfix operators. I believe that this makes the structure of parsing for expressions much, much clearer.

bal-e commented 1 year ago

Basically, with this approach, the binary operators are implemented more in terms of data rather than in code, which means that we'll be able to add new operators much more easily. It also makes checking correctness much easier per operator (the core binary expression logic is complicated, I know, but it only needs to be checked once).

jdonszelmann commented 1 year ago

I in many ways prefer the existing implementation of parsing operators, although the precedence of not should change on main as well lol