|
@@ -2,6 +2,7 @@
|
2
|
2
|
/*#include <QtGui>*/
|
3
|
3
|
#include <QVariant>
|
4
|
4
|
#include <QDebug>
|
|
5
|
+#include "utils/vector3d.h"
|
5
|
6
|
#include "utils/wavefrontobj.h"
|
6
|
7
|
#include "lexer-wavefront-obj.h"
|
7
|
8
|
|
|
@@ -13,22 +14,26 @@ extern int wavefront_objlex(void);
|
13
|
14
|
|
14
|
15
|
// Bison uses the yyerror function for informing us when a parsing error has
|
15
|
16
|
// occurred.
|
16
|
|
-void wavefront_objerror(const char *s);
|
|
17
|
+void wavefront_objerror(WaveFrontObjData* data, const char *s);
|
17
|
18
|
%}
|
18
|
19
|
|
19
|
20
|
%define api.prefix {wavefront_obj}
|
20
|
21
|
%define api.token.prefix {TOK_}
|
21
|
22
|
|
|
23
|
+%parse-param {struct WaveFrontObjData* wavefrontData}
|
|
24
|
+
|
22
|
25
|
// Here we define our custom variable types.
|
23
|
26
|
// Custom types must be of fixed size.
|
24
|
27
|
%union {
|
25
|
|
- float number;
|
|
28
|
+ double number;
|
|
29
|
+ int integer;
|
26
|
30
|
char* string;
|
27
|
|
- void* wavefront;
|
|
31
|
+ Vector3D* vector3d;
|
|
32
|
+ QList<int>* integers;
|
28
|
33
|
}
|
29
|
34
|
|
30
|
35
|
// Define the terminal expression types.
|
31
|
|
-%token <float_number> NUMBER
|
|
36
|
+%token <number> NUMBER
|
32
|
37
|
%token <string> STRING
|
33
|
38
|
%token SLASH
|
34
|
39
|
%token MTLLIB
|
|
@@ -41,18 +46,20 @@ void wavefront_objerror(const char *s);
|
41
|
46
|
%token F
|
42
|
47
|
%token S
|
43
|
48
|
|
|
49
|
+%destructor { free($$); } <string>
|
|
50
|
+%destructor { delete $$; } <vector3d>
|
|
51
|
+%destructor { delete $$; } <integers>
|
|
52
|
+
|
44
|
53
|
// Define the non-terminal expression types.
|
45
|
|
-%type <wavefront> wavefront_obj
|
|
54
|
+%type <vector3d> vertex
|
|
55
|
+%type <integer> face_vertex
|
|
56
|
+%type <integers> face_vertex_list
|
|
57
|
+%type <integers> face
|
46
|
58
|
|
47
|
|
-%%
|
48
|
59
|
|
49
|
|
-start: wavefront_obj {
|
50
|
|
-/* qDebug() << $1;*/
|
51
|
|
-};
|
|
60
|
+%%
|
52
|
61
|
|
53
|
|
-wavefront_obj: stmt_list {
|
54
|
|
- }
|
55
|
|
- ;
|
|
62
|
+wavefront_obj: stmt_list {};
|
56
|
63
|
|
57
|
64
|
|
58
|
65
|
stmt_list: {}
|
|
@@ -61,11 +68,11 @@ stmt_list: {}
|
61
|
68
|
stmt: mtllib {}
|
62
|
69
|
| usemtl {}
|
63
|
70
|
| named_object {}
|
64
|
|
- | vertex {}
|
|
71
|
+ | vertex { wavefrontData->_vertexes.append(*$1); delete $1; }
|
65
|
72
|
| texture_coordinate {}
|
66
|
73
|
| vertex_normal {}
|
67
|
74
|
| vertex_space {}
|
68
|
|
- | face {}
|
|
75
|
+ | face { wavefrontData->_faces.append(*$1); delete $1; }
|
69
|
76
|
| smooth {};
|
70
|
77
|
|
71
|
78
|
mtllib: MTLLIB STRING {};
|
|
@@ -74,8 +81,8 @@ usemtl: USEMTL STRING {};
|
74
|
81
|
|
75
|
82
|
named_object: O STRING {};
|
76
|
83
|
|
77
|
|
-vertex: V NUMBER NUMBER NUMBER {}
|
78
|
|
- | V NUMBER NUMBER NUMBER NUMBER {};
|
|
84
|
+vertex: V NUMBER NUMBER NUMBER { $$ = new Vector3D($2, $3, $4); }
|
|
85
|
+ | V NUMBER NUMBER NUMBER NUMBER { $$ = new Vector3D($2, $3, $4); };
|
79
|
86
|
|
80
|
87
|
texture_coordinate: VT NUMBER NUMBER {}
|
81
|
88
|
| VT NUMBER NUMBER NUMBER {};
|
|
@@ -84,22 +91,22 @@ vertex_normal: VN NUMBER NUMBER NUMBER {};
|
84
|
91
|
|
85
|
92
|
vertex_space: VP NUMBER NUMBER NUMBER {};
|
86
|
93
|
|
87
|
|
-face: F face_vertex_list {};
|
|
94
|
+face: F face_vertex_list { $$ = $2; };
|
88
|
95
|
|
89
|
|
-face_vertex_list: {}
|
90
|
|
- | face_vertex_list face_vertex {};
|
|
96
|
+face_vertex_list: { $$ = new QList<int>(); }
|
|
97
|
+ | face_vertex_list face_vertex { $1->append($2); };
|
91
|
98
|
|
92
|
|
-face_vertex: NUMBER {}
|
93
|
|
- | NUMBER SLASH NUMBER {}
|
94
|
|
- | NUMBER SLASH NUMBER SLASH NUMBER {}
|
95
|
|
- | NUMBER SLASH SLASH NUMBER {};
|
|
99
|
+face_vertex: NUMBER { $$ = $1; }
|
|
100
|
+ | NUMBER SLASH NUMBER { $$ = $1; }
|
|
101
|
+ | NUMBER SLASH NUMBER SLASH NUMBER { $$ = $1; }
|
|
102
|
+ | NUMBER SLASH SLASH NUMBER { $$ = $1; };
|
96
|
103
|
|
97
|
104
|
smooth: S NUMBER {}
|
98
|
105
|
| S STRING {};
|
99
|
106
|
|
100
|
107
|
%%
|
101
|
108
|
|
102
|
|
-void wavefront_objerror(const char *s)
|
|
109
|
+void wavefront_objerror(WaveFrontObjData* data, const char *s)
|
103
|
110
|
{
|
104
|
|
- qDebug() << "parse error:" << s << "at line" << wavefront_objlineno << "at" << wavefront_objtext;
|
|
111
|
+ data->_error = QString(s) + " at line " + QString::number(wavefront_objlineno) + " at " + QString(wavefront_objtext);
|
105
|
112
|
}
|