Merge branch 'ryzom/ark-features' into main/gingo-test
[ryzomcore.git] / nel / src / misc / config_file / cf_gramatical.cpp
blobd386b72ad9fdecc1843f4a2fce9b4a6defe7c539
2 /* A Bison parser, made from cf_gramatical.yxx
3 by GNU Bison version 1.28 */
5 #define YYBISON 1 /* Identify Bison output. */
7 #define yyparse cfparse
8 #define yylex cflex
9 #define yyerror cferror
10 #define yylval cflval
11 #define yychar cfchar
12 #define yydebug cfdebug
13 #define yynerrs cfnerrs
14 #define ADD_ASSIGN 257
15 #define ASSIGN 258
16 #define VARIABLE 259
17 #define STRING 260
18 #define SEMICOLON 261
19 #define PLUS 262
20 #define MINUS 263
21 #define MULT 264
22 #define DIVIDE 265
23 #define RPAREN 266
24 #define LPAREN 267
25 #define RBRACE 268
26 #define LBRACE 269
27 #define COMMA 270
28 #define INTEGER 271
29 #define REAL 272
30 #define FILELINE 273
32 #line 1 "cf_gramatical.yxx"
35 /* Includes */
37 #ifdef NL_OS_WINDOWS
38 #pragma warning (disable : 4786)
39 #endif // NL_OS_WINDOWS
42 #include "nel/misc/config_file.h"
43 #include "nel/misc/common.h"
44 #include "nel/misc/debug.h"
46 #include <cstdio>
47 #include <vector>
48 #include <string>
50 using namespace std;
51 using namespace NLMISC;
53 #ifdef DEBUG_NEW
54 #define new DEBUG_NEW
55 #endif
57 /* Constantes */
59 #define YYPARSE_PARAM pvararray
61 // WARNING!!!! DEBUG_PRINTF are commented using // so IT MUST HAVE NO INSTRUCTION AFTER A DEBUG_PRINTF OR THEY LL BE COMMENTED
63 #define DEBUG_PRINTF InfoLog->displayRaw
64 #define DEBUG_PRINT(a) InfoLog->displayRaw(a)
67 #define DEBUG_PRINT(a)
68 #ifdef __GNUC__
69 #define DEBUG_PRINTF(format, args...)
70 #else // __GNUC__
71 #define DEBUG_PRINTF // InfoLog->displayRaw
72 #endif // __GNUC__
75 /* Types */
77 enum cf_operation { OP_PLUS, OP_MINUS, OP_MULT, OP_DIVIDE, OP_NEG };
79 struct cf_value
81 NLMISC::CConfigFile::CVar::TVarType Type;
82 int Int;
83 double Real;
84 char String[1024];
87 /* Externals */
89 extern bool cf_Ignore;
91 extern bool LoadRoot;
93 extern FILE *yyin;
95 /* Variables */
97 NLMISC::CConfigFile::CVar cf_CurrentVar;
99 int cf_CurrentLine;
100 char *cf_CurrentFile;
102 bool cf_OverwriteExistingVariable; // setup in the config_file.cpp reparse()
106 /* Prototypes */
108 int yylex (void);
110 cf_value cf_op (cf_value a, cf_value b, cf_operation op);
112 void cf_print (cf_value Val);
114 void cf_setVar (NLMISC::CConfigFile::CVar &Var, cf_value Val);
116 int yyerror (const char *);
119 #line 85 "cf_gramatical.yxx"
120 typedef union {
121 cf_value Val;
122 } YYSTYPE;
123 #include <cstdio>
125 #ifndef __cplusplus
126 #ifndef __STDC__
127 #define const
128 #endif
129 #endif
133 #define YYFINAL 47
134 #define YYFLAG -32768
135 #define YYNTBASE 20
137 #define YYTRANSLATE(x) ((unsigned)(x) <= 273 ? yytranslate[x] : 29)
139 static const char yytranslate[] = { 0,
140 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
141 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
142 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
143 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
144 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
145 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
146 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
147 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
148 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
149 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
150 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
151 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
152 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
153 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
154 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
155 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
156 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
157 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
158 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
159 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
160 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
161 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
162 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
163 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
164 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
165 2, 2, 2, 2, 2, 1, 3, 4, 5, 6,
166 7, 8, 9, 10, 11, 12, 13, 14, 15, 16,
167 17, 18, 19
170 #if YYDEBUG != 0
171 static const short yyprhs[] = { 0,
172 0, 2, 3, 6, 8, 12, 17, 22, 24, 28,
173 33, 36, 38, 42, 44, 48, 52, 54, 58, 62,
174 65, 68, 72, 74, 76, 78, 80
177 static const short yyrhs[] = { 21,
178 0, 0, 21, 22, 0, 22, 0, 19, 6, 17,
179 0, 5, 4, 23, 7, 0, 5, 3, 23, 7,
180 0, 25, 0, 15, 24, 14, 0, 15, 24, 16,
181 14, 0, 15, 14, 0, 25, 0, 24, 16, 25,
182 0, 26, 0, 25, 8, 26, 0, 25, 9, 26,
183 0, 27, 0, 26, 10, 27, 0, 26, 11, 27,
184 0, 8, 27, 0, 9, 27, 0, 13, 23, 12,
185 0, 17, 0, 18, 0, 6, 0, 28, 0, 5,
189 #endif
191 #if YYDEBUG != 0
192 static const short yyrline[] = { 0,
193 104, 104, 107, 108, 111, 123, 185, 245, 246, 247,
194 248, 251, 252, 255, 256, 257, 260, 261, 262, 265,
195 266, 267, 268, 269, 270, 271, 274
197 #endif
200 #if YYDEBUG != 0 || defined (YYERROR_VERBOSE)
202 static const char * const yytname[] = { "$","error","$undefined.","ADD_ASSIGN",
203 "ASSIGN","VARIABLE","STRING","SEMICOLON","PLUS","MINUS","MULT","DIVIDE","RPAREN",
204 "LPAREN","RBRACE","LBRACE","COMMA","INTEGER","REAL","FILELINE","ROOT","instlist",
205 "inst","expression","exprbrace","expr2","expr3","expr4","variable", NULL
207 #endif
209 static const short yyr1[] = { 0,
210 20, 20, 21, 21, 22, 22, 22, 23, 23, 23,
211 23, 24, 24, 25, 25, 25, 26, 26, 26, 27,
212 27, 27, 27, 27, 27, 27, 28
215 static const short yyr2[] = { 0,
216 1, 0, 2, 1, 3, 4, 4, 1, 3, 4,
217 2, 1, 3, 1, 3, 3, 1, 3, 3, 2,
218 2, 3, 1, 1, 1, 1, 1
221 static const short yydefact[] = { 2,
222 0, 0, 1, 4, 0, 0, 0, 3, 27, 25,
223 0, 0, 0, 0, 23, 24, 0, 8, 14, 17,
224 26, 0, 5, 20, 21, 0, 11, 0, 12, 7,
225 0, 0, 0, 0, 6, 22, 9, 0, 15, 16,
226 18, 19, 10, 13, 0, 0, 0
229 static const short yydefgoto[] = { 45,
230 3, 4, 17, 28, 18, 19, 20, 21
233 static const short yypact[] = { -4,
234 17, 2, -4,-32768, 1, 1, -15,-32768,-32768,-32768,
235 50, 50, 1, 22,-32768,-32768, 10, 14, 23,-32768,
236 -32768, 25,-32768,-32768,-32768, 31,-32768, -3, 14,-32768,
237 50, 50, 50, 50,-32768,-32768,-32768, 36, 23, 23,
238 -32768,-32768,-32768, 14, 29, 46,-32768
241 static const short yypgoto[] = {-32768,
242 -32768, 44, -1,-32768, -14, 6, -8,-32768
246 #define YYLAST 68
249 static const short yytable[] = { 29,
250 1, 23, 24, 25, 22, 9, 10, 7, 11, 12,
251 37, 26, 38, 13, 2, 14, 30, 15, 16, 5,
252 6, 31, 32, 44, 41, 42, 9, 10, 46, 11,
253 12, 35, 33, 34, 13, 27, 39, 40, 15, 16,
254 9, 10, 36, 11, 12, 47, 8, 0, 13, 43,
255 0, 0, 15, 16, 9, 10, 0, 11, 12, 0,
256 0, 0, 13, 0, 0, 0, 15, 16
259 static const short yycheck[] = { 14,
260 5, 17, 11, 12, 6, 5, 6, 6, 8, 9,
261 14, 13, 16, 13, 19, 15, 7, 17, 18, 3,
262 4, 8, 9, 38, 33, 34, 5, 6, 0, 8,
263 9, 7, 10, 11, 13, 14, 31, 32, 17, 18,
264 5, 6, 12, 8, 9, 0, 3, -1, 13, 14,
265 -1, -1, 17, 18, 5, 6, -1, 8, 9, -1,
266 -1, -1, 13, -1, -1, -1, 17, 18
268 /* -*-C-*- Note some compilers choke on comments on `#line' lines. */
269 #line 3 "cfbison.simple"
270 /* This file comes from bison-1.28. */
272 /* Skeleton output parser for bison,
273 Copyright (C) 1984, 1989, 1990 Free Software Foundation, Inc.
275 This program is free software; you can redistribute it and/or modify
276 it under the terms of the GNU General Public License as published by
277 the Free Software Foundation; either version 2, or (at your option)
278 any later version.
280 This program is distributed in the hope that it will be useful,
281 but WITHOUT ANY WARRANTY; without even the implied warranty of
282 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
283 GNU General Public License for more details.
285 You should have received a copy of the GNU General Public License
286 along with this program; if not, write to the Free Software
287 Foundation, Inc., 59 Temple Place - Suite 330,
288 Boston, MA 02111-1307, USA. */
290 /* As a special exception, when this file is copied by Bison into a
291 Bison output file, you may use that output file without restriction.
292 This special exception was added by the Free Software Foundation
293 in version 1.24 of Bison. */
295 /* This is the parser code that is written into each bison parser
296 when the %semantic_parser declaration is not specified in the grammar.
297 It was written by Richard Stallman by simplifying the hairy parser
298 used when %semantic_parser is specified. */
300 #ifndef YYSTACK_USE_ALLOCA
301 #ifdef alloca
302 #define YYSTACK_USE_ALLOCA
303 #else /* alloca not defined */
304 #ifdef __GNUC__
305 #define YYSTACK_USE_ALLOCA
306 #define alloca __builtin_alloca
307 #else /* not GNU C. */
308 #if (!defined (__STDC__) && defined (sparc)) || defined (__sparc__) || defined (__sparc) || defined (__sgi) || (defined (__sun) && defined (__i386))
309 #define YYSTACK_USE_ALLOCA
310 #include <alloca.h>
311 #else /* not sparc */
312 /* We think this test detects Watcom and Microsoft C. */
313 /* This used to test MSDOS, but that is a bad idea
314 since that symbol is in the user namespace. */
315 #if (defined (_MSDOS) || defined (_MSDOS_)) && !defined (__TURBOC__)
316 #if 0 /* No need for malloc.h, which pollutes the namespace;
317 instead, just don't use alloca. */
318 #include <malloc.h>
319 #endif
320 #else /* not MSDOS, or __TURBOC__ */
321 #if defined(_AIX)
322 /* I don't know what this was needed for, but it pollutes the namespace.
323 So I turned it off. rms, 2 May 1997. */
324 /* #include <malloc.h> */
325 #pragma alloca
326 #define YYSTACK_USE_ALLOCA
327 #else /* not MSDOS, or __TURBOC__, or _AIX */
328 #if 0
329 #ifdef __hpux /* haible@ilog.fr says this works for HPUX 9.05 and up,
330 and on HPUX 10. Eventually we can turn this on. */
331 #define YYSTACK_USE_ALLOCA
332 #define alloca __builtin_alloca
333 #endif /* __hpux */
334 #endif
335 #endif /* not _AIX */
336 #endif /* not MSDOS, or __TURBOC__ */
337 #endif /* not sparc */
338 #endif /* not GNU C */
339 #endif /* alloca not defined */
340 #endif /* YYSTACK_USE_ALLOCA not defined */
342 #ifdef YYSTACK_USE_ALLOCA
343 #define YYSTACK_ALLOC alloca
344 #else
345 #define YYSTACK_ALLOC malloc
346 #endif
348 /* Note: there must be only one dollar sign in this file.
349 It is replaced by the list of actions, each action
350 as one case of the switch. */
352 #define yyerrok (yyerrstatus = 0)
353 #define yyclearin (yychar = YYEMPTY)
354 #define YYEMPTY -2
355 #define YYEOF 0
356 #define YYACCEPT goto yyacceptlab
357 #define YYABORT goto yyabortlab
358 #define YYERROR goto yyerrlab1
359 /* Like YYERROR except do call yyerror.
360 This remains here temporarily to ease the
361 transition to the new meaning of YYERROR, for GCC.
362 Once GCC version 2 has supplanted version 1, this can go. */
363 #define YYFAIL goto yyerrlab
364 #define YYRECOVERING() (!!yyerrstatus)
365 #define YYBACKUP(token, value) \
366 do \
367 if (yychar == YYEMPTY && yylen == 1) \
368 { yychar = (token), yylval = (value); \
369 yychar1 = YYTRANSLATE (yychar); \
370 YYPOPSTACK; \
371 goto yybackup; \
373 else \
374 { yyerror ("syntax error: cannot back up"); YYERROR; } \
375 while (0)
377 #define YYTERROR 1
378 #define YYERRCODE 256
380 #ifndef YYPURE
381 #define YYLEX yylex()
382 #endif
384 #ifdef YYPURE
385 #ifdef YYLSP_NEEDED
386 #ifdef YYLEX_PARAM
387 #define YYLEX yylex(&yylval, &yylloc, YYLEX_PARAM)
388 #else
389 #define YYLEX yylex(&yylval, &yylloc)
390 #endif
391 #else /* not YYLSP_NEEDED */
392 #ifdef YYLEX_PARAM
393 #define YYLEX yylex(&yylval, YYLEX_PARAM)
394 #else
395 #define YYLEX yylex(&yylval)
396 #endif
397 #endif /* not YYLSP_NEEDED */
398 #endif
400 /* If nonreentrant, generate the variables here */
402 #ifndef YYPURE
404 int yychar; /* the lookahead symbol */
405 YYSTYPE yylval; /* the semantic value of the */
406 /* lookahead symbol */
408 #ifdef YYLSP_NEEDED
409 YYLTYPE yylloc; /* location data for the lookahead */
410 /* symbol */
411 #endif
413 int yynerrs; /* number of parse errors so far */
414 #endif /* not YYPURE */
416 #if YYDEBUG != 0
417 int yydebug; /* nonzero means print parse trace */
418 /* Since this is uninitialized, it does not stop multiple parsers
419 from coexisting. */
420 #endif
422 /* YYINITDEPTH indicates the initial size of the parser's stacks */
424 #ifndef YYINITDEPTH
425 #define YYINITDEPTH 200
426 #endif
428 /* YYMAXDEPTH is the maximum size the stacks can grow to
429 (effective only if the built-in stack extension method is used). */
431 #if YYMAXDEPTH == 0
432 #undef YYMAXDEPTH
433 #endif
435 #ifndef YYMAXDEPTH
436 #define YYMAXDEPTH 10000
437 #endif
439 /* Define __yy_memcpy. Note that the size argument
440 should be passed with type unsigned int, because that is what the non-GCC
441 definitions require. With GCC, __builtin_memcpy takes an arg
442 of type size_t, but it can handle unsigned int. */
444 #if __GNUC__ > 1 /* GNU C and GNU C++ define this. */
445 #define __yy_memcpy(TO,FROM,COUNT) __builtin_memcpy(TO,FROM,COUNT)
446 #else /* not GNU C or C++ */
447 #ifndef __cplusplus
449 /* This is the most reliable way to avoid incompatibilities
450 in available built-in functions on various systems. */
451 static void
452 __yy_memcpy (to, from, count)
453 char *to;
454 char *from;
455 unsigned int count;
457 register char *f = from;
458 register char *t = to;
459 register int i = count;
461 while (i-- > 0)
462 *t++ = *f++;
465 #else /* __cplusplus */
467 /* This is the most reliable way to avoid incompatibilities
468 in available built-in functions on various systems. */
469 static void
470 __yy_memcpy (char *to, char *from, unsigned int count)
472 register char *t = to;
473 register char *f = from;
474 register int i = count;
476 while (i-- > 0)
477 *t++ = *f++;
480 #endif
481 #endif
483 #line 217 "cfbison.simple"
485 /* The user can define YYPARSE_PARAM as the name of an argument to be passed
486 into yyparse. The argument should have type void *.
487 It should actually point to an object.
488 Grammar actions can access the variable by casting it
489 to the proper pointer type. */
491 #ifdef YYPARSE_PARAM
492 #ifdef __cplusplus
493 #define YYPARSE_PARAM_ARG void *YYPARSE_PARAM
494 #define YYPARSE_PARAM_DECL
495 #else /* not __cplusplus */
496 #define YYPARSE_PARAM_ARG YYPARSE_PARAM
497 #define YYPARSE_PARAM_DECL void *YYPARSE_PARAM;
498 #endif /* not __cplusplus */
499 #else /* not YYPARSE_PARAM */
500 #define YYPARSE_PARAM_ARG
501 #define YYPARSE_PARAM_DECL
502 #endif /* not YYPARSE_PARAM */
504 /* Prevent warning if -Wstrict-prototypes. */
505 #ifdef __GNUC__
506 #ifdef YYPARSE_PARAM
507 int yyparse (void *);
508 #else
509 int yyparse (void);
510 #endif
511 #endif
514 yyparse(YYPARSE_PARAM_ARG)
515 YYPARSE_PARAM_DECL
517 register int yystate;
518 register int yyn;
519 register short *yyssp;
520 register YYSTYPE *yyvsp;
521 int yyerrstatus; /* number of tokens to shift before error messages enabled */
522 int yychar1 = 0; /* lookahead token as an internal (translated) token number */
524 short yyssa[YYINITDEPTH]; /* the state stack */
525 YYSTYPE yyvsa[YYINITDEPTH]; /* the semantic value stack */
527 short *yyss = yyssa; /* refer to the stacks thru separate pointers */
528 YYSTYPE *yyvs = yyvsa; /* to allow yyoverflow to reallocate them elsewhere */
530 #ifdef YYLSP_NEEDED
531 YYLTYPE yylsa[YYINITDEPTH]; /* the location stack */
532 YYLTYPE *yyls = yylsa;
533 YYLTYPE *yylsp;
535 #define YYPOPSTACK (yyvsp--, yyssp--, yylsp--)
536 #else
537 #define YYPOPSTACK (yyvsp--, yyssp--)
538 #endif
540 int yystacksize = YYINITDEPTH;
541 int yyfree_stacks = 0;
543 #ifdef YYPURE
544 int yychar;
545 YYSTYPE yylval;
546 int yynerrs;
547 #ifdef YYLSP_NEEDED
548 YYLTYPE yylloc;
549 #endif
550 #endif
552 YYSTYPE yyval; /* the variable used to return */
553 /* semantic values from the action */
554 /* routines */
555 // ace: big fake for VC7 because it checks if yyval is init or not
556 yyval.Val.Int = 0;
557 int yylen;
559 #if YYDEBUG != 0
560 if (yydebug)
561 fprintf(stderr, "Starting parse\n");
562 #endif
564 yystate = 0;
565 yyerrstatus = 0;
566 yynerrs = 0;
567 yychar = YYEMPTY; /* Cause a token to be read. */
569 /* Initialize stack pointers.
570 Waste one element of value and location stack
571 so that they stay on the same level as the state stack.
572 The wasted elements are never initialized. */
574 yyssp = yyss - 1;
575 yyvsp = yyvs;
576 #ifdef YYLSP_NEEDED
577 yylsp = yyls;
578 #endif
580 /* Push a new state, which is found in yystate . */
581 /* In all cases, when you get here, the value and location stacks
582 have just been pushed. so pushing a state here evens the stacks. */
583 yynewstate:
585 *++yyssp = yystate;
587 if (yyssp >= yyss + yystacksize - 1)
589 /* Give user a chance to reallocate the stack */
590 /* Use copies of these so that the &'s don't force the real ones into memory. */
591 YYSTYPE *yyvs1 = yyvs;
592 short *yyss1 = yyss;
593 #ifdef YYLSP_NEEDED
594 YYLTYPE *yyls1 = yyls;
595 #endif
597 /* Get the current used size of the three stacks, in elements. */
598 int size = yyssp - yyss + 1;
600 #ifdef yyoverflow
601 /* Each stack pointer address is followed by the size of
602 the data in use in that stack, in bytes. */
603 #ifdef YYLSP_NEEDED
604 /* This used to be a conditional around just the two extra args,
605 but that might be undefined if yyoverflow is a macro. */
606 yyoverflow("parser stack overflow",
607 &yyss1, size * sizeof (*yyssp),
608 &yyvs1, size * sizeof (*yyvsp),
609 &yyls1, size * sizeof (*yylsp),
610 &yystacksize);
611 #else
612 yyoverflow("parser stack overflow",
613 &yyss1, size * sizeof (*yyssp),
614 &yyvs1, size * sizeof (*yyvsp),
615 &yystacksize);
616 #endif
618 yyss = yyss1; yyvs = yyvs1;
619 #ifdef YYLSP_NEEDED
620 yyls = yyls1;
621 #endif
622 #else /* no yyoverflow */
623 /* Extend the stack our own way. */
624 if (yystacksize >= YYMAXDEPTH)
626 yyerror("parser stack overflow");
627 if (yyfree_stacks)
629 free (yyss);
630 free (yyvs);
631 #ifdef YYLSP_NEEDED
632 free (yyls);
633 #endif
635 return 2;
637 yystacksize *= 2;
638 if (yystacksize > YYMAXDEPTH)
639 yystacksize = YYMAXDEPTH;
640 #ifndef YYSTACK_USE_ALLOCA
641 yyfree_stacks = 1;
642 #endif
643 yyss = (short *) YYSTACK_ALLOC (yystacksize * sizeof (*yyssp));
644 __yy_memcpy ((char *)yyss, (char *)yyss1,
645 size * (unsigned int) sizeof (*yyssp));
646 yyvs = (YYSTYPE *) YYSTACK_ALLOC (yystacksize * sizeof (*yyvsp));
647 __yy_memcpy ((char *)yyvs, (char *)yyvs1,
648 size * (unsigned int) sizeof (*yyvsp));
649 #ifdef YYLSP_NEEDED
650 yyls = (YYLTYPE *) YYSTACK_ALLOC (yystacksize * sizeof (*yylsp));
651 __yy_memcpy ((char *)yyls, (char *)yyls1,
652 size * (unsigned int) sizeof (*yylsp));
653 #endif
654 #endif /* no yyoverflow */
656 yyssp = yyss + size - 1;
657 yyvsp = yyvs + size - 1;
658 #ifdef YYLSP_NEEDED
659 yylsp = yyls + size - 1;
660 #endif
662 #if YYDEBUG != 0
663 if (yydebug)
664 fprintf(stderr, "Stack size increased to %d\n", yystacksize);
665 #endif
667 if (yyssp >= yyss + yystacksize - 1)
668 YYABORT;
671 #if YYDEBUG != 0
672 if (yydebug)
673 fprintf(stderr, "Entering state %d\n", yystate);
674 #endif
676 goto yybackup;
677 yybackup:
679 /* Do appropriate processing given the current state. */
680 /* Read a lookahead token if we need one and don't already have one. */
681 /* yyresume: */
683 /* First try to decide what to do without reference to lookahead token. */
685 yyn = yypact[yystate];
686 if (yyn == YYFLAG)
687 goto yydefault;
689 /* Not known => get a lookahead token if don't already have one. */
691 /* yychar is either YYEMPTY or YYEOF
692 or a valid token in external form. */
694 if (yychar == YYEMPTY)
696 #if YYDEBUG != 0
697 if (yydebug)
698 fprintf(stderr, "Reading a token: ");
699 #endif
700 yychar = YYLEX;
703 /* Convert token to internal form (in yychar1) for indexing tables with */
705 if (yychar <= 0) /* This means end of input. */
707 yychar1 = 0;
708 yychar = YYEOF; /* Don't call YYLEX any more */
710 #if YYDEBUG != 0
711 if (yydebug)
712 fprintf(stderr, "Now at end of input.\n");
713 #endif
715 else
717 yychar1 = YYTRANSLATE(yychar);
719 #if YYDEBUG != 0
720 if (yydebug)
722 fprintf (stderr, "Next token is %d (%s", yychar, yytname[yychar1]);
723 /* Give the individual parser a way to print the precise meaning
724 of a token, for further debugging info. */
725 #ifdef YYPRINT
726 YYPRINT (stderr, yychar, yylval);
727 #endif
728 fprintf (stderr, ")\n");
730 #endif
733 yyn += yychar1;
734 if (yyn < 0 || yyn > YYLAST || yycheck[yyn] != yychar1)
735 goto yydefault;
737 yyn = yytable[yyn];
739 /* yyn is what to do for this token type in this state.
740 Negative => reduce, -yyn is rule number.
741 Positive => shift, yyn is new state.
742 New state is final state => don't bother to shift,
743 just return success.
744 0, or most negative number => error. */
746 if (yyn < 0)
748 if (yyn == YYFLAG)
749 goto yyerrlab;
750 yyn = -yyn;
751 goto yyreduce;
753 else if (yyn == 0)
754 goto yyerrlab;
756 if (yyn == YYFINAL)
757 YYACCEPT;
759 /* Shift the lookahead token. */
761 #if YYDEBUG != 0
762 if (yydebug)
763 fprintf(stderr, "Shifting token %d (%s), ", yychar, yytname[yychar1]);
764 #endif
766 /* Discard the token being shifted unless it is eof. */
767 if (yychar != YYEOF)
768 yychar = YYEMPTY;
770 *++yyvsp = yylval;
771 #ifdef YYLSP_NEEDED
772 *++yylsp = yylloc;
773 #endif
775 /* count tokens shifted since error; after three, turn off error status. */
776 if (yyerrstatus) yyerrstatus--;
778 yystate = yyn;
779 goto yynewstate;
781 /* Do the default action for the current state. */
782 yydefault:
784 yyn = yydefact[yystate];
785 if (yyn == 0)
786 goto yyerrlab;
788 /* Do a reduction. yyn is the number of a rule to reduce with. */
789 yyreduce:
790 yylen = yyr2[yyn];
791 if (yylen > 0)
792 yyval = yyvsp[1-yylen]; /* implement default value of the action */
794 #if YYDEBUG != 0
795 if (yydebug)
797 int i;
799 fprintf (stderr, "Reducing via rule %d (line %d), ",
800 yyn, yyrline[yyn]);
802 /* Print the symbols being reduced, and their result. */
803 for (i = yyprhs[yyn]; yyrhs[i] > 0; i++)
804 fprintf (stderr, "%s ", yytname[yyrhs[i]]);
805 fprintf (stderr, " -> %s\n", yytname[yyr1[yyn]]);
807 #endif
810 switch (yyn) {
812 case 2:
813 #line 104 "cf_gramatical.yxx"
815 break;}
816 case 3:
817 #line 107 "cf_gramatical.yxx"
819 break;}
820 case 4:
821 #line 108 "cf_gramatical.yxx"
823 break;}
824 case 5:
825 #line 112 "cf_gramatical.yxx"
827 DEBUG_PRINTF("Forcing current file %s and line %u\n", yyvsp[-1].Val.String, yyvsp[0].Val.Int-1);
829 if (cf_CurrentFile != NULL)
830 free(cf_CurrentFile);
831 // store the filename
832 cf_CurrentFile = strdup(yyvsp[-1].Val.String);
833 // store the current line minus 1 because the #fileline count for a line
834 cf_CurrentLine = yyvsp[0].Val.Int-1;
836 break;}
837 case 6:
838 #line 124 "cf_gramatical.yxx"
840 DEBUG_PRINTF(" (TYPE %d VARIABLE=", yyvsp[-3].Val.Type);
841 cf_print (yyvsp[-3].Val);
842 DEBUG_PRINTF("), (TYPE %d VALUE=", yyvsp[-1].Val.Type);
843 cf_print (yyvsp[-1].Val);
844 DEBUG_PRINT(")\n");
845 int i;
846 // on recherche l'existence de la variable
847 for(i = 0; i < (int)((*((vector<NLMISC::CConfigFile::CVar>*)(YYPARSE_PARAM))).size()); i++)
849 if ((*((vector<NLMISC::CConfigFile::CVar>*)(YYPARSE_PARAM)))[i].Name == yyvsp[-3].Val.String)
851 if (cf_OverwriteExistingVariable || (*((vector<NLMISC::CConfigFile::CVar>*)(YYPARSE_PARAM)))[i].Root || !strcmp(yyvsp[-3].Val.String,"RootConfigFilename"))
853 DEBUG_PRINTF("Variable '%s' existe deja, ecrasement\n", yyvsp[-3].Val.String);
855 break;
858 NLMISC::CConfigFile::CVar Var;
859 Var.Comp = false;
860 Var.Callback = NULL;
861 if (cf_CurrentVar.Comp)
863 DEBUG_PRINTF ("yacc: new assign complex variable '%s'\n", yyvsp[-3].Val.String);
864 Var = cf_CurrentVar;
866 else
868 DEBUG_PRINTF ("yacc: new assign normal variable '%s'\n", yyvsp[-3].Val.String);
869 cf_setVar (Var, yyvsp[-1].Val);
871 Var.Name = yyvsp[-3].Val.String;
872 if (i == (int)((*((vector<NLMISC::CConfigFile::CVar>*)(YYPARSE_PARAM))).size ()))
874 // nouvelle variable
875 DEBUG_PRINTF ("yacc: new assign var '%s'\n", yyvsp[-3].Val.String);
876 (*((vector<NLMISC::CConfigFile::CVar>*)(YYPARSE_PARAM))).push_back (Var);
878 else if (cf_OverwriteExistingVariable || (*((vector<NLMISC::CConfigFile::CVar>*)(YYPARSE_PARAM)))[i].Root || !strcmp(yyvsp[-3].Val.String,"RootConfigFilename"))
880 // reaffectation d'une variable
881 Var.Callback = (*((vector<NLMISC::CConfigFile::CVar>*)(YYPARSE_PARAM)))[i].Callback;
882 DEBUG_PRINTF ("yacc: reassign var name '%s' type %d\n", Var.Name.c_str(), Var.Type);
883 if (Var != (*((vector<NLMISC::CConfigFile::CVar>*)(YYPARSE_PARAM)))[i] && Var.Callback != NULL)
884 (Var.Callback)(Var);
885 (*((vector<NLMISC::CConfigFile::CVar>*)(YYPARSE_PARAM)))[i] = Var;
887 else
889 DEBUG_PRINTF ("yacc: don't reassign var '%s' because the variable already exists\n", yyvsp[-3].Val.String);
892 cf_CurrentVar.IntValues.clear ();
893 cf_CurrentVar.RealValues.clear ();
894 cf_CurrentVar.StrValues.clear ();
895 cf_CurrentVar.Comp = false;
896 cf_CurrentVar.Type = NLMISC::CConfigFile::CVar::T_UNKNOWN;
898 break;}
899 case 7:
900 #line 186 "cf_gramatical.yxx"
902 DEBUG_PRINT(" (VARIABLE+=");
903 cf_print (yyvsp[-3].Val);
904 DEBUG_PRINT("), (VALUE=");
905 cf_print (yyvsp[-1].Val);
906 DEBUG_PRINT(")\n");
907 int i;
908 // on recherche l'existence de la variable
909 for(i = 0; i < (int)((*((vector<NLMISC::CConfigFile::CVar>*)(YYPARSE_PARAM))).size()); i++)
911 if ((*((vector<NLMISC::CConfigFile::CVar>*)(YYPARSE_PARAM)))[i].Name == yyvsp[-3].Val.String)
913 DEBUG_PRINTF("Variable '%s' existe deja, ajout\n", yyvsp[-3].Val.String);
914 break;
917 NLMISC::CConfigFile::CVar Var;
918 Var.Comp = false;
919 Var.Callback = NULL;
920 if (cf_CurrentVar.Comp) Var = cf_CurrentVar;
921 else cf_setVar (Var, yyvsp[-1].Val);
922 Var.Name = yyvsp[-3].Val.String;
923 if (i == (int)((*((vector<NLMISC::CConfigFile::CVar>*)(YYPARSE_PARAM))).size ()))
925 // nouvelle variable
926 DEBUG_PRINTF ("yacc: new add assign var '%s'\n", yyvsp[-3].Val.String);
927 (*((vector<NLMISC::CConfigFile::CVar>*)(YYPARSE_PARAM))).push_back (Var);
929 else
931 // reaffectation d'une variable
932 Var.Callback = (*((vector<NLMISC::CConfigFile::CVar>*)(YYPARSE_PARAM)))[i].Callback;
933 DEBUG_PRINTF ("yacc: add assign var '%s'\n", yyvsp[-3].Val.String);
934 if ((*((vector<NLMISC::CConfigFile::CVar>*)(YYPARSE_PARAM)))[i].FromLocalFile)
936 // this var was created in the current cfg, append the new value at the end
937 (*((vector<NLMISC::CConfigFile::CVar>*)(YYPARSE_PARAM)))[i].add(Var);
939 if (Var.size() > 0 && Var.Callback != NULL)
940 (Var.Callback)((*((vector<NLMISC::CConfigFile::CVar>*)(YYPARSE_PARAM)))[i]);
942 else
944 // this var has been created in a parent Cfg, append at the beginning of the array
945 Var.add ((*((vector<NLMISC::CConfigFile::CVar>*)(YYPARSE_PARAM)))[i]);
946 if (Var != (*((vector<NLMISC::CConfigFile::CVar>*)(YYPARSE_PARAM)))[i] && Var.Callback != NULL)
947 (Var.Callback)(Var);
948 (*((vector<NLMISC::CConfigFile::CVar>*)(YYPARSE_PARAM)))[i] = Var;
952 cf_CurrentVar.IntValues.clear ();
953 cf_CurrentVar.RealValues.clear ();
954 cf_CurrentVar.StrValues.clear ();
955 cf_CurrentVar.Comp = false;
956 cf_CurrentVar.Type = NLMISC::CConfigFile::CVar::T_UNKNOWN;
958 break;}
959 case 8:
960 #line 245 "cf_gramatical.yxx"
961 { yyval.Val = yyvsp[0].Val; cf_CurrentVar.Comp = false; DEBUG_PRINT("false\n"); ;
962 break;}
963 case 9:
964 #line 246 "cf_gramatical.yxx"
965 { yyval.Val = yyvsp[-1].Val; cf_CurrentVar.Comp = true; DEBUG_PRINT("true\n"); ;
966 break;}
967 case 10:
968 #line 247 "cf_gramatical.yxx"
969 { yyval.Val = yyvsp[-2].Val; cf_CurrentVar.Comp = true; DEBUG_PRINT("true\n"); ;
970 break;}
971 case 11:
972 #line 248 "cf_gramatical.yxx"
973 { yyval.Val = yyvsp[0].Val; cf_CurrentVar.Comp = true; DEBUG_PRINT("true\n"); ;
974 break;}
975 case 12:
976 #line 251 "cf_gramatical.yxx"
977 { yyval.Val = yyvsp[0].Val; /*cf_CurrentVar.Type = $1.Type;*/ cf_setVar (cf_CurrentVar, yyvsp[0].Val); ;
978 break;}
979 case 13:
980 #line 252 "cf_gramatical.yxx"
981 { yyval.Val = yyvsp[0].Val; /*cf_CurrentVar.Type = $3.Type;*/ cf_setVar (cf_CurrentVar, yyvsp[0].Val); ;
982 break;}
983 case 14:
984 #line 255 "cf_gramatical.yxx"
985 { yyval.Val = yyvsp[0].Val; ;
986 break;}
987 case 15:
988 #line 256 "cf_gramatical.yxx"
989 { yyval.Val = cf_op(yyvsp[-2].Val, yyvsp[0].Val, OP_PLUS); ;
990 break;}
991 case 16:
992 #line 257 "cf_gramatical.yxx"
993 { yyval.Val = cf_op(yyvsp[-2].Val, yyvsp[0].Val, OP_MINUS); ;
994 break;}
995 case 17:
996 #line 260 "cf_gramatical.yxx"
997 { yyval.Val = yyvsp[0].Val; ;
998 break;}
999 case 18:
1000 #line 261 "cf_gramatical.yxx"
1001 { yyval.Val = cf_op(yyvsp[-2].Val, yyvsp[0].Val, OP_MULT); ;
1002 break;}
1003 case 19:
1004 #line 262 "cf_gramatical.yxx"
1005 { yyval.Val = cf_op (yyvsp[-2].Val, yyvsp[0].Val, OP_DIVIDE); ;
1006 break;}
1007 case 20:
1008 #line 265 "cf_gramatical.yxx"
1009 { yyval.Val = yyvsp[0].Val; ;
1010 break;}
1011 case 21:
1012 #line 266 "cf_gramatical.yxx"
1013 { cf_value v; v.Type=NLMISC::CConfigFile::CVar::T_INT; /* just to avoid a warning, I affect 'v' with a dummy value */ yyval.Val = cf_op(yyvsp[0].Val,v,OP_NEG); ;
1014 break;}
1015 case 22:
1016 #line 267 "cf_gramatical.yxx"
1017 { yyval.Val = yyvsp[-1].Val; ;
1018 break;}
1019 case 23:
1020 #line 268 "cf_gramatical.yxx"
1021 { yyval.Val = yylval.Val; ;
1022 break;}
1023 case 24:
1024 #line 269 "cf_gramatical.yxx"
1025 { yyval.Val = yylval.Val; ;
1026 break;}
1027 case 25:
1028 #line 270 "cf_gramatical.yxx"
1029 { yyval.Val = yylval.Val; ;
1030 break;}
1031 case 26:
1032 #line 271 "cf_gramatical.yxx"
1033 { yyval.Val = yyvsp[0].Val; ;
1034 break;}
1035 case 27:
1036 #line 275 "cf_gramatical.yxx"
1038 DEBUG_PRINT("yacc: cont\n");
1039 bool ok=false;
1040 int i;
1041 for(i = 0; i < (int)((*((vector<NLMISC::CConfigFile::CVar>*)(YYPARSE_PARAM))).size()); i++)
1043 if ((*((vector<NLMISC::CConfigFile::CVar>*)(YYPARSE_PARAM)))[i].Name == yyvsp[0].Val.String)
1045 ok = true;
1046 break;
1049 if (ok)
1051 cf_value Var;
1052 Var.Type = (*((vector<NLMISC::CConfigFile::CVar>*)(YYPARSE_PARAM)))[i].Type;
1053 DEBUG_PRINTF("vart %d\n", Var.Type);
1054 switch (Var.Type)
1056 case NLMISC::CConfigFile::CVar::T_INT: Var.Int = (*((vector<NLMISC::CConfigFile::CVar>*)(YYPARSE_PARAM)))[i].IntValues[0]; break;
1057 case NLMISC::CConfigFile::CVar::T_REAL: Var.Real = (*((vector<NLMISC::CConfigFile::CVar>*)(YYPARSE_PARAM)))[i].RealValues[0]; break;
1058 case NLMISC::CConfigFile::CVar::T_STRING: strcpy (Var.String, (*((vector<NLMISC::CConfigFile::CVar>*)(YYPARSE_PARAM)))[i].StrValues[0].c_str()); break;
1059 default: DEBUG_PRINT("*** CAN T DO THAT!!!\n"); break;
1061 yyval.Val = Var;
1063 else
1065 DEBUG_PRINT("var existe pas\n");
1068 break;}
1070 /* the action file gets copied in in place of this dollarsign */
1071 #line 543 "cfbison.simple"
1073 yyvsp -= yylen;
1074 yyssp -= yylen;
1075 #ifdef YYLSP_NEEDED
1076 yylsp -= yylen;
1077 #endif
1079 #if YYDEBUG != 0
1080 if (yydebug)
1082 short *ssp1 = yyss - 1;
1083 fprintf (stderr, "state stack now");
1084 while (ssp1 != yyssp)
1085 fprintf (stderr, " %d", *++ssp1);
1086 fprintf (stderr, "\n");
1088 #endif
1090 *++yyvsp = yyval;
1092 #ifdef YYLSP_NEEDED
1093 yylsp++;
1094 if (yylen == 0)
1096 yylsp->first_line = yylloc.first_line;
1097 yylsp->first_column = yylloc.first_column;
1098 yylsp->last_line = (yylsp-1)->last_line;
1099 yylsp->last_column = (yylsp-1)->last_column;
1100 yylsp->text = 0;
1102 else
1104 yylsp->last_line = (yylsp+yylen-1)->last_line;
1105 yylsp->last_column = (yylsp+yylen-1)->last_column;
1107 #endif
1109 /* Now "shift" the result of the reduction.
1110 Determine what state that goes to,
1111 based on the state we popped back to
1112 and the rule number reduced by. */
1114 yyn = yyr1[yyn];
1116 yystate = yypgoto[yyn - YYNTBASE] + *yyssp;
1117 if (yystate >= 0 && yystate <= YYLAST && yycheck[yystate] == *yyssp)
1118 yystate = yytable[yystate];
1119 else
1120 yystate = yydefgoto[yyn - YYNTBASE];
1122 goto yynewstate;
1124 yyerrlab: /* here on detecting error */
1126 if (! yyerrstatus)
1127 /* If not already recovering from an error, report this error. */
1129 ++yynerrs;
1131 #ifdef YYERROR_VERBOSE
1132 yyn = yypact[yystate];
1134 if (yyn > YYFLAG && yyn < YYLAST)
1136 int size = 0;
1137 char *msg;
1138 int x, count;
1140 count = 0;
1141 /* Start X at -yyn if nec to avoid negative indexes in yycheck. */
1142 for (x = (yyn < 0 ? -yyn : 0);
1143 x < (sizeof(yytname) / sizeof(char *)); x++)
1144 if (yycheck[x + yyn] == x)
1145 size += strlen(yytname[x]) + 15, count++;
1146 msg = (char *) malloc(size + 15);
1147 if (msg != 0)
1149 strcpy(msg, "parse error");
1151 if (count < 5)
1153 count = 0;
1154 for (x = (yyn < 0 ? -yyn : 0);
1155 x < (sizeof(yytname) / sizeof(char *)); x++)
1156 if (yycheck[x + yyn] == x)
1158 strcat(msg, count == 0 ? ", expecting `" : " or `");
1159 strcat(msg, yytname[x]);
1160 strcat(msg, "'");
1161 count++;
1164 yyerror(msg);
1165 free(msg);
1167 else
1168 yyerror ("parse error; also virtual memory exceeded");
1170 else
1171 #endif /* YYERROR_VERBOSE */
1172 yyerror("parse error");
1175 goto yyerrlab1;
1176 yyerrlab1: /* here on error raised explicitly by an action */
1178 if (yyerrstatus == 3)
1180 /* if just tried and failed to reuse lookahead token after an error, discard it. */
1182 /* return failure if at end of input */
1183 if (yychar == YYEOF)
1184 YYABORT;
1186 #if YYDEBUG != 0
1187 if (yydebug)
1188 fprintf(stderr, "Discarding token %d (%s).\n", yychar, yytname[yychar1]);
1189 #endif
1191 yychar = YYEMPTY;
1194 /* Else will try to reuse lookahead token
1195 after shifting the error token. */
1197 yyerrstatus = 3; /* Each real token shifted decrements this */
1199 goto yyerrhandle;
1201 yyerrdefault: /* current state does not do anything special for the error token. */
1203 #if 0
1204 /* This is wrong; only states that explicitly want error tokens
1205 should shift them. */
1206 yyn = yydefact[yystate]; /* If its default is to accept any token, ok. Otherwise pop it.*/
1207 if (yyn) goto yydefault;
1208 #endif
1210 yyerrpop: /* pop the current state because it cannot handle the error token */
1212 if (yyssp == yyss) YYABORT;
1213 yyvsp--;
1214 yystate = *--yyssp;
1215 #ifdef YYLSP_NEEDED
1216 yylsp--;
1217 #endif
1219 #if YYDEBUG != 0
1220 if (yydebug)
1222 short *ssp1 = yyss - 1;
1223 fprintf (stderr, "Error: state stack now");
1224 while (ssp1 != yyssp)
1225 fprintf (stderr, " %d", *++ssp1);
1226 fprintf (stderr, "\n");
1228 #endif
1230 yyerrhandle:
1232 yyn = yypact[yystate];
1233 if (yyn == YYFLAG)
1234 goto yyerrdefault;
1236 yyn += YYTERROR;
1237 if (yyn < 0 || yyn > YYLAST || yycheck[yyn] != YYTERROR)
1238 goto yyerrdefault;
1240 yyn = yytable[yyn];
1241 if (yyn < 0)
1243 if (yyn == YYFLAG)
1244 goto yyerrpop;
1245 yyn = -yyn;
1246 goto yyreduce;
1248 else if (yyn == 0)
1249 goto yyerrpop;
1251 if (yyn == YYFINAL)
1252 YYACCEPT;
1254 #if YYDEBUG != 0
1255 if (yydebug)
1256 fprintf(stderr, "Shifting error token, ");
1257 #endif
1259 *++yyvsp = yylval;
1260 #ifdef YYLSP_NEEDED
1261 *++yylsp = yylloc;
1262 #endif
1264 yystate = yyn;
1265 goto yynewstate;
1267 yyacceptlab:
1268 /* YYACCEPT comes here. */
1269 if (yyfree_stacks)
1271 free (yyss);
1272 free (yyvs);
1273 #ifdef YYLSP_NEEDED
1274 free (yyls);
1275 #endif
1277 return 0;
1279 yyabortlab:
1280 /* YYABORT comes here. */
1281 if (yyfree_stacks)
1283 free (yyss);
1284 free (yyvs);
1285 #ifdef YYLSP_NEEDED
1286 free (yyls);
1287 #endif
1289 return 1;
1291 #line 307 "cf_gramatical.yxx"
1294 /* compute the good operation with a, b and op */
1295 cf_value cf_op (cf_value a, cf_value b, cf_operation op)
1297 DEBUG_PRINTF("[OP:%d; ", op);
1298 cf_print(a);
1299 DEBUG_PRINT("; ");
1300 cf_print(b);
1301 DEBUG_PRINT("; ");
1303 switch (op)
1305 case OP_MULT: // *********************
1306 switch (a.Type)
1308 case NLMISC::CConfigFile::CVar::T_INT:
1309 switch (b.Type)
1311 case NLMISC::CConfigFile::CVar::T_INT: a.Int *= b.Int; break;
1312 case NLMISC::CConfigFile::CVar::T_REAL: a.Int *= (int)b.Real; break;
1313 case NLMISC::CConfigFile::CVar::T_STRING: DEBUG_PRINT("ERROR: int*str\n"); break;
1314 default: break;
1316 break;
1317 case NLMISC::CConfigFile::CVar::T_REAL:
1318 switch (b.Type)
1320 case NLMISC::CConfigFile::CVar::T_INT: a.Real *= (double)b.Int; break;
1321 case NLMISC::CConfigFile::CVar::T_REAL: a.Real *= b.Real; break;
1322 case NLMISC::CConfigFile::CVar::T_STRING: DEBUG_PRINT("ERROR: real*str\n"); break;
1323 default: break;
1325 break;
1326 case NLMISC::CConfigFile::CVar::T_STRING:
1327 switch (b.Type)
1329 case NLMISC::CConfigFile::CVar::T_INT: DEBUG_PRINT("ERROR: str*int\n"); break;
1330 case NLMISC::CConfigFile::CVar::T_REAL: DEBUG_PRINT("ERROR: str*real\n"); break;
1331 case NLMISC::CConfigFile::CVar::T_STRING: DEBUG_PRINT("ERROR: str*str\n"); break;
1332 default: break;
1334 break;
1335 default: break;
1337 break;
1338 case OP_DIVIDE: // //////////////////////
1339 switch (a.Type)
1341 case NLMISC::CConfigFile::CVar::T_INT:
1342 switch (b.Type)
1344 case NLMISC::CConfigFile::CVar::T_INT: a.Int /= b.Int; break;
1345 case NLMISC::CConfigFile::CVar::T_REAL: a.Int /= (int)b.Real; break;
1346 case NLMISC::CConfigFile::CVar::T_STRING: DEBUG_PRINT("ERROR: int/str\n"); break;
1347 default: break;
1349 break;
1350 case NLMISC::CConfigFile::CVar::T_REAL:
1351 switch (b.Type)
1353 case NLMISC::CConfigFile::CVar::T_INT: a.Real /= (double)b.Int; break;
1354 case NLMISC::CConfigFile::CVar::T_REAL: a.Real /= b.Real; break;
1355 case NLMISC::CConfigFile::CVar::T_STRING: DEBUG_PRINT("ERROR: real/str\n"); break;
1356 default: break;
1358 break;
1359 case NLMISC::CConfigFile::CVar::T_STRING:
1360 switch (b.Type)
1362 case NLMISC::CConfigFile::CVar::T_INT: DEBUG_PRINT("ERROR: str/int\n"); break;
1363 case NLMISC::CConfigFile::CVar::T_REAL: DEBUG_PRINT("ERROR: str/real\n"); break;
1364 case NLMISC::CConfigFile::CVar::T_STRING: DEBUG_PRINT("ERROR: str/str\n"); break;
1365 default: break;
1367 break;
1368 default: break;
1370 break;
1371 case OP_PLUS: // ++++++++++++++++++++++++
1372 switch (a.Type)
1374 case NLMISC::CConfigFile::CVar::T_INT:
1375 switch (b.Type)
1377 case NLMISC::CConfigFile::CVar::T_INT: a.Int += b.Int; break;
1378 case NLMISC::CConfigFile::CVar::T_REAL: a.Int += (int)b.Real; break;
1379 case NLMISC::CConfigFile::CVar::T_STRING: a.Int += atoi(b.String); break;
1380 default: break;
1382 break;
1383 case NLMISC::CConfigFile::CVar::T_REAL:
1384 switch (b.Type)
1386 case NLMISC::CConfigFile::CVar::T_INT: a.Real += (double)b.Int; break;
1387 case NLMISC::CConfigFile::CVar::T_REAL: a.Real += b.Real; break;
1388 case NLMISC::CConfigFile::CVar::T_STRING: a.Real += atof (b.String); break;
1389 default: break;
1391 break;
1392 case NLMISC::CConfigFile::CVar::T_STRING:
1393 switch (b.Type)
1395 case NLMISC::CConfigFile::CVar::T_INT: { char str2[60]; NLMISC::smprintf(str2, 60, "%d", b.Int); strcat(a.String, str2); break; }
1396 case NLMISC::CConfigFile::CVar::T_REAL: { char str2[60]; NLMISC::smprintf(str2, 60, "%f", b.Real); strcat(a.String, str2); break; }
1397 case NLMISC::CConfigFile::CVar::T_STRING: strcat (a.String, b.String); break;
1398 default: break;
1400 break;
1401 default: break;
1403 break;
1404 case OP_MINUS: // -------------------------
1405 switch (a.Type)
1407 case NLMISC::CConfigFile::CVar::T_INT:
1408 switch (b.Type)
1410 case NLMISC::CConfigFile::CVar::T_INT: a.Int -= b.Int; break;
1411 case NLMISC::CConfigFile::CVar::T_REAL: a.Int -= (int)b.Real; break;
1412 case NLMISC::CConfigFile::CVar::T_STRING: DEBUG_PRINT("ERROR: int-str\n"); break;
1413 default: break;
1415 break;
1416 case NLMISC::CConfigFile::CVar::T_REAL:
1417 switch (b.Type)
1419 case NLMISC::CConfigFile::CVar::T_INT: a.Real -= (double)b.Int; break;
1420 case NLMISC::CConfigFile::CVar::T_REAL: a.Real -= b.Real; break;
1421 case NLMISC::CConfigFile::CVar::T_STRING: DEBUG_PRINT("ERROR: real-str\n"); break;
1422 default: break;
1424 break;
1425 case NLMISC::CConfigFile::CVar::T_STRING:
1426 switch (b.Type)
1428 case NLMISC::CConfigFile::CVar::T_INT: DEBUG_PRINT("ERROR: str-int\n"); break;
1429 case NLMISC::CConfigFile::CVar::T_REAL: DEBUG_PRINT("ERROR: str-real\n"); break;
1430 case NLMISC::CConfigFile::CVar::T_STRING: DEBUG_PRINT("ERROR: str-str\n"); break;
1431 default: break;
1433 break;
1434 default: break;
1436 break;
1437 case OP_NEG: // neg
1438 switch (a.Type)
1440 case NLMISC::CConfigFile::CVar::T_INT: a.Int = -a.Int; break;
1441 case NLMISC::CConfigFile::CVar::T_REAL: a.Real = -a.Real; break;
1442 case NLMISC::CConfigFile::CVar::T_STRING: DEBUG_PRINT("ERROR: -str\n"); break;
1443 default: break;
1445 break;
1447 cf_print(a);
1448 DEBUG_PRINT("]\n");
1449 return a;
1452 /* print a value, it's only for debug purpose */
1453 void cf_print (cf_value Val)
1455 switch (Val.Type)
1457 case NLMISC::CConfigFile::CVar::T_INT:
1458 DEBUG_PRINTF("'%d'", Val.Int);
1459 break;
1460 case NLMISC::CConfigFile::CVar::T_REAL:
1461 DEBUG_PRINTF("`%f`", Val.Real);
1462 break;
1463 case NLMISC::CConfigFile::CVar::T_STRING:
1464 DEBUG_PRINTF("\"%s\"", Val.String);
1465 break;
1466 default: break;
1470 /* put a value into a var */
1471 void cf_setVar (NLMISC::CConfigFile::CVar &Var, cf_value Val)
1473 DEBUG_PRINTF("Set var (type %d var name '%s') with new var type %d with value : ", Var.Type, Var.Name.c_str(), Val.Type);
1474 cf_print(Val);
1475 DEBUG_PRINTF("\n");
1476 Var.Root = LoadRoot;
1477 if (Var.Type == NLMISC::CConfigFile::CVar::T_UNKNOWN || Var.Type == Val.Type)
1479 if (Var.Type == NLMISC::CConfigFile::CVar::T_UNKNOWN)
1481 DEBUG_PRINTF("var type is unknown, set to the val type\n");
1483 else
1485 DEBUG_PRINTF("val type is same var type, just add\n");
1488 Var.Type = Val.Type;
1489 switch (Val.Type)
1491 case NLMISC::CConfigFile::CVar::T_INT: Var.IntValues.push_back (Val.Int); break;
1492 case NLMISC::CConfigFile::CVar::T_REAL: Var.RealValues.push_back (Val.Real); break;
1493 case NLMISC::CConfigFile::CVar::T_STRING: Var.StrValues.push_back(Val.String); break;
1494 default: break;
1497 else
1499 // need to convert the type
1500 switch (Var.Type)
1502 case NLMISC::CConfigFile::CVar::T_INT:
1503 switch (Val.Type)
1505 case NLMISC::CConfigFile::CVar::T_REAL: Var.IntValues.push_back ((int)Val.Real); break;
1506 case NLMISC::CConfigFile::CVar::T_STRING: { int val = 0; NLMISC::fromString(Val.String, val); Var.IntValues.push_back(val); break; }
1507 default: break;
1509 break;
1510 case NLMISC::CConfigFile::CVar::T_REAL:
1511 switch (Val.Type)
1513 case NLMISC::CConfigFile::CVar::T_INT: Var.RealValues.push_back ((double)Val.Int); break;
1514 case NLMISC::CConfigFile::CVar::T_STRING: { double val = 0.0; NLMISC::fromString(Val.String, val); Var.RealValues.push_back(val); break; }
1515 default: break;
1517 break;
1518 case NLMISC::CConfigFile::CVar::T_STRING:
1519 switch (Val.Type)
1521 case NLMISC::CConfigFile::CVar::T_INT: Var.StrValues.push_back(toString(Val.Int)); break;
1522 case NLMISC::CConfigFile::CVar::T_REAL: Var.StrValues.push_back(toString(Val.Real)); break;
1523 default: break;
1525 break;
1526 default: break;
1531 int yyerror (const char *s)
1533 DEBUG_PRINTF("%s\n",s);
1534 return 1;