1
This commit is contained in:
parent
ee8724d50b
commit
6bf47d6566
61
a8/lisp.h
Normal file
61
a8/lisp.h
Normal 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_;
|
||||
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user