-
Notifications
You must be signed in to change notification settings - Fork 0
/
parser.hpp
59 lines (47 loc) · 924 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
48
49
50
51
52
53
54
55
56
57
58
59
#ifndef PARSER_HPP
#define PARSER_HPP
#include <assert.h>
#include <ctype.h>
#include <vector>
#include <string>
class Object;
class Parser {
public:
Parser(const std::string &input);
Object *parseProg(bool *);
Object *parse(bool *);
Object *parseList(char);
Object *parseFixnum(char);
Object *parseAtom(char);
Object *parseQuote(char);
void putBack() {
--ix;
}
bool hasNext() {
return ix < (intptr_t) input.length();
}
char getNext() {
assert(hasNext());
return input[ix++];
}
char getNextSkipWS(bool *ok = NULL) {
while (hasNext()) {
char c = input[ix++];
if (isspace(c)) {
continue;
}
if (ok) *ok = true;
return c;
}
if (ok) *ok = false;
return 0;
}
private:
Handle symQuote,
symQuasiQuote,
symUnquote,
symUnquoteSplicing;
const std::string &input;
intptr_t ix;
};
#endif