d2501611eee396c8c7f2e4036d115937e967eec3
1 #include <stdio.h>
2 #include <string.h>
3 #include <assert.h>
7 /*
8 static char source_test[] =
9 "(* Main module *)"
10 "MODULE Test;"
11 "IMPORT Out;"
12 ""
13 "TYPE"
14 " R = LONGINT;"
15 ""
16 "PROCEDURE Factorial(n : R) : R;"
17 "BEGIN"
18 " IF n <= 1 THEN"
19 " RETURN 1;"
20 " ELSE"
21 " RETURN n * Factorial(n - 1);"
22 " END;"
23 " RETURN 0; (* Детектор ретурнов - дерьмо *)"
24 "END Factorial;"
25 ""
26 "BEGIN"
27 " Out.Open();"
28 " Out.Int(Factorial(0), 0); Out.Ln;"
29 " Out.Int(Factorial(1), 0); Out.Ln;"
30 " Out.Int(Factorial(2), 0); Out.Ln;"
31 " Out.Int(Factorial(3), 0); Out.Ln;"
32 " Out.Int(Factorial(4), 0); Out.Ln;"
33 " Out.Int(Factorial(5), 0); Out.Ln;"
34 " Out.Int(Factorial(6), 0); Out.Ln;"
35 " Out.Int(Factorial(7), 0); Out.Ln;"
36 " Out.Int(Factorial(8), 0); Out.Ln;"
37 " Out.Int(Factorial(9), 0); Out.Ln;"
38 " Out.Int(Factorial(10), 0); Out.Ln;"
39 " Out.Int(Factorial(11), 0); Out.Ln;"
40 " Out.Int(Factorial(12), 0); Out.Ln;"
41 " Out.Int(Factorial(13), 0); Out.Ln;"
42 " Out.Int(Factorial(14), 0); Out.Ln;"
43 " Out.Int(Factorial(15), 0); Out.Ln;"
44 " Out.Int(Factorial(16), 0); Out.Ln;"
45 " Out.Int(Factorial(17), 0); Out.Ln;"
46 " Out.Int(Factorial(18), 0); Out.Ln;"
47 " Out.Int(Factorial(19), 0); Out.Ln;"
48 " Out.Int(Factorial(20), 0); Out.Ln;"
49 "END Test."
50 ;
51 */
54 "(* Main module *)"
55 "MODULE Test;"
56 "IMPORT Out;"
57 ""
58 "TYPE"
59 " R = LONGREAL;"
60 ""
61 "PROCEDURE Factorial(n : R) : R;"
62 "BEGIN"
63 " IF n <= 1 THEN"
64 " RETURN 1;"
65 " ELSE"
66 " RETURN n * Factorial(n - 1);"
67 " END;"
68 " RETURN 0; (* Детектор ретурнов - дерьмо *)"
69 "END Factorial;"
70 ""
71 "BEGIN"
72 " Out.Open();"
73 " Out.LongReal(Factorial(0), 0); Out.Ln;"
74 " Out.LongReal(Factorial(1), 0); Out.Ln;"
75 " Out.LongReal(Factorial(2), 0); Out.Ln;"
76 " Out.LongReal(Factorial(3), 0); Out.Ln;"
77 " Out.LongReal(Factorial(4), 0); Out.Ln;"
78 " Out.LongReal(Factorial(5), 0); Out.Ln;"
79 " Out.LongReal(Factorial(6), 0); Out.Ln;"
80 " Out.LongReal(Factorial(7), 0); Out.Ln;"
81 " Out.LongReal(Factorial(8), 0); Out.Ln;"
82 " Out.LongReal(Factorial(9), 0); Out.Ln;"
83 " Out.LongReal(Factorial(10), 0); Out.Ln;"
84 " Out.LongReal(Factorial(11), 0); Out.Ln;"
85 " Out.LongReal(Factorial(12), 0); Out.Ln;"
86 " Out.LongReal(Factorial(13), 0); Out.Ln;"
87 " Out.LongReal(Factorial(14), 0); Out.Ln;"
88 " Out.LongReal(Factorial(15), 0); Out.Ln;"
89 " Out.LongReal(Factorial(16), 0); Out.Ln;"
90 " Out.LongReal(Factorial(17), 0); Out.Ln;"
91 " Out.LongReal(Factorial(18), 0); Out.Ln;"
92 " Out.LongReal(Factorial(19), 0); Out.Ln;"
93 " Out.LongReal(Factorial(20), 0); Out.Ln;"
94 " Out.LongReal(Factorial(170), 0); Out.Ln;"
95 "END Test."
96 ;
99 "MODULE Out;"
100 " PROCEDURE Open*;"
101 " END Open;"
102 ""
103 " PROCEDURE Char* (ch : CHAR);"
104 " END Char;"
105 ""
106 " PROCEDURE String* (str : ARRAY OF CHAR);"
107 " END String;"
108 ""
109 " PROCEDURE Int*(i, n : LONGINT);"
110 " END Int;"
111 ""
112 " PROCEDURE Real*(x : REAL; n : INTEGER);"
113 " END Real;"
114 ""
115 " PROCEDURE LongReal*(x : LONGREAL; n : INTEGER);"
116 " END LongReal;"
117 ""
118 " PROCEDURE Ln*;"
119 " END Ln;"
120 ""
121 "END Out."
122 ;
129 {
131 {
133 }
135 {
137 }
138 else
139 {
141 }
142 }
147 {
148 }
153 {
158 {
160 }
162 }
167 {
172 {
174 }
176 }
181 {
183 }
186 {
195 }
198 {
201 }
203 int
205 {
211 // init_system_modules();
213 // oberon_generator_dump(ctx, "dump.txt");
215 // start_module();
219 }