readtensegrity.l
Go to the documentation of this file.
1 %{
2 /*
3 * Lexical analizer for tensegrity files
4 */
5 
8 #include <stdlib.h>
9 #include <string.h>
10 #include "defines.h"
11 #include "error_tensegrity.h"
12 #include "color.h" /* Tcolor used in %union */
13 #include "interval.h" /* Tinterval used in %union */
14 #include "htransform.h" /* Tinterval used in %union */
15 #include "readtensegrity.tab.h"
16 
17 int ReadTensegritylex(void);
18 
19 extern unsigned int RTline; /*current line number (declared in the YACC module and updated here)*/
20 
21 %}
22 %s IN_COMMENT
23 
24 EMPTY [ \t]+
25 RETURN \n
26 DIGIT [0-9]
27 LETTER [a-zA-Z]
28 R_NUMBER (({DIGIT}+(\.{DIGIT}+)?)|(\.{DIGIT}+))((E|e)[+-]?{DIGIT}+)?
29 I_NUMBER {DIGIT}+
30 STRING \"[^\"]+\"
31 IDENTIFIER {LETTER}({DIGIT}|{LETTER}|"_")*
32 COMMENT \%[^\n]*
33 COMMENT2 \#[^\n]*
34 COMMENT3 \/\/[^\n]*
35 
36 %%
37 {COMMENT} { }
38 {COMMENT2} { }
39 {COMMENT3} { }
40 
41 <INITIAL>{
42  "/*" BEGIN(IN_COMMENT);
43 }
44 <IN_COMMENT>{
45  "*/" BEGIN(INITIAL);
46  [^*\n]+ // eat comment in chunks
47  "*" // eat the lone star
48  \n RTline++;
49 }
50 
51 {EMPTY} { }
52 
53 {RETURN} { RTline++; }
54 
55 "[CONSTANTS]" {
56  return(_CONSTANTS);
57  }
58 
59 ":=" {
60  return(_ASSIGN);
61  }
62 
63 "==" {
64  return(_EQUAL);
65  }
66 
67 "!=" {
68  return(_NOT_EQUAL);
69  }
70 
71 "<=" {
72  return(_LESS_EQUAL);
73  }
74 
75 ">=" {
76  return(_GREATER_EQUAL);
77  }
78 
79 "<" {
80  return(_LESS);
81  }
82 
83 ">" {
84  return(_GREATER);
85  }
86 
87 PI {
88  return(_PI);
89  }
90 
91 EXP {
92  return(_EXP);
93  }
94 
95 PARAMETER {
96  return(_PARAMETER);
97  }
98 
99 SIN {
100  return(_SIN);
101  }
102 
103 COS {
104  return(_COS);
105  }
106 
107 TAN {
108  return(_TAN);
109  }
110 
111 COT {
112  return(_COT);
113  }
114 
115 ACOS {
116  return(_ACOS);
117  }
118 
119 ASIN {
120  return(_ASIN);
121  }
122 
123 ATAN {
124  return(_ATAN);
125  }
126 
127 ATAN2 {
128  return(_ATAN2);
129  }
130 
131 SQRT {
132  return(_SQRT);
133  }
134 
135 ABS {
136  return(_ABS);
137  }
138 
139 PRINT {
140  return(_PRINT);
141  }
142 
143 TX {
144  return(_TX);
145  }
146 
147 TY {
148  return(_TY);
149  }
150 
151 TZ {
152  return(_TZ);
153  }
154 
155 RX {
156  return(_RX);
157  }
158 
159 RY {
160  return(_RY);
161  }
162 
163 RZ {
164  return(_RZ);
165  }
166 
167 "PLANAR" {
168  return(_PLANAR);
169  }
170 
171 "FREE" {
172  return(_FREE);
173  }
174 
175 "FLYING" {
176  return(_FLYING);
177  }
178 
179 "STRUCTURE" {
180  return(_STRUCTURE);
181  }
182 
183 "STRUT" {
184  return(_STRUT);
185  }
186 
187 "BAR" {
188  return(_BAR);
189  }
190 
191 "PRISMATIC" {
192  return(_PRISMATIC);
193  }
194 
195 "CABLE" {
196  return(_CABLE);
197  }
198 
199 "SPRING" {
200  return(_SPRING);
201  }
202 
203 "LOOPS" {
204  return(_LOOPS);
205  }
206 
207 "STIFFNESS" {
208  return(_STIFFNESS);
209  }
210 
211 "REST" {
212  return(_REST);
213  }
214 
215 "FORCE" {
216  return(_FORCE);
217  }
218 
219 "GRANULARITY" {
220  return(_GRANULARITY);
221  }
222 
223 "HIDDEN" {
224  return(_HIDDEN);
225  }
226 
227 "DECORATION" {
228  return(_DECORATION);
229  }
230 
231 "[COUPLE]" {
232  return(_COUPLE);
233  }
234 
235 "ORIENTATION" {
236  return(_ORIENTATION);
237  }
238 
239 "[FORCES]" {
240  return(_FORCES);
241  }
242 
243 "[ADDONS]" {
244  return(_ADDONS);
245  }
246 
247 "NO" {
248  return(_NO);
249  }
250 
251 "NULL" {
252  return(_NULL);
253  }
254 
255 "[FIXED POINTS]" {
256  return(_FIXED_POINTS);
257  }
258 
259 "X" {
260  return(_X);
261  }
262 
263 "Y" {
264  return(_Y);
265  }
266 
267 "Z" {
268  return(_Z);
269  }
270 
271 "[OBSTACLES]" {
272  return(_OBSTACLES);
273  }
274 
275 "BODY" {
276  return(_BODY);
277  }
278 
279 "LENGTH" {
280  return(_LENGTH);
281  }
282 
283 "RADIUS" {
284  return(_RADIUS);
285  }
286 
287 "BOX" {
288  return(_BOX);
289  }
290 
291 "PRISM" {
292  return(_PRISM);
293  }
294 
295 "SPHERE" {
296  return(_SPHERE);
297  }
298 
299 "CYLINDER" {
300  return(_CYLINDER);
301  }
302 
303 "COLOR" {
304  return(_COLOR);
305  }
306 
307 "RED" {
308  return(_RED);
309  }
310 
311 "GREEN" {
312  return(_GREEN);
313  }
314 
315 "BLUE" {
316  return(_BLUE);
317  }
318 
319 "WHITE" {
320  return(_WHITE);
321  }
322 
323 "BLACK" {
324  return(_BLACK);
325  }
326 
327 "GREY" {
328  return(_GREY);
329  }
330 
331 "YELLOW" {
332  return(_YELLOW);
333  }
334 
335 "CYAN" {
336  return(_CYAN);
337  }
338 
339 "PURPLE" {
340  return(_PURPLE);
341  }
342 
343 "[COLLISIONS]" {
344  return(_COLLISIONS);
345  }
346 
347 "CHECK" {
348  return(_CHECK);
349  }
350 
351 "DO" {
352  return(_DO);
353  }
354 
355 "NOT" {
356  return(_NOT);
357  }
358 
359 "ALL" {
360  return(_ALL);
361  }
362 
363 "CONNECTED" {
364  return(_CONNECTED);
365  }
366 
367 {I_NUMBER} {
368  char string_tmp[100];
369 
370  memcpy(string_tmp,ReadTensegritytext,(unsigned int)ReadTensegrityleng);
371  string_tmp[ReadTensegrityleng]=0;
372  ReadTensegritylval.int_number=atoi(string_tmp);
373  return(_INTEGER);
374  }
375 
376 {R_NUMBER} {
377  char string_tmp[100];
378 
379  memcpy(string_tmp,ReadTensegritytext,(unsigned int)ReadTensegrityleng);
380  string_tmp[ReadTensegrityleng]=0;
381  ReadTensegritylval.real_number=atof(string_tmp);
382 
383  return(_REAL);
384  }
385 
386 {STRING} {
387  NEW(ReadTensegritylval.string,ReadTensegrityleng,char);
388 
389  memcpy(ReadTensegritylval.string,&(ReadTensegritytext[1]),(unsigned int)ReadTensegrityleng-2);
390  ReadTensegritylval.string[ReadTensegrityleng-2]=0;
391 
392  return(_STRING);
393  }
394 
395 {IDENTIFIER} {
396  NEW(ReadTensegritylval.id,ReadTensegrityleng+1,char);
397  memcpy(ReadTensegritylval.id,ReadTensegritytext,(unsigned int)ReadTensegrityleng);
398 
399  ReadTensegritylval.id[ReadTensegrityleng]=0;
400 
401  return(_IDENTIFIER);
402  }
403 
404 . { return(ReadTensegritytext[0]); }
405 
406 %%
407 
408 /*
409  * This function is automatically called by the parser at the end of a file.
410  * If 1 is returned the lexical analysis is stopped.
411  */
412 int ReadTensegritywrap()
413 {
414  return(1);
415 }
416 
#define PURPLE
Purple.
Definition: color.h:72
Error function specific of the tensegrity parser.
#define BLUE
Blue.
Definition: color.h:37
#define BAR
One of the possible types of legs.
Definition: world.h:142
unsigned int RTline
Number of the line currently parsed when reading a .tensegrity file.
#define STRUT
One of the possible types of legs.
Definition: world.h:134
#define CYLINDER
One of the possible type of polyhedrons.
Definition: polyhedron.h:80
#define WHITE
White.
Definition: color.h:58
#define BLACK
Black.
Definition: color.h:44
Definitions of constants and macros used in several parts of the cuik library.
#define YELLOW
Yellow.
Definition: color.h:65
#define GREEN
Green.
Definition: color.h:30
#define GREY
Grey.
Definition: color.h:51
Definition of the THTransform type and the associated functions.
#define SPHERE
One of the possible type of polyhedrons.
Definition: polyhedron.h:70
Definition of the Tcolor type and the associated functions.
#define CYAN
Cyan.
Definition: color.h:79
#define CABLE
One of the possible types of legs.
Definition: world.h:150
#define RED
Red.
Definition: color.h:23
#define SPRING
One of the possible types of legs.
Definition: world.h:159
Definition of the Tinterval type and the associated functions.