-
Notifications
You must be signed in to change notification settings - Fork 0
/
Parser.h
109 lines (89 loc) · 2.27 KB
/
Parser.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
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
#ifndef Parser_h
#define Parser_h
#include "Vector.h"
#include "Point.h"
#include "Color.h"
#include <iostream>
#include <string>
#include <map>
class Camera;
class Background;
class Light;
class Material;
class Object;
class Scene;
class Parser {
struct Token {
enum type {
end_of_file,
integer, real, string,
left_brace, right_brace,
left_bracket, right_bracket,
comma,
};
type token_type;
std::string string_value;
int integer_value;
double real_value;
int line_number;
int column_number;
};
std::istream &input;
int line_number;
int column_number;
Token next_token;
Material *default_material;
std::map< std::string, Material * > defined_materials;
std::map< std::string, Object * > defined_objects;
void throwParseException(
std::string const &message ) const;
void readNextToken();
bool peek(
Token::type const type );
bool peek(
std::string const &keyword );
Token match(
Token::type const type,
std::string const &failure_message );
Token match(
std::string const &keyword,
std::string const &failure_message );
std::string parseString();
bool parseBoolean();
int parseInteger();
double parseReal();
Vector const parseVector();
Point const parsePoint();
Color const parseColor();
Camera *parsePinholeCamera();
Camera *parseCamera();
Background *parseConstantBackground();
Background *parseBackground();
Light *parsePointLight();
Light *parseLight();
Material *parseCheckeredMaterial();
Material *parseLambertianMaterial();
Material *parseMetalMaterial();
Material *parsePerlinMaterial();
Material *parseRefractionMaterial();
Material *parseSpecularMaterial();
Material *parseMaterial();
Object *parseBoxObject();
Object *parseDiscObject();
Object *parseGroupObject();
Object *parsePlaneObject();
Object *parsePlyObject();
Object *parseRingObject();
Object *parseSphereObject();
Object *parseTriangleObject();
Object *parseObject();
public:
Parser(
std::istream &input );
Scene *parseScene(
std::string &filename );
int maxTime() const { return max_time; }
private:
int max_time;
};
#endif