[antlr-interest] parsing empty function parameters
Sohail Somani
sohail at taggedtype.net
Fri Oct 5 13:04:37 PDT 2007
Isn't this just:
argList : arg (COMMA arg?)* ;
----- Original Message -----
Subject: [antlr-interest] parsing empty function parameters
Date: Fri, October 5, 2007 12:09
From: "Andy Tripp" <antlr at jazillian.com>
> Using ANTLR v3.0.1,
> I'm trying to parse function parameters which can be empty, like this:
> f(a, , c, d);
> g(,,,,)
>
> I have:
> argList
> : argSpec (COMMA argSpec)*
> ;
>
> But then whenever I try to allow "argSpec" to have an empty alternative,
> ANTLR itself
> produces an OutOfMemoryError.
>
> Here's the original "argSpec" rule, which doesn't allow empty:
>
> argSpec
> : argPassingType? argSpec2
> ;
>
> I tried making the whole thing optional:
> argSpec
> : (argPassingType? argSpec2)?
> ;
>
> I tried a syntactic predicate:
> argSpec
> : (','|')') => // if next token is comma or rparen,
> nothing to consume.
> | argPassingType? argSpec2
> ;
>
> I tried a semantic predicate:
> argSpec
> : {input.LT(1).getText().equals(",") ||
> input.LT(1).getText().equals(")")}?
> | argPassingType? argSpec2
> ;
>
> As I said, all these cause ANTLR to produce OutOfMemoryError, presumably
> in an infinite loop matching this rule, but consuming no token.
> Any suggestions?
>
>
>
More information about the antlr-interest
mailing list