[antlr-interest] parsing empty function parameters

Jim Idle jimi at temporal-wave.com
Fri Oct 5 16:54:08 PDT 2007


This tends to indicate that you have made a production with an empty alt,
also optional, akin to:

 

x    : arg? (COMMA arg?)* 

;

 

arg

     : expr

     | // Don’t do this

     ;

 

This may not be your exact problem but my bet is that it is something that
simplifies down to that.

 

Jim

 

From: antlr-interest-bounces at antlr.org
[mailto:antlr-interest-bounces at antlr.org] On Behalf Of Andy Tripp
Sent: Friday, October 05, 2007 1:40 PM
Cc: antlr-interest
Subject: Re: [antlr-interest] parsing empty function parameters

 

It should be that simple, but (at least with my grammar) when arg
can be empty, ANTLR bombs out.

Sohail Somani wrote: 

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" HYPERLINK
"mailto:antlr at jazillian.com"<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?
 
 
 
    

 
  

 

 

No virus found in this incoming message.
Checked by AVG Free Edition.
Version: 7.5.488 / Virus Database: 269.14.1/1050 - Release Date: 10/4/2007
5:03 PM


No virus found in this outgoing message.
Checked by AVG Free Edition. 
Version: 7.5.488 / Virus Database: 269.14.1/1050 - Release Date: 10/4/2007
5:03 PM
 
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.antlr.org/pipermail/antlr-interest/attachments/20071005/74dd54ee/attachment.html 


More information about the antlr-interest mailing list