I'd appreciate a pointer as to why I'm getting two errors for this line of code one for the + in += One for 'if myMoves == UP: 1 else: -1'
myFloor += if myMoves == UP: 1 else: -1
myfloor is defined as int, myMoves is derived from 'for myMoves in s.data' where s.data is a string and UP is '('
This also works (with or without parens):
inc myFloor, if myMoves == UP: 1 else: -1
Read grammar.txt to find out why: A binary expression consists of primary expressions and their definition is:
primary = simplePrimary (commandStart expr)
/ operatorB primary
/ routineExpr
/ rawTypeDesc
/ prefixOperator primary
which does not include if or case or try expressions. Would it hurt to add these? For this you need to analyse the first and follow sets of the grammar rules. This is tedious to do manually so somebody should patch tools / grammar_nanny.nim to do it automatically. PRs are welcome. ;-)