ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/libgender/doom3map_parser.y++
Revision: 1.5
Committed: Sat Nov 6 01:56:20 2004 UTC (19 years, 7 months ago) by root
Branch: MAIN
Changes since 1.4: +3 -6 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 pokla: '(' NUMBER NUMBER NUMBER ')';
71 ;
72
73 mods: mod
74 | mods mod
75 ;
76
77 mod: '(' NUMBER NUMBER NUMBER ')'
78 |
79 ;
80
81 modidxs: modidx
82 | modidxs modidx
83 ;
84
85 modidx: NUMBER NUMBER NUMBER
86 ;
87
88 surfaces: surface
89 | surfaces surface
90 ;
91
92 surface: '{' STRING NUMBER NUMBER vertexes triangles '}'
93 {
94 geoid = new geometry_indexed_2d (testmat, GL_TRIANGLES, tmpvtx, tmpidx);
95 entity *e = new entity (geoid);
96 e->move (vec3 (1000,0,-1000));
97 e->show ();
98 tmpvtx.clear ();
99 tmpidx.clear ();
100 }
101 ;
102
103 vertexes: vertex
104 | vertexes vertex
105 ;
106
107 vertex: '(' NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER ')'
108 {
109 tmpvtx.push_back (vertex_t2f_n3f_v3f (point ($2, $4, $3), -vec3 ($7, $9, $8), tex2 ($5, $6)));
110 }
111 ;
112
113 triangles: triangle
114 | triangles triangle
115 ;
116
117 triangle: NUMBER NUMBER NUMBER {
118 tmpidx.push_back ((GLushort) $1);
119 tmpidx.push_back ((GLushort) $2);
120 tmpidx.push_back ((GLushort) $3);
121 }
122
123 %%
124
125 extern FILE *yyin;
126
127 bool doom3parse (const char *f) {
128 yyin = fopen (f, "r");
129 if (!yyin) return false;
130 yyparse ();
131 }
132