FreeWRL / FreeX3D 4.3.0
CParseLexer.h
1/*
2
3
4Lexer (input of terminal symbols) for CParse
5
6Tables of user-defined IDs: userNodeNames (DEFs) is scoped with a
7simple stack, as every PROTO has its scope completely *different* from
8the rest of the world. userNodeTypes (PROTO definitions) needs to be
9available up through the whole stack, values are stored in a vector,
10and the indices where each stack level ends are stored in a stack.
11fields are not scoped and therefore stored in a simple vector.
12
13*/
14
15/****************************************************************************
16 This file is part of the FreeWRL/FreeX3D Distribution.
17
18 Copyright 2009 CRC Canada. (http://www.crc.gc.ca)
19
20 FreeWRL/FreeX3D is free software: you can redistribute it and/or modify
21 it under the terms of the GNU Lesser Public License as published by
22 the Free Software Foundation, either version 3 of the License, or
23 (at your option) any later version.
24
25 FreeWRL/FreeX3D is distributed in the hope that it will be useful,
26 but WITHOUT ANY WARRANTY; without even the implied warranty of
27 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
28 GNU General Public License for more details.
29
30 You should have received a copy of the GNU General Public License
31 along with FreeWRL/FreeX3D. If not, see <http://www.gnu.org/licenses/>.
32****************************************************************************/
33
34
35#ifndef __FREEWRL_CPARSE_LEXER_H__
36#define __FREEWRL_CPARSE_LEXER_H__
37
38/* for Stack typedef */
39#include "../scenegraph/Vector.h"
40
41/* Undefined ID (for special "class", like builtIn and exposed) */
42#ifdef ID_UNDEFINED
43#undef ID_UNDEFINED
44#endif
45#define ID_UNDEFINED -1
46
47#define LEXER_INPUT_STACK_MAX 16
48
49/* This is our lexer-object. */
51{
52 char* nextIn; /* Next input character. */
53 char* startOfStringPtr[LEXER_INPUT_STACK_MAX]; /* beginning address of string, for FREE calls */
54 char* curID; /* Currently input but not lexed id. */
55 BOOL isEof; /* Error because of EOF? */
56
57 int lexerInputLevel; /* which level are we at? used for putting PROTO expansions into the input stream, etc */
58 char *oldNextIn[LEXER_INPUT_STACK_MAX]; /* old nextIn pointer, before the push */
59
60 Stack* userNodeNames;
61 struct Vector* userNodeTypesVec;
62 Stack* userNodeTypesStack;
63 struct Vector* user_initializeOnly;
64 struct Vector* user_inputOutput;
65 struct Vector* user_inputOnly;
66 struct Vector* user_outputOnly;
67};
68
69/* Constructor and destructor */
70struct VRMLLexer* newLexer();
71void deleteLexer(struct VRMLLexer*);
72
73/* Other clean up. */
74void lexer_destroyData(struct VRMLLexer* me);
75void lexer_destroyIdStack(Stack*);
76
77/* Count of elements to pop off the PROTO vector for scope-out */
78#define lexer_getProtoPopCnt(me) \
79 (vectorSize(me->userNodeTypesVec)-stack_top(int, me->userNodeTypesStack))
80
81/* Set input */
82void lexer_fromString (struct VRMLLexer *, char *);
83void lexer_forceStringCleanup (struct VRMLLexer *me);
84
85/* Is EOF? */
86#define lexer_eof(me) \
87 ((me)->isEof && !(me)->curID)
88
89/* int index -> char* conversion */
90#define lexer_stringUFieldName(me, index, type) \
91 vector_get(char*, me->user_##type, index)
92#define lexer_stringUser_initializeOnly(me, index) \
93 lexer_stringUFieldName(me, index, initializeOnly)
94#define lexer_stringUser_inputOutput(me, index) \
95 lexer_stringUFieldName(me, index, inputOutput)
96#define lexer_stringUser_inputOnly(me, index) \
97 lexer_stringUFieldName(me, index, inputOnly)
98#define lexer_stringUser_outputOnly(me, index) \
99 lexer_stringUFieldName(me, index, outputOnly)
100/* User field name -> char*, takes care of access mode */
101const char* lexer_stringUser_fieldName(struct VRMLLexer* me, int name, int mode);
102
103/* Skip whitespace and comments. */
104void lexer_skip(struct VRMLLexer*);
105
106/* Ensures that curID is set. */
107BOOL lexer_setCurID(struct VRMLLexer*);
108
109/* Some operations with IDs */
110void lexer_scopeIn(struct VRMLLexer*);
111void lexer_scopeOut(struct VRMLLexer*);
112void lexer_scopeOut_PROTO(struct VRMLLexer*);
113BOOL lexer_keyword(struct VRMLLexer*, int);
114BOOL lexer_specialID(struct VRMLLexer*, int* retB, int* retU,
115 const char**, const int, struct Vector*);
116BOOL lexer_specialID_string(struct VRMLLexer*, int* retB, int* retU,
117 const char**, const int, struct Vector*, const char*);
118BOOL lexer_defineID(struct VRMLLexer*, int*, struct Vector*, BOOL);
119#define lexer_defineNodeName(me, ret) \
120 lexer_defineID(me, ret, stack_top(struct Vector*, me->userNodeNames), TRUE)
121#define lexer_defineNodeType(me, ret) \
122 lexer_defineID(me, ret, me->userNodeTypesVec, FALSE)
123#define lexer_define_initializeOnly(me, ret) \
124 lexer_defineID(me, ret, me->user_initializeOnly, TRUE)
125#define lexer_define_inputOutput(me, ret) \
126 lexer_defineID(me, ret, me->user_inputOutput, TRUE)
127#define lexer_define_inputOnly(me, ret) \
128 lexer_defineID(me, ret, me->user_inputOnly, TRUE)
129#define lexer_define_outputOnly(me, ret) \
130 lexer_defineID(me, ret, me->user_outputOnly, TRUE)
131BOOL lexer_initializeOnly(struct VRMLLexer*, int*, int*, int*, int*);
132BOOL lexer_event(struct VRMLLexer*, struct X3D_Node*,
133 int*, int*, int*, int*, int routeToFrom);
134#define lexer_inputOnly(me, node, a, b, c, d) \
135 lexer_event(me, node, a, b, c, d, ROUTED_FIELD_EVENT_IN)
136#define lexer_outputOnly(me, node, a, b, c, d) \
137 lexer_event(me, node, a, b, c, d, ROUTED_FIELD_EVENT_OUT)
138#define lexer_node(me, r1, r2) \
139 lexer_specialID(me, r1, r2, NODES, NODES_COUNT, me->userNodeTypesVec)
140#define lexer_nodeName(me, ret) \
141 lexer_specialID(me, NULL, ret, NULL, 0, \
142 stack_top(struct Vector*, me->userNodeNames))
143#define lexer_protoFieldMode(me, r) \
144 lexer_specialID(me, r, NULL, PROTOKEYWORDS, PROTOKEYWORDS_COUNT, NULL)
145#define lexer_fieldType(me, r) \
146 lexer_specialID(me, r, NULL, FIELDTYPES, FIELDTYPES_COUNT, NULL)
147int lexer_string2id(const char*, const struct Vector*);
148#define lexer_nodeName2id(me, str) \
149 lexer_string2id(str, stack_top(struct Vector*, me->userNodeNames))
150
151/* Input the basic literals */
152BOOL lexer_int32(struct VRMLLexer*, vrmlInt32T*);
153BOOL lexer_float(struct VRMLLexer*, vrmlFloatT*);
154BOOL lexer_double(struct VRMLLexer*, vrmlDoubleT*);
155BOOL lexer_string(struct VRMLLexer*, vrmlStringT*);
156
157/* Checks for the five operators of VRML */
158BOOL lexer_operator(struct VRMLLexer*, char);
159#define lexer_point(me) \
160 lexer_operator(me, '.')
161#define lexer_openCurly(me) \
162 lexer_operator(me, '{')
163#define lexer_closeCurly(me) \
164 lexer_operator(me, '}')
165#define lexer_openSquare(me) \
166 lexer_operator(me, '[')
167#define lexer_closeSquare(me) \
168 lexer_operator(me, ']')
169#define lexer_colon(me) \
170 lexer_operator(me,':')
171
172/* recursively skip to the closing curly bracket */
173void skipToEndOfOpenCurly(struct VRMLLexer *me, int level);
174
175void concatAndGiveToLexer(struct VRMLLexer *me, const char *str_a, const char *str_b);
176
177/* other function protos */
178BOOL lexer_field(struct VRMLLexer* me,int* retBO, int* retBE, int* retUO, int* retUE);
179
180
181#endif /* __FREEWRL_CPARSE_LEXER_H__ */