ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/libgender/doom3map_parser.y++
Revision: 1.6
Committed: Sat Nov 6 04:31:01 2004 UTC (19 years, 6 months ago) by root
Branch: MAIN
CVS Tags: HEAD
Changes since 1.5: +8 -5 lines
Log Message:
*** empty log message ***

File Contents

# Content
1 %{
2 #include <cstdio>
3 #include <cstdlib>
4 #include <vector>
5 #include <list>
6 #include "entity.h"
7 #include "material.h"
8 #include "util.h"
9
10 #define YYDEBUG 1
11
12 extern int yylex(void);
13 static void yyerror (char const *msg)
14 {
15 extern int yylineno;
16
17 printf ("%s (line %d)", msg, yylineno);
18 abort ();
19 }
20
21 using namespace std;
22
23 static vector<gl::vertex_t2f_n3f_v3f> tmpvtx;
24 static vector<GLushort> tmpidx;
25 static list<geometry_indexed_2d *> models;
26 static geometry_indexed_2d *geoid;
27
28 %}
29
30
31 %union {
32 char *ident;
33 char *string;
34 float num;
35 }
36
37
38 %token MODEL IAPO NODES SHADOWMODEL
39 %token <string> ID
40 %token <string> STRING
41 %token <num> NUMBER
42
43 %%
44
45 proc: ID sections
46 ;
47
48 sections: section
49 | sections section
50 ;
51 section: MODEL '{' STRING NUMBER '}'
52 | MODEL '{' STRING NUMBER surfaces '}'
53 | IAPO '{' NUMBER NUMBER pos '}'
54 | NODES '{' NUMBER nodes '}'
55 | SHADOWMODEL '{' STRING NUMBER NUMBER NUMBER NUMBER NUMBER mods modidxs '}'
56 ;
57
58 nodes: node
59 | nodes node
60 ;
61
62 node: '(' NUMBER NUMBER NUMBER NUMBER ')' NUMBER NUMBER
63 |
64 ;
65
66 pos: po
67 | pos po
68 ;
69
70 po: NUMBER NUMBER NUMBER pokla pokla pokla pokla
71 ;
72
73 pokla: '(' NUMBER NUMBER NUMBER ')';
74 ;
75
76 mods: mod
77 | mods mod
78 ;
79
80 mod: '(' NUMBER NUMBER NUMBER ')'
81 |
82 ;
83
84 modidxs: modidx
85 | modidxs modidx
86 ;
87
88 modidx: NUMBER NUMBER NUMBER
89 ;
90
91 surfaces: surface
92 | surfaces surface
93 ;
94
95 surface: '{' STRING NUMBER NUMBER vertexes triangles '}'
96 {
97 geoid = new geometry_indexed_2d (testmat, GL_TRIANGLES, tmpvtx, tmpidx);
98 entity *e = new entity (geoid);
99 e->move (vec3 (1000,0,-1000));
100 e->show ();
101 tmpvtx.clear ();
102 tmpidx.clear ();
103 }
104 ;
105
106 vertexes: vertex
107 | vertexes vertex
108 ;
109
110 vertex: '(' NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER ')'
111 {
112 tmpvtx.push_back (vertex_t2f_n3f_v3f (point ($2, $4, $3), vec3 ($7, $9, $8), tex2 ($5, $6)));
113 }
114 ;
115
116 triangles: triangle
117 | triangles triangle
118 ;
119
120 triangle: NUMBER NUMBER NUMBER {
121 tmpidx.push_back ((GLushort) $1);
122 tmpidx.push_back ((GLushort) $2);
123 tmpidx.push_back ((GLushort) $3);
124 }
125
126 %%
127
128 extern FILE *yyin;
129
130 bool doom3parse (const char *f) {
131 yyin = fopen (f, "r");
132 if (!yyin) return false;
133 yyparse ();
134 }
135