dschmenk / PLASMA

Proto Language AsSeMbler for All (formerly Apple)
MIT License
189 stars 26 forks source link

Disallow '5:' syntax #22

Closed ZornsLemma closed 7 years ago

ZornsLemma commented 7 years ago

As a Python programmer I have a habit of writing ':' at the end of if statements by accident, as in the following PLASMA code:

word i
i = 1
if i == 5:
        i = 7
fin
done

Here I intended to compare i with 5, but I am actually comparing i with the contents of the word at address 5, because '5:' acts like '5:0' (i.e. access word 0 of a structure starting at address 5). This leads to hair-pulling, which I can ill-afford. :-)

Would it be possible to have the compiler generate an error here instead of implicitly using a value of 0 on the rhs of the colon operator? I don't believe this is ever done deliberately, as

find . -name \*.pla -exec grep ':$' '{}' \;

doesn't return anything except false positives in the PLASMA repository.

dschmenk commented 7 years ago

This is the "expressiveness" of PLASMA ;-) Also, having to add ':' is one of my pet-peeves of Python. But I'll look at the value parser to validate.

dschmenk commented 7 years ago

So it's not a pretty fix but it should catch this case and similar errors.

ZornsLemma commented 7 years ago

Thanks Dave, much appreciated!