For a description of the options used in the following examples, see CodeGenerationOptions.
>
|
|
Translate a simple expression and assign it to the name in the target code.
>
|
|
w = -2 * x * z + y * z + x
| |
Translate a list and assign it to an array with the name in the target code.
>
|
|
w[0][0] = x
w[0][1] = 2 * y
w[1][0] = 5
w[1][1] = z
| |
Translate a computation sequence. Optimize the input first.
>
|
|
>
|
|
s = 0.10e1 + x
t1 = log(s)
t2 = exp(-x)
t = t2 * t1
r = x * t + t2
| |
Declare that is a float and is an integer. Return the result in a string.
>
|
|
Translate a procedure. Assume that all untyped variables have type integer.
>
|
f := proc(x, y, z) return x*y-y*z+x*z; end proc:
|
>
|
|
func f (x: Int32, y: Int32, z: Int32) -> Int32 {
return(y * x - y * z + x * z);
}
| |
Translate a procedure containing an implicit return. A new variable is created to hold the return value.
>
|
f := proc(n)
local x, i;
x := 0.0;
for i to n do
x := x + i;
end do;
end proc:
|
func f (n: Int32) -> Double {
var x: Double
var i: Int32
var cgret: Double
x = 0.0e0
for i in 1...n
{
x = x + i
cgret = x
}
return(cgret);
}
| |