refal works!

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
$ENTRY Go {
= <Prout <Calc <Spar <Numbers <Check<Card>>>>>>;
}
Check {
e.1 = <Skip('0123456789+* ()') e.1>;
}
Skip {
(e.L s.X e.R) s.X e.1 =
s.X<Skip (e.L s.X e.R) e.1>;
(e.S) s.X e.1 = <Skip (e.S) e.1>;
(e.S) = ;
}
Spar { e.1 = <Spar1 (L) e.1>; }
Spar1 {
(e.S) '(' e.T = <Spar1 ((e.S)) e.T>;
((e.S) e.1) ')' e.T = <Spar1 (e.S (e.1)) e.T>;
(L e.S) ')' e.T = ERROR;
(e.S) s.X e.T = <Spar1 (e.S s.X) e.T>;
(L e.S) = e.S;
(e.S) = ERROR;
}
Numbers {
e.1 = <N1 ('0123456789')e.1>;
}
N1 {
(e.L s.X e.R) s.X e.1 =
<N2 (e.L s.X e.R) (s.X) e.1>;
(e.S) s.X e.1 = s.X <N1 (e.S) e.1>;
(e.S) = ;
}
N2 {
(e.L s.X e.R) (e.N) s.X e.1 =
<N2 (e.L s.X e.R) (e.N s.X) e.1>;
(e.S) (e.N) e.1 =
<Numb e.N><N1 (e.S) e.1>;
}
Calc {
' ' e.1 = <Calc e.1>;
e.1 ' ' = <Calc e.1>;
'+' e.1 = <AddMy e.1>;
'*' e.1 = <MulMy e.1>;
e.L (e.S) e.T = e.L <Calc e.S> e.T;
}
AddMy {
' ' e.1 = <AddMy e.1>;
(e.S) = <Calc e.S>;
(e.S) e.R t.1 = <Add <Calc e.S> <AddMy e.R t.1>>;
t.1 e.L (e.S) e.R = <Add t.1 <AddMy e.L (e.S) e.R>>;
t.1 = t.1;
t.1 e.2 = <Add t.1 <AddMy e.2>>;
}
MulMy {
' ' e.1 = <MulMy e.1>;
(e.S) = <Calc e.S>;
(e.S) e.R t.1 = <Mul <Calc e.S> <MulMy e.R t.1>>;
t.1 e.L (e.S) e.R = <Mul t.1 <MulMy e.L (e.S) e.R>>;
t.1 = t.1;
t.1 e.2 = <Mul t.1 <MulMy e.2>>;
}