-
Notifications
You must be signed in to change notification settings - Fork 0
/
LispNode.h
75 lines (57 loc) · 1.13 KB
/
LispNode.h
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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
#ifndef LISP_NODE_H
#define LISP_NODE_H
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "types.h"
// Forward declaration
struct LispNode;
struct Box;
#include "RCPointer.hpp"
using LispNodeRC = RCPointer<LispNode>;
using BoxRC = RCPointer<Box>;
enum LispType : unsigned char {
AtomPure,
AtomBoolean,
AtomString,
AtomCharacter,
AtomNumericIntegral,
AtomNumericReal,
List
};
struct LispNode {
LispType type;
union {
char *string;
Integral number_i;
Real number_r;
BoxRC head;
};
public:
LispNode(LispType type);
~LispNode();
Box *get_head_pointer() const {
return head.get_pointer();
}
bool operator==(const LispNode &other) const;
bool is_atom();
bool is_list();
bool is_pure();
bool is_boolean();
bool is_string();
bool is_character();
bool is_numeric();
bool is_numeric_integral();
bool is_numeric_real();
void print();
};
struct Box {
LispNodeRC item;
BoxRC next;
Box(const LispNodeRC &item): item{item}, next{nullptr} {}
Box(LispNodeRC &&item) noexcept: item{item}, next{nullptr} {}
Box *get_next_pointer() const {
return next.get_pointer();
}
};
#endif /* LISP_NODE_H */