1 using System; 2 using System.IO; 3 using antlr; 4 using antlr.collections; 5 6 /** A simple node to represent an INT */ 7 public class INTNode : CalcAST { 8 int v=0; 9 INTNode()10 public INTNode() { 11 } 12 INTNode(Token tok)13 public INTNode(Token tok) { 14 v = Convert.ToInt32(tok.getText()); 15 } 16 initialize(int t, String txt)17 public override void initialize(int t, String txt) { 18 if (t == CalcParserTokenTypes.INT) 19 v = Convert.ToInt32(txt); 20 } initialize(AST t)21 public override void initialize(AST t) { 22 if (t.Type == CalcParserTokenTypes.INT) 23 v = Convert.ToInt32(t.getText()); 24 } initialize(IToken tok)25 public override void initialize(IToken tok) { 26 if (tok.Type == CalcParserTokenTypes.INT) 27 v = Convert.ToInt32(tok.getText()); 28 } 29 30 /** Compute value of subtree; this is heterogeneous part :) */ Value()31 public override int Value() { 32 return v; 33 } 34 ToString()35 public override string ToString() { 36 return " "+v; 37 } 38 xmlSerializeNode(TextWriter outWriter)39 public override void xmlSerializeNode(TextWriter outWriter) { 40 outWriter.Write("<int>"+v+"</int>"); 41 } 42 } 43