forked from darius/regexercise
-
Notifications
You must be signed in to change notification settings - Fork 0
/
literals_hal.py
28 lines (25 loc) · 832 Bytes
/
literals_hal.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
"""
Fill in this stub.
"""
def compile_pattern(strings):
"""Given a sequence of strings, return a HAL 100 assembly-language
program that will report as soon as any of the strings appears in the
machine's input."""
raise NotImplementedError
def compile_just_A():
"""Return a HAL 100 program that will report when the letter 'A'
appears in its input. This is just an example of what you might
do for compile_pattern(['A'])."""
program = """
;; Execution starts here at address 0.
getch r1
ifne r1,'A',fail
found
fail notfound
"""
return program.splitlines()
if __name__ == '__main__':
import hal_vm, hal_watch
program = compile_just_A()
sample_input = "An A and a gold star just for you!"
hal_watch.run(hal_vm.load_program(program, sample_input))