1 22 23 package org.netbeans.lib.terminalemulator; 24 25 public abstract class AbstractInterp implements Interp { 26 27 protected interface Actor { 28 public String action(AbstractInterp interp, char c); 29 } 30 31 protected static class State { 32 33 Actor act_error = new Actor() { 35 public String action(AbstractInterp ai, char c) { 36 return "generic error"; } 38 }; 39 40 public String name() { 41 return name; 42 } 43 private String name; 44 45 46 class Action { 47 public State new_state = null; 48 public Actor actor = act_error; 49 }; 50 51 private Action action[] = new Action[128]; 52 private Action action_regular = new Action(); 53 54 public State(String name) { 55 this.name = name; 56 for (int i = 0; i < action.length; i++) 57 action[i] = new Action(); 58 action_regular.actor = null; 59 action_regular.new_state = null; 60 } 61 62 65 public void setRegular(State new_state, Actor actor) { 66 action_regular.actor = actor; 67 action_regular.new_state = new_state; 68 } 69 70 public void setAction(char c, State new_state, Actor actor) { 71 if ((int) c > 127) 72 return; 73 action[c].actor = actor; 74 action[c].new_state = new_state; 75 } 76 77 public Action getAction(char c) { 78 if ((int) c > 127) 79 return action_regular; 80 return action[c]; 81 } 82 }; 83 84 89 91 public Ops ops; 92 public State state; 94 98 99 protected AbstractInterp(Ops ops) { 100 this.ops = ops; 101 } 102 103 public void reset() { 104 ; 105 } 106 107 110 111 private static final int max_numbers = 5; 112 private int numberx = 0; 113 private String number[] = new String [max_numbers]; 114 115 protected void resetNumber() { 116 for (int x = 0; x < max_numbers; x++) { 117 number[x] = ""; 118 } 119 numberx = 0; 120 } 121 protected void remember_digit(char c) { 122 number[numberx] += c; 123 } 124 protected boolean pushNumber() { 125 numberx++; 126 return (numberx < max_numbers); 127 } 128 protected boolean noNumber() { 129 return number[0].equals(""); } 131 protected int numberAt(int position) { 132 if (position > numberx) { 133 return 1; 134 } 135 return Integer.parseInt(number[position]); 136 } 137 protected int nNumbers() { 138 return numberx; 139 } 140 141 142 } 143 | Popular Tags |