mirror of
https://github.com/samsonjs/compiler.git
synced 2026-04-27 14:57:45 +00:00
finished bitwise AND, OR, and XOR
This commit is contained in:
parent
8f5269fffc
commit
f7e44b7472
1 changed files with 15 additions and 5 deletions
20
compiler.rb
20
compiler.rb
|
|
@ -53,6 +53,9 @@ class Compiler
|
||||||
# Include :all for a very general test.
|
# Include :all for a very general test.
|
||||||
}.merge(:all => Ops.values.flatten.map{|op| op[0, 1]}.sort.uniq)
|
}.merge(:all => Ops.values.flatten.map{|op| op[0, 1]}.sort.uniq)
|
||||||
|
|
||||||
|
FALSE = 0
|
||||||
|
TRUE = -1
|
||||||
|
|
||||||
attr_reader :asm
|
attr_reader :asm
|
||||||
|
|
||||||
def initialize(input, asm)
|
def initialize(input, asm)
|
||||||
|
|
@ -99,6 +102,13 @@ class Compiler
|
||||||
end
|
end
|
||||||
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.
|
# Parse and translate an identifier or function call.
|
||||||
def identifier
|
def identifier
|
||||||
name = get_name
|
name = get_name
|
||||||
|
|
@ -217,7 +227,6 @@ class Compiler
|
||||||
|
|
||||||
def bit_expression
|
def bit_expression
|
||||||
arithmetic_expression
|
arithmetic_expression
|
||||||
# XXX need a token of lookahead
|
|
||||||
while op?(:bit, @look)
|
while op?(:bit, @look)
|
||||||
scan
|
scan
|
||||||
case @value
|
case @value
|
||||||
|
|
@ -225,9 +234,8 @@ class Compiler
|
||||||
when '^': bitxor_expression
|
when '^': bitxor_expression
|
||||||
when '&': bitand_expression
|
when '&': bitand_expression
|
||||||
else
|
else
|
||||||
puts ">> token: #@token"
|
backtrack
|
||||||
puts ">> value: #@value"
|
return
|
||||||
raise 'not actually a bit op!'
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
@ -792,7 +800,9 @@ class Compiler
|
||||||
# Match literal input.
|
# Match literal input.
|
||||||
def match_word(word, options={})
|
def match_word(word, options={})
|
||||||
scan if options[:scan]
|
scan if options[:scan]
|
||||||
expected(word) unless @value == word
|
match = @value == word
|
||||||
|
expected(word) unless match
|
||||||
|
match
|
||||||
end
|
end
|
||||||
|
|
||||||
# Parse zero or more consecutive characters for which the test is
|
# Parse zero or more consecutive characters for which the test is
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue