[Grace-core] In praise of consistency

Andrew P. Black black at cs.pdx.edu
Thu May 17 17:11:54 PDT 2012


I've been playing with James' example

	print "hello".reversed on output.mainStream

This _looks_ ambiguous to me:  I though that it meant

	request method print()on()								(1)
	from (implicit) receiver self
	with arg1 = "hello".reversed
	and agr2 = output.mainStream

whereas my parser thought that it meant 

	request method print()									(2)
	from (implicit) receiver self
	with arg1 = (
			request method reversed()
			from receiver "hello"
			with arg1 = (
					request method on()
					from (implicit) receiver self 
					with arg1 = output.mainStream
			)
	)


So, the rule I proposed in today's meeting — that we require parenthesis whenever there is an ambiguity — would require parens, right?  And that would solve the problem, right.  Unfortunately, no.

The problem is that while it's easy to come up with a parenthesisation for the second interpretation:

	print ( "hello".reversed on output.mainStream ) ,

I can't see a way of adding parenthesis that will make it mean the first.

Putting parens around the whole thing

	( print "hello".reversed on output.mainStream )

obviously doesn't help.

My parser does actually do interpretation (1) with

	print ("hello".reversed) on (output.mainStream)

but someone who does not know the rule that method names go on as long as possible could still miss-parse it.

The ambiguity is whether method names are as long as possible or as short as possible.   I thought that my grammar attempted to make them as long as possible, but I clearly got it wrong.

I don't see a solution other than telling students that "method names go on as long as possible".

	Andrew







More information about the Grace-core mailing list