[antlr-interest] Optional keyword causes ambiguity in parser
Gavin Lambert
antlr at mirality.co.nz
Fri Apr 18 15:51:59 PDT 2008
At 03:55 19/04/2008, Ramon Verbruggen wrote:
>You really looked at the grammar in depth! I agree that it looks
>silly, but the point of the 'addressable' is that you can start
>with a variable or argument, and use methods and attributes of
>this variable or argument to chain them together (e.g.
>myarg.SomeGetMethod().AnotherMethod().GetAttribute()) so yes, an
>Identifier by itself is a valid addressable.
I think you may have missed my point. You've said that an
"addressable" by itself is a valid statement. Obviously a method
call is a valid statement. But is an object or field reference a
valid statement?
To give examples (not all of these may actually be valid in your
language, I'm just speculating on the language structure):
"myarg.SomeGetMethod().AnotherMethod().GetAttribute()": method
call, definitely a statement.
"myarg.somefield.AnotherMethod()": also a method call, through
a field this time, but still clearly a statement.
"myarg.SomeMethod().somefield": method call but then a field
reference. This is a value, which may be a good expression but is
it really a statement?
"myarg()": method call; probably a good statement, although it
depends if your language allows global functions or method
pointers (like C/C++) or if you have to call through an instance
object (like Java/C#)
"myarg": variable reference, a value; again it's obviously an
expression but is it really a statement?
C/C++ permit expressions to be statements in their own right, but
C# (and I think Java too) don't. From the looks of your grammar
it sounded like you didn't want expressions to be statements
normally, with the single exception of the final one in the
function (acting as a return value). (Although having said that,
it does raise the question of why you want to break consistency
just to permit leaving out one keyword ;))
(Of course, I also strongly dislike single-exit-point languages;
they can lead to excessive nesting and temporary variable
shenanigans, especially when simply trying to assert
preconditions. But hey, whatever makes you happy.) :)
More information about the antlr-interest
mailing list