Added SynAn tests

This commit is contained in:
Gašper Dobrovoljc 2025-03-23 15:14:18 +01:00
parent ffcb50c707
commit a4773edb76
No known key found for this signature in database
GPG Key ID: 0E7E037018CFA5A5
25 changed files with 224 additions and 53 deletions

View File

@ -1,53 +0,0 @@
from collections import defaultdict
data = open('./grammar.txt').read().split()
productions = defaultdict(lambda: [])
def recurse(prod):
prods = []
if prod not in productions.keys():
prods.append(prod)
else:
for p in productions[prod]:
if len(p):
prods += recurse(p[0])
return prods
while len(data):
name = data.pop(0)
data.pop(0) # ->
symbols = []
while True:
symbol = data.pop(0)
if symbol == '.':
productions[name].append(symbols)
break
if symbol == '|':
productions[name].append(symbols)
symbols = []
continue
symbols.append(symbol)
for prod, defs in productions.items():
func = f"""private void {prod}() {{
Token token = lexAn.peekToken();
switch(token.symbol()) {{
"""
for d in defs:
for r in recurse(d[0]):
func += f" case {r}:\n"
func += f' System.out.println("{prod} -> {defs}");'
for d2 in d:
if d2.isupper():
func += f"check({d2});"
func += """ }
}"""
print(func)

2
prg/synan/fail1.pins25 Normal file
View File

@ -0,0 +1,2 @@
fun a() =
!+-^+++(a||b==(1 != 2 && 1/a%e+2-f/d*sa < (2 && 3) || (1>2>3) || (1<=2) && 1 >= c))^^^^^

4
prg/synan/fail10.pins25 Normal file
View File

@ -0,0 +1,4 @@
fun a() =
while 1 then
neki
end

24
prg/synan/fail11.pins25 Normal file
View File

@ -0,0 +1,24 @@
var _kfoai = 8 * "neki"
var fkaio92j0a = 1 * 'a'
fun a (c,dvv,d,f,d)
fun a() =
if !+-^+++(a||b==(1 != 2 && 1/a%e+2-f/d*sa < (2 && 3) || (1>2) || (1<=2) && 1 >= c))^^^^^ then
mfksa(arg1, arg2) = kdoisk(),
kajs(a,c,c,1,4,(1+2)&&9^^),
a,// komentar
_kpofad29-a0as
else
mfksa(arg1, arg2) = kdoisk(),
kajs(a,c,c,1,4,(1+2)&&9^^),
a,// komentar
_kpofad29-a0as
end
while !+-^+++(a||b==(1 != 2 && 1/a%e+2-f/d*sa < (2 && 3) || (1>2) || (1<=2) && 1 >= c))^^^^^ do
mfksa(arg1, arg2) = kdoisk(),
kajs(a,c,c,1,4,(1+2)&&9^^),
a,// komentar
_kpofad29-a0as
end

1
prg/synan/fail12.pins25 Normal file
View File

@ -0,0 +1 @@
fun a() =

2
prg/synan/fail13.pins25 Normal file
View File

@ -0,0 +1,2 @@
fun a() =
1,2,

26
prg/synan/fail14.pins25 Normal file
View File

@ -0,0 +1,26 @@
fun a() =
let var a = 1 in 1 end,
let fun a (c,dvv,d,f,d)=
!+-^+++(a||b==(1 != 2 && 1/a%e+2-f/d*sa < (2 && 3) || (1>2) || (1<=2) && 1 >= c))^^^^^,
mfksa(arg1, arg2) = kdoisk(),
kajs(a,c,c,1,4,(1+2)&&9^^),
a,// komentar
_kpofad29-a0as,
if !+-^+++(a||b==(1 != 2 && 1/a%e+2-f/d*sa < (2 && 3) || (1>2) || (1<=2) && 1 >= c))^^^^^ then
mfksa(arg1, arg2) = kdoisk(),
kajs(a,c,c,1,4,(1+2)&&9^^),
a,// komentar
_kpofad29-a0as
end,
var a = 10 * "wawawaw"
fun b() fun c(a,a,v) in
!+-^+++(a||b==(1 != 2 && 1/a%e+2-f/d*sa < (2 && 3) || (1>2) || (1<=2) && 1 >= c))^^^^^,
mfksa(arg1, arg2) = kdoisk(),
kajs(a,c,c,1,4,(1+2)&&9^^),
a,// komentar
_kpofad29-a0as
end

26
prg/synan/fail15.pins25 Normal file
View File

@ -0,0 +1,26 @@
fun a() =
let var a = 1 in 1 end,
let fun a (c,dvv,d,f,d)=
!+-^+++(a||b==(1 != 2 && 1/a%e+2-f/d*sa < (2 && 3) || (1>2) || (1<=2) && 1 >= c))^^^^^,
mfksa(arg1, arg2) = kdoisk(),
kajs(a,c,c,1,4,(1+2)&&9^^),
a,// komentar
_kpofad29-a0as,
if !+-^+++(a||b==(1 != 2 && 1/a%e+2-f/d*sa < (2 && 3) || (1>2) || (1<=2) && 1 >= c))^^^^^ then
mfksa(arg1, arg2) = kdoisk(),
kajs(a,c,c,1,4,(1+2)&&9^^),
a,// komentar
_kpofad29-a0as
end
var a = 10 * "wawawaw"
fun b(), fun c(a,a,v) in
!+-^+++(a||b==(1 != 2 && 1/a%e+2-f/d*sa < (2 && 3) || (1>2) || (1<=2) && 1 >= c))^^^^^,
mfksa(arg1, arg2) = kdoisk(),
kajs(a,c,c,1,4,(1+2)&&9^^),
a,// komentar
_kpofad29-a0as
end

1
prg/synan/fail16.pins25 Normal file
View File

@ -0,0 +1 @@
var a = "10" * "msl"

1
prg/synan/fail17.pins25 Normal file
View File

@ -0,0 +1 @@
var a = "10" * 10

1
prg/synan/fail18.pins25 Normal file
View File

@ -0,0 +1 @@
fun a(b,1)

2
prg/synan/fail19.pins25 Normal file
View File

@ -0,0 +1,2 @@
fun a() =
nka(aka(a((1 != 2 && 1/a%e+2-f/d*sa = (1 != 2 && 1/a%e+2-f/d*sa)))

2
prg/synan/fail2.pins25 Normal file
View File

@ -0,0 +1,2 @@
fun a() =
a==b==c

1
prg/synan/fail20.pins25 Normal file
View File

@ -0,0 +1 @@
var a = 10 + "a"

2
prg/synan/fail3.pins25 Normal file
View File

@ -0,0 +1,2 @@
fun a =
1

1
prg/synan/fail4.pins25 Normal file
View File

@ -0,0 +1 @@
var a = 1 + 1

0
prg/synan/fail5.pins25 Normal file
View File

1
prg/synan/fail6.pins25 Normal file
View File

@ -0,0 +1 @@
fun a(g,d,d,g,g,f,,gf)

4
prg/synan/fail7.pins25 Normal file
View File

@ -0,0 +1,4 @@
fun a() =
1,
2
3

3
prg/synan/fail8.pins25 Normal file
View File

@ -0,0 +1,3 @@
fun a() =
1//komentar,
2

6
prg/synan/fail9.pins25 Normal file
View File

@ -0,0 +1,6 @@
fun a() =
if !+-^+++(a||b==(1 != 2 && 1/a%e+2-f/d*sa < (2 && 3) || (1>2) || (1<=2) && 1 >= c))^^^^^ then
mfksa(arg1, arg2) = kdoisk(),
kajs(a,c,c,1,4,(1+2)&&9^^),
a,// komentar
_kpofad29-a0as

44
prg/synan/pass1.pins25 Normal file
View File

@ -0,0 +1,44 @@
var _kfoai = 8 * "neki"
var fkaio92j0a = 1 * 'a'
fun a (c,dvv,d,f,d)
fun b() =
1
fun a() =
!+-^+++(a||b==(1 != 2 && 1/a%e+2-f/d*sa < (2 && 3) || (1>2) || (1<=2) && 1 >= c))^^^^^,
mfksa(arg1, arg2) = kdoisk(),
kajs(a,c,c,1,4,(1+2)&&9^^),
a,// komentar
_kpofad29-a0as,
nka(aka(a(1 != 2 && 1/a%e+2-f/d*sa, (1 != 2 && 1/a%e+2-f/d*sa)))) = 1 != 2 && 1/a%e+2-f/d*sa,
nka(aka(a(1 != 2 && 1/a%e+2-f/d*sa, (1 != 2 && 1/a%e+2-f/d*sa))), njc(1+'a')) = 1 != 2 && 1/a%e+2-f/d*sa,
if !+-^+++(a||b==(1 != 2 && 1/a%e+2-f/d*sa < (2 && 3) || (1>2) || (1<=2) && 1 >= c))^^^^^ then
mfksa(arg1, arg2) = kdoisk(),
kajs(a,c,c,1,4,(1+2)&&9^^),
a,// komentar
_kpofad29-a0as
end,
if !+-^+++(a||b==(1 != 2 && 1/a%e+2-f/d*sa < (2 && 3) || (1>2) || (1<=2) && 1 >= c))^^^^^ then
mfksa(arg1, arg2) = kdoisk(),
kajs(a,c,c,1,4,(1+2)&&9^^),
a,// komentar
_kpofad29-a0as
else
mfksa(arg1, arg2) = kdoisk(),
kajs(a,c,c,1,4,(1+2)&&9^^),
a,// komentar
_kpofad29-a0as
end
,while !+-^+++(a-n()||b==(1 != (2 && 1)/a%(e+a()-2+mkla(a,g,"kof"-"string"%3+'j'&&2))-f/d*sa && osid*'a' < (2 && 3) || (1>2) || (1<=2) && 1 >= c))^^^^^ do
mfksa(arg1, arg2) = kdoisk(),
kajs(a,c,c,1,4,(1+2)&&9^^),
a,// komentar
_kpofad29-a0as
end

37
prg/synan/pass2.pins25 Normal file
View File

@ -0,0 +1,37 @@
fun noarg()
fun onearg(a)
fun multargs(a, b)
fun funcassign(a) =
a = 1
var a = 1
var b = 'a'
var c = "test"
var e = 'a', "test", 4, 4 * 'a'
var f = 1 * 3
var g = 1 * 'a'
var h = 4 * "aaa"
var i =
fun a() =
1, 'a', "a",
a, neki(a, 1, 'a', "a"),
a^, a^^,
+a, -a, !a, ^a, +-!^a,
a * b, a / b, a % b, a * b / c % d,
a + b, a - b,
a == b, a != b, a < b, a > b, a <= b, a >= b,
a && b, a && b && c,
a || b, a || b || c,
(1), (a + b), (a - (!(1) * 2)),
a + 1 = b - 1,
if a then b end,
if a == 3 then b = 1, !c end,
if !a then b else a = 3 * a end,
if a then b else a, b end,
while a <= 10 do a + 1 end,
while a <= 10 do a + 1, ^c end,
let fun a(b, c) in !b end,
let fun a(b, c) var e = 'o' in !b end,
let fun a(b, c) in !b, 4 end,
!+-^+++(a||b==(1 != 2 && 1/a%e+2-f/d*sa < (2 && 3) || (1>2) || (1<=2) && 1 >= c))^^^^^

26
prg/synan/pass3.pins25 Normal file
View File

@ -0,0 +1,26 @@
fun a() =
let var a = 1 in 1 end,
let fun a (c,dvv,d,f,d)=
!+-^+++(a||b==(1 != 2 && 1/a%e+2-f/d*sa < (2 && 3) || (1>2) || (1<=2) && 1 >= c))^^^^^,
mfksa(arg1, arg2) = kdoisk(),
kajs(a,c,c,1,4,(1+2)&&9^^),
a,// komentar
_kpofad29-a0as,
if !+-^+++(a||b==(1 != 2 && 1/a%e+2-f/d*sa < (2 && 3) || (1>2) || (1<=2) && 1 >= c))^^^^^ then
mfksa(arg1, arg2) = kdoisk(),
kajs(a,c,c,1,4,(1+2)&&9^^),
a,// komentar
_kpofad29-a0as
end
var a = 10 * "wawawaw"
fun b() fun c(a,a,v) in
!+-^+++(a||b==(1 != 2 && 1/a%e+2-f/d*sa < (2 && 3) || (1>2) || (1<=2) && 1 >= c))^^^^^,
mfksa(arg1, arg2) = kdoisk(a(1)),
kajs(a,c,c,1,4,(1+2)&&9^^),
a,// komentar
_kpofad29-a0as
end

7
prg/synan/run-tests.sh Normal file
View File

@ -0,0 +1,7 @@
#!/bin/bash
for file in *.pins25; do
echo "Running $file"
java ../../src/pins25/phase/SynAn.java "$file" 2>&1 | tail -n 1
printf "\n"
done