/* * @topic T10173 Desktop Calculator v3 * @brief class AstNode represents a building block for AST, the abstract syntax tree */ package wk03_calc_v3; public class AstNode { //--------------------------- // constants //--------------------------- public static final int NUMBER = 'N'; public static final int END = 'Z'; public static final int ERROR = 'E'; //--------------------------- // data //--------------------------- public int type; public String value; public AstNode leftNode; public AstNode rightNode; //--------------------------- // constructors //--------------------------- public AstNode(int type) { this.type = type; this.value = ""; this.leftNode = null; this.rightNode = null; }//AstNode public AstNode(int type, String value) { this.type = type; this.value = value; this.leftNode = null; this.rightNode = null; }//AstNode //--------------------------- // operations //--------------------------- public void print( int level ) { for ( int idx = 0; idx < level; ++idx ) System.out.print( "." ); System.out.println( value ); if ( leftNode != null ) leftNode.print( level + 1 ); if ( rightNode != null ) rightNode.print( level + 1 ); }//print }//class AstNode