VTK  9.5.2
vtkVRMLImporter_Yacc.h
Go to the documentation of this file.
1// SPDX-FileCopyrightText: Copyright (c) Ken Martin, Will Schroeder, Bill Lorensen
2// SPDX-FileCopyrightText: Copyright (C) 1984, 1989, 1990 Free Software Foundation, Inc.
3// SPDX-FileCopyrightText: Copyright (C) 1996 Silicon Graphics, Inc.
4// SPDX-License-Identifier: BSD-3-Clause AND GPL-3.0 WITH Bison-exception-2.2
9
10#ifndef vtkVRMLImporter_Yacc_h
11#define vtkVRMLImporter_Yacc_h
12
13
14#include "vtkFloatArray.h"
15#include "vtkIdTypeArray.h"
16#include "vtkPoints.h"
17#include "vtkVRML.h"
18#include "vtkVRMLImporter.h"
19
20#include <cassert>
21#include <cstdio>
22#include <cstring>
23
24//
25// The VrmlNodeType class is responsible for storing information about node
26// or prototype types.
27//
28
29// used to hold the VRML DEF names and assoc vtkObjects
30VTK_ABI_NAMESPACE_BEGIN
32public:
33 vtkVRMLUseStruct( char *n, vtkObject *o) { defName = n; defObject = o; }
34 char *defName;
36
37 void* operator new(size_t n)
38 {
39 return vtkVRMLAllocator::AllocateMemory(n);
40 }
41
42 void operator delete(void *vtkNotUsed(ptr)) {}
43};
44
45
46
48public:
49 // Constructor. Takes name of new type (e.g. "Transform" or "Box")
50 // Copies the string given as name.
51 VrmlNodeType(const char *nm);
52
53 // Destructor exists mainly to deallocate storage for name
55
56 // Routines for adding/getting eventIns/Outs/fields
57 void addEventIn(const char *name, int type);
58 void addEventOut(const char *name, int type);
59 void addField(const char *name, int type);
60 void addExposedField(const char *name, int type);
61
62 int hasEventIn(const char *name) const;
63 int hasEventOut(const char *name) const;
64 int hasField(const char *name) const;
65 int hasExposedField(const char *name) const;
66
67 const char *getName() const { return name; }
68
69 void* operator new(size_t n)
70 {
71 return vtkVRMLAllocator::AllocateMemory(n);
72 }
73
74 void operator delete(void *vtkNotUsed(ptr)) {}
75
76 struct NameTypeRec {
77 char *name;
78 int type;
79
80 void* operator new(size_t n)
81 {
82 return vtkVRMLAllocator::AllocateMemory(n);
83 }
84
85 void operator delete(void *vtkNotUsed(ptr)) {}
86
87 };
88
89 // This is used to keep track of which field in which type of node is being
90 // parsed. Field are nested (nodes are contained inside MFNode/SFNode fields)
91 // so a stack of these is needed:
92 struct FieldRec
93 {
95 const char *fieldName;
96 };
97
98private:
99 void add(vtkVRMLVectorType<NameTypeRec*> &,const char *,int);
100 int has(const vtkVRMLVectorType<NameTypeRec*> &,const char *) const;
101
102 char *name;
103
104 vtkVRMLVectorType<NameTypeRec*> eventIns;
105 vtkVRMLVectorType<NameTypeRec*> eventOuts;
106 vtkVRMLVectorType<NameTypeRec*> fields;
107};
108
110{
111public:
114 typedef unsigned char YY_CHAR;
115 typedef int yy_state_type;
116private:
117 vtkVRMLYaccData(const vtkVRMLYaccData&) = delete;
118 vtkVRMLYaccData& operator=(const vtkVRMLYaccData&) = delete;
119public:
120 // Parser variables and functions:
121 // Currently-being-define proto. Prototypes may be nested, so a stack
122 // is needed:
123 vtkVRMLVectorType<VrmlNodeType*> *CurrentProtoStack;// = nullptr;
124
125 // Some helper routines defined below:
126 void beginProto(const char *);
127 void endProto();
128
129 int addField(const char *type, const char *name);
130 int addEventIn(const char *type, const char *name);
131 int addEventOut(const char *type, const char *name);
132 int addExposedField(const char *type, const char *name);
133 int add(void (VrmlNodeType::*)(const char *, int), const char *,
134 const char *);
135 int fieldType(const char *type);
136 void inScript();
137 void expect(int type);
138
139 void yyerror(const char *);
140 int yylex(vtkVRMLImporter* self);
141
142 class FakeAlloca;
143
144 typedef union {
145 char *string;
146
147 /* Other types that will be needed by a true VRML implementation
148 * (but are not defined by this parser due to the complexity):
149 * Node *node;
150 * list<Node *> *nodeList;
151 */
152
153 float sffloat;
157 int sfint;
158 float vec4f[4];
159 } YYSTYPE;
160
161
162 typedef
163 struct yyltype
164 {
170 char *text;
171 }
173
174
175 int yychar; /* the lookahead symbol */
176 YYSTYPE yylval; /* the semantic value of the */
177 /* lookahead symbol */
178 yyltype yylloc; /* location data for the lookahead */
179 /* symbol */
180 int yynerrs; /* number of parse errors so far */
181 // Lexer variables and functions:
183 FILE *yyin, *yyout;
184 int yywrap();
185
187 {
189
190 char *yy_ch_buf; /* input buffer */
191 char *yy_buf_pos; /* current position in input buffer */
192
193 /* Size of input buffer in bytes, not including room for EOB
194 * characters.
195 */
197
198 /* Number of characters read into yy_ch_buf, not including EOB
199 * characters.
200 */
202
203 /* Whether this is an "interactive" input source; if so, and
204 * if we're using stdio for input, then we want to use getc()
205 * instead of fread(), to make sure we stop fetching input after
206 * each newline.
207 */
209
210 /* Whether to try to fill the input buffer when we reach the
211 * end of it.
212 */
214
218 /* When an EOF's been seen but there's still some text to process
219 * then we mark the buffer as YY_EOF_PENDING, to indicate that we
220 * shouldn't try reading from the input source any more. We might
221 * still have a bunch of tokens to match, though, because of
222 * possible backing-up.
223 *
224 * When we actually see the EOF, we change the status to "new"
225 * (via yyrestart()), so that the user can continue scanning by
226 * just pointing yyin at a new input file.
227 */
229 };
231
232 };
234
236
237 /* yy_hold_char holds the character lost when yytext is formed. */
239
240 int yy_n_chars; /* number of characters read into yy_ch_buf */
241
242
243 /* Points to current character in buffer. */
244 char *yy_c_buf_p;// = (char *) 0;
245 int yy_init;// = 1; /* whether we need to initialize */
246 int yy_start;// = 0; /* start state number */
247
248 /* Flag which is used to allow yywrap()'s to do buffer switches
249 * instead of setting up a fresh yyin. A bit of a hack ...
250 */
252
253 void yyrestart ( FILE *input_file );
254 void yy_switch_to_buffer ( YY_BUFFER_STATE new_buffer );
255 void yy_load_buffer_state ();
256 YY_BUFFER_STATE yy_create_buffer ( FILE *file, int size );
258 void yy_init_buffer ( YY_BUFFER_STATE b, FILE *file );
259
260 void *yy_flex_alloc ( unsigned int );
261 void *yy_flex_realloc ( void *, unsigned int );
262 void yy_flex_free ( void * );
263
264 char *yytext;
265
268 int yy_get_next_buffer ();
269 void yy_fatal_error ( const char msg[] );
270
273
274 int yy_flex_debug;// = 1;
275
276 // used to reset the lexer input after initialization of VRML nodes
277 void (*theyyInput)(char *, int &, int, vtkVRMLYaccData*);
278
279
280 /* Current line number */
283
284 /* The YACC parser sets this to a token to direct the lexer */
285 /* in cases where just syntax isn't enough: */
286 int expectToken;// = 0;
287
288 /* True when parsing a multiple-valued field: */
289 int parsing_mf;// = 0;
290
291 /* These are used when parsing SFImage fields: */
294
295 int yydebug; /* nonzero means print parse trace */
296 int yyparse(vtkVRMLImporter* self);
297
298 static void memyyInput(char *buf, int &result, int max_size, vtkVRMLYaccData* self);
299 static void defyyInput(char *buf, int &result, int max_size, vtkVRMLYaccData* self);
300
301 int memyyInput_i;// = 0;
302 int memyyInput_j;// = 0;
303
304 // Used during the parsing
305 int creatingDEF;// = 0;
307
308 // Node types are stored in this data structure:
309 vtkVRMLVectorType<VrmlNodeType*>* typeList;
310 vtkVRMLVectorType<vtkVRMLUseStruct *>* useList;
311 vtkVRMLVectorType<VrmlNodeType::FieldRec*>* currentField;
312
313 // Moved from VrmlNodeType when getting rid of static data
314 //
315 // Namespace management functions. PROTO definitions add node types
316 // to the namespace. PROTO implementations are a separate node
317 // namespace, and require that any nested PROTOs NOT be available
318 // outside the PROTO implementation.
319 // addToNameSpace will print an error to stderr if the given type
320 // is already defined.
322 void pushNameSpace();
323 void popNameSpace();
324
325 // Find a node type, given its name. Returns nullptr if type is not defined.
326 const VrmlNodeType *find(const char *nm);
327
328};
329
330//------------------------------------------------------------------------------------
331//
332// Implementation of the above begins here
333//
334
335inline VrmlNodeType::VrmlNodeType(const char *nm)
336{
337 assert(nm != nullptr);
338 name = static_cast<char*>(
339 vtkVRMLAllocator::AllocateMemory((strlen(nm)+1)*sizeof(char)));
340 strcpy(name, nm);
341}
342
344{
345 // Free strings duplicated when fields/eventIns/eventOuts added:
346
347 int i;
348 for (i = 0;i < eventIns.Count(); i++)
349 {
350 NameTypeRec *r = eventIns[i];
351// free(r->name);
352 delete r;
353 }
354 for (i = 0;i < eventOuts.Count(); i++)
355 {
356 NameTypeRec *r = eventOuts[i];
357// free(r->name);
358 delete r;
359 }
360 for (i = 0;i < fields.Count(); i++)
361 {
362 NameTypeRec *r = fields[i];
363// free(r->name);
364 delete r;
365 }
366}
367inline void
368VrmlNodeType::addEventIn(const char *nodeName, int type)
369{
370 add(eventIns, nodeName, type);
371}
372inline void
373VrmlNodeType::addEventOut(const char *nodeName, int type)
374{
375 add(eventOuts, nodeName, type);
376}
377inline void
378VrmlNodeType::addField(const char *nodeName, int type)
379{
380 add(fields, nodeName, type);
381}
382inline void
383VrmlNodeType::addExposedField(const char *nodeName, int type)
384{
385 size_t length = 20 + strlen(nodeName);
386 std::vector<char> tmp(length);
387 add(fields, nodeName, type);
388 snprintf(tmp.data(), length, "set_%s", nodeName);
389 add(eventIns, tmp.data(), type);
390 snprintf(tmp.data(), length, "%s_changed", nodeName);
391 add(eventOuts, tmp.data(), type);
392}
393
394inline void
395VrmlNodeType::add(vtkVRMLVectorType<NameTypeRec*> &recs, const char *nodeName, int type)
396{
397 NameTypeRec *r = new NameTypeRec;
398 r->name = vtkVRMLAllocator::StrDup(nodeName); //strdup(nodeName);
399 r->type = type;
400 recs += r;
401}
402
403inline int
404VrmlNodeType::hasEventIn(const char *nodeName) const
405{
406 return has(eventIns, nodeName);
407}
408inline int
409VrmlNodeType::hasEventOut(const char *nodeName) const
410{
411 return has(eventOuts, nodeName);
412}
413inline int
414VrmlNodeType::hasField(const char *nodeName) const
415{
416 return has(fields, nodeName);
417}
418inline int
419VrmlNodeType::hasExposedField(const char *nodeName) const
420{
421 // Must have field "name", eventIn "set_name", and eventOut
422 // "name_changed", all with same type:
423 int type;
424 if ( (type = has(fields, nodeName)) == 0) return 0;
425
426 if (type != has(eventIns, nodeName)) return 0;
427
428 if (type != has(eventOuts, nodeName)) return 0;
429
430 return type;
431}
432inline int
433VrmlNodeType::has(const vtkVRMLVectorType<NameTypeRec*> &recs, const char *nodeName) const
434{
435 for (int i = 0;i < recs.Count(); i++)
436 {
437 NameTypeRec *n = recs.Get(i);
438 if (strcmp(n->name, nodeName) == 0)
439 return n->type;
440 }
441 return 0;
442}
443
444
445
446
447//----------------------------------------------------------------------------
449{
450 yy_current_buffer = nullptr;
451 yy_c_buf_p = nullptr;
452 yy_init = 1;
453 yy_start = 0;
454 yy_flex_debug = 1;
455 yyin = nullptr;
456 yyout = nullptr;
458 expectToken = 0;
459 parsing_mf = 0;
462 memyyInput_i = 0;
463 memyyInput_j = 0;
464 creatingDEF = 0;
465 theyyInput = nullptr;
466
467 typeList = nullptr;
468 useList = nullptr;
469 currentField = nullptr;
470}
471
472//----------------------------------------------------------------------------
481
482
484{
485 if (find(_type->getName()) != nullptr)
486 {
487 cerr << "PROTO " << _type->getName() << " already defined\n";
488 return;
489 }
490 *typeList += _type;
491}
492
493//
494// One list is used to store all the node types. Nested namespaces are
495// separated by nullptr elements.
496// This isn't terribly efficient, but it is nice and simple.
497//
499{
500 *typeList += (VrmlNodeType *) nullptr;
501}
502
504{
505 // Remove everything up to and including the next nullptr marker:
506 for (int i = 0;i < typeList->Count(); i++)
507 {
508 VrmlNodeType *nodeType = typeList->Pop();
509
510 if (nodeType == nullptr)
511 {
512 break;
513 }
514 else
515 {
516 // NOTE: Instead of just deleting the VrmlNodeTypes, you will
517 // probably want to reference count or garbage collect them, since
518 // any nodes created as part of the PROTO implementation will
519 // probably point back to their VrmlNodeType structure.
520 delete nodeType;
521 }
522 }
523}
524
525inline const VrmlNodeType* vtkVRMLYaccData::find(const char *_name)
526{
527 // Look through the type stack:
528 for (int i = 0;i < typeList->Count(); i++)
529 {
530 const VrmlNodeType *nt = (*typeList)[i];
531 if (nt != nullptr && strcmp(nt->getName(),_name) == 0)
532 {
533 return nt;
534 }
535 }
536 return nullptr;
537}
538
539
540// Begin of Auto-generated Parser Code
541
542
543/* A Bison parser, made from parser.y with Bison version GNU Bison version 1.24
544 */
545
546#define YYBISON 1 /* Identify Bison output. */
547
548#define IDENTIFIER 258
549#define DEF 259
550#define USE 260
551#define PROTO 261
552#define EXTERNPROTO 262
553#define TO 263
554#define IS 264
555#define ROUTE 265
556#define SFN_NULL 266
557#define EVENTIN 267
558#define EVENTOUT 268
559#define FIELD 269
560#define EXPOSEDFIELD 270
561#define SFBOOL 271
562#define SFCOLOR 272
563#define SFFLOAT 273
564#define SFIMAGE 274
565#define SFINT32 275
566#define SFNODE 276
567#define SFROTATION 277
568#define SFSTRING 278
569#define SFTIME 279
570#define SFVEC2F 280
571#define SFVEC3F 281
572#define MFCOLOR 282
573#define MFFLOAT 283
574#define MFINT32 284
575#define MFROTATION 285
576#define MFSTRING 286
577#define MFVEC2F 287
578#define MFVEC3F 288
579#define MFNODE 289
580
581
582
583//
584// Parser for VRML 2.0 files.
585// This is a minimal parser that does NOT generate an in-memory scene graph.
586//
587
588// The original parser was developed on a Windows 95 PC with
589// Borland's C++ 5.0 development tools. This was then ported
590// to a Windows 95 PC with Microsoft's MSDEV C++ 4.0 development
591// tools. The port introduced the ifdef's for
592// USING_BORLAND_CPP_5 : since this provides a "std namespace",
593// TWO_ARGUMENTS_FOR_STL_STACK : STL is a moving target. The stack template
594// class takes either one or two arguments.
595
596
597#define YYDEBUG 1
598
599VTK_ABI_NAMESPACE_END
600#include <stdlib.h>
601
602
603
604
605// This is used when the parser knows what kind of token it expects
606// to get next-- used when parsing field values (whose types are declared
607// and read by the parser) and at certain other places:
608//extern int expectToken;
609
610// Current line number (set by lexer)
611//extern int currentLineNumber;
612
613// Some helper routines defined below:
614//static void beginProto(const char *);
615//static void endProto();
616
617//static int addField(const char *type, const char *name);
618//static int addEventIn(const char *type, const char *name);
619//static int addEventOut(const char *type, const char *name);
620//static int addExposedField(const char *type, const char *name);
621//static int add(void (VrmlNodeType::*)(const char *, int), const char *,
622// const char *);
623//static int fieldType(const char *type);
624//static void inScript();
625//static void expect(int type);
626
627//void yyerror(const char *);
628//int yylex(vtkVRMLImporter* self);
629
630
631
632#ifndef YYLTYPE
633
634#define YYLTYPE yyltype
635#endif
636
637#define YYFINAL 128
638#define YYFLAG -32768
639#define YYNTBASE 40
640
641#define YYTRANSLATE(x) ((unsigned)(x) <= 289 ? yytranslate[x] : 68)
642
643static const char yytranslate[] = { 0,
644 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
645 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
646 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
647 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
648 2, 2, 2, 2, 2, 39, 2, 2, 2, 2,
649 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
650 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
651 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
652 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
653 35, 2, 36, 2, 2, 2, 2, 2, 2, 2,
654 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
655 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
656 2, 2, 37, 2, 38, 2, 2, 2, 2, 2,
657 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
658 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
659 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
660 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
661 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
662 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
663 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
664 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
665 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
666 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
667 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
668 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
669 2, 2, 2, 2, 2, 1, 2, 3, 4, 5,
670 6, 7, 8, 9, 10, 11, 12, 13, 14, 15,
671 16, 17, 18, 19, 20, 21, 22, 23, 24, 25,
672 26, 27, 28, 29, 30, 31, 32, 33, 34
673};
674
675#if YYDEBUG != 0
676static const short yyprhs[] = { 0,
677 0, 2, 3, 6, 8, 10, 12, 14, 15, 16,
678 22, 25, 27, 29, 30, 40, 41, 42, 51, 52,
679 55, 59, 63, 64, 70, 71, 77, 78, 81, 85,
680 89, 93, 97, 106, 107, 113, 114, 117, 118, 122,
681 124, 126, 130, 134, 135, 141, 147, 153, 155, 157,
682 159, 161, 163, 165, 167, 169, 171, 173, 175, 177,
683 179, 181, 183, 185, 187, 190, 193, 196, 199, 203,
684 205, 206
685};
686
687static const short yyrhs[] = { 41,
688 0, 0, 41, 42, 0, 43, 0, 46, 0, 58,
689 0, 59, 0, 0, 0, 4, 44, 3, 45, 59,
690 0, 5, 3, 0, 47, 0, 49, 0, 0, 6,
691 3, 48, 35, 52, 36, 37, 41, 38, 0, 0,
692 0, 7, 3, 50, 35, 56, 36, 51, 65, 0,
693 0, 52, 53, 0, 12, 3, 3, 0, 13, 3,
694 3, 0, 0, 14, 3, 3, 54, 65, 0, 0,
695 15, 3, 3, 55, 65, 0, 0, 56, 57, 0,
696 12, 3, 3, 0, 13, 3, 3, 0, 14, 3,
697 3, 0, 15, 3, 3, 0, 10, 3, 39, 3,
698 8, 3, 39, 3, 0, 0, 3, 60, 37, 61,
699 38, 0, 0, 61, 62, 0, 0, 3, 63, 65,
700 0, 58, 0, 46, 0, 12, 3, 3, 0, 13,
701 3, 3, 0, 0, 14, 3, 3, 64, 65, 0,
702 12, 3, 3, 9, 3, 0, 13, 3, 3, 9,
703 3, 0, 16, 0, 17, 0, 27, 0, 18, 0,
704 28, 0, 19, 0, 20, 0, 29, 0, 22, 0,
705 30, 0, 23, 0, 31, 0, 24, 0, 25, 0,
706 32, 0, 26, 0, 33, 0, 21, 43, 0, 21,
707 11, 0, 34, 66, 0, 9, 3, 0, 35, 67,
708 36, 0, 43, 0, 0, 67, 43, 0
709};
710
711#endif
712
713#if YYDEBUG != 0
714static const short yyrline[] = { 0,
715 106, 109, 111, 114, 116, 117, 120, 122, 123, 124,
716 125, 128, 130, 133, 135, 139, 141, 143, 145, 147,
717 150, 153, 155, 157, 158, 160, 163, 165, 168, 171,
718 173, 175, 179, 184, 186, 189, 191, 194, 196, 197,
719 198, 201, 202, 203, 206, 207, 209, 213, 215, 216,
720 217, 218, 219, 220, 221, 222, 223, 224, 225, 226,
721 227, 228, 229, 230, 232, 233, 234, 235, 238, 240,
722 243, 245
723};
724
725static const char * const yytname[] = { "$","error","$undefined.","IDENTIFIER",
726 "DEF","USE","PROTO","EXTERNPROTO","TO","IS","ROUTE","SFN_NULL","EVENTIN","EVENTOUT",
727 "FIELD","EXPOSEDFIELD","SFBOOL","SFCOLOR","SFFLOAT","SFIMAGE","SFINT32","SFNODE",
728 "SFROTATION","SFSTRING","SFTIME","SFVEC2F","SFVEC3F","MFCOLOR","MFFLOAT","MFINT32",
729 "MFROTATION","MFSTRING","MFVEC2F","MFVEC3F","MFNODE","'['","']'","'{'","'}'",
730 "'.'","vrmlscene","declarations","declaration","nodeDeclaration","@1","@2","protoDeclaration",
731 "proto","@3","externproto","@4","@5","interfaceDeclarations","interfaceDeclaration",
732 "@6","@7","externInterfaceDeclarations","externInterfaceDeclaration","routeDeclaration",
733 "node","@8","nodeGuts","nodeGut","@9","@10","fieldValue","mfnodeValue","nodes",
734 ""
735};
736#endif
737
738static const short yyr1[] = { 0,
739 40, 41, 41, 42, 42, 42, 43, 44, 45, 43,
740 43, 46, 46, 48, 47, 50, 51, 49, 52, 52,
741 53, 53, 54, 53, 55, 53, 56, 56, 57, 57,
742 57, 57, 58, 60, 59, 61, 61, 63, 62, 62,
743 62, 62, 62, 64, 62, 62, 62, 65, 65, 65,
744 65, 65, 65, 65, 65, 65, 65, 65, 65, 65,
745 65, 65, 65, 65, 65, 65, 65, 65, 66, 66,
746 67, 67
747};
748
749static const short yyr2[] = { 0,
750 1, 0, 2, 1, 1, 1, 1, 0, 0, 5,
751 2, 1, 1, 0, 9, 0, 0, 8, 0, 2,
752 3, 3, 0, 5, 0, 5, 0, 2, 3, 3,
753 3, 3, 8, 0, 5, 0, 2, 0, 3, 1,
754 1, 3, 3, 0, 5, 5, 5, 1, 1, 1,
755 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
756 1, 1, 1, 1, 2, 2, 2, 2, 3, 1,
757 0, 2
758};
759
760static const short yydefact[] = { 2,
761 1, 34, 8, 0, 0, 0, 0, 3, 4, 5,
762 12, 13, 6, 7, 0, 0, 11, 14, 16, 0,
763 36, 9, 0, 0, 0, 0, 0, 19, 27, 0,
764 38, 0, 0, 0, 35, 41, 40, 37, 10, 0,
765 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
766 0, 20, 0, 0, 0, 0, 17, 28, 0, 0,
767 48, 49, 51, 53, 54, 0, 56, 58, 60, 61,
768 63, 50, 52, 55, 57, 59, 62, 64, 0, 39,
769 42, 43, 44, 0, 0, 0, 0, 2, 0, 0,
770 0, 0, 0, 0, 68, 66, 65, 71, 70, 67,
771 0, 0, 0, 21, 22, 23, 25, 0, 29, 30,
772 31, 32, 18, 33, 0, 46, 47, 45, 0, 0,
773 15, 69, 72, 24, 26, 0, 0, 0
774};
775
776static const short yydefgoto[] = { 126,
777 1, 8, 9, 16, 27, 10, 11, 23, 12, 24,
778 93, 40, 52, 119, 120, 41, 58, 13, 14, 15,
779 26, 38, 43, 103, 80, 100, 115
780};
781
782static const short yypact[] = {-32768,
783 79,-32768,-32768, -1, 0, 3, 4,-32768,-32768,-32768,
784 -32768,-32768,-32768,-32768, -28, 11,-32768,-32768,-32768, -18,
785 -32768,-32768, -6, 5, 32, -2, 38,-32768,-32768, 35,
786 -32768, 39, 41, 45,-32768,-32768,-32768,-32768,-32768, 19,
787 66, 48, 43, 50, 51, 54, 84, 85, 87, 88,
788 55,-32768, 90, 91, 92, 93,-32768,-32768, 58, 95,
789 -32768,-32768,-32768,-32768,-32768, 34,-32768,-32768,-32768,-32768,
790 -32768,-32768,-32768,-32768,-32768,-32768,-32768,-32768, 23,-32768,
791 94, 96,-32768, 97, 98, 101, 103,-32768, 104, 105,
792 106, 107, 43, 108,-32768,-32768,-32768,-32768,-32768,-32768,
793 109, 110, 43,-32768,-32768,-32768,-32768, 12,-32768,-32768,
794 -32768,-32768,-32768,-32768, 20,-32768,-32768,-32768, 43, 43,
795 -32768,-32768,-32768,-32768,-32768, 99, 114,-32768
796};
797
798static const short yypgoto[] = {-32768,
799 27,-32768, -66,-32768,-32768, 100,-32768,-32768,-32768,-32768,
800 -32768,-32768,-32768,-32768,-32768,-32768,-32768, 102, 89,-32768,
801 -32768,-32768,-32768,-32768, -73,-32768,-32768
802};
803
804
805#define YYLAST 128
806
807
808static const short yytable[] = { 97,
809 31, 17, 18, 5, 6, 19, 20, 7, 21, 32,
810 33, 34, 99, 22, 2, 3, 4, 5, 6, 113,
811 25, 7, 2, 3, 4, 2, 3, 4, 28, 118,
812 47, 48, 49, 50, 30, 35, 2, 3, 4, 29,
813 2, 44, 42, 45, 96, 124, 125, 46, 123, 121,
814 59, 60, 81, 82, 51, 122, 83, 98, 61, 62,
815 63, 64, 65, 66, 67, 68, 69, 70, 71, 72,
816 73, 74, 75, 76, 77, 78, 79, 53, 54, 55,
817 56, 2, 3, 4, 5, 6, 84, 85, 7, 86,
818 87, 88, 89, 90, 91, 92, 94, 95, 127, 104,
819 105, 57, 101, 106, 102, 107, 109, 110, 111, 112,
820 114, 116, 117, 128, 108, 39, 0, 0, 0, 0,
821 0, 0, 0, 0, 0, 36, 0, 37
822};
823
824static const short yycheck[] = { 66,
825 3, 3, 3, 6, 7, 3, 3, 10, 37, 12,
826 13, 14, 79, 3, 3, 4, 5, 6, 7, 93,
827 39, 10, 3, 4, 5, 3, 4, 5, 35, 103,
828 12, 13, 14, 15, 3, 38, 3, 4, 5, 35,
829 3, 3, 8, 3, 11, 119, 120, 3, 115, 38,
830 3, 9, 3, 3, 36, 36, 3, 35, 16, 17,
831 18, 19, 20, 21, 22, 23, 24, 25, 26, 27,
832 28, 29, 30, 31, 32, 33, 34, 12, 13, 14,
833 15, 3, 4, 5, 6, 7, 3, 3, 10, 3,
834 3, 37, 3, 3, 3, 3, 39, 3, 0, 3,
835 3, 36, 9, 3, 9, 3, 3, 3, 3, 3,
836 3, 3, 3, 0, 88, 27, -1, -1, -1, -1,
837 -1, -1, -1, -1, -1, 26, -1, 26
838};
839/* -*-C-*- Note some compilers choke on comments on `#line' lines. */
840
841//extern int yylex(vtkVRMLImporter* self);
842//extern void yyerror();
843
844#include <list>
845//
846// This file was originally generated from a yacc grammar source
847// file, but subsequently it has been locally modified to suit
848// VTK's needs. The use of alloca -- part of the original parser
849// boilerplate became problematic because the confusing
850// preprocessor #defines with respect to alloca were causing
851// compile problems with newer versions of CLang.
852//
853// This class replaces alloca with a malloc-based allocator that
854// cleans up after itself when the FakeAlloca object goes out of
855// scope. Whatever performance penalty this incurs is minor and
856// would only be noticeably if a very large, deeply nested VRML
857// file was imported; in the real world, I think alloca was very
858// rarely called here.
859
860VTK_ABI_NAMESPACE_BEGIN
862{
863public:
864 typedef std::list<void *> list_type;
866 {
867 for(list_type::iterator it = this->m_allocs.begin();
868 it != this->m_allocs.end(); ++it)
869 {
870 free(*it);
871 }
872 }
873 void *Allocate(size_t size)
874 {
875 void *rval = malloc(size);
876 m_allocs.push_back(rval);
877 return rval;
878 }
879private:
880 list_type m_allocs;
881};
882/* This is the parser code that is written into each bison parser
883 when the %semantic_parser declaration is not specified in the grammar.
884 It was written by Richard Stallman by simplifying the hairy parser
885 used when %semantic_parser is specified. */
886
887/* Note: there must be only one dollar sign in this file.
888 It is replaced by the list of actions, each action
889 as one case of the switch. */
890
891#define yyerrok (yyerrstatus = 0)
892#define yyclearin (yychar = YYEMPTY)
893#define YYEMPTY -2
894#define YYEOF 0
895#define YYACCEPT return(0)
896#define YYABORT return(1)
897#define YYERROR goto yyerrlab1
898/* Like YYERROR except do call yyerror.
899 This remains here temporarily to ease the
900 transition to the new meaning of YYERROR, for GCC.
901 Once GCC version 2 has supplanted version 1, this can go. */
902#define YYFAIL goto yyerrlab
903#define YYRECOVERING() (!!yyerrstatus)
904#define YYBACKUP(token, value) \
905do \
906 if (yychar == YYEMPTY && yylen == 1) \
907 { yychar = (token), yylval = (value); \
908 yychar1 = YYTRANSLATE (yychar); \
909 YYPOPSTACK; \
910 goto yybackup; \
911 } \
912 else \
913 { yyerror ("syntax error: cannot back up"); YYERROR; } \
914while (0)
915
916#define YYTERROR 1
917#define YYERRCODE 256
918
919
920/* YYINITDEPTH indicates the initial size of the parser's stacks */
921
922#ifndef YYINITDEPTH
923#define YYINITDEPTH 200
924#endif
925
926/* YYMAXDEPTH is the maximum size the stacks can grow to
927 (effective only if the built-in stack extension method is used). */
928
929#if defined(YYMAXDEPTH) && (YYMAXDEPTH == 0)
930#undef YYMAXDEPTH
931#endif
932
933#ifndef YYMAXDEPTH
934#define YYMAXDEPTH 10000
935#endif
936
937static void
938yy_memcpy (char *from, char *to, int count)
939{
940 char *f = from;
941 char *t = to;
942 int i = count;
943
944 while (i-- > 0)
945 *t++ = *f++;
946}
947
948
950{
951 FakeAlloca yyallocator;
952 int yystate;
953 int yyn;
954 short *yyssp;
955 YYSTYPE *yyvsp;
956 int yyerrstatus; /* number of tokens to shift before error messages enabled */
957 int yychar1 = 0; /* lookahead token as an internal (translated) token number */
958
959 short yyssa[YYINITDEPTH]; /* the state stack */
960 YYSTYPE yyvsa[YYINITDEPTH]; /* the semantic value stack */
961
962 short *yyss = yyssa; /* refer to the stacks through separate pointers */
963 YYSTYPE *yyvs = yyvsa; /* to allow yyoverflow to reallocate them elsewhere */
964
965#ifdef YYLSP_NEEDED
966 YYLTYPE yylsa[YYINITDEPTH]; /* the location stack */
967 YYLTYPE *yyls = yylsa;
968 YYLTYPE *yylsp;
969
970#define YYPOPSTACK (yyvsp--, yyssp--, yylsp--)
971#else
972#define YYPOPSTACK (yyvsp--, yyssp--)
973#endif
974
975 int yystacksize = YYINITDEPTH;
976
977#ifdef YYPURE
978 int yychar;
980 int yynerrs;
981#ifdef YYLSP_NEEDED
983#endif
984#endif
985
986 YYSTYPE yyval; /* the variable used to return */
987 /* semantic values from the action */
988 /* routines */
989
990 int yylen;
991
992#if YYDEBUG != 0
993 if (yydebug)
994 fprintf(stderr, "Starting parse\n");
995#endif
996
997 yystate = 0;
998 yyerrstatus = 0;
999 yynerrs = 0;
1000 yychar = YYEMPTY; /* Cause a token to be read. */
1001
1002 /* Initialize stack pointers.
1003 Waste one element of value and location stack
1004 so that they stay on the same level as the state stack.
1005 The wasted elements are never initialized. */
1006
1007 yyssp = yyss - 1;
1008 yyvsp = yyvs;
1009#ifdef YYLSP_NEEDED
1010 yylsp = yyls;
1011#endif
1012
1013 /* Push a new state, which is found in yystate . */
1014 /* In all cases, when you get here, the value and location stacks
1015 have just been pushed. so pushing a state here evens the stacks. */
1016 yynewstate:
1017
1018 *++yyssp = yystate;
1019
1020 if (yyssp >= yyss + yystacksize - 1)
1021 {
1022 /* Give user a chance to reallocate the stack */
1023 /* Use copies of these so that the &'s don't force the real ones into memory. */
1024 YYSTYPE *yyvs1 = yyvs;
1025 short *yyss1 = yyss;
1026#ifdef YYLSP_NEEDED
1027 YYLTYPE *yyls1 = yyls;
1028#endif
1029
1030 /* Get the current used size of the three stacks, in elements. */
1031 int size = yyssp - yyss + 1;
1032
1033#ifdef yyoverflow
1034 /* Each stack pointer address is followed by the size of
1035 the data in use in that stack, in bytes. */
1036#ifdef YYLSP_NEEDED
1037 /* This used to be a conditional around just the two extra args,
1038 but that might be undefined if yyoverflow is a macro. */
1039 yyoverflow("parser stack overflow",
1040 &yyss1, size * sizeof (*yyssp),
1041 &yyvs1, size * sizeof (*yyvsp),
1042 &yyls1, size * sizeof (*yylsp),
1043 &yystacksize);
1044#else
1045 yyoverflow("parser stack overflow",
1046 &yyss1, size * sizeof (*yyssp),
1047 &yyvs1, size * sizeof (*yyvsp),
1048 &yystacksize);
1049#endif
1050
1051 yyss = yyss1; yyvs = yyvs1;
1052#ifdef YYLSP_NEEDED
1053 yyls = yyls1;
1054#endif
1055#else /* no yyoverflow */
1056 /* Extend the stack our own way. */
1057 if (yystacksize >= YYMAXDEPTH)
1058 {
1059 yyerror("parser stack overflow");
1060 return 2;
1061 }
1062 yystacksize *= 2;
1063 if (yystacksize > YYMAXDEPTH)
1064 yystacksize = YYMAXDEPTH;
1065 yyss = (short *) yyallocator.Allocate (yystacksize * sizeof (*yyssp));
1066 yy_memcpy ((char *)yyss1, (char *)yyss, size * sizeof (*yyssp));
1067 yyvs = (YYSTYPE *) yyallocator.Allocate (yystacksize * sizeof (*yyvsp));
1068 yy_memcpy ((char *)yyvs1, (char *)yyvs, size * sizeof (*yyvsp));
1069#ifdef YYLSP_NEEDED
1070 yyls = (YYLTYPE *) yyallocator.Allocate (yystacksize * sizeof (*yylsp));
1071 yy_memcpy ((char *)yyls1, (char *)yyls, size * sizeof (*yylsp));
1072#endif
1073#endif /* no yyoverflow */
1074
1075 yyssp = yyss + size - 1;
1076 yyvsp = yyvs + size - 1;
1077#ifdef YYLSP_NEEDED
1078 yylsp = yyls + size - 1;
1079#endif
1080
1081#if YYDEBUG != 0
1082 if (yydebug)
1083 fprintf(stderr, "Stack size increased to %d\n", yystacksize);
1084#endif
1085
1086 if (yyssp >= yyss + yystacksize - 1)
1087 YYABORT;
1088 }
1089
1090#if YYDEBUG != 0
1091 if (yydebug)
1092 fprintf(stderr, "Entering state %d\n", yystate);
1093#endif
1094
1095 goto yybackup;
1096 yybackup:
1097
1098 /* Do appropriate processing given the current state. */
1099 /* Read a lookahead token if we need one and don't already have one. */
1100 /* yyresume: */
1101
1102 /* First try to decide what to do without reference to lookahead token. */
1103
1104 yyn = yypact[yystate];
1105 if (yyn == YYFLAG)
1106 goto yydefault;
1107
1108 /* Not known => get a lookahead token if don't already have one. */
1109
1110 /* yychar is either YYEMPTY or YYEOF
1111 or a valid token in external form. */
1112
1113 if (yychar == YYEMPTY)
1114 {
1115#if YYDEBUG != 0
1116 if (yydebug)
1117 fprintf(stderr, "Reading a token: ");
1118#endif
1119 yychar = yylex(self);
1120 }
1121
1122 /* Convert token to internal form (in yychar1) for indexing tables with */
1123
1124 if (yychar <= 0) /* This means end of input. */
1125 {
1126 yychar1 = 0;
1127 yychar = YYEOF; /* Don't call YYLEX any more */
1128
1129#if YYDEBUG != 0
1130 if (yydebug)
1131 fprintf(stderr, "Now at end of input.\n");
1132#endif
1133 }
1134 else
1135 {
1136 yychar1 = YYTRANSLATE(yychar);
1137
1138#if YYDEBUG != 0
1139 if (yydebug)
1140 {
1141 fprintf (stderr, "Next token is %d (%s", yychar, yytname[yychar1]);
1142 /* Give the individual parser a way to print the precise meaning
1143 of a token, for further debugging info. */
1144#ifdef YYPRINT
1145 YYPRINT (stderr, yychar, yylval);
1146#endif
1147 fprintf (stderr, ")\n");
1148 }
1149#endif
1150 }
1151
1152 yyn += yychar1;
1153 if (yyn < 0 || yyn > YYLAST || yycheck[yyn] != yychar1)
1154 goto yydefault;
1155
1156 yyn = yytable[yyn];
1157
1158 /* yyn is what to do for this token type in this state.
1159 Negative => reduce, -yyn is rule number.
1160 Positive => shift, yyn is new state.
1161 New state is final state => don't bother to shift,
1162 just return success.
1163 0, or most negative number => error. */
1164
1165 if (yyn < 0)
1166 {
1167 if (yyn == YYFLAG)
1168 goto yyerrlab;
1169 yyn = -yyn;
1170 goto yyreduce;
1171 }
1172 else if (yyn == 0)
1173 goto yyerrlab;
1174
1175 if (yyn == YYFINAL)
1176 YYACCEPT;
1177
1178 /* Shift the lookahead token. */
1179
1180#if YYDEBUG != 0
1181 if (yydebug)
1182 fprintf(stderr, "Shifting token %d (%s), ", yychar, yytname[yychar1]);
1183#endif
1184
1185 /* Discard the token being shifted unless it is eof. */
1186 if (yychar != YYEOF)
1187 yychar = YYEMPTY;
1188
1189 *++yyvsp = yylval;
1190#ifdef YYLSP_NEEDED
1191 *++yylsp = yylloc;
1192#endif
1193
1194 /* count tokens shifted since error; after three, turn off error status. */
1195 if (yyerrstatus) yyerrstatus--;
1196
1197 yystate = yyn;
1198 goto yynewstate;
1199
1200 /* Do the default action for the current state. */
1201 yydefault:
1202
1203 yyn = yydefact[yystate];
1204 if (yyn == 0)
1205 goto yyerrlab;
1206
1207 /* Do a reduction. yyn is the number of a rule to reduce with. */
1208 yyreduce:
1209 yylen = yyr2[yyn];
1210 if (yylen > 0)
1211 yyval = yyvsp[1-yylen]; /* implement default value of the action */
1212 else
1213 yyval.sfint = 0;
1214
1215#if YYDEBUG != 0
1216 if (yydebug)
1217 {
1218 int i;
1219
1220 fprintf (stderr, "Reducing via rule %d (line %d), ",
1221 yyn, yyrline[yyn]);
1222
1223 /* Print the symbols being reduced, and their result. */
1224 for (i = yyprhs[yyn]; yyrhs[i] > 0; i++)
1225 fprintf (stderr, "%s ", yytname[yyrhs[i]]);
1226 fprintf (stderr, " -> %s\n", yytname[yyr1[yyn]]);
1227 }
1228#endif
1229
1230
1231 // Note: several free() methods are commented out due to the use of
1232 // vtkVRMLAllocator.
1233 switch (yyn) {
1234
1235 case 8:
1236 { creatingDEF = 1;
1237 break;}
1238 case 9:
1239 { curDEFName = yyvsp[0].string;
1240 break;}
1241 case 10:
1242 { creatingDEF = 0;
1243 break;}
1244 case 11:
1245 { self->useNode(yyvsp[0].string);//free(yyvsp[0].string); ;
1246 break;}
1247 case 14:
1248 { beginProto(yyvsp[0].string);
1249 break;}
1250 case 15:
1251 { endProto(); //free(yyvsp[-7].string);
1252 break;}
1253 case 16:
1254 { beginProto(yyvsp[0].string);
1255 break;}
1256 case 17:
1257 { expect(MFSTRING);
1258 break;}
1259 case 18:
1260 { endProto(); //free(yyvsp[-6].string); ;
1261 break;}
1262 case 21:
1263 { addEventIn(yyvsp[-1].string, yyvsp[0].string);
1264 //free(yyvsp[-1].string); free(yyvsp[0].string); ;
1265 break;}
1266 case 22:
1267 { addEventOut(yyvsp[-1].string, yyvsp[0].string);
1268 //free(yyvsp[-1].string); free(yyvsp[0].string); ;
1269 break;}
1270 case 23: