end
SPACE = /([ \t\v\n\r]+|#.*\n)/
- IDENT = /[_a-zA-Z][_a-zA-Z0-9]*!?/
+ IDENT = /[_a-zA-Z][_a-zA-Z0-9]*/
BRACES = /[\(\)\[\]\{\}\.]/
OPERATORS = /[:,<>*\/=+\-\$?!%]+/
INTEGER = /[0-9]+/
elsif @data.scan(OPERATORS)
type = @data.matched
end
- Tok.new(@data.matched, @file, @data.pos, type) if type
+ tok = Tok.new(@data.matched, @file, @data.pos, type) if type
else
- Tok.new("EOF", @file, @data.pos, :eof)
+ tok = Tok.new("EOF", @file, @data.pos, :eof)
end
+# pp tok
+ tok
end
end
def expression()
left = simple_expr()
if matches_any(["==", "!=", "<", "<=", ">", ">="])
+ loc = location
+ op = consume()
right = simple_expr()
- left = IR::Op.new(op.location, nil, op.text, left, right)
+ left = IR::Op.new(loc, nil, op.text, left, right)
end
left
end
def simple_expr()
# Handle unary ops first
if matches_any(["+", "-", :not])
+ loc = location
op = consume()
left = term()
- left = IR::Op.new(op.location, nil, op.text, left, nil)
+ left = IR::Op.new(location, nil, op.text, left, nil)
else
left = term()
end
# now look for binary ops
while matches_any(["+", "-", :or])
+ loc = location
op = consume()
- right = term();
- left = IR::Op.new(location, nil, op.text, left, right)
+ right = term()
+ left = IR::Op.new(loc, nil, op.text, left, right)
end
left
end
def term()
left = factor()
while matches_any(["*", "/", "%", :and])
+ loc = location
op = consume()
right = factor();
- left = IR::Op.new(location, nil, op.text, left, right)
+ left = IR::Op.new(loc, nil, op.text, left, right)
end
left
end
elsif tok.type == :ident
IR::Var.new(tok.pos, nil, tok.text.to_sym)
else
- error("invalid constant")
+ error("invalid constant #{tok}")
end
end
end
puts " modi"
when "<"
puts " lti"
+ when "<="
+ puts " ltei"
+ when ">"
+ puts " gti"
+ when ">="
+ puts " gtei"
+ when "=="
+ puts " eqi"
+ when "!="
+ puts " nei"
else
raise "not implemented"
end