Skip to content
Browse files

finished bitwise AND, OR, and XOR

  • Loading branch information...
1 parent 8f5269f commit f7e44b74728b91035b17e57054476d4b4a2bc9dc @samsonjs committed Feb 14, 2010
Showing with 15 additions and 5 deletions.
  1. +15 −5 compiler.rb
View
20 compiler.rb
@@ -53,6 +53,9 @@ class Compiler
# Include :all for a very general test.
}.merge(:all => Ops.values.flatten.map{|op| op[0, 1]}.sort.uniq)
+ FALSE = 0
+ TRUE = -1
+
attr_reader :asm
def initialize(input, asm)
@@ -99,6 +102,13 @@ def scan
end
end
+ # put back the most recently parsed value
+ def backtrack
+ @input.ungetc(@look[0])
+ @value.reverse.each_byte {|i| @input.ungetc(i)}
+ get_char
+ end
+
# Parse and translate an identifier or function call.
def identifier
name = get_name
@@ -217,17 +227,15 @@ def divide
def bit_expression
arithmetic_expression
- # XXX need a token of lookahead
while op?(:bit, @look)
scan
case @value
when '|': bitor_expression
when '^': bitxor_expression
when '&': bitand_expression
else
- puts ">> token: #@token"
- puts ">> value: #@value"
- raise 'not actually a bit op!'
+ backtrack
+ return
end
end
end
@@ -792,7 +800,9 @@ def match(char)
# Match literal input.
def match_word(word, options={})
scan if options[:scan]
- expected(word) unless @value == word
+ match = @value == word
+ expected(word) unless match
+ match
end
# Parse zero or more consecutive characters for which the test is

0 comments on commit f7e44b7

Please sign in to comment.
Something went wrong with that request. Please try again.