differentmatt / filbert

JavaScript parser of Python
Other
133 stars 27 forks source link

Problems with compound conditions in if statements. #59

Open nemoyatpeace opened 9 years ago

nemoyatpeace commented 9 years ago

When trying to combine or and and conditionals inside of if statements I get wonky calculations.

if (3==3 or 2==2) and 5==5:
  print('hi')

Gives SyntaxError: Unexpected token

If I add a set of parenthesis:

if ((3==3 or 2==2) and 5==5):
  print('hi')

Then it works fine.

But, I just had a case where I realized it might be parsing things improperly. I was running this code in the level zero-sum:

if ((soldiers < 2 or soldiers <= archers/5) and self.gold >= self.costOf("soldier")):
        self.summon("soldier")

This was attempting to summon a soldier even when I didn't have enough gold. But when I tried a simplified version in the Interactive testing, I couldn't replicate it, maybe I just had something wrong in my code, but when I simply split that statement to:

if (soldiers < 2 or soldiers <= archers/5) 
    if self.gold >= self.costOf("soldier"):
        self.summon("soldier")

It no longer attempted to summon the soldier.