adds while statement to vool

This commit is contained in:
Torsten Ruger
2017-04-03 11:49:21 +03:00
parent 5335d08408
commit c545bfdfc6
4 changed files with 56 additions and 11 deletions

View File

@ -118,11 +118,10 @@ module Vool
w
end
def on_while_statement statement
branch_type , condition , statements = *statement
w = WhileStatement.new()
w.branch_type = branch_type
w.condition = process(condition)
def on_while statement
condition , statements = *statement
w = WhileStatement.new( process(condition) )
simplify_condition(w)
w.statements = process(statements)
w
end
@ -130,16 +129,18 @@ module Vool
def on_if statement
# puts "IF #{statement}"
condition , if_true , if_false = *statement
w = IfStatement.new()
w.condition = process(condition)
if(w.condition.is_a?(ScopeStatement) and w.condition.single?)
w.condition = w.condition.first
end
w = IfStatement.new( process(condition) )
simplify_condition(w)
w.if_true = process(if_true)
w.if_false = process(if_false)
w
end
def simplify_condition( cond )
return unless cond.condition.is_a?(ScopeStatement)
cond.condition = cond.condition.first if cond.condition.single?
end
def on_operator_value statement
operator , left_e , right_e = *statement
w = OperatorStatement.new()

View File

@ -1,5 +1,9 @@
module Vool
class WhileStatement < Statement
attr_accessor :branch_type , :condition , :statements
attr_accessor :condition , :statements
def initialize( condition )
@condition = condition
end
end
end