edits
[lambda.git] / temp.mdwn
1 <textarea id="INPUT" style="border: 2px solid black; color: black; font-family: monospace; height: 3in; overflow: auto; padding: 0.5em; width: 100%;">
2 let true = \x y. x in
3 let false = \x y. y in
4 let and = \l r. l r false in
5 (
6         (and true true yes no)
7         (and true false yes no)
8         (and false true yes no)
9         (and false false yes no)
10 )
11 </textarea>
12 <input id="PARSE" value="Normalize" type="button">
13 <input id="ETA" type="checkbox">do eta-reductions too
14 <noscript><p>You may not see it because you have JavaScript turned off. Uffff!</p></noscript>
15 <script src="/code/lambda.js"></script>
16 <script src="/code/tokens.js"></script>
17 <script src="/code/parse.js"></script>
18 <script src="/code/json2.js"></script>
19 <pre id="OUTPUT">
20 </pre>
21 <script>
22 /*jslint evil: true */
23
24 /*members create, error, message, name, prototype, stringify, toSource,
25     toString, write
26 */
27
28 /*global JSON, make_parse, parse, source, tree */
29
30 // Make a new object that inherits members from an existing object.
31
32 if (typeof Object.create !== 'function') {
33     Object.create = function (o) {
34         function F() {}
35         F.prototype = o;
36         return new F();
37     };
38 }
39
40 // Transform a token object into an exception object and throw it.
41
42 Object.prototype.error = function (message, t) {
43     t = t || this;
44     t.name = "SyntaxError";
45     t.message = message;
46     throw t;
47 };
48
49
50 (function () {
51     var parse = make_parse();
52
53     function go(source) {
54         var string, tree, expr, eta;
55         try {
56             tree = parse(source);
57  //           string = JSON.stringify(tree, ['key', 'name', 'message', 'value', 'arity', 'first', 'second', 'third', 'fourth'], 4);
58                         expr = tree.handler();
59             // string = JSON.stringify(expr, ['key', 'name', 'message', 'value', 'arity', 'first', 'second', 'tag', 'variable', 'left', 'right', 'bound', 'body' ], 4);
60 //                      string = expr.to_string() + "\n\n~~>\n\n";
61                         string = '';
62                         eta = document.getElementById('ETA').checked;
63                         string = string + reduce(expr, eta, false).to_string();
64         } catch (e) {
65             string = JSON.stringify(e, ['name', 'message', 'from', 'to', 'key',
66                     'value', 'arity', 'first', 'second', 'third', 'fourth'], 4);
67         }
68         document.getElementById('OUTPUT').innerHTML = string
69             .replace(/&/g, '&amp;')
70             .replace(/[<]/g, '&lt;');
71     }
72
73     document.getElementById('PARSE').onclick = function (e) {
74         go(document.getElementById('INPUT').value);
75     };
76 }());
77
78 </script>