[antlr-interest] Can't Use Subclass LLkParser?

wnreynolds grendel at swcp.com
Sun May 4 16:26:52 PDT 2003


<html>
<body>
<p>
(cross posted to jGuru forum).
I'm using the latest version (2.7.2) of antlr. I want to specify
something like

<font size=2>
<pre>
class SubGrammar extends Parser (Foo) ;
</pre>
</font>

<p>
so that my gramamr inherits off my custom subclass Foo of LLkParser.

<p>
Looking at antlr.g, this seems to be allowed (code from antlr.g
attached at end of this post).

<p>
Trying to compile the following simple grammar:

<font size=2>
<pre>
header
{
}


{
    import antlr.*;
}

class SubGrammar extends Parser (Foo) ;

rule: "rule";
</pre>
</font>

<p>
fails:

<font size=2><pre>
ANTLR Parser Generator   Version 2.7.2   1989-2003 jGuru.com
SubGrammar.g:10:33: expecting SEMI, found '(Foo)'
</pre></font>

<p>
I tried debugging antlr, and the '(Foo)' token was correctly consumed
by the superClass rule in antlr.g, as was the terminal SEMI (see
below), but antlr still gives the error.


<p>
Any thoughts?

<p>
Bill Reynolds

<p>
(relevant excerpts fron antlr.g follow)

<font size=2>
<pre>
parserSpec[String doc]
{
	Token idTok;
	String sup=null;
}
	:	"class"
		idTok = id
		(	"extends" "Parser"
			(sup=superClass)?
		|	{
			antlrTool.warning("use 'class X extends Parser'", getFilename(),
idTok.getLine(), idTok.getColumn());
//			System.out.println("warning: line " +
//				idTok.getLine() + ": use 'class X extends Parser'");
			}
		)
		{behavior.startParser(getFilename(), idTok, sup, doc);}
		SEMI
		(parserOptionsSpec)?
		{ behavior.endOptions(); }
		(tokensSpec)?
		( a:ACTION {behavior.refMemberAction(a);} )?
	;

superClass returns [String sup]
{sup=null;}
	:	LPAREN
			{sup = LT(1).getText();}
			(TOKEN_REF|RULE_REF)
		RPAREN
	;
</pre>
</font>
</body>
</html>



 

Your use of Yahoo! Groups is subject to http://docs.yahoo.com/info/terms/ 




More information about the antlr-interest mailing list