1 %{
2 //////////////////////////////////////////////////////////////////////
3 //
4 // Pixie
5 //
6 // Copyright � 1999 - 2003, Okan Arikan
7 //
8 // Contact: okan@cs.utexas.edu
9 //
10 // This library is free software; you can redistribute it and/or
11 // modify it under the terms of the GNU Lesser General Public
12 // License as published by the Free Software Foundation; either
13 // version 2.1 of the License, or (at your option) any later version.
14 //
15 // This library is distributed in the hope that it will be useful,
16 // but WITHOUT ANY WARRANTY; without even the implied warranty of
17 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
18 // Lesser General Public License for more details.
19 //
20 // You should have received a copy of the GNU Lesser General Public
21 // License along with this library; if not, write to the Free Software
22 // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
23 //
24 ///////////////////////////////////////////////////////////////////////
25 ///////////////////////////////////////////////////////////////////////
26 //
27 // File : variable.y
28 // Classes : -
29 // Description : Parse a variable declaration
30 //
31 ////////////////////////////////////////////////////////////////////////
32 #undef alloca
33 #include <math.h>
34
35 #include "common/global.h"
36 #include "common/containers.h"
37 #include "renderer.h"
38 #include "error.h"
39 #include "ri_config.h"
40
41 // Some forward definitions
42 void varerror(const char *); // Forward definition for stupid yacc
43 int varlex(void ); // Forward definition for stupid yacc
44
45 static CVariable *currentVariable;
46 static const char *currentName;
47 static const char *currentDecl;
48 %}
49 %union varval {
50 float real;
51 }
52 %token VAR_GLOBAL
53 %token VAR_CONSTANT
54 %token VAR_UNIFORM
55 %token VAR_VARYING
56 %token VAR_FACEVARYING
57 %token VAR_VERTEX
58 %token VAR_INTEGER
59 %token VAR_VECTOR
60 %token VAR_COLOR
61 %token VAR_NORMAL
62 %token VAR_POINT
63 %token VAR_HTPOINT
64 %token VAR_MATRIX
65 %token VAR_DOUBLE
66 %token VAR_STRING
67 %token VAR_OPEN
68 %token VAR_CLOSE
69 %token<real> VAR_FLOAT
70 %token VAR_IDENTIFIER
71 %%
72 start: varStorage
73 varType
74 varItems
75 varName
76 {
77 }
78 ;
79
80 varGlobalMarker:
81 VAR_GLOBAL
82 {
83 currentVariable->storage = STORAGE_GLOBAL;
84 }
85 |
86 {
87 currentVariable->storage = STORAGE_NONE;
88 }
89 ;
90
91 varStorage: varGlobalMarker
92 VAR_CONSTANT
93 {
94 currentVariable->container = CONTAINER_CONSTANT;
95 }
96 |
97 varGlobalMarker
98 VAR_UNIFORM
99 {
100 currentVariable->container = CONTAINER_UNIFORM;
101 }
102 |
103 varGlobalMarker
104 VAR_VARYING
105 {
106 currentVariable->container = CONTAINER_VARYING;
107 }
108 |
109 varGlobalMarker
110 VAR_FACEVARYING
111 {
112 currentVariable->container = CONTAINER_FACEVARYING;
113 }
114 |
115 varGlobalMarker
116 VAR_VERTEX
117 {
118 currentVariable->container = CONTAINER_VERTEX;
119 }
120 |
121 varGlobalMarker
122 {
123 currentVariable->container = CONTAINER_VERTEX; // The defa
124 }
125 ;
126
127 varType: VAR_INTEGER
128 {
129 currentVariable->type = TYPE_INTEGER;
130 currentVariable->numFloats = 1;
131 }
132 |
133 VAR_FLOAT
134 {
135 currentVariable->type = TYPE_FLOAT;
136 currentVariable->numFloats = 1;
137 }
138 |
139 VAR_VECTOR
140 {
141 currentVariable->type = TYPE_VECTOR;
142 currentVariable->numFloats = 3;
143 }
144 |
145 VAR_COLOR
146 {
147 currentVariable->type = TYPE_COLOR;
148 currentVariable->numFloats = 3;
149 }
150 |
151 VAR_NORMAL
152 {
153 currentVariable->type = TYPE_NORMAL;
154 currentVariable->numFloats = 3;
155 }
156 |
157 VAR_POINT
158 {
159 currentVariable->type = TYPE_POINT;
160 currentVariable->numFloats = 3;
161 }
162 |
163 VAR_MATRIX
164 {
165 currentVariable->type = TYPE_MATRIX;
166 currentVariable->numFloats = 16;
167 }
168 |
169 VAR_HTPOINT
170 {
171 currentVariable->type = TYPE_QUAD;
172 currentVariable->numFloats = 4;
173 }
174 |
175 VAR_DOUBLE
176 {
177 currentVariable->type = TYPE_DOUBLE;
178 currentVariable->numFloats = 2;
179 }
180 |
181 VAR_STRING
182 {
183 currentVariable->type = TYPE_STRING;
184 currentVariable->numFloats = 1;
185 }
186 ;
187
188 varName: VAR_IDENTIFIER
189 |
190 {
191 strcpy(currentVariable->name,"");
192 }
193 ;
194
195 varItems: VAR_OPEN
196 VAR_FLOAT
197 VAR_CLOSE
198 {
199 currentVariable->numItems = (int) $2;
200 currentVariable->numFloats *= currentVariable->numItems;
201 }
202 |
203 {
204 currentVariable->numItems = 1;
205 }
206 ;
207 %%
208
209 #include "lex.var.cpp"
210
211 static int numErrors = 0;
212
varerror(const char * str)213 void varerror(const char *str) {
214 //error(CODE_BADTOKEN,"Variable declaration error \"%s\" \"%s\"\n",(currentName == NULL ? "NULL" : currentName),currentDecl);
215 numErrors++;
216 }
217
218
219 ///////////////////////////////////////////////////////////////////////
220 // Function : sfParseVariable
221 // Description : Parse a variable but do not commit it into the global variables
222 // Return Value :
223 // Comments :
parseVariable(CVariable * var,const char * name,const char * decl)224 int parseVariable(CVariable *var,const char *name,const char *decl) {
225 CVariable *savedVariable;
226 const char *savedName;
227 const char *savedDecl;
228
229 YY_BUFFER_STATE savedState = YY_CURRENT_BUFFER;
230 YY_BUFFER_STATE newState;
231
232 numErrors = 0;
233
234 savedVariable = currentVariable;
235 savedName = currentName;
236 savedDecl = currentDecl;
237
238 currentVariable = var;
239 if (name != NULL)
240 currentName = name;
241 currentDecl = decl;
242
243 newState = var_scan_string(decl);
244 varparse();
245 var_delete_buffer(newState);
246
247 var_switch_to_buffer( savedState );
248
249 currentVariable = savedVariable;
250 currentName = savedName;
251 currentDecl = savedDecl;
252
253 if (numErrors == 0) {
254 if (name != NULL) strcpy(var->name,name);
255 return TRUE;
256 }
257
258 return FALSE;
259 }
260
261