[antlr-interest] C# line numbers and subclass of CommonAST

parisinmydreams roberthoglund at hotmail.com
Mon Jul 26 04:41:47 PDT 2004


Hi,

When searching through the archives I found a post this post
http://groups.yahoo.com/group/antlr-interest/message/7078
that describes how to get line numbers into the AST. If I understood
it correctly you should only have to subclass the CommonAST and add
fields to store the line number and any extra information you could
want. 
I did just that, created a class
public class LineNumberAST : antlr.CommonAST
	{
	private int _LineNumber;
	public LineNumberAST()
	{
	}
	
	public LineNumberAST(Token tok):base(tok) 
	{
	}
		

	public override void initialize(Token tok) 
	{
		base.initialize(tok);
		_LineNumber = tok.getLine();
	}

	public int LineNumber 
	{
	get {
	return _LineNumber;
	}
	set {
	_LineNumber = value;
	}
	}
}

and then instructed both my Parser and TreeParser to use my subclass
with ASTLabelType="LineNumberAST".

When I try to run my program I get the following error:

An unhandled exception of type 'System.InvalidCastException' occurred
in parser.new.dll

Additional information: Specified cast is not valid.

at the following line:

i_AST = (LineNumberAST) astFactory.create(i);

where i_AST is of type LineNumberAST

Could someone please help solve this problem

Regards,

Robert




 
Yahoo! Groups Links

<*> To visit your group on the web, go to:
    http://groups.yahoo.com/group/antlr-interest/

<*> To unsubscribe from this group, send an email to:
    antlr-interest-unsubscribe at yahoogroups.com

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



More information about the antlr-interest mailing list