mirror of
https://github.com/samsonjs/compiler.git
synced 2026-04-26 14:47:43 +00:00
[NEW] Parse numbers of any length, instead of only one digit.
This commit is contained in:
parent
42ca4451a8
commit
c008ed007a
2 changed files with 7 additions and 4 deletions
|
|
@ -89,9 +89,12 @@ class Compiler
|
||||||
# Get a number.
|
# Get a number.
|
||||||
def get_num
|
def get_num
|
||||||
expected('integer') unless digit?(@look)
|
expected('integer') unless digit?(@look)
|
||||||
c = @look
|
value = ''
|
||||||
get_char
|
while digit?(@look)
|
||||||
return c
|
value << @look
|
||||||
|
get_char
|
||||||
|
end
|
||||||
|
value
|
||||||
end
|
end
|
||||||
|
|
||||||
# Define a constant in the .data section.
|
# Define a constant in the .data section.
|
||||||
|
|
|
||||||
2
test.rb
2
test.rb
|
|
@ -25,7 +25,7 @@ def main(arg)
|
||||||
File.open(arg)
|
File.open(arg)
|
||||||
else
|
else
|
||||||
# StringIO.new("5*(3-5)*2+2-9/3-8/2-4*(5+5+5)\n")
|
# StringIO.new("5*(3-5)*2+2-9/3-8/2-4*(5+5+5)\n")
|
||||||
StringIO.new("abc=9\nabc-9\n")
|
StringIO.new("abc=999\nabc-888\n")
|
||||||
end
|
end
|
||||||
data, bss, code = *parse(input)
|
data, bss, code = *parse(input)
|
||||||
template = File.read("template.asm")
|
template = File.read("template.asm")
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue