Start PS4
This commit is contained in:
16
exercises/04/vslc/vsl_programs/Makefile
Normal file
16
exercises/04/vslc/vsl_programs/Makefile
Normal file
@@ -0,0 +1,16 @@
|
||||
VSLC := ../src/vslc
|
||||
|
||||
PS2_EXAMPLES := $(patsubst ps2-parser/%.vsl, ps2-parser/%.ast, $(wildcard ps2-parser/*.vsl))
|
||||
PS3_EXAMPLES := $(patsubst ps3-simplify/%.vsl, ps3-simplify/%.ast, $(wildcard ps3-simplify/*.vsl))
|
||||
PS4_EXAMPLES := $(patsubst ps4-symtab/%.vsl, ps4-symtab/%.ast, $(wildcard ps4-symtab/*.vsl))
|
||||
|
||||
all: $(PS2_EXAMPLES) $(PS3_EXAMPLES) $(PS4_EXAMPLES)
|
||||
ps2: $(PS2_EXAMPLES)
|
||||
ps3: $(PS3_EXAMPLES)
|
||||
ps4: $(PS4_EXAMPLES)
|
||||
|
||||
%.ast: %.vsl
|
||||
$(VSLC) -t < $^ > $@
|
||||
|
||||
clean:
|
||||
-rm -r */*.ast
|
||||
14
exercises/04/vslc/vsl_programs/ps2-parser/assignments.vsl
Normal file
14
exercises/04/vslc/vsl_programs/ps2-parser/assignments.vsl
Normal file
@@ -0,0 +1,14 @@
|
||||
// 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
|
||||
end
|
||||
@@ -0,0 +1,8 @@
|
||||
func add(a, b) begin
|
||||
return a + b
|
||||
end
|
||||
|
||||
func main()
|
||||
begin
|
||||
print add(40, 2)
|
||||
end
|
||||
3
exercises/04/vslc/vsl_programs/ps2-parser/helloworld.vsl
Normal file
3
exercises/04/vslc/vsl_programs/ps2-parser/helloworld.vsl
Normal file
@@ -0,0 +1,3 @@
|
||||
func main() begin
|
||||
print "Hello, World!"
|
||||
end
|
||||
25
exercises/04/vslc/vsl_programs/ps2-parser/if_else.vsl
Normal file
25
exercises/04/vslc/vsl_programs/ps2-parser/if_else.vsl
Normal file
@@ -0,0 +1,25 @@
|
||||
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?
|
||||
end
|
||||
19
exercises/04/vslc/vsl_programs/ps2-parser/variables.vsl
Normal file
19
exercises/04/vslc/vsl_programs/ps2-parser/variables.vsl
Normal file
@@ -0,0 +1,19 @@
|
||||
|
||||
var global_var
|
||||
|
||||
func my_func(param)
|
||||
begin
|
||||
var local_var, local_var2
|
||||
local_var := 1
|
||||
end
|
||||
|
||||
var glob1, glob2
|
||||
|
||||
func main()
|
||||
begin
|
||||
var main_local_var
|
||||
begin
|
||||
var main_local_nested_var
|
||||
main_local_nested_var := main_local_var
|
||||
end
|
||||
end
|
||||
10
exercises/04/vslc/vsl_programs/ps2-parser/while.vsl
Normal file
10
exercises/04/vslc/vsl_programs/ps2-parser/while.vsl
Normal file
@@ -0,0 +1,10 @@
|
||||
// check parsing of do-while loop
|
||||
|
||||
func main()
|
||||
begin
|
||||
var i
|
||||
i := 2
|
||||
while i < 9000 do
|
||||
i := i * i
|
||||
print i
|
||||
end
|
||||
@@ -0,0 +1,9 @@
|
||||
|
||||
func main() begin
|
||||
var a
|
||||
a := 1 + 2 + 4 + 5 + 6 + 7 + 8 + 9
|
||||
b := (10 + 10 * 4) * (2 + 2 * (1 + 1)) / 10 + 2 * 5 + 6 / 3
|
||||
|
||||
if a = b then
|
||||
print "The answer is", b
|
||||
end
|
||||
16
exercises/04/vslc/vsl_programs/ps3-simplify/lists.vsl
Normal file
16
exercises/04/vslc/vsl_programs/ps3-simplify/lists.vsl
Normal file
@@ -0,0 +1,16 @@
|
||||
|
||||
func my_fun(a, b, c, d, e, f, g, h) begin
|
||||
var i, j, k, l, m
|
||||
|
||||
i := a + b + d
|
||||
|
||||
if i = f then begin
|
||||
print "hmmm"
|
||||
end
|
||||
end
|
||||
|
||||
func main() begin
|
||||
var n, o, p, q, r, s, t, u, v, w
|
||||
n := 5
|
||||
n += my_func(1, 2, 3, 5, 8, 13, 21, 34)
|
||||
end
|
||||
11
exercises/04/vslc/vsl_programs/ps4-symtab/globals.vsl
Normal file
11
exercises/04/vslc/vsl_programs/ps4-symtab/globals.vsl
Normal file
@@ -0,0 +1,11 @@
|
||||
var global_var0, global_var1
|
||||
|
||||
func my_func(param0, param1) begin
|
||||
var a
|
||||
return 0
|
||||
end
|
||||
|
||||
func main() begin
|
||||
var a
|
||||
print "a string"
|
||||
end
|
||||
17
exercises/04/vslc/vsl_programs/ps4-symtab/shadow.vsl
Normal file
17
exercises/04/vslc/vsl_programs/ps4-symtab/shadow.vsl
Normal file
@@ -0,0 +1,17 @@
|
||||
|
||||
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
|
||||
end
|
||||
print b
|
||||
end
|
||||
Reference in New Issue
Block a user