Correct some operator in parser
This commit is contained in:
parent
9a7a2f0955
commit
81ecb0e900
1 changed files with 33 additions and 12 deletions
|
@ -3,24 +3,41 @@ module Mm2ep
|
||||||
class And_op
|
class And_op
|
||||||
attr_reader :expr1, :expr2
|
attr_reader :expr1, :expr2
|
||||||
def initialize expr1, expr2
|
def initialize expr1, expr2
|
||||||
@expr1 = expr1
|
unless expr1.value.to_s.match(/true/).nil?
|
||||||
@expr2 = expr2
|
@expr1 = true
|
||||||
|
else
|
||||||
|
@expr1 = false
|
||||||
|
end
|
||||||
|
unless expr2.value.to_s.match(/true/).nil?
|
||||||
|
@expr2 = true
|
||||||
|
else
|
||||||
|
@expr2 = false
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def and_op
|
def and_op
|
||||||
return expr1 && expr2
|
binding.pry
|
||||||
|
return @expr1 && @expr2
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
class Or_op
|
class Or_op
|
||||||
attr_reader :expr1, :expr2
|
attr_reader :expr1, :expr2
|
||||||
def initialize expr1, expr2
|
def initialize expr1, expr2
|
||||||
@expr1 = expr1
|
unless expr1.value.to_s.match(/true/).nil?
|
||||||
@expr2 = expr2
|
@expr1 = true
|
||||||
|
else
|
||||||
|
@expr1 = false
|
||||||
|
end
|
||||||
|
unless expr2.value.to_s.match(/true/).nil?
|
||||||
|
@expr2 = true
|
||||||
|
else
|
||||||
|
@expr2 = false
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def or_op
|
def or_op
|
||||||
return expr1 || expr2
|
return @expr1 || @expr2
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -32,7 +49,7 @@ module Mm2ep
|
||||||
|
|
||||||
def not_op
|
def not_op
|
||||||
# binding.pry
|
# binding.pry
|
||||||
return true unless expr.value.to_s.eql? 'true'
|
return true unless @expr.value.to_s.eql? 'true'
|
||||||
return false
|
return false
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -40,19 +57,23 @@ module Mm2ep
|
||||||
class Eq_op
|
class Eq_op
|
||||||
attr_reader :val, :other
|
attr_reader :val, :other
|
||||||
def initialize val, other
|
def initialize val, other
|
||||||
@val = val
|
@val = val.value.to_s
|
||||||
@other = other
|
if other.value.to_s.match(/true/).nil?
|
||||||
|
@other = true
|
||||||
|
else
|
||||||
|
@other = false
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def eq_op
|
def eq_op
|
||||||
return val = other
|
return val = @other
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
class Parser < Rly::Yacc
|
class Parser < Rly::Yacc
|
||||||
|
|
||||||
precedence :left, 'OR_OP', 'EQ_OP'
|
precedence :left, 'OR_OP', 'EQ_OP'
|
||||||
precedence :right, 'AND_OP', 'NOT_OP'
|
precedence :left, 'AND_OP', 'NOT_OP'
|
||||||
|
|
||||||
rule 'statement : expr' do |st, e|
|
rule 'statement : expr' do |st, e|
|
||||||
st.value = e.value
|
st.value = e.value
|
||||||
|
|
Loading…
Reference in a new issue