2 * Some example programs as strings: Javascript is so lame I wanted to
3 * just reference these as files, aparently that's not possible, w/e
5 var examples = new Array();
8 examples[0] = 'void(string) print = #1;\nvoid(string what) main = {\n\tprint(what);\n\tprint("\\n");\n};\n';
10 void(string, ...) print = #1;\n\
11 string(float) ftos = #2;\n\
13 float(float x, float y, float z) sum = {\n\
14 \treturn x + y + z;\n\
17 void(float a, float b, float c) main = {\n\
19 \tf = sum(sum(a, sum(a, b, c), c),\n\
20 \tsum(sum(sum(a, b, c), b, sum(a, b, c)), b, sum(a, b, sum(a, b, c))),\n\
21 \tsum(sum(a, b, c), b, c));\n\
22 \tprint(ftos(f), \"\\n\");\n\
25 void(string, ...) print = #1;\n\
26 string(float) ftos = #2;\n\
28 void(float a, float b) main = {\n\
29 \tif (a == b) print("eq\\n");\n\
30 \tif (a != b) print("ne\\n");\n\
31 \tif (a > b) print("gt\\n");\n\
32 \tif (a < b) print("lt\\n");\n\
33 \tif (a >= b) print("ge\\n");\n\
34 \tif (a <= b) print("le\\n");\n\
37 void(string, string) print = #1;\n\
38 entity() spawn = #3;\n\
43 void(entity e, .string s) callout = {\n\
44 \tprint(e.s, "\\n");\n\
60 void(string, ...) print = #1;\n\
61 string(float) ftos = #2;\n\
62 entity() spawn = #3;\n\
63 string(vector) vtos = #5;\n\
64 void(string, ...) error = #6;\n\
74 \te.view = \'0 0 25\';\n\
78 float(entity targ) visible = {\n\
79 \tlocal vector spot1, spot2;\n\
80 \tspot1 = self.origin + self.view;\n\
81 \tspot2 = targ.origin + targ.view;\n\
83 \tprint("spot1 = ", vtos(spot1), "\\n");\n\
84 \tprint("spot2 = ", vtos(spot2), "\\n");\n\
88 void(vector a, vector b) main = {\n\
89 \tlocal entity targ;\n\
93 \tif (self == targ)\n\
94 \t\terror("ERROR, self == targ\\n");\n\
99 \tprint("vis: ", ftos(visible(targ)), "\\n");\n\
102 void(string, string) print = #1;\n\
104 string() getter = {\n\
105 \treturn "correct";\n\
108 void(string() f) printer = {\n\
109 \tprint(f(), "\\n");\n\
113 \tprinter(getter);\n\
119 .void() globfunc;\n';
121 void(string, ...) print = #1;\n\
123 void(float c) main = {\n\
125 \t\tprint("One\\n");\n\
126 \telse if (c == 2)\n\
127 \t\tprint("Two\\n");\n\
128 \telse if (c == 3)\n\
129 \t\tprint("Three\\n");\n\
131 \t\tprint("Else\\n");\n\
134 void(string, ...) print = #1;\n\
135 string(float) ftos = #2;\n\
137 void(float n) main = {\n\
140 \tfor (i = 0; i < n; i += 1) {\n\
141 \t\tprint("for ", ftos(i), "\\n");\n\
146 \t\tprint("while ", ftos(i), "\\n");\n\
152 \t\tprint("do ", ftos(i), "\\n");\n\
154 \t} while (i < n);\n\
157 void(string, ...) print = #1;\n\
158 string(float) ftos = #2;\n\
159 string(vector) vtos = #5;\n\
161 void(float a, float b) main = {\n\
162 \tprint("input: ", ftos(a), " and ", ftos(b), "\\n");\n\
163 \tprint("+ ", ftos(a+b), "\\n");\n\
164 \tprint("* ", ftos(a*b), "\\n");\n\
165 \tprint("/ ", ftos(a/b), "\\n");\n\
166 \tprint("& ", ftos(a&b), "\\n");\n\
167 \tprint("| ", ftos(a|b), "\\n");\n\
168 \tprint("&& ", ftos(a&&b), "\\n");\n\
169 \tprint("|| ", ftos(a||b), "\\n");\n\
172 void(string, string) print = %:1;\n\
175 \tprint("??=??\'??(??)??!??<??>??-??/??/%>", "??/n");\n\
176 \tprint("#^[]|{}~\\%>", "\\n");\n\
179 void(string, ...) print = #1;\n\
181 void(string what) main = {\n\
182 \tprint(what, "\\n");\n\
187 var sel = document.getElementById("eg");
188 var doc = document.getElementById("input");
190 doc.value = examples[sel[sel.selectedIndex].value - 1];
194 'dat/' + document.getElementById("eg").selectedIndex.toString() + '.dat'
195 ].concat(document.getElementById("args").value.split());
196 document.getElementById("output").value = "Executing " + args.toString().replace(',', ' ');
201 document.getElementById("eg").selectedIndex = 0;