Add initial files
This commit is contained in:
12
exercises/02/vslc/vsl_programs/Makefile
Normal file
12
exercises/02/vslc/vsl_programs/Makefile
Normal file
@@ -0,0 +1,12 @@
|
||||
VSLC := ../src/vslc
|
||||
|
||||
PS2_EXAMPLES := $(patsubst ps2-parser/%.vsl, ps2-parser/%.ast, $(wildcard ps2-parser/*.vsl))
|
||||
|
||||
all: $(PS2_EXAMPLES)
|
||||
echo $(PS2_EXAMPLES)
|
||||
|
||||
%.ast: %.vsl
|
||||
$(VSLC) -t < $^ > $@
|
||||
|
||||
clean:
|
||||
-rm -r */*.ast
|
||||
14
exercises/02/vslc/vsl_programs/ps2-parser/assignments.vsl
Normal file
14
exercises/02/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/02/vslc/vsl_programs/ps2-parser/helloworld.vsl
Normal file
3
exercises/02/vslc/vsl_programs/ps2-parser/helloworld.vsl
Normal file
@@ -0,0 +1,3 @@
|
||||
func main() begin
|
||||
print "Hello, World!"
|
||||
end
|
||||
25
exercises/02/vslc/vsl_programs/ps2-parser/if_else.vsl
Normal file
25
exercises/02/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/02/vslc/vsl_programs/ps2-parser/variables.vsl
Normal file
19
exercises/02/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/02/vslc/vsl_programs/ps2-parser/while.vsl
Normal file
10
exercises/02/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
|
||||
Reference in New Issue
Block a user