fun foo()
fun bar()
a:int;
begin
a:= 2*z /* Illegal. z not declared */
end
z : int;
begin
blah() /* Illegal. blah not declared */
end
fun blah()
begin
...
end
fun foo()
a : int[50];
b : int[50];
c : int[50];
i : int;
begin
c := a * b; /* Illegal. Can't assign to c.
Can't have a and b in expression as arrays */
c[i] := a[i] * b[i]; /* This is okay */
end
a : int[50];
b : int[50];
...
foo(a,b);
fun foo()
begin
skip /* Do nothing, return nothing */
end
fun bar()
x : int;
begin
x := 3+foo(); /* Error: foo returns no value */
end
a : int[40]; /* Legal */ b : int[40*50+2]; /* Legal */ c : int[x]; /* Always illegal */
Project 2
if 1 then print("Yes!\n")
else print("No.\n")
while x - 100 do
...
Instead, you need to use one of the relational operators ==, !=, < > <=, or >=. For example:
if 1 == 1 then print("Yes!\n")
else print("No.\n")
while x - 100 != 0 do
...
while x >= 0 and x < 100 do
...
fun foo(x : int)
y : int;
z : int;
fun bar(y : int)
begin
...
end; <-- note semicolon here
a : float; <-- and here
begin
...
end
fun foo(x : int)
begin
x := 2*x;
write(x) <-- No semicolon here.
end
return(3*x) return 0 return 2*4+x
a := foo(3,4,5); /* Use as an expression */ foo(6,7,8); /* Use as a statement */
Additional checks on the expression are performed later. For instance, we will need to make sure indices are integers at a later stage of the compiler project.a : int[20]; /* Declaration */ b : int[20*20]; /* Declaration */ a[2*i] := 4; /* Assignment */ read(b[4*i*j]); /* Read into a location */