-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathparser.hpp
47 lines (37 loc) · 944 Bytes
/
parser.hpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
#ifndef PARSER_HPP
#define PARSER_HPP
#include <vector>
#include <algorithm>
#include <iostream>
#include <functional>
#include <cctype>
#include <map>
#include "lexer.hpp"
struct Cell;
struct Token;
struct Environment;
using Cells = std::vector<Cell>;
using Tokenlist = std::vector<Token>;
using csi = std::string::const_iterator;
using coord = std::tuple<int, int>;
using proc_t = std::function<Cell(const Cells&)>;
enum CellType {
Symbol,
Number,
String,
List,
Proc,
Fn
};
struct Cell {
CellType type;
std::string val;
Cells list;
proc_t proc;
Environment* env;
Cell(CellType t = Symbol): type(t), val(""), list(), env(nullptr){}
Cell(CellType t, const std::string& val): type(t), val(val), list(), env(nullptr) {}
Cell(proc_t proc): type(Proc), val(""), list(), proc(proc), env(nullptr) {}
};
Cell parse(TokenListCIter& tli, const TokenListCIter& end);
#endif // PARSER_HPP