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
9 #define yyerror cferror
12 #define yydebug cfdebug
13 #define yynerrs cfnerrs
14 #define ADD_ASSIGN 257
32 #line 1 "cf_gramatical.yxx"
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"
51 using namespace NLMISC
;
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)
69 #define DEBUG_PRINTF(format, args...)
71 #define DEBUG_PRINTF // InfoLog->displayRaw
77 enum cf_operation
{ OP_PLUS
, OP_MINUS
, OP_MULT
, OP_DIVIDE
, OP_NEG
};
81 NLMISC::CConfigFile::CVar::TVarType Type
;
89 extern bool cf_Ignore
;
97 NLMISC::CConfigFile::CVar cf_CurrentVar
;
100 char *cf_CurrentFile
;
102 bool cf_OverwriteExistingVariable
; // setup in the config_file.cpp reparse()
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"
134 #define YYFLAG -32768
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,
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,
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
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
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,
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
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)
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
302 #define YYSTACK_USE_ALLOCA
303 #else /* alloca not defined */
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
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. */
320 #else /* not MSDOS, or __TURBOC__ */
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> */
326 #define YYSTACK_USE_ALLOCA
327 #else /* not MSDOS, or __TURBOC__, or _AIX */
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
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
345 #define YYSTACK_ALLOC malloc
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)
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) \
367 if (yychar == YYEMPTY && yylen == 1) \
368 { yychar = (token), yylval = (value); \
369 yychar1 = YYTRANSLATE (yychar); \
374 { yyerror ("syntax error: cannot back up"); YYERROR; } \
378 #define YYERRCODE 256
381 #define YYLEX yylex()
387 #define YYLEX yylex(&yylval, &yylloc, YYLEX_PARAM)
389 #define YYLEX yylex(&yylval, &yylloc)
391 #else /* not YYLSP_NEEDED */
393 #define YYLEX yylex(&yylval, YYLEX_PARAM)
395 #define YYLEX yylex(&yylval)
397 #endif /* not YYLSP_NEEDED */
400 /* If nonreentrant, generate the variables here */
404 int yychar
; /* the lookahead symbol */
405 YYSTYPE yylval
; /* the semantic value of the */
406 /* lookahead symbol */
409 YYLTYPE yylloc
; /* location data for the lookahead */
413 int yynerrs
; /* number of parse errors so far */
414 #endif /* not YYPURE */
417 int yydebug
; /* nonzero means print parse trace */
418 /* Since this is uninitialized, it does not stop multiple parsers
422 /* YYINITDEPTH indicates the initial size of the parser's stacks */
425 #define YYINITDEPTH 200
428 /* YYMAXDEPTH is the maximum size the stacks can grow to
429 (effective only if the built-in stack extension method is used). */
436 #define YYMAXDEPTH 10000
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++ */
449 /* This is the most reliable way to avoid incompatibilities
450 in available built-in functions on various systems. */
452 __yy_memcpy (to
, from
, count
)
457 register char *f
= from
;
458 register char *t
= to
;
459 register int i
= count
;
465 #else /* __cplusplus */
467 /* This is the most reliable way to avoid incompatibilities
468 in available built-in functions on various systems. */
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
;
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. */
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. */
507 int yyparse (void *);
514 yyparse(YYPARSE_PARAM_ARG
)
517 register int yystate
;
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 */
531 YYLTYPE yylsa
[YYINITDEPTH
]; /* the location stack */
532 YYLTYPE
*yyls
= yylsa
;
535 #define YYPOPSTACK (yyvsp--, yyssp--, yylsp--)
537 #define YYPOPSTACK (yyvsp--, yyssp--)
540 int yystacksize
= YYINITDEPTH
;
541 int yyfree_stacks
= 0;
552 YYSTYPE yyval
; /* the variable used to return */
553 /* semantic values from the action */
555 // ace: big fake for VC7 because it checks if yyval is init or not
561 fprintf(stderr
, "Starting parse\n");
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. */
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. */
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
;
594 YYLTYPE
*yyls1
= yyls
;
597 /* Get the current used size of the three stacks, in elements. */
598 int size
= yyssp
- yyss
+ 1;
601 /* Each stack pointer address is followed by the size of
602 the data in use in that stack, in bytes. */
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
),
612 yyoverflow("parser stack overflow",
613 &yyss1
, size
* sizeof (*yyssp
),
614 &yyvs1
, size
* sizeof (*yyvsp
),
618 yyss
= yyss1
; yyvs
= yyvs1
;
622 #else /* no yyoverflow */
623 /* Extend the stack our own way. */
624 if (yystacksize
>= YYMAXDEPTH
)
626 yyerror("parser stack overflow");
638 if (yystacksize
> YYMAXDEPTH
)
639 yystacksize
= YYMAXDEPTH
;
640 #ifndef YYSTACK_USE_ALLOCA
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
));
650 yyls
= (YYLTYPE
*) YYSTACK_ALLOC (yystacksize
* sizeof (*yylsp
));
651 __yy_memcpy ((char *)yyls
, (char *)yyls1
,
652 size
* (unsigned int) sizeof (*yylsp
));
654 #endif /* no yyoverflow */
656 yyssp
= yyss
+ size
- 1;
657 yyvsp
= yyvs
+ size
- 1;
659 yylsp
= yyls
+ size
- 1;
664 fprintf(stderr
, "Stack size increased to %d\n", yystacksize
);
667 if (yyssp
>= yyss
+ yystacksize
- 1)
673 fprintf(stderr
, "Entering state %d\n", yystate
);
679 /* Do appropriate processing given the current state. */
680 /* Read a lookahead token if we need one and don't already have one. */
683 /* First try to decide what to do without reference to lookahead token. */
685 yyn
= yypact
[yystate
];
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
)
698 fprintf(stderr
, "Reading a token: ");
703 /* Convert token to internal form (in yychar1) for indexing tables with */
705 if (yychar
<= 0) /* This means end of input. */
708 yychar
= YYEOF
; /* Don't call YYLEX any more */
712 fprintf(stderr
, "Now at end of input.\n");
717 yychar1
= YYTRANSLATE(yychar
);
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. */
726 YYPRINT (stderr
, yychar
, yylval
);
728 fprintf (stderr
, ")\n");
734 if (yyn
< 0 || yyn
> YYLAST
|| yycheck
[yyn
] != yychar1
)
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,
744 0, or most negative number => error. */
759 /* Shift the lookahead token. */
763 fprintf(stderr
, "Shifting token %d (%s), ", yychar
, yytname
[yychar1
]);
766 /* Discard the token being shifted unless it is eof. */
775 /* count tokens shifted since error; after three, turn off error status. */
776 if (yyerrstatus
) yyerrstatus
--;
781 /* Do the default action for the current state. */
784 yyn
= yydefact
[yystate
];
788 /* Do a reduction. yyn is the number of a rule to reduce with. */
792 yyval
= yyvsp
[1-yylen
]; /* implement default value of the action */
799 fprintf (stderr
, "Reducing via rule %d (line %d), ",
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
]]);
813 #line 104 "cf_gramatical.yxx"
817 #line 107 "cf_gramatical.yxx"
821 #line 108 "cf_gramatical.yxx"
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;
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
);
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
);
858 NLMISC::CConfigFile::CVar Var
;
861 if (cf_CurrentVar
.Comp
)
863 DEBUG_PRINTF ("yacc: new assign complex variable '%s'\n", yyvsp
[-3].Val
.String
);
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 ()))
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
)
885 (*((vector
<NLMISC::CConfigFile::CVar
>*)(YYPARSE_PARAM
)))[i
] = Var
;
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
;
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
);
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
);
917 NLMISC::CConfigFile::CVar Var
;
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 ()))
926 DEBUG_PRINTF ("yacc: new add assign var '%s'\n", yyvsp
[-3].Val
.String
);
927 (*((vector
<NLMISC::CConfigFile::CVar
>*)(YYPARSE_PARAM
))).push_back (Var
);
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
]);
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
)
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
;
960 #line 245 "cf_gramatical.yxx"
961 { yyval
.Val
= yyvsp
[0].Val
; cf_CurrentVar
.Comp
= false; DEBUG_PRINT("false\n"); ;
964 #line 246 "cf_gramatical.yxx"
965 { yyval
.Val
= yyvsp
[-1].Val
; cf_CurrentVar
.Comp
= true; DEBUG_PRINT("true\n"); ;
968 #line 247 "cf_gramatical.yxx"
969 { yyval
.Val
= yyvsp
[-2].Val
; cf_CurrentVar
.Comp
= true; DEBUG_PRINT("true\n"); ;
972 #line 248 "cf_gramatical.yxx"
973 { yyval
.Val
= yyvsp
[0].Val
; cf_CurrentVar
.Comp
= true; DEBUG_PRINT("true\n"); ;
976 #line 251 "cf_gramatical.yxx"
977 { yyval
.Val
= yyvsp
[0].Val
; /*cf_CurrentVar.Type = $1.Type;*/ cf_setVar (cf_CurrentVar
, yyvsp
[0].Val
); ;
980 #line 252 "cf_gramatical.yxx"
981 { yyval
.Val
= yyvsp
[0].Val
; /*cf_CurrentVar.Type = $3.Type;*/ cf_setVar (cf_CurrentVar
, yyvsp
[0].Val
); ;
984 #line 255 "cf_gramatical.yxx"
985 { yyval
.Val
= yyvsp
[0].Val
; ;
988 #line 256 "cf_gramatical.yxx"
989 { yyval
.Val
= cf_op(yyvsp
[-2].Val
, yyvsp
[0].Val
, OP_PLUS
); ;
992 #line 257 "cf_gramatical.yxx"
993 { yyval
.Val
= cf_op(yyvsp
[-2].Val
, yyvsp
[0].Val
, OP_MINUS
); ;
996 #line 260 "cf_gramatical.yxx"
997 { yyval
.Val
= yyvsp
[0].Val
; ;
1000 #line 261 "cf_gramatical.yxx"
1001 { yyval
.Val
= cf_op(yyvsp
[-2].Val
, yyvsp
[0].Val
, OP_MULT
); ;
1004 #line 262 "cf_gramatical.yxx"
1005 { yyval
.Val
= cf_op (yyvsp
[-2].Val
, yyvsp
[0].Val
, OP_DIVIDE
); ;
1008 #line 265 "cf_gramatical.yxx"
1009 { yyval
.Val
= yyvsp
[0].Val
; ;
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
); ;
1016 #line 267 "cf_gramatical.yxx"
1017 { yyval
.Val
= yyvsp
[-1].Val
; ;
1020 #line 268 "cf_gramatical.yxx"
1021 { yyval
.Val
= yylval
.Val
; ;
1024 #line 269 "cf_gramatical.yxx"
1025 { yyval
.Val
= yylval
.Val
; ;
1028 #line 270 "cf_gramatical.yxx"
1029 { yyval
.Val
= yylval
.Val
; ;
1032 #line 271 "cf_gramatical.yxx"
1033 { yyval
.Val
= yyvsp
[0].Val
; ;
1036 #line 275 "cf_gramatical.yxx"
1038 DEBUG_PRINT("yacc: cont\n");
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
)
1052 Var
.Type
= (*((vector
<NLMISC::CConfigFile::CVar
>*)(YYPARSE_PARAM
)))[i
].Type
;
1053 DEBUG_PRINTF("vart %d\n", 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;
1065 DEBUG_PRINT("var existe pas\n");
1070 /* the action file gets copied in in place of this dollarsign */
1071 #line 543 "cfbison.simple"
1082 short *ssp1
= yyss
- 1;
1083 fprintf (stderr
, "state stack now");
1084 while (ssp1
!= yyssp
)
1085 fprintf (stderr
, " %d", *++ssp1
);
1086 fprintf (stderr
, "\n");
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
;
1104 yylsp
->last_line
= (yylsp
+yylen
-1)->last_line
;
1105 yylsp
->last_column
= (yylsp
+yylen
-1)->last_column
;
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. */
1116 yystate
= yypgoto
[yyn
- YYNTBASE
] + *yyssp
;
1117 if (yystate
>= 0 && yystate
<= YYLAST
&& yycheck
[yystate
] == *yyssp
)
1118 yystate
= yytable
[yystate
];
1120 yystate
= yydefgoto
[yyn
- YYNTBASE
];
1124 yyerrlab
: /* here on detecting error */
1127 /* If not already recovering from an error, report this error. */
1131 #ifdef YYERROR_VERBOSE
1132 yyn
= yypact
[yystate
];
1134 if (yyn
> YYFLAG
&& yyn
< YYLAST
)
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);
1149 strcpy(msg
, "parse error");
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
]);
1168 yyerror ("parse error; also virtual memory exceeded");
1171 #endif /* YYERROR_VERBOSE */
1172 yyerror("parse error");
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
)
1188 fprintf(stderr
, "Discarding token %d (%s).\n", yychar
, yytname
[yychar1
]);
1194 /* Else will try to reuse lookahead token
1195 after shifting the error token. */
1197 yyerrstatus
= 3; /* Each real token shifted decrements this */
1201 yyerrdefault
: /* current state does not do anything special for the error token. */
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
;
1210 yyerrpop
: /* pop the current state because it cannot handle the error token */
1212 if (yyssp
== yyss
) YYABORT
;
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");
1232 yyn
= yypact
[yystate
];
1237 if (yyn
< 0 || yyn
> YYLAST
|| yycheck
[yyn
] != YYTERROR
)
1256 fprintf(stderr
, "Shifting error token, ");
1268 /* YYACCEPT comes here. */
1280 /* YYABORT comes here. */
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
);
1305 case OP_MULT
: // *********************
1308 case NLMISC::CConfigFile::CVar::T_INT
:
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;
1317 case NLMISC::CConfigFile::CVar::T_REAL
:
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;
1326 case NLMISC::CConfigFile::CVar::T_STRING
:
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;
1338 case OP_DIVIDE
: // //////////////////////
1341 case NLMISC::CConfigFile::CVar::T_INT
:
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;
1350 case NLMISC::CConfigFile::CVar::T_REAL
:
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;
1359 case NLMISC::CConfigFile::CVar::T_STRING
:
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;
1371 case OP_PLUS
: // ++++++++++++++++++++++++
1374 case NLMISC::CConfigFile::CVar::T_INT
:
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;
1383 case NLMISC::CConfigFile::CVar::T_REAL
:
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;
1392 case NLMISC::CConfigFile::CVar::T_STRING
:
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;
1404 case OP_MINUS
: // -------------------------
1407 case NLMISC::CConfigFile::CVar::T_INT
:
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;
1416 case NLMISC::CConfigFile::CVar::T_REAL
:
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;
1425 case NLMISC::CConfigFile::CVar::T_STRING
:
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;
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;
1452 /* print a value, it's only for debug purpose */
1453 void cf_print (cf_value Val
)
1457 case NLMISC::CConfigFile::CVar::T_INT
:
1458 DEBUG_PRINTF("'%d'", Val
.Int
);
1460 case NLMISC::CConfigFile::CVar::T_REAL
:
1461 DEBUG_PRINTF("`%f`", Val
.Real
);
1463 case NLMISC::CConfigFile::CVar::T_STRING
:
1464 DEBUG_PRINTF("\"%s\"", Val
.String
);
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
);
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");
1485 DEBUG_PRINTF("val type is same var type, just add\n");
1488 Var
.Type
= 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;
1499 // need to convert the type
1502 case NLMISC::CConfigFile::CVar::T_INT
:
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; }
1510 case NLMISC::CConfigFile::CVar::T_REAL
:
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; }
1518 case NLMISC::CConfigFile::CVar::T_STRING
:
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;
1531 int yyerror (const char *s
)
1533 DEBUG_PRINTF("%s\n",s
);