/** * Visit a variable node. The value of the variable is obtained from the symbol table (symTab) and * pushed onto the stack. */ public Object visit(ASTVarNode node, Object data) throws ParseException { // try to get the variable object Variable var = symTab.getVar(node.getVarName()); if (var == null) { String message = "Could not evaluate " + node.getVarName() + ": "; throw new ParseException(message + "the variable was not found in the symbol table"); } // get the variable value // Object temp = var.getValue(); Object temp = var.getValue(); if (trapNullValues && temp == null) { String message = "Could not evaluate " + node.getVarName() + ": "; throw new ParseException(message + "variable not set"); } // all is fine // push the value on the stack stack.push(temp); return data; }
/** * Gets the object representing the variable with a given name. * * @param name the name of the variable to find. * @return the Variable object or null if name not found. * @since 2.3.0 alpha */ public Variable getVar(String name) { return symTab.getVar(name); }
/** * Returns the value of the variable with given name. * * @param name name of the variable. * @return the current value of the variable. * @since 2.3.0 alpha */ public Object getVarValue(String name) { return symTab.getVar(name).getValue(); }