init ps6
This commit is contained in:
@@ -0,0 +1,9 @@
|
||||
func add(a, b) begin
|
||||
print "adding", a, "and", b
|
||||
return a + b
|
||||
end
|
||||
|
||||
func main()
|
||||
begin
|
||||
print 2 + add(40, 2) + 2
|
||||
end
|
||||
@@ -0,0 +1,3 @@
|
||||
func main() begin
|
||||
print "Hello, World!"
|
||||
end
|
||||
30
exercises/06/vslc/vsl_programs/ps5-codegen1/ps5.vsl
Normal file
30
exercises/06/vslc/vsl_programs/ps5-codegen1/ps5.vsl
Normal file
@@ -0,0 +1,30 @@
|
||||
// This program tests activation records, function call and return
|
||||
func funcall ()
|
||||
begin
|
||||
var x,y,z
|
||||
x := 5
|
||||
y := 10
|
||||
print "Calling my_function with parameters", x, y
|
||||
z := my_function ( x, y )
|
||||
print "The returned result is", z
|
||||
z := my_other_function ()
|
||||
print "The other returned result is", z
|
||||
return 0
|
||||
end
|
||||
|
||||
func my_function ( s, t )
|
||||
begin
|
||||
var u
|
||||
u := s*s + t*t
|
||||
print "Parameter s is", s
|
||||
print "Parameter t is", t
|
||||
print "The sum of their squares is", u
|
||||
return u
|
||||
end
|
||||
|
||||
func my_other_function ()
|
||||
begin
|
||||
var x
|
||||
x := 42
|
||||
return x
|
||||
end
|
||||
24
exercises/06/vslc/vsl_programs/ps5-codegen1/shadow.vsl
Normal file
24
exercises/06/vslc/vsl_programs/ps5-codegen1/shadow.vsl
Normal file
@@ -0,0 +1,24 @@
|
||||
|
||||
func main() begin
|
||||
var a, b
|
||||
a := 1
|
||||
begin
|
||||
var a
|
||||
a := 2
|
||||
b := 40
|
||||
begin
|
||||
var a
|
||||
a := b + 2
|
||||
print a, b
|
||||
end
|
||||
print a
|
||||
begin
|
||||
var b
|
||||
b := 38
|
||||
a := b + 3
|
||||
print a, b
|
||||
end
|
||||
print a
|
||||
end
|
||||
print b
|
||||
end
|
||||
Reference in New Issue
Block a user