Correct some operator in parser

This commit is contained in:
Roguelearg 2017-09-12 15:13:01 +02:00
parent 9a7a2f0955
commit 81ecb0e900

View file

@ -3,24 +3,41 @@ module Mm2ep
class And_op
attr_reader :expr1, :expr2
def initialize expr1, expr2
@expr1 = expr1
@expr2 = expr2
unless expr1.value.to_s.match(/true/).nil?
@expr1 = true
else
@expr1 = false
end
unless expr2.value.to_s.match(/true/).nil?
@expr2 = true
else
@expr2 = false
end
end
def and_op
return expr1 && expr2
binding.pry
return @expr1 && @expr2
end
end
class Or_op
attr_reader :expr1, :expr2
def initialize expr1, expr2
@expr1 = expr1
@expr2 = expr2
unless expr1.value.to_s.match(/true/).nil?
@expr1 = true
else
@expr1 = false
end
unless expr2.value.to_s.match(/true/).nil?
@expr2 = true
else
@expr2 = false
end
end
def or_op
return expr1 || expr2
return @expr1 || @expr2
end
end
@ -32,7 +49,7 @@ module Mm2ep
def not_op
# binding.pry
return true unless expr.value.to_s.eql? 'true'
return true unless @expr.value.to_s.eql? 'true'
return false
end
end
@ -40,19 +57,23 @@ module Mm2ep
class Eq_op
attr_reader :val, :other
def initialize val, other
@val = val
@other = other
@val = val.value.to_s
if other.value.to_s.match(/true/).nil?
@other = true
else
@other = false
end
end
def eq_op
return val = other
return val = @other
end
end
class Parser < Rly::Yacc
precedence :left, 'OR_OP', 'EQ_OP'
precedence :right, 'AND_OP', 'NOT_OP'
precedence :left, 'OR_OP', 'EQ_OP'
precedence :left, 'AND_OP', 'NOT_OP'
rule 'statement : expr' do |st, e|
st.value = e.value