-
Notifications
You must be signed in to change notification settings - Fork 0
/
lst.h
51 lines (42 loc) · 1.24 KB
/
lst.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
/**
* File: schemelist.h
* ------------------
* Helps manage the notion of a Scheme list.
* Recall that some lists are function calls,
* and some lists are pure data lists. This
* class manages both of them. Note that
* when these lists are asked to evaluate themselves,
* the car of the list is assumed to be a Callable,
* and the cdr of the list identifies all of the
* arguments that need to be fed to that Callable.
*
* You're well aware that we need to be able to
* support car, cdr
*/
#ifndef __scheme_list__
#define __scheme_list__
#include "genlib.h"
#include "expression.h"
#include "vector.h"
class ListExpression : public Expression {
public:
ListExpression(Scanner& scanner);
string toString();
Expression *eval(EvalState& state);
// constructors and methods in place to make the
// implementation of car, cdr, cons, list, and null.
Expression *car();
ListExpression *cdr();
ListExpression(Expression *first, ListExpression *rest);
ListExpression(Vector<Expression *>& expressions);
bool isEmpty() { return head == NULL; }
protected:
struct ConsCell {
Expression *car;
ConsCell *cdr;
ConsCell(Expression *car, ConsCell *cdr);
};
ConsCell *head;
ListExpression(ConsCell *head);
};
#endif // __scheme_list__