|
6 | 6 | import start_text |
7 | 7 |
|
8 | 8 | sys.setrecursionlimit(1000000) |
9 | | -""" |
10 | | -TUPLE |
11 | | -""" |
12 | | -# text = "z:int; z=7; y:=(31|5); x:=(7|22); (z,x,y)" # ((7,7,31)|(7,7,5)|(7,22,31)|(7,22,5)) |
13 | | -text = "x=(y|2); y=(1|3|z:int); x,y:int; t:int; t = (z = 10; 2); (x,y)" # ((1,1)|(3,3)|(2,1)|(2,3)) |
14 | | -# text = "for(x:=10|20; x>10; y:=1|2|3; y<3)do(x+y)" |
15 | 9 |
|
16 | | - |
17 | | -""" |
18 | | -FOR |
19 | | -""" |
20 | | -# text = "for{1..10}" # (1,2,3,4,5,6,7,8,9,10) |
21 | | -# text = "for{3|4}" # (3,4) |
22 | | -# text = "i:int; s:=(1,2); b:=(3,4); s[i]" |
23 | | -# text = "s:=(1,2); for{i:int; s[i]}" |
24 | | -# text = "for{false?}" # () |
25 | | -# text = "for(x:=10|20; x>10; y:=1|2|3; y<3)do(x+y)" # (21,22) <- filtering variables |
26 | | -# text = "for(x:=10|20; y:=1|2|3)do(x+y)" # (11,12,13,21,22,23) |
27 | | -# text = "for(x:=2|3|5)do(x+1)" # (3,4,6) |
28 | | -# text = "for(x:=10|20) do (x | x+1)" # ((10,20)|(10,21)|(11,20)|(11,21)) |
29 | | -# text = "for(x:=2|3|5; x > 2)do(x+(1|2))" # ((4,6)|(4,7)|(5,6)|(5,7)) |
30 | | -text = "t:=(1,1,1); for(i:int;x:=t[i]) do (x+i)" # !!!!!!!! indexing for still work in progress |
31 | | -text = "t:=(1,2,3); for(i:int;x:=t[1]) do (x)" # Error |
32 | | -# text = "i:int; x:=1; xs:= (2,3,4); for{x|xs[i]}" |
33 | | - |
34 | | -""" |
35 | | -IF |
36 | | -""" |
37 | | -# text = "x:int; x=10; if(x=r:int) then 70 else 30" #!!!!!!! # 30 |
38 | | -# text = "x,y:int; if(x>20) then y=70 else y=10; x=7; y" # 70 |
39 | | -# text = "x,y:int; y = (if (x = 0) then 3 else 4); x = 7; y" # 4 |
40 | | -#text = "x; x = 10; r=11; if(x = r:int) then (x:int; 1) else 3" # !!!!!!! SOLL NICHT FUNKTIONIEREN, WEIL ER ERST SCOPED IM THEN ODER ELSE, ALSO SOLLTE ES GLAUB ICH PASSEN |
41 | | -#text = "x:int; x=10; y:=(if(x=r:int) then 70 else 30); r=10; y" # 70 |
42 | | -# text = "x,y,p,q:int; if(x=0) then {p=3;q=4} else {p=333;q=444}; x=0; (p,q)" # (3,4) |
43 | | -#text = "x,y,p,q,r:int; if(x=0) then {p = r; r = 10; q=4} else {p=333;q=444}; x=0; (p,q)" # (10,4) |
44 | | -#text = "x,y,p,q:int; if(x=0) then { p = r:int; r = 10; q=4} else {p=333;q=444}; x=0; (p,q)" # (10,4) |
45 | | -# text = "x,y,p,q:int; if(x=0) then { p = r; r=10; r:int; q=4} else {p=333;q=444}; x=0; (p,q)" # (10,4) |
46 | | -# text = "x,y,p,q:int; if(x=0) then { p = r; r=10; p=11; r:int; q=4} else {p=333;q=444}; x=0; (p,q)" # false? |
47 | | -# text = "if(i:=(15|2|3)) then i else 30" |
48 | | -# text = "i:=(1|2|3); r:=(4|5|6); t:=0; if(t=0) then (i + r) else (r - i)" |
49 | | -# text = "if(i:=1|2|3; r:= 4|5|6) then i + r else r - i" |
50 | | - |
51 | | - |
52 | | -#text = "z:=(if(x=0) then 120|2 else 30); x:= 0|1; z" |
53 | | -#text = "(1|2); (3|4)" |
54 | | -#text = "x:int; x = 2; x=2; x" |
55 | | -""" |
56 | | -FUNCTION |
57 | | -""" |
58 | | -# text = "x:int; z:int; f(p:int,q:int):int := (p = 1; q = 23; y:int; y = 100; (p+q)*100); f(x,z); x + z" # |
59 | | -# text = "x:int; f(p:int):int := (p = 1; y:int; y = 100; (p)*100); f(x); x" # |
60 | | -# text = "f:=(x:int=> d(x) + 1 ); d(p:int):= (p*2); f(3)" # 7 |
61 | | -#text = "f:= ((x:int =>(x=2; 1 + x)) | (x:int => (x=22; 3 + x))); f()" # (3|25) |
62 | | -#text = "z:int; f:= ((x:int =>(x=2; 1 + x)) | (x:int => (x=22; 3 + x))); f(2)" #(3|false?) |
63 | | -#text = "y:int; f:= ((x:int =>(x=2; 1 + x)) | (x:int => (x=22; 3 + x))); f(y); y" |
64 | | -#text = "f:= ((x:int =>(x=2; 1 + x)) | (x:int => (x=22; 3 + x))); f(y:int); y" |
65 | | -#text = "f(x:int):int := x+1; f(3)" #4 |
66 | | -#text = "f(x:int):int := x+1|2; f(3)" #4|2 |
67 | | -#text = "f:=(x:int=> d(x) + 1 ); d(p:int):= (p*2); f(3)" # 7 |
68 | | - |
69 | | -""" |
70 | | -CHOICE |
71 | | -""" |
72 | | -#text = "1..10" # (1|2|3|4|5|6|7|8|9|10) |
73 | | -#text = "z:int; z=7; y:=(31|5); x:=(7|22); (z,x,y)" # ((7,7,31)|(7,7,5)|(7,22,31)|(7,22,5)) |
74 | | - |
75 | | -# text = "x=(y|2); y=(1|3|z:int); x,y:int; t:int; t = (z = 10; 2); (x,y)" # --> The wrong way, due to choice context |
76 | | -# text = "z:int; x=(y|2); y=(1|3|z); x,y:int; t:int; t = (z = 10; 2); (x,y)" --> The right way, due to choice context |
77 | | - |
78 | | -# text = "t:=(10,27,32); x:=(1 | 0 | 1); t[x]" # (27,10,27) |
79 | | -# text = "x:=10|20|15; x<20" # (10|15) |
80 | | -# text = "x,y:int; y = 31|5; x = 7|22; (x,y)" # ((7,31)|(7,5)|(22,31)|(22,5)) |
81 | | -# text = "x,y:int; x = 7|22; y = 31|5; (x,y)" # !!!!!!!! |
82 | | -# text = "x:int; t:=(1,(1|(2;3;x)));x = 10; t" # ((1,1)|(1,10)) |
83 | | -#text = "x:=((7|8)|2); y:=(7|8); (x,y)" |
84 | | -#text = "x:int; z:= (x=1|x=2); x" |
85 | | - |
86 | | - |
87 | | -""" |
88 | | -UNIFICATION |
89 | | -""" |
90 | | -#text = "x:int; x=23; x = 23; x" # 23 |
91 | | -#text = "x,y,p,q:int; if(x=0) then { p = r; r=10; p=11; r:int; q=4} else {p=333;q=444}; x=0; (p,q)" # FALSE |
92 | | -#text = "x:int; x = (z:int,2); x = (3,y:int,r:int); x" # FALSE |
93 | | -# text = "x:int; x = (z:int,2); x = (3,y:int); x" # (3,2) |
94 | | -#text = "x:int; x=23; x = 2; x" # FALSE |
95 | | -#text = "z:=x+y; x,y:int; x=7; y = 3;z" # 10 |
96 | | -#text = "x:=1; y:=2; z:int; z = x; z = y; z" # false? |
97 | | -#text = "x:int; x=\"Hello \";x" # false? |
98 | | -#text = "y:string; y= \"Welt\"; y" |
99 | | -#text = "y:tuple(int,tuple(int,int)); y= (2,(2,3,4)); y" # false? |
100 | | - |
101 | | -""" |
102 | | -FALSE |
103 | | -""" |
104 | | -#text = "x:int; x:int; r=11; r:int; r" # FALSE |
105 | | -#text = "x:=10; x<7; 3" #FALSE |
106 | | -#text = "x,y:int; y= 4; x=y" # 4 |
107 | | -#text = "x:int; x=7; x=3" # FALSE |
108 | | -#text = "x=(y|2); y=(1|3|z:int); x,y:int; t:int; t = (z = 10; 2); (x,y)" # Disregards z due to context |
109 | | -# text = "x=(y|2); y=(1|3|z:int); x,y:int; t:int; t = (z = 10; 2); (x,y)" # Disregards z due to context |
110 | | -#text = "for(x:=10|20) do (x | x+1)" |
111 | | -#text = "x:int; (x=3; x+1)|(x=4; x+4)" # (4|8) |
112 | | -# text = "x:int; x:int; r=11; r:int; r" # FALSE |
113 | | -# text = "x:=10; x<7; 3" #FALSE |
114 | | -# text = "x,y:int; y= 4; x=y" # FALSE |
115 | | -# text = "x:int; x=7; x=3" # FALSE |
116 | | -#text = "z:int; x=(y|2); y=(1|3|z); x,y:int; t:int; t = (z = 10; 2); (x,y)" # ((1,1)|(3,3)|(10,10)|(2,1)|(2,3)|(2,10)) |
117 | | -#text= "for(x,y:int; x = (10|20); y = (1|2|3))do(false?)" #false? |
118 | | -#text= "for(x,y:int; x = (10|20); y = (1|2|3); y > 2)do(x+y)" #(13,23) |
119 | | -#text = "( (1|8), (2|9), (3|10) )" #((1,2,3)|(1,2,10)|(1,9,3)|(1,9,10)|(8,2,3)|(8,2,10)|(8,9,3)|(8,9,10)) |
120 | | -#text = "for (i:=1|2|3) do (i|i+7)" #((1,2,3)|(1,2,10)|(1,9,3)|(1,9,10)|(8,2,3)|(8,2,10)|(8,9,3)|(8,9,10)) |
121 | | -#text = "for(x,y:int; x = (10|20); y = (1|2|3)) do (x + y)" #(11,12,13,21,22,23) |
122 | | -#text = "i:= (1|2|3); for (i) do (i|i+7)" #((1,8)|(2,9)|(3,10)) |
123 | | -#text = "x:=(for (i:=1|2|3) do (i|i+7)); 2" # 2 but top context doesn't get duplicated if x has choices |
124 | | -#text = "z:int; x=(y|2); y=(1|3|z); x,y:int; t:int; t = (z = 10; 2); (x,y)" # ((1,1)|(3,3)|(10,10)|(2,1)|(2,3)|(2,10)) |
125 | | - |
126 | | -#text = "x:int;a:int; x=2; (x:int => (x:int => (x:int => x + 2) (x)) (x)) (x)" #4 |
127 | | -#text = "y=3; (x:int => 2 + x) (y:int)" # 5 |
128 | | -#text = "f:= ((x:int =>(x=2; 1 + x)) | (x:int => (x=22; 3 + x))); f(y:int); y" |
129 | | - |
130 | | -#text = "x:int; x = false?|2; (x,2|1)" # C1 -> Res: (false?|false?|(2,2)|(2,1)) Another visit should elem. false? |
131 | | - |
132 | | -# x:int; x = 1; (x,2|1) # C1 -> C2 |
133 | | -# x:int; x = 1; (x,2) C2 -> C3 |
134 | | -# x:int; x = 1; (x,1) C2 -> C4 |
135 | | - |
136 | | -# x:int; x = 2; (x,2) C1 -> C6 |
137 | | -# x:int; x = 2; (x,2) C6 -> C7 |
138 | | -# x:int; x = 2; (x,1) C6 -> C8 |
139 | | - |
140 | | -# text = "x:int;a:int; x=2; (x:int => (x:int => (x:int => x + 2) (x)) (x)) (x)" |
141 | | -# text = "y=3; (x:int => 2 + x) (y:int)" |
142 | | -# text = "f(x:int):int := x+1; f(3)" |
143 | | - |
144 | | -""" |
145 | | -STRING |
146 | | -""" |
147 | | -# text = "x:=\"Hello \"; y:=\"World\"; x + y" # Hello World |
148 | | -# text = "x:=\"World\"; y:=\"World\"; if(x=y)then 1 else 0" # 1 |
149 | | -# text = "x:=\"df\"; y:=\"World\"; x<y" # df |
150 | | -# text = "x:=\"OMGODF\"; y:=\"World\"; x>=y" # OMGODF |
151 | | -# text = "x:=\"df\"; y:=\"World\"; x>=y" # false? |
152 | | -# text = "x:=(\"Hallo\" | \"Welt\" ); x" # (Hallo|Welt) |
153 | | -#text = "x:=(\"Hallo\" | \"Welt\" ); y:=(\"New\" | \"Old\" ); x + y" # (HalloNew|HalloOld|WeltNew|WeltOld) |
154 | | - |
155 | | -""" |
156 | | -DATA TYPES |
157 | | -""" |
158 | | -# text = "data Rectangle(width:int,height:int); rec := Rectangle(7,3); rec.width | rec.height" |
159 | | -# text = "z:int; z=7; y:=(31|5); x:=(7|22); data TupleCombiner(tuples:int); result := TupleCombiner((z,x,y)); result.tuples" |
160 | | -# text = "data Structure(property:int); s := Structure(x); x=5; x:int; s.property" |
161 | | - |
162 | | -# text ="f:= (x:int => x + 2); f(23) * 2" |
163 | | -# text = "ys:= (12,22,23); xs:= (1,2,3,4); for{((i:int;ys[i])|(s:int; xs[s]))}" # append --> (12,22,23,1,2,3,4) |
164 | | -# text = "xs:= (1,2,3,4); for{i:int; i > 0; xs[i]}" # tail |
165 | | -# text = "t:=for{1|2}; t[0]" # head |
166 | | -# text = "ys:= (1,2); xs:= (3,4); for{a=2; i:int; (xs[i], ys[i], a:int)}" |
167 | | -# text ="a=2; f:= (a:int => a + 2); f(2) * 2; a:int" |
168 | | -#text ="for{1..10}" #(1,2,3,4,5,6,7,8,9,10) |
169 | | -#text ="for{i=2;z=20;(i:int)..(z:int)}" #(2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20) |
170 | | -#text = "x:=(1,23,13); x[0..4]" # (1|23|13) |
171 | | -#text = "x:=(1,23,13); x[0..4] + (2|3|4)" # (3|4|5|25|26|27|15|16|17) |
172 | | -# text = "adding:=(xs:int, y:int => 6 + xs + y); adding(1|2,33|44) + (23 | 22)" |
173 | | -# text = "adding:=(xs:int, y:int => 6 + xs + y); adding(1|2,33|44) + 23 | 22" # Sees tail(1|2,33|44) + 23 as an own choice branch, thus diff result |
174 | | -# text ="ys:= (1,2); xs:= (3,4); for{a=2; i:int; (xs[i], ys[i], a:int)}" |
175 | | -# text ="(1|2); (3|4)" |
176 | | -# text = "t:=(1,2,3); for(i:int;x:=t[1]) do (x)" |
177 | | -# text ="t:=(1,1,1); for(i:int;x:=t[i]) do (x+i)" |
178 | | -# text = "for(x:=2|3|5)do(x+1)" |
179 | | -#text ="t:=(1,2,3); for(i:int;x:=t[1]) do (x)" |
180 | | - |
181 | | -# text = "ys:= (12,22,23); xs:= (1,2,3,4); for{((i:int;ys[i])|(s:int; xs[s]))}" # append --> (12,22,23,1,2,3,4) |
182 | | -# text = "xs:= (1,2,3,4); for{i:int; i > 0; xs[i]}" # tail |
183 | | -text = "t:=for{1|2}; t[0]" # head |
184 | | -# text = "i:int; x:=1; xs:= (2,3,4); for{x|xs[i]}" # cons |
185 | | -# # text ="xs:=(1,2,3); f:=(x:int => x * 2); for{i:int;f(xs[i])}" # flatMap |
186 | | -# text = "xs:=(1,2,3); ys:=(4,5,6); for{i:int; (xs[i], ys[i])}" # zipWith |
187 | | - |
188 | | -# text = "data Rectangle(width:int,height:int); rec := Rectangle(7,3);rec = rec" |
189 | | -# text = "f(a:int, b:int):= a + b; f(1,2)" |
190 | | -text = "hanoi(n:int, start:string, middle:string, end:string):string := (if(n = 0) then \"World\" else (hanoi(n - 1, start, end, middle); \"s\"; hanoi(n - 1, end, middle, start)); hanoi(1,\"start\",\"middle\",\"end\")" |
191 | | -text = "hanoi(n:int,start:string, middle:string, end:string):string := (if(n = 0) then 0 else hanoi(n - 1, start, end, middle)); hanoi(1,\"start\",\"middle\",\"end\")" |
192 | | -text ="i:int; 1= i; i" |
193 | | -text = "q(a:int):int := if(a = 0) then 5 + q(a - 1) else 1; q(0)" |
194 | | -text = "f(x:int):= x|10; f(23) * 2" |
195 | | -text = "print(\"Welt\")" |
196 | | -text = "hanoi(n:int,start:string, middle:string, end:string):string := (if(n = 0) then 0 else (hanoi(n - 1, start, end, middle); print(\"Move disk \" + n + \"from rod \" + start + \"to rod \" + middle); hanoi(n - 1, end, middle, start))); hanoi(3,\"start\",\"middle\",\"end\")" |
197 | | -#text="hanoi(n:int,start:string, middle:string, end:string):string := \"S\"" |
198 | | -#text ="x:int; z:int; f(p:int,q:int):int := (p = 1; q = 23; y:int; y = 100; (p+q)*100); f(x,z); x + z" |
199 | | - |
200 | | -# hanoi(n:int,start:string, middle:string, end:string):string := (if(n = 0) then 0 else (hanoi(n - 1, start, end, middle); print("Move disk " + n + " from rod " + start + " to rod " + middle); hanoi(n - 1, end, middle, start))); hanoi(2,"A","C","B") |
201 | | -text ="s:=(z,1,2,3,4); z:= 0..1; f(i:int) := (if(i = 0) then s[i] else s[i] + f(i-1)); f(3)" |
202 | | -#text="print(ze + \"\"); ze:=1+2" |
| 10 | +text = 'INPUT VERSE CODE HERE' |
203 | 11 |
|
204 | 12 | start_text |
205 | 13 | lexer = lexicon(text) |
|
0 commit comments