fsacer / FailLang

Language based on lox from book "Crafting Interpreters" by @munificent
17 stars 5 forks source link

Fix associativity of power, unary #8

Closed patrickfeltes closed 6 years ago

patrickfeltes commented 6 years ago

This should fix associativity issues with exponentiation. 2^2^4 = 65536.

A few extra additions:

I also updated the readme to add my additions to the grammar.

I hope you decide to add this!

Should fix #7

fsacer commented 6 years ago

Thanks didn't notice that when I was making it, I was also thinking that exponent should be after postfix too (so right before call). So maybe if you could change that? Also noticed operator precedence table is a bit out of date.

patrickfeltes commented 6 years ago

So, you want exponent to have higher precedence than postfix, so that something like

var x = 1;
print x++**2;

would be invalid without proper parentheses around x++?

patrickfeltes commented 6 years ago

I fixed the precedence table and added the change that you requested. Now the above code will not work unless the x++ is surrounded by parentheses.

fsacer commented 6 years ago

Looking at this doesn't seem to be right either. I think think the right thing to do is to keep the first version but split the unary to unary and prefix operators so prefix and postfix have seperate precedenes higher than the exponent operator while exponent having higher precedence than unary. (so from lower to higher: unary<exponent<prefix<postfix)

patrickfeltes commented 6 years ago

Will do! Thanks for the feedback

patrickfeltes commented 6 years ago

Here are the changes. Now x++^2 and ++x^2 should work correctly, along with the other fixes.

fsacer commented 6 years ago

merged