From c008ed007a033b7f2f50829ba576ea7111bdaf28 Mon Sep 17 00:00:00 2001 From: sjs Date: Wed, 13 May 2009 23:29:52 -0700 Subject: [PATCH] [NEW] Parse numbers of any length, instead of only one digit. --- compiler.rb | 9 ++++++--- test.rb | 2 +- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/compiler.rb b/compiler.rb index 98be766..b64c38e 100644 --- a/compiler.rb +++ b/compiler.rb @@ -89,9 +89,12 @@ class Compiler # Get a number. def get_num expected('integer') unless digit?(@look) - c = @look - get_char - return c + value = '' + while digit?(@look) + value << @look + get_char + end + value end # Define a constant in the .data section. diff --git a/test.rb b/test.rb index 5c9aaf1..247d8f8 100644 --- a/test.rb +++ b/test.rb @@ -25,7 +25,7 @@ def main(arg) File.open(arg) else # 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 data, bss, code = *parse(input) template = File.read("template.asm")