-
Notifications
You must be signed in to change notification settings - Fork 0
/
lispparser.h
91 lines (77 loc) · 1.94 KB
/
lispparser.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
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
#ifndef AJUC_LISP_PARSER_LISP_PARSER_H
#define AJUC_LISP_PARSER_LISP_PARSER_H
#include <string>
#include <sstream>
#include <iostream>
#include <vector>
#include <map>
#include <cstdlib>
#include <memory>
#define SYNTAX_ERROR(line_no, x) { std::cerr << (line_no) << ": " << x << std::endl; exit(-1); }
/**
* Using this library is simple:
* the only function useful for end user is parse(input stream)
*
*/
namespace AjucLispParser {
class Expression {
public:
Expression();
virtual ~Expression();
virtual const std::string toString() const = 0;
private:
};
class Float : public Expression {
public:
Float(const std::string& text);
~Float();
const std::string toString() const;
const float value() const;
private:
float _value;
};
class String : public Expression {
public:
String(const std::string& text);
~String();
const std::string toString() const;
const std::string value() const;
private:
std::string _value;
};
class Identifier : public Expression {
public:
Identifier(const std::string& text);
~Identifier();
const std::string toString() const;
const std::string name() const;
private:
std::string _name;
};
class Atom : public Expression {
public:
Atom(const std::string& text);
~Atom();
const std::string toString() const;
const std::string name() const;
private:
std::string _name;
};
class List : public Expression {
public:
List();
List(std::vector< std::shared_ptr< Expression> > elements);
~List();
const std::string toString() const;
std::shared_ptr<Expression> first() const;
std::shared_ptr<Expression> item(const int index) const;
const int size() const;
bool empty() const;
private:
std::vector< std::shared_ptr< Expression> > elements;
};
/** Parses input into expression. */
std::shared_ptr<Expression> parse(std::istream& input, int& line_no, bool topLevel);
std::shared_ptr<Expression> parse(std::istream& input);
};
#endif /*AJUC_LISP_PARSER_LISP_PARSER_H*/