still trying that while loop. Check as everything else works
This commit is contained in:
@ -25,23 +25,19 @@ HERE
|
||||
@string_input = <<HERE
|
||||
while 1 do
|
||||
tmp = a
|
||||
a = b
|
||||
puts(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=>[{:l=>{:name=>"tmp"}, :o=>"= ", :r=>{:name=>"a"}}, {:l=>{:name=>"a"}, :o=>"= ", :r=>{:name=>"b"}}],
|
||||
:end=>"end"}}
|
||||
:while_cond=>{:expressions=>[{:integer=>"1"}],
|
||||
:do=>"do"},
|
||||
:body=>{:expressions=>[{:l=>{:name=>"tmp"}, :o=>"= ", :r=>{:name=>"a"}},
|
||||
{:function_call=>{:name=>"puts"}, :argument_list=>[{:argument=>{:name=>"b"}}]}], :end=>"end"}}
|
||||
@transform_output = Ast::WhileExpression.new(
|
||||
Ast::IntegerExpression.new(1),
|
||||
[Ast::OperatorExpression.new("=", Ast::NameExpression.new("tmp"),Ast::NameExpression.new("a")),
|
||||
Ast::OperatorExpression.new("=", Ast::NameExpression.new("a"),Ast::NameExpression.new("b"))] )
|
||||
@parser = @parser.while
|
||||
[Ast::IntegerExpression.new(1)],
|
||||
[Ast::OperatorExpression.new("=", Ast::NameExpression.new("tmp"),Ast::NameExpression.new("a")),
|
||||
Ast::FuncallExpression.new("puts", [Ast::NameExpression.new("b")] )] )
|
||||
@parser = @parser.while_do
|
||||
end
|
||||
end
|
@ -31,24 +31,39 @@ HERE
|
||||
@parser = @parser.function_definition
|
||||
end
|
||||
|
||||
def ttest_function_while
|
||||
def test_function_if
|
||||
@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
|
||||
def ofthen(n)
|
||||
if(0)
|
||||
42
|
||||
else
|
||||
667
|
||||
end
|
||||
end
|
||||
HERE
|
||||
@parse_output = { :function_definition => { :name => "foo" } ,
|
||||
:parmeter_list => [{ :parmeter => { :name => "x" } }],
|
||||
:expressions => [ { :asignee => { :name => "abba" }, :asigned => { :integer => "5" } } ]
|
||||
}
|
||||
@parse_output = {:function_definition=>{:name=>"ofthen"},
|
||||
:parmeter_list=>[{:parmeter=>{:name=>"n"}}],
|
||||
:expressions=>[
|
||||
{:if=>"if", :conditional=>{:integer=>"0"},
|
||||
:if_true=>{:expressions=>[{:integer=>"42"}],
|
||||
:else=>"else"},
|
||||
:if_false=>{:expressions=>[{:integer=>"667"}], :end=>"end"}}], :end=>"end"}
|
||||
@transform_output = Ast::FunctionExpression.new(:ofthen,
|
||||
[Ast::NameExpression.new("n")] ,
|
||||
[Ast::ConditionalExpression.new(Ast::IntegerExpression.new(0),
|
||||
[Ast::IntegerExpression.new(42)],[Ast::IntegerExpression.new(667)] )] )
|
||||
@parser = @parser.function_definition
|
||||
end
|
||||
|
||||
def test_function_while
|
||||
@string_input = <<HERE
|
||||
def fibonaccit(n)
|
||||
a = 0
|
||||
while n do
|
||||
1
|
||||
end
|
||||
HERE
|
||||
@parse_output = nil
|
||||
@transform_output = nil
|
||||
@parser = @parser.function_definition
|
||||
end
|
||||
|
Reference in New Issue
Block a user