This commit is contained in:
aozhiwei 2023-03-02 22:04:34 +08:00
parent ee8724d50b
commit 6bf47d6566

61
a8/lisp.h Normal file
View File

@ -0,0 +1,61 @@
#pragma once
/*
: symbol
: list
: atom
*/
namespace a8
{
namespace lisp
{
struct List
{
std::vector<std::shared_ptr<Value>> elements;
};
struct Atom
{
double val = 0;
};
struct Symbol
{
std::string name;
};
struct Value
{
int value_type = 0;
std::shared_ptr<Atom> atom;
std::shared_ptr<List> list;
}
class Scope
{
private:
std::map<std::string, Value> vars_;
std::shared_ptr<scope> outer_;
};
class Expr
{
public:
bool Compile(const std::string& script);
std::shared_ptr<List> Eval();
std::shared_ptr<List> GetExprList() { return list_; };
private:
std::shared_ptr<List> list_;
};
}
}