| 22 | private Scanner scanner; |
| 23 | |
| 24 | public PCodeExecutor(ArrayList<PCode> codes, FileWriter writer, Scanner scanner) { |
| 25 | this.codes = codes; |
| 26 | this.writer = writer; |
| 27 | this.scanner = scanner; |
| 28 | for (int i = 0; i < codes.size(); i++) { |
| 29 | PCode code = codes.get(i); |
| 30 | // get main function address |
| 31 | if (code.getType().equals(CodeType.MAIN)) { |
| 32 | mainAddress = i; |
| 33 | } |
| 34 | // get all label |
| 35 | if (code.getType().equals(CodeType.LABEL)) { |
| 36 | labelTable.put((String) code.getValue1(), i); |
| 37 | } |
| 38 | //get all function |
| 39 | if (code.getType().equals(CodeType.FUNC)) { |
| 40 | funcTable.put((String) code.getValue1(), new Func(i, (int) code.getValue2())); |
| 41 | } |
| 42 | } |
| 43 | } |
| 44 | |
| 45 | private void push(int i) { |
| 46 | stack.add(i); |