21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
|
# File 'lib/asmrepl/parser.rb', line 21
def next_token
return if @scanner.eos?
if @scanner.scan(INTEGER)
[:on_int, @scanner.matched]
elsif @scanner.scan(/\[/)
[:on_lbracket, @scanner.matched]
elsif @scanner.scan(/\]/)
[:on_rbracket, @scanner.matched]
elsif @scanner.scan(/,/)
[:on_comma, @scanner.matched]
elsif @scanner.scan(/qword/)
[:qword, @scanner.matched]
elsif @scanner.scan(/dword/)
[:dword, @scanner.matched]
elsif @scanner.scan(/word/)
[:word, @scanner.matched]
elsif @scanner.scan(/byte/)
[:byte, @scanner.matched]
elsif @scanner.scan(/ptr/)
[:ptr, @scanner.matched]
elsif @scanner.scan(/rip/i)
[:on_rip, @scanner.matched]
elsif @scanner.scan(/int/i)
[:on_instruction, Fisk::Instructions::INT]
elsif @scanner.scan(/movabs/i)
[:on_instruction, Fisk::Instructions::MOV]
elsif @scanner.scan(/\w+/)
ident = @scanner.matched
if INSTRUCTIONS.include?(ident.upcase)
[:on_instruction, Fisk::Instructions.const_get(ident.upcase)]
elsif REGISTERS.include?(ident.upcase)
[:on_register, Fisk::Registers.const_get(ident.upcase)]
else
[:on_ident, @scanner.matched]
end
elsif @scanner.scan(/\s+/)
[:on_sp, @scanner.matched]
elsif @scanner.scan(/\+/)
[:plus, @scanner.matched]
elsif @scanner.scan(/-/)
[:minus, @scanner.matched]
else
raise
end
end
|