Add more classes

This commit is contained in:
Glenn Y. Rolland 2017-09-12 16:05:50 +02:00
parent 4df35173a6
commit 390caddd52

View file

@ -1,31 +1,37 @@
module Mm2ep module Mm2ep
module Depend module Depend
class Treenode class TreeExpr
def initialize
end
# c
def compute def compute
raise NotImplementedError raise NotImplementedError
end end
end end
class VarExpr < Treenode class TreeValue
attr_accessor :value
end
class VarValue < TreeValue
attr_accessor :value
def initialize str def initialize str
@name = str @name = str
@value = nil @value = nil
end end
def set value
@value = value
end
def compute def compute
# FIXME: test if @value is a boolean
# raise an exception in all other cases
@value @value
end end
end end
class BoolExpr < Treenode class NumberValue < TreeValue
end
class StringValue < TreeValue
end
class BoolValue < TreeValue
def initialize str def initialize str
@value = case str @value = case str
when /true/i then true when /true/i then true
@ -39,7 +45,7 @@ module Mm2ep
end end
end end
class AndOp < Treenode class AndOp < TreeExpr
attr_reader :expr1, :expr2 attr_reader :expr1, :expr2
def initialize expr1, expr2 def initialize expr1, expr2
@expr1 = expr1 @expr1 = expr1
@ -72,7 +78,7 @@ module Mm2ep
end end
end end
class Not_op class NotOp
attr_reader :expr attr_reader :expr
def initialize expr def initialize expr
@expr = expr @expr = expr
@ -87,17 +93,11 @@ module Mm2ep
class EqOp class EqOp
attr_reader :val, :other attr_reader :val, :other
def initialize val, other def initialize var, value
@val = val.value.to_s
unless other.value.to_s.match(/true/).nil?
@other = true
else
@other = false
end
end end
def compute def compute
return if val == @other return if val.value == @other.value
end end
end end
@ -111,7 +111,10 @@ module Mm2ep
end end
rule 'expr : VAR' do |ex, l| rule 'expr : VAR' do |ex, l|
ex.value = VarExpr.new(l.value) ex.value = EqOp.new(
VarExpr.new(l.value),
BoolValue.new('true')
)
end end
rule 'expr : T_BOOL' do |ex, l| rule 'expr : T_BOOL' do |ex, l|
@ -123,7 +126,7 @@ module Mm2ep
end end
rule 'expr : NOT_OP SPACE expr' do |ex, l, s, e| rule 'expr : NOT_OP SPACE expr' do |ex, l, s, e|
ex.value = Not_op.new(e.value) ex.value = NotOp.new(e.value)
end end
rule 'expr : expr SPACE AND_OP SPACE expr' do |ex, l, s, e, sp, r| rule 'expr : expr SPACE AND_OP SPACE expr' do |ex, l, s, e, sp, r|