1 Here are the definitions pre-loaded for working on assignment 3:
4 <textarea id="INPUT" style="border: 2px solid black;
5 color: black; font-family: monospace; height: 3in;
6 overflow: auto; padding: 0.5em; width: 100%;">
10 let and = \l r. l (r true false) false in
11 let make_pair = \f s g. g f s in
14 let empty = make_pair true junk in
15 let isempty = \x. x fst in
16 let make_list = \h t. make_pair false (make_pair h t) in
17 let head = \l. isempty l err (l snd fst) in
18 let tail = \l. isempty l err (l snd snd) in
20 ; a list of numbers to experiment on
21 let mylist = make_list 1 (make_list 2 (make_list 3 empty)) in
24 let iszero = \n. n (\x. false) true in
25 let succ = \n s z. s (n s z) in
26 let mul = \m n s. m (n s) in
27 let pred = \n. iszero n 0 (length (tail (n (\p. make_list junk p) empty))) in
28 let leq = \m n. iszero(n pred m) in
29 let eq = \m n. and (leq m n)(leq n m) in
31 ; a fixed-point combinator for defining recursive functions
32 let Y = \f. (\h. f (h h)) (\h. f (h h)) in
34 let length = Y (\length l. isempty l 0 (succ (length (tail l)))) in
37 let makePair = make_pair in
39 let isNil = isempty in
40 let makeList = make_list in
41 let isZero = iszero in
47 <input id="PARSE" value="Normalize" type="button">
48 <input id="ETA" type="checkbox">do eta-reductions too
49 <noscript><p>You may not see it because you have JavaScript turned off. Uffff!</p></noscript>
50 <script src="/code/lambda.js"></script>
51 <script src="/code/tokens.js"></script>
52 <script src="/code/parse.js"></script>
53 <script src="/code/json2.js"></script>
57 /*jslint evil: true */
59 /*members create, error, message, name, prototype, stringify, toSource,
63 /*global JSON, make_parse, parse, source, tree */
65 // Make a new object that inherits members from an existing object.
67 if (typeof Object.create !== 'function') {
68 Object.create = function (o) {
75 // Transform a token object into an exception object and throw it.
77 Object.prototype.error = function (message, t) {
79 t.name = "SyntaxError";
86 var parse = make_parse();
89 var string, tree, expr, eta;
92 // string = JSON.stringify(tree, ['key', 'name', 'message', 'value', 'arity', 'first', 'second', 'third', 'fourth'], 4);
93 expr = tree.handler();
94 // string = JSON.stringify(expr, ['key', 'name', 'message', 'value', 'arity', 'first', 'second', 'tag', 'variable', 'left', 'right', 'bound', 'body' ], 4);
95 // string = expr.to_string() + "\n\n~~>\n\n";
97 eta = document.getElementById('ETA').checked;
98 string = string + reduce(expr, eta, false).to_string();
100 string = JSON.stringify(e, ['name', 'message', 'from', 'to', 'key',
101 'value', 'arity', 'first', 'second', 'third', 'fourth'], 4);
103 document.getElementById('OUTPUT').innerHTML = string
104 .replace(/&/g, '&')
105 .replace(/[<]/g, '<');
108 document.getElementById('PARSE').onclick = function (e) {
109 go(document.getElementById('INPUT').value);