[grammarians] ambiguity with method call?
Terence Parr
parrt at cs.usfca.edu
Wed Nov 30 13:10:28 EST 2005
On Nov 29, 2005, at 11:47 PM, Ryan Davis wrote:
>
> On Nov 29, 2005, at 12:59 PM, Terence Parr wrote:
>
>> Howdy,
>>
>> What does
>>
>> foo [1]
>
> sudo gem install ParseTree (!!)
>
> % echo "foo [1]" | parse_tree_show -f
> ...
> [:fcall, :foo, [:array, [:array, [:lit, 1]]]]
>
> without any other context to go on, it is assumed it is an fcall,
> in other contexts it could be an lvar, dvar, or a regular call.
>
> You should also do a gem unpack ParseTree and look through the unit
> tests. That might answer quite a few of your questions as well.
Yep. Thanks, Ryan.
Here's the thing. The impl does not specify the language definition;
i've seen mistakes in C compilers. My point is that the language
rules as described everywhere I look could easily be seen to
interpret foo[1] in two ways:
(foo)[1]
and
foo([1])
even when we know foo is a function call. how could it not? There
is no syntax to distinguish. Remember that structure imparts
meaning. Just because his implementation picks one doesn't mean
there isn't a real ambiguity here. For example, C++ clearly
identifies the ambiguity between decl and expr statements and says in
the book that if some input can be either, choose decl (it's still a
bad thing, but it's known and specified).
Languages do have ambiguities such as the if-then-else bugaboo, but
it needs to be clearly outlined rather than just biting somebody.
More importantly, computer languages should be defined as
deterministically/unambiguously as possible. It's already bad enough
in ruby that I have to look backwards to see how it was used first
lexically (particularly when there are two interpretations possible
given foo=1 and def foo). Adding in this unspecified preference to
resolve the ambiguity is pretty rough on a guy. It's a bug in hiding
waiting to bite you 2 years hence when that code execs and gives you
a runtime type exception.
All that said, the point of this exercise is probably to get a real
spec driven from a real grammatical description. Am I the first
person to run across this ambiguity before?
Ter
More information about the Rubygrammar-grammarians
mailing list