2 * CDE - Common Desktop Environment
4 * Copyright (c) 1993-2012, The Open Group. All rights reserved.
6 * These libraries and programs are free software; you can
7 * redistribute them and/or modify them under the terms of the GNU
8 * Lesser General Public License as published by the Free Software
9 * Foundation; either version 2 of the License, or (at your option)
12 * These libraries and programs are distributed in the hope that
13 * they will be useful, but WITHOUT ANY WARRANTY; without even the
14 * implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
15 * PURPOSE. See the GNU Lesser General Public License for more
18 * You should have received a copy of the GNU Lesser General Public
19 * License along with these librararies and programs; if not, write
20 * to the Free Software Foundation, Inc., 51 Franklin Street, Fifth
21 * Floor, Boston, MA 02110-1301 USA
23 // $TOG: defParser.C /main/5 1997/12/23 11:16:25 bill $
25 static const char defParsersccsid[] = "@(#)yaccpar 1.8 (Berkeley) 01/20/90";
27 #define defParserBYACC 1
34 #include "FeatureDefDictionary.h"
39 #define alloca(x) (malloc(x))
41 def_list_t* g_def_list = 0;
43 extern void defParsererror(char*);
44 extern int defParserlex();
50 unsigned char charData;
51 unsigned char* charPtrData;
54 FeatureValue* valueData;
56 defv_t* valueListPtrData;
57 TypeValues* typeValuesPtrData;
58 type_values_list_t* typeValuesListPtrData;
60 def_list_t* defListPtrData;
61 FeatureDef* defPtrData;
67 #define SEMI_COLON 260
70 #define OPER_parenopen 263
71 #define OPER_parenclose 264
74 #define NORMAL_STRING 267
75 #define QUOTED_STRING 268
78 #define ValueListOpt 271
79 #define defParserERRCODE 256
80 short defParserlhs[] = { -1,
81 0, 11, 11, 6, 6, 6, 6, 8, 10, 7,
82 9, 1, 5, 5, 4, 4, 3, 3, 2, 2,
85 short defParserlen[] = { 2,
86 1, 2, 1, 1, 1, 1, 1, 4, 4, 2,
87 2, 1, 3, 1, 4, 1, 3, 1, 1, 1,
90 short defParserdefred[] = { 0,
91 0, 12, 0, 0, 3, 6, 4, 7, 5, 0,
92 11, 0, 10, 0, 2, 0, 14, 0, 0, 0,
93 0, 9, 8, 19, 21, 20, 18, 0, 13, 0,
96 short defParserdgoto[] = { 3,
97 4, 27, 28, 17, 18, 5, 6, 7, 8, 9,
100 short defParsersindex[] = { -256,
101 -258, 0, 0, -240, 0, 0, 0, 0, 0, -256,
102 0, -262, 0, -256, 0, -249, 0, -254, -257, -250,
103 -262, 0, 0, 0, 0, 0, 0, -251, 0, -250,
106 short defParserrindex[] = { 0,
107 0, 0, 0, 0, 0, 0, 0, 0, 0, 9,
108 0, 0, 0, 0, 0, -236, 0, 0, 0, 0,
109 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
112 short defParsergindex[] = { 0,
113 0, -13, 0, 2, 0, -7, 0, 0, 0, 0,
116 #define defParserTABLESIZE 25
117 short defParsertable[] = { 1,
118 1, 11, 15, 21, 23, 22, 30, 16, 1, 2,
119 2, 15, 31, 20, 24, 25, 32, 26, 12, 13,
122 short defParsercheck[] = { 257,
123 257, 260, 10, 258, 262, 260, 258, 270, 0, 267,
124 267, 19, 264, 263, 265, 266, 30, 268, 259, 260,
125 261, 258, 21, 260, 14,
127 #define defParserFINAL 3
128 #ifndef defParserDEBUG
129 #define defParserDEBUG 0
131 #define defParserMAXTOKEN 271
133 char *defParsername[] = {
134 "end-of-file",0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
135 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
136 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
137 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
138 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
139 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
140 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,"STAR","COMMA","COLON",
141 "SEMI_COLON","FSOPEN","FSCLOSE","OPER_parenopen","OPER_parenclose","INTEGER",
142 "REAL","NORMAL_STRING","QUOTED_STRING","REF_NAME","TYPE","ValueListOpt",
144 char *defParserrule[] = {
145 "$accept : featureDef",
146 "featureDef : DefList",
147 "DefList : DefList Def",
149 "Def : CompositeDef",
150 "Def : PrimitiveDef",
151 "Def : DefReference",
153 "CompositeDef : Name FSOPEN DefList FSCLOSE",
154 "PrimitiveDef : Name COLON TypeValuesList SEMI_COLON",
155 "DefReference : Name SEMI_COLON",
156 "WildCardDef : STAR SEMI_COLON",
157 "Name : NORMAL_STRING",
158 "TypeValuesList : TypeValuesList COMMA TypeValues",
159 "TypeValuesList : TypeValues",
160 "TypeValues : TYPE OPER_parenopen ValueList OPER_parenclose",
162 "ValueList : ValueList COMMA Value",
165 "Value : QUOTED_STRING",
169 #define defParserclearin (defParserchar=(-1))
170 #define defParsererrok (defParsererrflag=0)
171 #ifdef defParserSTACKSIZE
172 #ifndef defParserMAXDEPTH
173 #define defParserMAXDEPTH defParserSTACKSIZE
176 #ifdef defParserMAXDEPTH
177 #define defParserSTACKSIZE defParserMAXDEPTH
179 #define defParserSTACKSIZE 500
180 #define defParserMAXDEPTH 500
185 int defParsererrflag;
188 defParserSTYPE *defParservsp;
189 defParserSTYPE defParserval;
190 defParserSTYPE defParserlval;
191 short defParserss[defParserSTACKSIZE];
192 defParserSTYPE defParservs[defParserSTACKSIZE];
193 #define defParserstacksize defParserSTACKSIZE
196 void defParsererror(char *errorstr)
201 #define defParserABORT goto defParserabort
202 #define defParserACCEPT goto defParseraccept
203 #define defParserERROR goto defParsererrlab
206 extern char *getenv(const char *);
212 register int defParserm, defParsern, defParserstate;
214 register char *defParsers;
216 if (defParsers = getenv("defParserDEBUG"))
218 defParsern = *defParsers;
219 if (defParsern >= '0' && defParsern <= '9')
220 defParserdebug = defParsern - '0';
225 defParsererrflag = 0;
226 defParserchar = (-1);
228 defParserssp = defParserss;
229 defParservsp = defParservs;
230 *defParserssp = defParserstate = 0;
233 if ((defParsern = defParserdefred[defParserstate])) goto defParserreduce;
234 if (defParserchar < 0)
236 if ((defParserchar = defParserlex()) < 0) defParserchar = 0;
241 if (defParserchar <= defParserMAXTOKEN) defParsers = defParsername[defParserchar];
242 if (!defParsers) defParsers = "illegal-symbol";
243 printf("defParserdebug: state %d, reading %d (%s)\n", defParserstate,
244 defParserchar, defParsers);
248 if ((defParsern = defParsersindex[defParserstate]) && (defParsern += defParserchar) >= 0 &&
249 defParsern <= defParserTABLESIZE && defParsercheck[defParsern] == defParserchar)
253 printf("defParserdebug: state %d, shifting to state %d\n",
254 defParserstate, defParsertable[defParsern]);
256 if (defParserssp >= defParserss + defParserstacksize - 1)
258 goto defParseroverflow;
260 *++defParserssp = defParserstate = defParsertable[defParsern];
261 *++defParservsp = defParserlval;
262 defParserchar = (-1);
263 if (defParsererrflag > 0) --defParsererrflag;
266 if ((defParsern = defParserrindex[defParserstate]) && (defParsern += defParserchar) >= 0 &&
267 defParsern <= defParserTABLESIZE && defParsercheck[defParsern] == defParserchar)
269 defParsern = defParsertable[defParsern];
270 goto defParserreduce;
272 if (defParsererrflag) goto defParserinrecovery;
276 goto defParsernewerror;
280 defParsererror((char*)"syntax error");
284 goto defParsererrlab;
290 if (defParsererrflag < 3)
292 defParsererrflag = 3;
295 if ((defParsern = defParsersindex[*defParserssp]) && (defParsern += defParserERRCODE) >= 0 &&
296 defParsern <= defParserTABLESIZE && defParsercheck[defParsern] == defParserERRCODE)
300 printf("defParserdebug: state %d, error recovery shifting\
301 to state %d\n", *defParserssp, defParsertable[defParsern]);
303 if (defParserssp >= defParserss + defParserstacksize - 1)
305 goto defParseroverflow;
307 *++defParserssp = defParserstate = defParsertable[defParsern];
308 *++defParservsp = defParserlval;
315 printf("defParserdebug: error recovery discarding state %d\n",
318 if (defParserssp <= defParserss) goto defParserabort;
326 if (defParserchar == 0) goto defParserabort;
331 if (defParserchar <= defParserMAXTOKEN) defParsers = defParsername[defParserchar];
332 if (!defParsers) defParsers = "illegal-symbol";
333 printf("defParserdebug: state %d, error recovery discards token %d (%s)\n",
334 defParserstate, defParserchar, defParsers);
337 defParserchar = (-1);
343 printf("defParserdebug: state %d, reducing by rule %d (%s)\n",
344 defParserstate, defParsern, defParserrule[defParsern]);
346 defParserm = defParserlen[defParsern];
347 defParserval = defParservsp[1-defParserm];
352 g_def_list = defParservsp[0].defListPtrData;
357 defParserval.defListPtrData=defParservsp[-1].defListPtrData;
359 if ( defParservsp[0].defPtrData -> type() == FeatureDef::WILDCARD )
360 defParserval.defListPtrData -> prepend(defParservsp[0].defPtrData);
362 defParserval.defListPtrData -> append(defParservsp[0].defPtrData);
367 defParserval.defListPtrData=new def_list_t();
368 defParserval.defListPtrData -> append(defParservsp[0].defPtrData);
373 defParserval.defPtrData=defParservsp[0].defPtrData;
378 defParserval.defPtrData=defParservsp[0].defPtrData;
383 defParserval.defPtrData=defParservsp[0].defPtrData;
388 defParserval.defPtrData=defParservsp[0].defPtrData;
393 defParserval.defPtrData= new FeatureDefComposite((char*)defParservsp[-3].charPtrData, defParservsp[-1].defListPtrData);
394 delete defParservsp[-3].charPtrData;
399 defParserval.defPtrData= new FeatureDefPrimitive((char*)defParservsp[-3].charPtrData, defParservsp[-1].typeValuesListPtrData);
400 delete defParservsp[-3].charPtrData;
405 defParserval.defPtrData= new FeatureDefReference((char*)defParservsp[-1].charPtrData);
406 delete defParservsp[-1].charPtrData;
411 defParserval.defPtrData= new FeatureDefWildCard("*");
416 defParserval.charPtrData=defParservsp[0].charPtrData;
421 defParserval.typeValuesListPtrData=defParservsp[-2].typeValuesListPtrData;
422 defParserval.typeValuesListPtrData -> append(defParservsp[0].typeValuesPtrData);
427 defParserval.typeValuesListPtrData=new type_values_list_t();
428 defParserval.typeValuesListPtrData -> append(defParservsp[0].typeValuesPtrData);
433 defParserval.typeValuesPtrData=new TypeValues((char*)defParservsp[-3].charPtrData, defParservsp[-1].valueListPtrData);
434 delete defParservsp[-3].charPtrData;
439 defParserval.typeValuesPtrData=new TypeValues((char*)defParservsp[0].charPtrData, 0);
440 delete defParservsp[0].charPtrData;
445 defParservsp[-2].valueListPtrData -> append(defParservsp[0].valueData);
446 defParserval.valueListPtrData=defParservsp[-2].valueListPtrData;
451 defParserval.valueListPtrData = new defv_t();
452 defParserval.valueListPtrData -> append(defParservsp[0].valueData);
458 defParserval.valueData=new FeatureValueInt(defParservsp[0].intData);
463 defParserval.valueData=new FeatureValueString((char*)defParservsp[0].charPtrData);
464 delete defParservsp[0].charPtrData;
469 defParserval.valueData=new FeatureValueReal(defParservsp[0].realData);
473 defParserssp -= defParserm;
474 defParserstate = *defParserssp;
475 defParservsp -= defParserm;
476 defParserm = defParserlhs[defParsern];
477 if (defParserstate == 0 && defParserm == 0)
481 printf("defParserdebug: after reduction, shifting from state 0 to\
482 state %d\n", defParserFINAL);
484 defParserstate = defParserFINAL;
485 *++defParserssp = defParserFINAL;
486 *++defParservsp = defParserval;
487 if (defParserchar < 0)
489 if ((defParserchar = defParserlex()) < 0) defParserchar = 0;
494 if (defParserchar <= defParserMAXTOKEN) defParsers = defParsername[defParserchar];
495 if (!defParsers) defParsers = "illegal-symbol";
496 printf("defParserdebug: state %d, reading %d (%s)\n",
497 defParserFINAL, defParserchar, defParsers);
501 if (defParserchar == 0) goto defParseraccept;
504 if ((defParsern = defParsergindex[defParserm]) && (defParsern += defParserstate) >= 0 &&
505 defParsern <= defParserTABLESIZE && defParsercheck[defParsern] == defParserstate)
506 defParserstate = defParsertable[defParsern];
508 defParserstate = defParserdgoto[defParserm];
511 printf("defParserdebug: after reduction, shifting from state %d \
512 to state %d\n", *defParserssp, defParserstate);
514 if (defParserssp >= defParserss + defParserstacksize - 1)
516 goto defParseroverflow;
518 *++defParserssp = defParserstate;
519 *++defParservsp = defParserval;
522 defParsererror((char*)"yacc stack overflow");