goby-lang / goby

Goby - Yet another programming language written in Go
MIT License
3.49k stars 171 forks source link

Arithmetic operations with multiple right values are allowed #444

Closed 64kramsystem closed 6 years ago

64kramsystem commented 7 years ago

In Goby, it's allowed to perform an arithmetic operation with two right values:

1 * *[2, 3] #=> 2

I think this should be forbidden; if so, probably the best place to forbid this is at parser level, otherwise, argument checks should be added for each operation method.

st0012 commented 7 years ago

This is a bug and should be fixed in Parser

ear7h commented 6 years ago

I was looking into this today and I found it only happens with , not ** or other operators. I think it's caused by the registering of asterisk as a prefix expression.

Removing this line and adding the following line seems to fix this specific issue. But running go test ./... yields several parser related test failures before a SIGSEGV. I'm willing to work on this but unsure how to proceed.

p.registerInfix(token.Asterisk, p.parseInfixExpression)
st0012 commented 6 years ago

@ear7h Maybe adding check inside p.parseInfixExpression? * * is two tokens for the parser while ** is one. So when we proceed to the second * the left expression will also be *, and then we can know user are using it in the wrong way