ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/libgender/doom3map_parser.y++
Revision: 1.3
Committed: Sat Nov 6 01:10:11 2004 UTC (19 years, 7 months ago) by root
Branch: MAIN
Changes since 1.2: +2 -1 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 using namespace std;
21 vector<gl::vertex_t2f_n3f_v3f> tmpvtx;
22 vector<GLushort> tmpidx;
23 list<geometry_indexed_2d*> models;
24 geometry_indexed_2d *geoid;
25 %}
26
27
28 %union {
29 char *ident;
30 char *string;
31 float num;
32 }
33
34
35 %token MODEL IAPO NODES SHADOWMODEL
36 %token <string> ID
37 %token <string> STRING
38 %token <num> NUMBER
39
40 %%
41
42 proc: ID sections
43 ;
44
45 sections: section
46 | sections section
47 ;
48 section: MODEL '{' STRING NUMBER '}'
49 | MODEL '{' STRING NUMBER surfaces '}'
50 | IAPO '{' NUMBER NUMBER pos '}'
51 | NODES '{' NUMBER nodes '}'
52 | SHADOWMODEL '{' STRING NUMBER NUMBER NUMBER NUMBER NUMBER mods modidxs '}'
53 ;
54
55 nodes: node
56 | nodes node
57 ;
58
59 node: '(' NUMBER NUMBER NUMBER NUMBER ')' NUMBER NUMBER
60 |
61 ;
62
63 pos: po
64 | pos po
65 ;
66
67 po: NUMBER NUMBER NUMBER pokla pokla pokla pokla
68 ;
69
70 poklas: pokla
71 | poklas pokla
72 ;
73
74 pokla: '(' NUMBER NUMBER NUMBER ')';
75 ;
76
77 mods: mod
78 | mods mod
79 ;
80
81 mod: '(' NUMBER NUMBER NUMBER ')'
82 |
83 ;
84
85 modidxs: modidx
86 | modidxs modidx
87 ;
88
89 modidx: NUMBER NUMBER NUMBER
90 ;
91
92 surfaces: surface
93 | surfaces surface
94 ;
95
96 surface: '{' STRING NUMBER NUMBER vertexes triangles '}'
97 {
98 geoid = new geometry_indexed_2d (testmat, GL_TRIANGLES, tmpvtx, tmpidx);
99 entity *e = new entity (geoid);
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, $3, $4), vec3 ($7, $8, $9), 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