This commit is contained in:
2022-03-31 21:23:57 +02:00
parent 7c3e5aaefa
commit d266ac400e
33 changed files with 1719 additions and 0 deletions

View File

@@ -0,0 +1,42 @@
VSLC := ../src/vslc
AS := gcc
# This updated makefile calls the relevant print for each assignment
# The added target compile will attempt to compile all vsl source files,
# while the compile-ps5 target attempts to compile a selection of sources
# that should work after ps5 is done.
# Call `vslc -h` to see the available flags, and call `vslc [flags] < file.vsl`
# to compile a single file.
PS2_EXAMPLES := $(patsubst ps2-parser/%.vsl, ps2-parser/%.ast, $(wildcard ps2-parser/*.vsl))
PS3_EXAMPLES := $(patsubst ps3-simplify/%.vsl, ps3-simplify/%.sast, $(wildcard ps3-simplify/*.vsl))
PS4_EXAMPLES := $(patsubst ps4-symtab/%.vsl, ps4-symtab/%.sym, $(wildcard ps4-symtab/*.vsl))
PS5_EXAMPLES := $(patsubst ps5-codegen1/%.vsl, ps5-codegen1/%.S, $(wildcard ps5-codegen1/*.vsl))
PS5_OBJECTS := $(PS5_EXAMPLES:.S=.bin)
OBJECTS := $(PS5_OBJECTS) $(PS4_EXAMPLES:.sym=.bin) $(PS3_EXAMPLES:.sast=.bin) $(PS2_EXAMPLES:.ast=.bin)
all: $(PS2_EXAMPLES) $(PS3_EXAMPLES) $(PS4_EXAMPLES)
ps2: $(PS2_EXAMPLES)
ps3: $(PS3_EXAMPLES)
ps4: $(PS4_EXAMPLES)
ps5: $(PS5_EXAMPLES)
%.ast: %.vsl
$(VSLC) -t -q < $^ > $@ 2> $@
%.sast: %.vsl
$(VSLC) -T -q < $^ > $@ 2> $@
%.sym: %.vsl
$(VSLC) -s -q < $^ > $@ 2> $@
%.S: %.vsl
$(VSLC) < $^ > $@
# This target is only tested on x86-linux
%.bin: %.S
$(AS) -no-pie -o $@ $^
ps5-compile: $(PS5_OBJECTS)
compile: $(OBJECTS)
clean:
-rm -r */*.ast */*.sast */*.sym */*.bin */*.s */*.S

View 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

View File

@@ -0,0 +1,9 @@
func add(a, b) begin
return a + b
end
func main()
begin
print add(40, 2)
return 0
end

View File

@@ -0,0 +1,4 @@
func helloworld() begin
print "Hello, World!"
return 0
end

View 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

View 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

View 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

View File

@@ -0,0 +1,10 @@
func main() begin
var a, b
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
return 0
end

View File

@@ -0,0 +1,18 @@
func my_func(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
return i
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)
return 0
end

View File

@@ -0,0 +1,12 @@
var global_var0, global_var1
func my_func(param0, param1) begin
var a
return 0
end
func main() begin
var a
print "a string"
return 0
end

View File

@@ -0,0 +1,25 @@
// Checking symbol shadowing
func shadow() 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
return 0
end

View File

@@ -0,0 +1,9 @@
func add(a, b) begin
return a + b
end
func main()
begin
print add(40, 2)
return 0
end

View File

@@ -0,0 +1,4 @@
func helloworld() begin
print "Hello, World!"
return 0
end

View 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

View File

@@ -0,0 +1,25 @@
// Checking symbol shadowing
func shadow() 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
return 0
end