2017-09-04 09:19:29 +00:00
|
|
|
module Mm2ep
|
|
|
|
module Depend
|
2017-09-11 12:33:29 +00:00
|
|
|
class And_op
|
|
|
|
attr_reader :expr1, :expr2
|
|
|
|
def initialize expr1, expr2
|
2017-09-12 13:13:01 +00:00
|
|
|
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
|
2017-09-11 12:33:29 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
def and_op
|
2017-09-12 13:44:10 +00:00
|
|
|
# binding.pry
|
2017-09-12 13:13:01 +00:00
|
|
|
return @expr1 && @expr2
|
2017-09-11 12:33:29 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
class Or_op
|
|
|
|
attr_reader :expr1, :expr2
|
|
|
|
def initialize expr1, expr2
|
2017-09-12 13:13:01 +00:00
|
|
|
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
|
2017-09-11 12:33:29 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
def or_op
|
2017-09-12 13:13:01 +00:00
|
|
|
return @expr1 || @expr2
|
2017-09-11 12:33:29 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
class Not_op
|
|
|
|
attr_reader :expr
|
|
|
|
def initialize expr
|
|
|
|
@expr = expr
|
|
|
|
end
|
|
|
|
|
|
|
|
def not_op
|
2017-09-12 09:21:07 +00:00
|
|
|
# binding.pry
|
2017-09-12 13:13:01 +00:00
|
|
|
return true unless @expr.value.to_s.eql? 'true'
|
2017-09-11 12:33:29 +00:00
|
|
|
return false
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
class Eq_op
|
|
|
|
attr_reader :val, :other
|
|
|
|
def initialize val, other
|
2017-09-12 13:13:01 +00:00
|
|
|
@val = val.value.to_s
|
2017-09-12 13:44:10 +00:00
|
|
|
unless other.value.to_s.match(/true/).nil?
|
2017-09-12 13:13:01 +00:00
|
|
|
@other = true
|
|
|
|
else
|
|
|
|
@other = false
|
|
|
|
end
|
2017-09-11 12:33:29 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
def eq_op
|
2017-09-12 13:44:10 +00:00
|
|
|
return if val == @other
|
2017-09-11 12:33:29 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2017-09-07 15:05:06 +00:00
|
|
|
class Parser < Rly::Yacc
|
|
|
|
|
2017-09-12 13:13:01 +00:00
|
|
|
precedence :left, 'OR_OP', 'EQ_OP'
|
|
|
|
precedence :left, 'AND_OP', 'NOT_OP'
|
2017-09-11 08:13:30 +00:00
|
|
|
|
2017-09-07 15:05:06 +00:00
|
|
|
rule 'statement : expr' do |st, e|
|
|
|
|
st.value = e.value
|
|
|
|
end
|
|
|
|
|
2017-09-11 08:13:30 +00:00
|
|
|
rule 'expr : VAR' do |ex, l|
|
|
|
|
ex.value = l.value
|
|
|
|
end
|
|
|
|
|
|
|
|
rule 'expr : T_BOOL' do |ex, l|
|
|
|
|
ex.value = l.value
|
|
|
|
end
|
|
|
|
|
|
|
|
rule 'expr : F_BOOL' do |ex, l|
|
|
|
|
ex.value = l.value
|
|
|
|
end
|
|
|
|
|
2017-09-07 15:05:06 +00:00
|
|
|
rule 'expr : NOT_OP SPACE expr' do |ex, l, s, e|
|
2017-09-11 12:33:29 +00:00
|
|
|
ex.value = Not_op.new(e).not_op
|
2017-09-07 15:05:06 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
rule 'expr : expr SPACE AND_OP SPACE expr' do |ex, l, s, e, sp, r|
|
2017-09-11 12:33:29 +00:00
|
|
|
ex.value = And_op.new(l, r).and_op
|
2017-09-07 15:05:06 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
rule 'expr : expr SPACE OR_OP SPACE expr' do |ex, l, s, e, sp, r|
|
2017-09-11 12:33:29 +00:00
|
|
|
ex.value = Or_op.new(l, r).or_op
|
2017-09-07 15:05:06 +00:00
|
|
|
end
|
|
|
|
rule 'expr : L_PAR SPACE expr SPACE R_PAR' do |ex, l, s, e, sp, r|
|
2017-09-11 12:33:29 +00:00
|
|
|
ex.value = e.value
|
2017-09-07 15:05:06 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
rule 'expr : VAR SPACE EQ_OP SPACE F_BOOL' do |ex, v, s, eq, _, n|
|
2017-09-11 12:33:29 +00:00
|
|
|
ex.value = Eq_op.new(v, n).eq_op
|
2017-09-07 15:05:06 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
rule 'expr : VAR SPACE EQ_OP SPACE T_BOOL' do |ex, v, s, eq, _, n|
|
2017-09-11 12:33:29 +00:00
|
|
|
ex.value = Eq_op.new(v, n).eq_op
|
2017-09-07 15:05:06 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
rule 'expr : VAR SPACE EQ_OP SPACE STRING' do |ex, v, s, eq, _, n|
|
2017-09-11 12:33:29 +00:00
|
|
|
ex.value = Eq_op.new(v, n).eq_op
|
2017-09-07 15:05:06 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
rule 'expr : VAR SPACE EQ_OP SPACE NUMBER' do |ex, v, s, eq, _, n|
|
2017-09-11 12:33:29 +00:00
|
|
|
ex.value = Eq_op.new(v, n).eq_op
|
2017-09-07 15:05:06 +00:00
|
|
|
end
|
|
|
|
|
2017-09-04 09:19:29 +00:00
|
|
|
end # class
|
|
|
|
end # module
|
|
|
|
end # module
|