71 lines
1.1 KiB
C++
71 lines
1.1 KiB
C++
#pragma once
|
|
|
|
/*
|
|
数据类型
|
|
符号: symbol
|
|
列表: list
|
|
原子: atom
|
|
*/
|
|
|
|
namespace a8
|
|
{
|
|
|
|
namespace lisp
|
|
{
|
|
enum class ValueType : int
|
|
{
|
|
kAtom = 1,
|
|
kList = 2,
|
|
kSymbol = 3,
|
|
kCProc = 4,
|
|
};
|
|
|
|
struct List
|
|
{
|
|
std::vector<std::shared_ptr<Value>> elements;
|
|
};
|
|
|
|
struct Atom
|
|
{
|
|
double val = 0;
|
|
};
|
|
|
|
struct Symbol
|
|
{
|
|
std::string name;
|
|
};
|
|
|
|
struct Value
|
|
{
|
|
ValueType type;
|
|
std::shared_ptr<Symbol> symbol;
|
|
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_;
|
|
|
|
};
|
|
|
|
}
|
|
|
|
}
|