Parsing bug

Monkey Forums/Monkey Bug Reports/Parsing bug

Goodlookinguy(Posted 2014) [#1]
Edit: Not a bug. Look a couple posts below where I'm complaining that the syntax for parenthesis-less statements is unclear and can lead to this confusion when reading the code.

This code gives the error

Error : Unable to find overload for Print(A).


Class A
	Field abc:String = "Hi"
End

Function Main:Int()
	Print (New A()).abc
End


Shouldn't the dot operator have higher operator precedence than function calls and grouping. This can't be right.

Also, it can get really weird if you do this...

Class A
	Field abc:String = "Hi"
End

Function Main:Int()
	Print (New A()).abc + " world"
End


Error : ConstExpr(" world") must be numeric for use with unary operator '+'



Midimaster(Posted 2014) [#2]
I think, that is is no bug, but an mistake of you:

This works:
Print New A().abc + "world"
Print (New A().abc + " world")


And this should not:
Local x:A=New A()
Print (X).abc + " world"

...but that's what you did


Goodlookinguy(Posted 2014) [#3]
I swear I just figured it out sitting in my bed trying to sleep. I realized that due to the fact that you aren't forced to use parenthesis, but can, it treated the statement

Print (New A()).abc


like

Print(New A()).abc // abc a member of the value returned by print


So, it was an error of thinking of my part.

Maybe Monkey should be more clear on how it handles functions without parenthesis around them. Like, if a single space occurs after the identifier, it should treat that as a function without parenthesis around it. Because who writes a space and then a parenthesis sign after an identifier?

This way of parsing is leading to a kind of inconsistency in the language structure...
Function Main:Int()
	Example(3)*3,33
End

Function Example:Int( a:Int, b:Int )
	Print a + ", " + b
	Return a
End



marksibly(Posted 2014) [#4]
Yeah, Monkey *tries* to get this right, but sometimes it just doesn't have enough information to get it right every time.

> Because who writes a space and then a parenthesis sign after an identifier?

Someone is bound to - pretty much everything I've ever thought 'no one would ever do that', someone ends up doing!