2015-09-18 20:55:02 +02:00
|
|
|
int fibonaccit(int n)
|
|
|
|
a = 0
|
|
|
|
b = 1
|
|
|
|
while( n > 1 )
|
|
|
|
tmp = a
|
|
|
|
a = b
|
|
|
|
b = tmp + b
|
|
|
|
puts(b)
|
|
|
|
n = n - 1
|
|
|
|
end
|
|
|
|
end
|
|
|
|
-- -- --
|
2015-10-09 16:28:47 +02:00
|
|
|
s(:statements,
|
2015-10-14 14:48:53 +02:00
|
|
|
s(:function, :Integer,
|
2015-09-20 11:56:06 +02:00
|
|
|
s(:name, :fibonaccit),
|
|
|
|
s(:parameters,
|
2015-10-14 14:48:53 +02:00
|
|
|
s(:parameter, :Integer, :n)),
|
2015-10-09 16:28:47 +02:00
|
|
|
s(:statements,
|
|
|
|
s(:assignment,
|
2015-09-20 11:56:06 +02:00
|
|
|
s(:name, :a),
|
|
|
|
s(:int, 0)),
|
2015-10-09 16:28:47 +02:00
|
|
|
s(:assignment,
|
2015-09-20 11:56:06 +02:00
|
|
|
s(:name, :b),
|
|
|
|
s(:int, 1)),
|
2015-10-09 16:28:47 +02:00
|
|
|
s(:while_statement,
|
2015-09-20 11:56:06 +02:00
|
|
|
s(:condition,
|
2015-10-09 16:28:47 +02:00
|
|
|
s(:operator_value, :>,
|
2015-09-20 11:56:06 +02:00
|
|
|
s(:name, :n),
|
|
|
|
s(:int, 1))),
|
2015-10-09 16:28:47 +02:00
|
|
|
s(:statements,
|
|
|
|
s(:assignment,
|
2015-09-20 11:56:06 +02:00
|
|
|
s(:name, :tmp),
|
|
|
|
s(:name, :a)),
|
2015-10-09 16:28:47 +02:00
|
|
|
s(:assignment,
|
2015-09-20 11:56:06 +02:00
|
|
|
s(:name, :a),
|
|
|
|
s(:name, :b)),
|
2015-10-09 16:28:47 +02:00
|
|
|
s(:assignment,
|
2015-09-20 11:56:06 +02:00
|
|
|
s(:name, :b),
|
2015-10-09 16:28:47 +02:00
|
|
|
s(:operator_value, :+,
|
2015-09-20 11:56:06 +02:00
|
|
|
s(:name, :tmp),
|
|
|
|
s(:name, :b))),
|
|
|
|
s(:call,
|
|
|
|
s(:name, :puts),
|
|
|
|
s(:arguments,
|
|
|
|
s(:name, :b))),
|
2015-10-09 16:28:47 +02:00
|
|
|
s(:assignment,
|
2015-09-20 11:56:06 +02:00
|
|
|
s(:name, :n),
|
2015-10-09 16:28:47 +02:00
|
|
|
s(:operator_value, :-,
|
2015-09-20 11:56:06 +02:00
|
|
|
s(:name, :n),
|
|
|
|
s(:int, 1))))))))
|