[antlr-interest] Inherit grammar and specify base scanner class
at the same time
Stanimir Stamenkov
stanio at myrealbox.com
Tue Jan 24 08:17:49 PST 2006
/Stanimir Stamenkov/:
> I'm new to the ANTLR framework and I'm currently trying to generate a
> lexer which employs grammar inheritance and specifies to be of specific
> |antlr.CharScanner| subtype, at the same type.
> [...]
> Is it possible what I'm trying?
If my explanation wasn't as clear as it needs, I'm posting the exact
example files attached - I'm trying to process the "mylexer.g"
grammar running:
antlr -glib superlexer.g mylexer.g
I'm using ANTLR 2.7.5.
--
Stanimir
-------------- next part --------------
/*
*
*/
class SuperLexer extends Lexer;
WS : ( ' ' | '\t' | '\f' | '\r' | '\n' )+;
-------------- next part --------------
/*
*
*/
header
{
package name.stanio;
}
class MyLexer extends SuperLexer("name.stanio.MyScanner");
//class MyLexer extends Lexer("name.stanio.MyScanner");
COMMENT : "//" (~('\n'|'\r'))* ('\n'|'\r'('\n')?) { myFancyMethod(); };
-------------- next part --------------
package name.stanio;
import antlr.CharScanner;
import antlr.LexerSharedInputState;
public abstract class MyScanner extends CharScanner {
public MyScanner(LexerSharedInputState inputState) {
super(inputState);
}
protected void myFancyMethod() {
System.out.println("Say \"Hi\"!");
}
}
More information about the antlr-interest
mailing list