[antlr-interest] Empty alternative causes error
Jamie Penney
jpen054 at ec.auckland.ac.nz
Mon Feb 18 16:37:55 PST 2008
You are correct. I am working on an unfinished grammar with Johannes
Luber. The extra symbols in the rewrite rule are needed by Johannes for
his project. Any chance you (or anyone else) could have a quick look at
it and give us some pointers? This is the Java target version, as I was
having difficulties debugging the C# target version.
Thanks,
Jamie Penney
Jim Idle wrote:
> My educated guess is that you are trying to write a C# parser and
> falling in to the trap of typing in the language spec too literally. The
> spec is not a spec for writing a grammar and so it creates ambiguities
> all over the place. Basically, you just cannot write it by following the
> language spec like that, you must left factor everything so it is a
> sensible grammar.
>
> I suspect that what is happening is that when you remove the empty alt,
> a rule higher up creates the ambiguity. There is a difference between
> generic declarations and generic invocations and you also need to be
> able to distinguish between generics and the < operator in some
> circumstances.
>
> Finally, you don't need the CLOSE_GENERICS element of the tree you are
> building.
>
> There are no bugs in this area that I am aware of, I am afraid that you
> probably need to rethink your grammar.
>
> Jim
>
>
>
>
>
>> -----Original Message-----
>> From: Jamie Penney [mailto:jpen054 at ec.auckland.ac.nz]
>> Sent: Monday, February 18, 2008 2:05 PM
>> To: antlr-interest at antlr.org
>> Subject: [antlr-interest] Empty alternative causes error
>>
>> Hi All,
>> I have the following rules:
>> type_argument_list_handler
>> : (type_argument_list)=> type_argument_list -> ^(OPTIONAL
>> type_argument_list)
>> | /*empty*/ -> ^(OPTIONAL)
>> ;
>>
>> type_argument_list
>> : LT type_parameters GT -> ^(OPEN_GENERICS[$LT] type_parameters
>> CLOSE_GENERICS[$GT])
>> ;
>>
>> If I try to remove the empty alternative, I get warnings about
>> type_argument_list_handler being able to handle LT using multiple
>> alternatives, yet there are no alternatives. If I leave it there, I
>>
> get
>
>> a test for the UP token generated from that rule, yet UP does not
>> exist.
>>
>> I have two possible answers to this problem.
>> 1) The grammar is wrong. Is there another way of specifying empty
>> rules?
>> 2) ANTLR is wrong. I know that Token.UP is really what it is searching
>> for, yet it uses UP instead. Is this possibly a bug?
>>
>> Thanks,
>> Jamie
>>
>
>
>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: grammar.zip
Type: application/x-zip-compressed
Size: 32139 bytes
Desc: not available
Url : http://www.antlr.org/pipermail/antlr-interest/attachments/20080219/79eb562e/attachment-0001.bin
More information about the antlr-interest
mailing list