/** * Evaluate the specified command. * * @param command The command. * @return The return value of the command, or null if there is none. * @exception Exception If something goes wrong processing the command. */ public String evaluateCommand(String command) throws Exception { if (command.trim().equals("")) { return ""; } PtParser parser = new PtParser(); ASTPtRootNode node = parser.generateSimpleAssignmentParseTree(command); String targetName = null; // Figure out if we got an assignment... if so, then get the // identifier name and only evaluated the expression part. if (node instanceof ASTPtAssignmentNode) { ASTPtAssignmentNode assignmentNode = (ASTPtAssignmentNode) node; targetName = assignmentNode.getIdentifier(); node = assignmentNode.getExpressionTree(); } final NamedObj model = ((ExpressionShellEffigy) getContainer()).getModel(); ParserScope scope = new ModelScope() { public ptolemy.data.Token get(String name) throws IllegalActionException { Variable result = getScopedVariable(null, model, name); if (result != null) { return result.getToken(); } else { return null; } } public ptolemy.data.type.Type getType(String name) throws IllegalActionException { Variable result = getScopedVariable(null, model, name); if (result != null) { return result.getType(); } else { return null; } } public InequalityTerm getTypeTerm(String name) throws IllegalActionException { Variable result = getScopedVariable(null, model, name); if (result != null) { return result.getTypeTerm(); } else { return null; } } public Set identifierSet() { return getAllScopedVariableNames(null, model); } }; Token result = _evaluator.evaluateParseTree(node, scope); // If a target was specified, instantiate a new token. if (targetName != null) { Attribute attribute = model.getAttribute(targetName); if (attribute != null && !(attribute instanceof Parameter)) { attribute.setContainer(null); attribute = null; } if (attribute == null) { attribute = new Parameter(model, targetName); } ((Parameter) attribute).setToken(result); } if (result == null) { return ""; } else { return result.toString(); } }