@426729/

Lambda Calculus Interpreter

React

No description

fork
loading
Files
  • src
    • App.js
    • App.css
    • index.css
    • index.js
    • logo.svg
  • public
  • package.json

This Plugin Crashed!

Error: Error: must not create an existing file {"type":"CREATE_FILE","wid":"0.30206728254801063","path":"src/App.js","file":{"path":"src/App.js","content":{"asEncoding":{"base64":"aW1wb3J0IFJlYWN0LCB7CiAgICBDb21wb25lbnQKfSBmcm9tICdyZWFjdCc7CmltcG9ydCAnLi9BcHAuY3NzJzsKaW1wb3J0IHsKICAgIFBhcmpzCn0gZnJvbSAncGFyanMnOwpsZXQgQXBwbGljYXRpb24gPSAvKiogQGNsYXNzICovIChmdW5jdGlvbigpIHsKICAgIGZ1bmN0aW9uIEFwcGxpY2F0aW9uKHZhbCkgewogICAgICAgIHRoaXMuX25hbWUgPSAiQXBwbGljYXRpb24iOwogICAgICAgIFt0aGlzLmZ1bmMsIHRoaXMudmFsXSA9IHZhbDsKICAgICAgICAvLyBjb25zb2xlLmxvZyh2YWwsIkFwcGxpY2F0aW9uIGRvbmUiKTsKICAgIH0KICAgIHJldHVybiBBcHBsaWNhdGlvbjsKfSgpKTsKbGV0IERlZmluaXRpb24gPSAvKiogQGNsYXNzICovIChmdW5jdGlvbigpIHsKICAgIGZ1bmN0aW9uIERlZmluaXRpb24odmFsKSB7CiAgICAgICAgdGhpcy5fbmFtZSA9ICJEZWZpbml0aW9uIjsKICAgICAgICBbdGhpcy5hcmcsIHRoaXMucmV0XSA9IHZhbDsKICAgICAgICAvLyBjb25zb2xlLmxvZyh2YWwsIkRlZmluaXRpb24gZG9uZSIpOwogICAgfQogICAgcmV0dXJuIERlZmluaXRpb247Cn0oKSk7CmxldCBMZXR0ZXIgPSAvKiogQGNsYXNzICovIChmdW5jdGlvbigpIHsKICAgIGZ1bmN0aW9uIExldHRlcihpbnB1dCkgewogICAgICAgIHRoaXMuX25hbWUgPSAiTGV0dGVyIjsKICAgICAgICB0aGlzLmlucHV0ID0gaW5wdXQ7CiAgICAgICAgLy8gY29uc29sZS5sb2coaW5wdXQsIkxldHRlciBkb25lIik7CiAgICB9CiAgICByZXR1cm4gTGV0dGVyOwp9KCkpOwpjbGFzcyBBcHAgZXh0ZW5kcyBDb21wb25lbnQgewogICAgY29uc3RydWN0b3IocHJvcHMpIHsKICAgICAgICBzdXBlcihwcm9wcyk7CiAgICAgICAgdGhpcy5zdGF0ZSA9IHsKICAgICAgICAgICAgaW5wdXQ6ICJcXGEuKGEgYSkiCiAgICAgICAgfTsKICAgICAgICB0aGlzLnNldHVwID0gdGhpcy5zZXR1cC5iaW5kKHRoaXMpOwogICAgfQogICAgcmVuZGVyKCkgewogICAgICAgIHJldHVybiAoIDwKICAgICAgICAgICAgZGl2IGNsYXNzTmFtZSA9ICJBcHAiID4KICAgICAgICAgICAgPAogICAgICAgICAgICBpbnB1dCB0eXBlID0gInRleHQiCiAgICAgICAgICAgIHJlZiA9ICJpbnB1dCIKICAgICAgICAgICAgdmFsdWUgPSB7CiAgICAgICAgICAgICAgICB0aGlzLnN0YXRlLmlucHV0CiAgICAgICAgICAgIH0KICAgICAgICAgICAgb25DaGFuZ2UgPSB7CiAgICAgICAgICAgICAgICB0aGlzLnVwZGF0ZSgiaW5wdXQiKQogICAgICAgICAgICB9CiAgICAgICAgICAgIC8+IDwKICAgICAgICAgICAgYnV0dG9uIG9uQ2xpY2sgPSB7CiAgICAgICAgICAgICAgICB0aGlzLnNldHVwCiAgICAgICAgICAgIH0gPiBSdW4gPCAvYnV0dG9uPiA8CiAgICAgICAgICAgIGlucHV0IHJlYWRPbmx5IHR5cGUgPSAidGV4dCIKICAgICAgICAgICAgcmVmID0gIm91dHB1dCIgLyA+CiAgICAgICAgICAgIDwKICAgICAgICAgICAgL2Rpdj4KICAgICAgICApOwogICAgfQogICAgdXBkYXRlKG5hbWUpIHsKICAgICAgICByZXR1cm4gKHZhbHVlKSA9PiB7CiAgICAgICAgICAgIHRoaXMuc2V0U3RhdGUoewogICAgICAgICAgICAgICAgW25hbWVdOiB2YW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Sk7CiAgICAgICAgY29uc29sZS5sb2cocmVzKTsKICAgICAgICBpZiAocmVzLmhhc093blByb3BlcnR5KCJ0cmFjZSIpKSBjb25zb2xlLmxvZyhQYXJqcy52aXN1YWxpemVyKHJlcy50cmFjZSkpOwoKICAgIH0KfQoKZXhwb3J0IGRlZmF1bHQgQXBwOwo="},"asBuffer":null},"loaded":true}}
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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
import React, {
    Component
} from 'react';
import './App.css';
import {
    Parjs
} from 'parjs';
let Application = /** @class */ (function() {
    function Application(val) {
        this._name = "Application";
        [this.func, this.val] = val;
        // console.log(val,"Application done");
    }
    return Application;
}());
let Definition = /** @class */ (function() {
    function Definition(val) {
        this._name = "Definition";
        [this.arg, this.ret] = val;
        // console.log(val,"Definition done");
    }
    return Definition;
}());
let Letter = /** @class */ (function() {
    function Letter(input) {
        this._name = "Letter";
        this.input = input;
        // console.log(input,"Letter done");
    }
    return Letter;
}());
class App extends Component {
    constructor(props) {
        super(props);
        this.state = {
            input: "\\a.(a a)"
        };
        this.setup = this.setup.bind(this);
    }
    render() {
        return ( <
            div className = "App" >
            <
            input type = "text"
            ref = "input"
            value = {
                this.state.input
            }
            onChange = {
                this.update("input")
            }
            /> <
            button onClick = {
                this.setup
            } > Run < /button> <
            input readOnly type = "text"
            ref = "output" / >
            <
            /div>
        );
    }
    update(name) {
        return (value) => {
            this.setState({
                [name]: value.target.value
            });
        }
    }
    setup() {
        let setName = (i, e) => ({
            action: Object.assign(i.action, {
                _name: e
            })
        });
        let term, exp, def, letter, application, _exp, _term;
        exp = Parjs.late(() => _exp);
        term = Parjs.late(() => _term);
        letter = setName(Parjs.letter, "letter");
        def = setName(Parjs.seq(Parjs.string("\\").q, letter, Parjs.string(".").q, exp).map(i => new Definition(i)).soft, "def");
        application = setName(Parjs.seq(term, Parjs.string(" "), exp).map(i => new Application(i)).soft, "application");
        _exp = setName(Parjs.any(term, application, def), "exp");
        _term = setName(Parjs.any(exp.between("(", ")").soft, letter).soft, "term");
        let res = exp.parse(this.refs.input.value);
        console.log(res);
        if (res.hasOwnProperty("trace")) console.log(Parjs.visualizer(res.trace));

    }
}

export default App;