MCPcopy Create free account
hub / github.com/geekcomputers/Python / scanner

Function scanner

Assembler/assembler.py:62–743  ·  view source on GitHub ↗

scanner: This function builds the tokens by the content of the file. The tokens will be saved in list 'tokens'

(string)

Source from the content-addressed store, hash-verified

60
61
62def scanner(string):
63 """
64 scanner: This function builds the tokens by the content of the file.
65 The tokens will be saved in list 'tokens'
66 """
67 global tokens
68 token = ""
69 state = 0 # init state
70
71 for ch in string:
72 match state:
73 case 0:
74 match ch:
75 case "m": # catch mov-command
76 state = 1
77 token += "m"
78
79 case "e": # catch register
80 state = 4
81 token += "e"
82
83 case "1": # catch a number
84 if ch <= "9" or ch == "-":
85 state = 6
86 token += ch
87
88 case "0": # catch a number or hex-code
89 state = 17
90 token += ch
91
92 case "a": # catch add-command
93 state = 7
94 token += ch
95
96 case "s": # catch sub command
97 state = 10
98 token += ch
99
100 case "i": # capture int command
101 state = 14
102 token += ch
103
104 case "p": # capture push or pop command
105 state = 19
106 token += ch
107
108 case "l": # capture label
109 state = 25
110 token += ch
111
112 case "j": # capture jmp command
113 state = 26
114 token += ch
115
116 case "c": # catch cmp-command
117 state = 29
118 token += ch
119

Callers 1

scanFunction · 0.85

Calls 3

InvalidSyntaxClass · 0.85
TokenClass · 0.85
appendMethod · 0.45

Tested by

no test coverage detected