(string)
| 56 | ################################################################################ |
| 57 | |
| 58 | def parse(string): |
| 59 | index = 0 |
| 60 | code = [] |
| 61 | ins = string[index:index+3] |
| 62 | while len(ins) == 3: |
| 63 | if ins in INS: |
| 64 | code.append(INS.index(ins)) |
| 65 | index += 3 |
| 66 | else: |
| 67 | index += 1 |
| 68 | ins = string[index:index+3] |
| 69 | return tuple(code) |
| 70 | |
| 71 | DECODE = ['END', 'P--', 'P++', 'EXE', 'I/O', 'M--', |
| 72 | 'M++', 'LOP', 'M=0', 'REG', 'OUT', 'INP'] |