[antlr-interest] Undocumented error message

Darien A Hager darien at technofovea.com
Sun Oct 11 14:58:22 PDT 2009


William B. Clodius wrote:
> First, what kind of parameters are expected for a rule in ANTLR and  
> how do I define them?
This may or may not answer your question, but the following example 
should give a similar error.
________________________________________
parser grammar temp;
tokens{
   MYTOK;
}

foo [Tshirt x]
   :    msg=bar[x]
   {
       System.out.println(msg);
   }
   ;

bar returns [String message]
   :    MYTOK      {
       message = "I went and parsed stuff and all I got was this lousy 
T-shirt that says "+x.getFrontText();
   }
   ;
________________________________________


What this flawed grammar is intended to do is pass an object of type 
Thingy in when executing the rule "foo". And then every time the rule 
"foo" goes and calls rule "bar", "bar" will also have access to that 
object. To fix it, I need to add an input parameter (really, a 
positional function argument) to the final rule:
________________________________________
bar [Tshirt x] returns [String message]
________________________________________

At least for me, the error message numbers mean the line/column where I 
tried to put bar[x] while bar was unable to accept any arguments.

--Darien


More information about the antlr-interest mailing list