Init ps5
This commit is contained in:
15
exercises/05/vslc/vsl_programs/ps2-parser/assignments.vsl
Normal file
15
exercises/05/vslc/vsl_programs/ps2-parser/assignments.vsl
Normal file
@@ -0,0 +1,15 @@
|
||||
// checking that comments are ignored
|
||||
|
||||
// This program checks the assignment operators
|
||||
|
||||
func main()
|
||||
begin
|
||||
var a
|
||||
a := 3
|
||||
a += 1
|
||||
a /= 2
|
||||
a *= 32
|
||||
a -= 2
|
||||
print a
|
||||
return 0
|
||||
end
|
||||
@@ -0,0 +1,9 @@
|
||||
func add(a, b) begin
|
||||
return a + b
|
||||
end
|
||||
|
||||
func main()
|
||||
begin
|
||||
print add(40, 2)
|
||||
return 0
|
||||
end
|
||||
4
exercises/05/vslc/vsl_programs/ps2-parser/helloworld.vsl
Normal file
4
exercises/05/vslc/vsl_programs/ps2-parser/helloworld.vsl
Normal file
@@ -0,0 +1,4 @@
|
||||
func helloworld() begin
|
||||
print "Hello, World!"
|
||||
return 0
|
||||
end
|
||||
26
exercises/05/vslc/vsl_programs/ps2-parser/if_else.vsl
Normal file
26
exercises/05/vslc/vsl_programs/ps2-parser/if_else.vsl
Normal file
@@ -0,0 +1,26 @@
|
||||
func main()
|
||||
begin
|
||||
var a, b, c, d
|
||||
c := 1
|
||||
a := 3
|
||||
b := a + c // 4
|
||||
d := a * 100 + 50
|
||||
print "a", a
|
||||
print "b", b
|
||||
print "c", c
|
||||
print "d", d
|
||||
if a = 14 then
|
||||
print 1, "N", d / 5 + a, "RPR", a, "TERS "
|
||||
else
|
||||
print "COMP", c, "L", "ERS "
|
||||
|
||||
print b, "R", a, " "
|
||||
|
||||
if a < b then
|
||||
if d > 42 then
|
||||
print b, "W", d, "ME"
|
||||
else
|
||||
print "L", b, "M", c
|
||||
// A dangling else, what could go wrong?
|
||||
return 0
|
||||
end
|
||||
21
exercises/05/vslc/vsl_programs/ps2-parser/variables.vsl
Normal file
21
exercises/05/vslc/vsl_programs/ps2-parser/variables.vsl
Normal file
@@ -0,0 +1,21 @@
|
||||
|
||||
var global_var
|
||||
|
||||
func my_func(param)
|
||||
begin
|
||||
var local_var, local_var2
|
||||
local_var := 1
|
||||
return local_var
|
||||
end
|
||||
|
||||
var glob1, glob2
|
||||
|
||||
func main()
|
||||
begin
|
||||
var main_local_var
|
||||
begin
|
||||
var main_local_nested_var
|
||||
main_local_nested_var := main_local_var + my_func(1)
|
||||
end
|
||||
return 0
|
||||
end
|
||||
11
exercises/05/vslc/vsl_programs/ps2-parser/while.vsl
Normal file
11
exercises/05/vslc/vsl_programs/ps2-parser/while.vsl
Normal file
@@ -0,0 +1,11 @@
|
||||
// check parsing of do-while loop
|
||||
|
||||
func main()
|
||||
begin
|
||||
var i
|
||||
i := 2
|
||||
while i < 42 do
|
||||
i := i * i
|
||||
print i
|
||||
return 0
|
||||
end
|
||||
Reference in New Issue
Block a user