1 9 10 11 package org.nfunk.jep.evaluation; 12 13 import org.nfunk.jep.*; 14 import java.util.*; 15 16 17 public class ExpressionCompiler implements ParserVisitor { 18 19 private Vector commands; 20 21 public ExpressionCompiler() { 22 commands = new Vector(); 23 } 24 25 public CommandElement[] compile(Node node) throws ParseException{ 26 commands.removeAllElements(); 27 node.jjtAccept(this, null); 28 CommandElement[] temp = new CommandElement[commands.size()]; 29 Enumeration enum = commands.elements(); 30 int i = 0; 31 while (enum.hasMoreElements()) { 32 temp[i++] = (CommandElement)enum.nextElement(); 33 } 34 return temp; 35 } 36 37 public Object visit(ASTFunNode node, Object data) throws ParseException { 38 node.childrenAccept(this,data); 39 40 CommandElement c = new CommandElement(); 41 c.setType(CommandElement.FUNC); 42 c.setPFMC(node.getPFMC()); 43 c.setNumParam(node.jjtGetNumChildren()); 44 commands.addElement(c); 45 46 return data; 47 } 48 49 public Object visit(ASTVarNode node, Object data) { 50 CommandElement c = new CommandElement(); 51 c.setType(CommandElement.VAR); 52 c.setVarName(node.getName()); 53 commands.addElement(c); 54 55 return data; 56 } 57 58 public Object visit(ASTConstant node, Object data) { 59 CommandElement c = new CommandElement(); 60 c.setType(CommandElement.CONST); 61 c.setValue(node.getValue()); 62 commands.addElement(c); 63 64 return data; 65 } 66 67 public Object visit(SimpleNode node, Object data) { 68 return data; 69 } 70 71 public Object visit(ASTStart node, Object data) { 72 return data; 73 } 74 } 75 | Popular Tags |