start to add while loop
This commit is contained in:
@ -20,5 +20,23 @@ HERE
|
||||
|
||||
@parser = @parser.conditional
|
||||
end
|
||||
|
||||
|
||||
def test_while
|
||||
@string_input = <<HERE
|
||||
while 1 do
|
||||
tmp = a
|
||||
a = b
|
||||
end
|
||||
HERE
|
||||
#go in there
|
||||
# b = tmp + b
|
||||
# puts(b)
|
||||
# n = n - 1
|
||||
|
||||
@parse_output = {:while=>"while", :while_cond=>{:integer=>"1"}, :do=>"do", :body=>{:expressions=>[{:asignee=>{:name=>"tmp"}, :asigned=>{:name=>"a"}}, {:asignee=>{:name=>"a"}, :asigned=>{:name=>"b"}}]}}
|
||||
@transform_output = Ast::WhileExpression.new(
|
||||
Ast::IntegerExpression.new(1),
|
||||
[Ast::AssignmentExpression.new("tmp", Ast::NameExpression.new("a")), Ast::AssignmentExpression.new("a", Ast::NameExpression.new("b"))] )
|
||||
@parser = @parser.while
|
||||
end
|
||||
end
|
@ -34,5 +34,26 @@ HERE
|
||||
@parser = @parser.function_definition
|
||||
end
|
||||
|
||||
|
||||
def test_function_while
|
||||
@string_input = <<HERE
|
||||
def fibonaccit(n)
|
||||
a = 0
|
||||
b = 1
|
||||
while n > 1 do
|
||||
tmp = a
|
||||
a = b
|
||||
b = tmp + b
|
||||
puts b
|
||||
n = n - 1
|
||||
end
|
||||
end
|
||||
HERE
|
||||
@parse_output = { :function_definition => { :name => "foo" } ,
|
||||
:parmeter_list => [{ :parmeter => { :name => "x" } }],
|
||||
:expressions => [ { :asignee => { :name => "abba" }, :asigned => { :integer => "5" } } ]
|
||||
}
|
||||
@transform_output = Ast::FunctionExpression.new( "foo", [Ast::NameExpression.new("x")],
|
||||
[Ast::AssignmentExpression.new( "abba", Ast::IntegerExpression.new(5) ) ])
|
||||
@parser = @parser.function_definition
|
||||
end
|
||||
end
|
13
test/runners/fibo_while.rb
Normal file
13
test/runners/fibo_while.rb
Normal file
@ -0,0 +1,13 @@
|
||||
def fibonaccit(n)
|
||||
a = 0
|
||||
b = 1
|
||||
while n > 1 do
|
||||
tmp = a
|
||||
a = b
|
||||
b = tmp + b
|
||||
puts b
|
||||
n = n - 1
|
||||
end
|
||||
end
|
||||
|
||||
fibonaccit( 10 )
|
Reference in New Issue
Block a user