1 8 package org.lsmp.djep.rpe; 9 10 11 public final class RpCommandList { 12 13 14 static final class RpCommand { 15 short command; 16 short aux1; 17 private RpCommand(short command){ 18 this.command = command; this.aux1 = -1; 19 } 20 private RpCommand(short command,short aux){ 21 this.command = command; this.aux1 = aux; 22 } 23 public String toString() { 24 switch(command) 25 { 26 case RpEval.CONST: return "Constant\tno "+aux1; 27 case RpEval.VAR: return "Variable\tnum "+aux1; 28 case RpEval.ADD: return "ADD"; 29 case RpEval.SUB: return "SUB"; 30 case RpEval.MUL: return "MUL"; 31 case RpEval.DIV: return "DIV"; 32 case RpEval.MOD: return "MOD"; 33 case RpEval.POW: return "POW"; 34 case RpEval.AND: return "AND"; 35 case RpEval.OR: return "OR"; 36 case RpEval.NOT: return "NOT"; 37 case RpEval.LT: return "LT"; 38 case RpEval.LE: return "LE"; 39 case RpEval.GT: return "GT"; 40 case RpEval.GE: return "GE"; 41 case RpEval.EQ: return "EQ"; 42 case RpEval.NE: return "NE"; 43 case RpEval.ASSIGN: return "Assign\tnum "+aux1; 44 case RpEval.FUN: return "Function\tnum "+aux1; 45 } 46 return "WARNING unknown command: "+command+" "+aux1; 47 } 48 } 49 50 51 private static final int STACK_INC=10; 52 53 RpCommand commands[] = new RpCommand[STACK_INC]; 54 55 private short commandPos; 56 57 private int finalType; 58 59 60 RpCommandList() {} 61 62 final void addCommand(short command,short aux) 63 { 64 if(commandPos == commands.length) 65 { 66 RpCommand newCommands[] = new RpCommand[commands.length+STACK_INC]; 67 System.arraycopy(commands,0,newCommands,0,commands.length); 68 commands = newCommands; 69 } 70 commands[commandPos]=new RpCommand(command,aux); 71 ++commandPos; 72 } 74 final void addCommand(short command) 75 { 76 if(commandPos == commands.length) 77 { 78 RpCommand newCommands[] = new RpCommand[commands.length+STACK_INC]; 79 System.arraycopy(commands,0,newCommands,0,commands.length); 80 commands = newCommands; 81 } 82 commands[commandPos]=new RpCommand(command); 83 ++commandPos; 84 } 86 87 public int getNumCommands() { return commandPos;} 88 public int getFinalType() { return finalType; } 89 public void setFinalType(int i) { finalType = i;} 90 91 public String toString() { 92 StringBuffer sb = new StringBuffer (); 93 for(int i=0;i<commandPos;++i) { 94 sb.append(commands[i].toString()); 95 sb.append("\n"); 96 } 97 return sb.toString(); 98 } 99 } | Popular Tags |