2019-08-03 15:45:14 -07:00
|
|
|
#pragma once
|
|
|
|
#include <memory>
|
|
|
|
#include <vector>
|
|
|
|
|
|
|
|
struct ast {
|
2019-08-05 00:08:13 -07:00
|
|
|
virtual ~ast() = default;
|
2019-08-03 15:45:14 -07:00
|
|
|
};
|
|
|
|
|
|
|
|
using ast_ptr = std::unique_ptr<ast>;
|
|
|
|
|
|
|
|
struct pattern {
|
2019-08-05 00:08:13 -07:00
|
|
|
virtual ~pattern() = default;
|
2019-08-03 15:45:14 -07:00
|
|
|
};
|
|
|
|
|
|
|
|
using pattern_ptr = std::unique_ptr<pattern>;
|
|
|
|
|
|
|
|
struct branch {
|
|
|
|
pattern_ptr pat;
|
|
|
|
ast_ptr expr;
|
|
|
|
|
2019-08-05 00:08:13 -07:00
|
|
|
branch(pattern_ptr p, ast_ptr a)
|
2019-08-03 15:45:14 -07:00
|
|
|
: pat(std::move(p)), expr(std::move(a)) {}
|
|
|
|
};
|
|
|
|
|
|
|
|
using branch_ptr = std::unique_ptr<branch>;
|
|
|
|
|
2019-08-05 00:08:13 -07:00
|
|
|
struct definition {
|
|
|
|
virtual ~definition() = default;
|
|
|
|
};
|
|
|
|
|
|
|
|
using definition_ptr = std::unique_ptr<definition>;
|
|
|
|
|
2019-08-03 15:45:14 -07:00
|
|
|
enum binop {
|
|
|
|
PLUS,
|
|
|
|
MINUS,
|
|
|
|
TIMES,
|
|
|
|
DIVIDE
|
|
|
|
};
|
|
|
|
|
2019-08-05 00:08:13 -07:00
|
|
|
struct ast_int : public ast {
|
|
|
|
int value;
|
|
|
|
|
|
|
|
explicit ast_int(int v)
|
|
|
|
: value(v) {}
|
|
|
|
};
|
|
|
|
|
|
|
|
struct ast_lid : public ast {
|
|
|
|
std::string id;
|
|
|
|
|
|
|
|
explicit ast_lid(std::string i)
|
|
|
|
: id(std::move(i)) {}
|
|
|
|
};
|
|
|
|
|
|
|
|
struct ast_uid : public ast {
|
|
|
|
std::string id;
|
|
|
|
|
|
|
|
explicit ast_uid(std::string i)
|
|
|
|
: id(std::move(i)) {}
|
|
|
|
};
|
|
|
|
|
2019-08-03 15:45:14 -07:00
|
|
|
struct ast_binop : public ast {
|
|
|
|
binop op;
|
|
|
|
ast_ptr left;
|
|
|
|
ast_ptr right;
|
|
|
|
|
2019-08-05 00:08:13 -07:00
|
|
|
ast_binop(binop o, ast_ptr l, ast_ptr r)
|
2019-08-03 15:45:14 -07:00
|
|
|
: op(o), left(std::move(l)), right(std::move(r)) {}
|
|
|
|
};
|
|
|
|
|
|
|
|
struct ast_app : public ast {
|
|
|
|
ast_ptr left;
|
|
|
|
ast_ptr right;
|
|
|
|
|
2019-08-05 00:08:13 -07:00
|
|
|
ast_app(ast_ptr l, ast_ptr r)
|
|
|
|
: left(std::move(l)), right(std::move(r)) {}
|
2019-08-03 15:45:14 -07:00
|
|
|
};
|
|
|
|
|
|
|
|
struct ast_case : public ast {
|
|
|
|
ast_ptr of;
|
|
|
|
std::vector<branch_ptr> branches;
|
|
|
|
|
2019-08-05 00:08:13 -07:00
|
|
|
ast_case(ast_ptr o, std::vector<branch_ptr> b)
|
|
|
|
: of(std::move(o)), branches(std::move(b)) {}
|
|
|
|
};
|
|
|
|
|
|
|
|
struct pattern_var : public pattern {
|
|
|
|
std::string var;
|
|
|
|
|
|
|
|
pattern_var(std::string v)
|
|
|
|
: var(std::move(v)) {}
|
|
|
|
};
|
|
|
|
|
|
|
|
struct pattern_constr : public pattern {
|
|
|
|
std::string constr;
|
|
|
|
std::vector<std::string> params;
|
|
|
|
|
|
|
|
pattern_constr(std::string c, std::vector<std::string> p)
|
|
|
|
: constr(std::move(c)), params(std::move(p)) {}
|
|
|
|
};
|
|
|
|
|
|
|
|
struct definition_defn : public definition {
|
|
|
|
std::string name;
|
|
|
|
std::vector<std::string> params;
|
|
|
|
ast_ptr body;
|
|
|
|
|
|
|
|
definition_defn(std::string n, std::vector<std::string> p, ast_ptr b)
|
|
|
|
: name(std::move(n)), params(std::move(p)), body(std::move(b)) {
|
|
|
|
|
2019-08-03 15:45:14 -07:00
|
|
|
}
|
|
|
|
};
|