mirror of
https://github.com/lisk77/lambda.git
synced 2025-10-24 18:28:49 +00:00
feat: added simple import support
This commit is contained in:
parent
c14c50dee1
commit
9ff3943819
6 changed files with 61 additions and 3 deletions
|
|
@ -6,7 +6,8 @@
|
|||
|
||||
// ast stuff lul
|
||||
struct Expr {
|
||||
virtual ~Expr() = default;
|
||||
virtual ~Expr() = default;
|
||||
virtual std::unique_ptr<Expr> clone() const = 0;
|
||||
};
|
||||
|
||||
// represents a simple symbol like "x" or even "thisIsACoolFunctionTrustme100"
|
||||
|
|
@ -16,6 +17,9 @@ struct Variable : Expr {
|
|||
std::string name;
|
||||
|
||||
Variable(std::string n) : name(std::move(n)) {}
|
||||
std::unique_ptr<Expr> clone() const override {
|
||||
return std::make_unique<Variable>(name);
|
||||
}
|
||||
};
|
||||
|
||||
// represents a function itself like \ x . x
|
||||
|
|
@ -24,6 +28,9 @@ struct Abstraction : Expr {
|
|||
std::unique_ptr<Expr> body;
|
||||
|
||||
Abstraction(std::string p, std::unique_ptr<Expr> b) : param(std::move(p)), body(std::move(b)) {}
|
||||
std::unique_ptr<Expr> clone() const override {
|
||||
return std::make_unique<Abstraction>(param, body->clone());
|
||||
}
|
||||
};
|
||||
|
||||
// wouldnt be turing complete if we couldnt apply to these functions innit
|
||||
|
|
@ -34,6 +41,9 @@ struct Application : Expr {
|
|||
std::unique_ptr<Expr> left, right;
|
||||
|
||||
Application(std::unique_ptr<Expr> l, std::unique_ptr<Expr> r) : left(std::move(l)), right(std::move(r)) {}
|
||||
std::unique_ptr<Expr> clone() const override {
|
||||
return std::make_unique<Application>(left->clone(), right->clone());
|
||||
}
|
||||
};
|
||||
|
||||
#endif // AST_HPP
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue