diff --git a/simple_test/fixtures/ast/binary.ast b/simple_test/fixtures/ast/binary.ast new file mode 100644 index 0000000..96976a2 --- /dev/null +++ b/simple_test/fixtures/ast/binary.ast @@ -0,0 +1,18 @@ +instructions => + Write: + expression => + Binary (DIV): + left => + Variable: + variable => + VAR BEGIN + type: + INTEGER + END VAR + right => + Variable: + variable => + VAR BEGIN + type: + INTEGER + END VAR diff --git a/simple_test/fixtures/ast/binary.sim b/simple_test/fixtures/ast/binary.sim new file mode 100644 index 0000000..570808d --- /dev/null +++ b/simple_test/fixtures/ast/binary.sim @@ -0,0 +1,5 @@ +PROGRAM x; + VAR a,b: INTEGER; +BEGIN + WRITE a DIV b +END x. diff --git a/simple_test/fixtures/ast/binary1.ast b/simple_test/fixtures/ast/binary1.ast new file mode 100644 index 0000000..1afb2fc --- /dev/null +++ b/simple_test/fixtures/ast/binary1.ast @@ -0,0 +1,26 @@ +instructions => + Assign: + location => + Variable: + variable => + VAR BEGIN + type: + ARRAY BEGIN + type: + INTEGER + length: + 5 + END ARRAY + END VAR + expression => + Variable: + variable => + VAR BEGIN + type: + ARRAY BEGIN + type: + INTEGER + length: + 5 + END ARRAY + END VAR diff --git a/simple_test/fixtures/ast/binary1.sim b/simple_test/fixtures/ast/binary1.sim new file mode 100644 index 0000000..5c7bfe8 --- /dev/null +++ b/simple_test/fixtures/ast/binary1.sim @@ -0,0 +1,5 @@ +PROGRAM x; + VAR a,b: ARRAY 5 OF INTEGER; +BEGIN + a := b +END x. diff --git a/simple_test/fixtures/ast/binary2.sim b/simple_test/fixtures/ast/binary2.sim new file mode 100644 index 0000000..5617500 --- /dev/null +++ b/simple_test/fixtures/ast/binary2.sim @@ -0,0 +1,6 @@ +PROGRAM x; + VAR a: ARRAY 5 OF INTEGER; + VAR b: ARRAY 5 OF INTEGER; +BEGIN + a := b +END x. diff --git a/simple_test/fixtures/ast/div.ast b/simple_test/fixtures/ast/div.ast new file mode 100644 index 0000000..96976a2 --- /dev/null +++ b/simple_test/fixtures/ast/div.ast @@ -0,0 +1,18 @@ +instructions => + Write: + expression => + Binary (DIV): + left => + Variable: + variable => + VAR BEGIN + type: + INTEGER + END VAR + right => + Variable: + variable => + VAR BEGIN + type: + INTEGER + END VAR diff --git a/simple_test/fixtures/ast/div.sim b/simple_test/fixtures/ast/div.sim new file mode 100644 index 0000000..570808d --- /dev/null +++ b/simple_test/fixtures/ast/div.sim @@ -0,0 +1,5 @@ +PROGRAM x; + VAR a,b: INTEGER; +BEGIN + WRITE a DIV b +END x. diff --git a/simple_test/fixtures/ast/empty.ast b/simple_test/fixtures/ast/empty.ast new file mode 100644 index 0000000..e69de29 diff --git a/simple_test/fixtures/ast/empty.sim b/simple_test/fixtures/ast/empty.sim new file mode 100644 index 0000000..aee7d28 --- /dev/null +++ b/simple_test/fixtures/ast/empty.sim @@ -0,0 +1 @@ +PROGRAM a; END a. diff --git a/simple_test/fixtures/ast/if1.ast b/simple_test/fixtures/ast/if1.ast new file mode 100644 index 0000000..3a704a2 --- /dev/null +++ b/simple_test/fixtures/ast/if1.ast @@ -0,0 +1,38 @@ +instructions => + If: + condition => + Condition (=): + left => + Variable: + variable => + VAR BEGIN + type: + INTEGER + END VAR + right => + Variable: + variable => + VAR BEGIN + type: + INTEGER + END VAR + true => + Write: + expression => + Variable: + variable => + VAR BEGIN + type: + INTEGER + END VAR + false => + Write: + expression => + Number: + value => + CONST BEGIN + type: + INTEGER + value: + 42 + END CONST diff --git a/simple_test/fixtures/ast/if1.sim b/simple_test/fixtures/ast/if1.sim new file mode 100644 index 0000000..4ef1079 --- /dev/null +++ b/simple_test/fixtures/ast/if1.sim @@ -0,0 +1,9 @@ +PROGRAM x; + VAR a,b: INTEGER; +BEGIN + IF a = b THEN + WRITE a + ELSE + WRITE 42 + END +END x. diff --git a/simple_test/fixtures/ast/if2.ast b/simple_test/fixtures/ast/if2.ast new file mode 100644 index 0000000..b25a6b5 --- /dev/null +++ b/simple_test/fixtures/ast/if2.ast @@ -0,0 +1,33 @@ +instructions => + If: + condition => + Condition (=): + left => + Number: + value => + CONST BEGIN + type: + INTEGER + value: + 0 + END CONST + right => + Number: + value => + CONST BEGIN + type: + INTEGER + value: + 0 + END CONST + true => + Write: + expression => + Number: + value => + CONST BEGIN + type: + INTEGER + value: + 10 + END CONST diff --git a/simple_test/fixtures/ast/if2.sim b/simple_test/fixtures/ast/if2.sim new file mode 100644 index 0000000..2e1a182 --- /dev/null +++ b/simple_test/fixtures/ast/if2.sim @@ -0,0 +1,6 @@ +PROGRAM x; +BEGIN + IF 0 = 0 THEN + WRITE 10 + END +END x. diff --git a/simple_test/fixtures/ast/modErr.sim b/simple_test/fixtures/ast/modErr.sim new file mode 100644 index 0000000..3925b45 --- /dev/null +++ b/simple_test/fixtures/ast/modErr.sim @@ -0,0 +1,3 @@ +PROGRAM peter; + VAR a : ARRAY 10 DIV (1 - 1) OF INTEGER; +END peter. diff --git a/simple_test/fixtures/ast/random.ast b/simple_test/fixtures/ast/random.ast new file mode 100644 index 0000000..2342ff0 --- /dev/null +++ b/simple_test/fixtures/ast/random.ast @@ -0,0 +1,200 @@ +instructions => + Assign: + location => + Variable: + variable => + VAR BEGIN + type: + INTEGER + END VAR + expression => + Number: + value => + CONST BEGIN + type: + INTEGER + value: + 1 + END CONST + If: + condition => + Condition (=): + left => + Number: + value => + CONST BEGIN + type: + INTEGER + value: + 0 + END CONST + right => + Number: + value => + CONST BEGIN + type: + INTEGER + value: + 0 + END CONST + true => + Repeat: + condition => + Condition (#): + left => + Number: + value => + CONST BEGIN + type: + INTEGER + value: + 0 + END CONST + right => + Number: + value => + CONST BEGIN + type: + INTEGER + value: + 0 + END CONST + instructions => + Assign: + location => + Variable: + variable => + VAR BEGIN + type: + INTEGER + END VAR + expression => + Binary (-): + left => + Binary (*): + left => + Number: + value => + CONST BEGIN + type: + INTEGER + value: + 16807 + END CONST + right => + Binary (MOD): + left => + Variable: + variable => + VAR BEGIN + type: + INTEGER + END VAR + right => + Number: + value => + CONST BEGIN + type: + INTEGER + value: + 127773 + END CONST + right => + Binary (*): + left => + Number: + value => + CONST BEGIN + type: + INTEGER + value: + 2836 + END CONST + right => + Binary (DIV): + left => + Variable: + variable => + VAR BEGIN + type: + INTEGER + END VAR + right => + Number: + value => + CONST BEGIN + type: + INTEGER + value: + 127773 + END CONST + If: + condition => + Condition (>): + left => + Variable: + variable => + VAR BEGIN + type: + INTEGER + END VAR + right => + Number: + value => + CONST BEGIN + type: + INTEGER + value: + 0 + END CONST + true => + Assign: + location => + Variable: + variable => + VAR BEGIN + type: + INTEGER + END VAR + expression => + Variable: + variable => + VAR BEGIN + type: + INTEGER + END VAR + false => + Assign: + location => + Variable: + variable => + VAR BEGIN + type: + INTEGER + END VAR + expression => + Binary (+): + left => + Variable: + variable => + VAR BEGIN + type: + INTEGER + END VAR + right => + Number: + value => + CONST BEGIN + type: + INTEGER + value: + 2147483647 + END CONST + Write: + expression => + Variable: + variable => + VAR BEGIN + type: + INTEGER + END VAR diff --git a/simple_test/fixtures/ast/random.sim b/simple_test/fixtures/ast/random.sim new file mode 100644 index 0000000..b57596d --- /dev/null +++ b/simple_test/fixtures/ast/random.sim @@ -0,0 +1,28 @@ +(* $Id: random.sim 30 2006-02-17 17:39:34Z phf $ *) + +PROGRAM Random; +CONST + a = 16807; + m = 2147483647; + q = m DIV a; + r = m MOD a; +VAR + Z: INTEGER; (* seed *) + g: INTEGER; (* temporary *) +BEGIN + Z := 1; + (* Forever... *) + WHILE 0 = 0 DO + (* ...make next random number... *) + g := a*(Z MOD q) - r*(Z DIV q); + IF g > 0 THEN Z := g ELSE Z := g + m END; + (* ...and print it. *) + WRITE Z + END +END Random. + +(* + This is an integer version of the random number generator + described in Wirth, Reiser: Programming in Oberon, 1992. + I guess the original reference is Park and Miller, 1988. +*)