Allow "REMAINDER" to function properly in expressions.
[asterisk/asterisk.git] / main / ast_expr2.c
1 /* A Bison parser, made by GNU Bison 2.3.  */
2
3 /* Skeleton implementation for Bison's Yacc-like parsers in C
4
5    Copyright (C) 1984, 1989, 1990, 2000, 2001, 2002, 2003, 2004, 2005, 2006
6    Free Software Foundation, Inc.
7
8    This program is free software; you can redistribute it and/or modify
9    it under the terms of the GNU General Public License as published by
10    the Free Software Foundation; either version 2, or (at your option)
11    any later version.
12
13    This program is distributed in the hope that it will be useful,
14    but WITHOUT ANY WARRANTY; without even the implied warranty of
15    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16    GNU General Public License for more details.
17
18    You should have received a copy of the GNU General Public License
19    along with this program; if not, write to the Free Software
20    Foundation, Inc., 51 Franklin Street, Fifth Floor,
21    Boston, MA 02110-1301, USA.  */
22
23 /* As a special exception, you may create a larger work that contains
24    part or all of the Bison parser skeleton and distribute that work
25    under terms of your choice, so long as that work isn't itself a
26    parser generator using the skeleton or a modified version thereof
27    as a parser skeleton.  Alternatively, if you modify or redistribute
28    the parser skeleton itself, you may (at your option) remove this
29    special exception, which will cause the skeleton and the resulting
30    Bison output files to be licensed under the GNU General Public
31    License without this special exception.
32
33    This special exception was added by the Free Software Foundation in
34    version 2.2 of Bison.  */
35
36 /* C LALR(1) parser skeleton written by Richard Stallman, by
37    simplifying the original so-called "semantic" parser.  */
38
39 /* All symbols defined below should begin with yy or YY, to avoid
40    infringing on user name space.  This should be done even for local
41    variables, as they might otherwise be expanded by user macros.
42    There are some unavoidable exceptions within include files to
43    define necessary library symbols; they are noted "INFRINGES ON
44    USER NAME SPACE" below.  */
45
46 /* Identify Bison output.  */
47 #define YYBISON 1
48
49 /* Bison version.  */
50 #define YYBISON_VERSION "2.3"
51
52 /* Skeleton name.  */
53 #define YYSKELETON_NAME "yacc.c"
54
55 /* Pure parsers.  */
56 #define YYPURE 1
57
58 /* Using locations.  */
59 #define YYLSP_NEEDED 1
60
61 /* Substitute the variable and function names.  */
62 #define yyparse ast_yyparse
63 #define yylex   ast_yylex
64 #define yyerror ast_yyerror
65 #define yylval  ast_yylval
66 #define yychar  ast_yychar
67 #define yydebug ast_yydebug
68 #define yynerrs ast_yynerrs
69 #define yylloc ast_yylloc
70
71 /* Tokens.  */
72 #ifndef YYTOKENTYPE
73 # define YYTOKENTYPE
74    /* Put the tokens into the symbol table, so that GDB and other debuggers
75       know about them.  */
76    enum yytokentype {
77      TOK_COMMA = 258,
78      TOK_COLONCOLON = 259,
79      TOK_COND = 260,
80      TOK_OR = 261,
81      TOK_AND = 262,
82      TOK_NE = 263,
83      TOK_LE = 264,
84      TOK_GE = 265,
85      TOK_LT = 266,
86      TOK_GT = 267,
87      TOK_EQ = 268,
88      TOK_MINUS = 269,
89      TOK_PLUS = 270,
90      TOK_MOD = 271,
91      TOK_DIV = 272,
92      TOK_MULT = 273,
93      TOK_COMPL = 274,
94      TOK_TILDETILDE = 275,
95      TOK_EQTILDE = 276,
96      TOK_COLON = 277,
97      TOK_LP = 278,
98      TOK_RP = 279,
99      TOKEN = 280
100    };
101 #endif
102 /* Tokens.  */
103 #define TOK_COMMA 258
104 #define TOK_COLONCOLON 259
105 #define TOK_COND 260
106 #define TOK_OR 261
107 #define TOK_AND 262
108 #define TOK_NE 263
109 #define TOK_LE 264
110 #define TOK_GE 265
111 #define TOK_LT 266
112 #define TOK_GT 267
113 #define TOK_EQ 268
114 #define TOK_MINUS 269
115 #define TOK_PLUS 270
116 #define TOK_MOD 271
117 #define TOK_DIV 272
118 #define TOK_MULT 273
119 #define TOK_COMPL 274
120 #define TOK_TILDETILDE 275
121 #define TOK_EQTILDE 276
122 #define TOK_COLON 277
123 #define TOK_LP 278
124 #define TOK_RP 279
125 #define TOKEN 280
126
127
128
129
130 /* Copy the first part of user declarations.  */
131 #line 1 "ast_expr2.y"
132
133 /* Written by Pace Willisson (pace@blitz.com) 
134  * and placed in the public domain.
135  *
136  * Largely rewritten by J.T. Conklin (jtc@wimsey.com)
137  *
138  * And then overhauled twice by Steve Murphy (murf@digium.com)
139  * to add double-quoted strings, allow mult. spaces, improve
140  * error messages, and then to fold in a flex scanner for the 
141  * yylex operation.
142  *
143  * $FreeBSD: src/bin/expr/expr.y,v 1.16 2000/07/22 10:59:36 se Exp $
144  */
145
146 #include "asterisk.h"
147
148 #include <sys/types.h>
149 #include <stdio.h>
150
151 #if !defined(STANDALONE) && !defined(STANDALONE2)       \
152         
153 ASTERISK_FILE_VERSION(__FILE__, "$Revision$")
154 #else
155 #ifndef __USE_ISOC99
156 #define __USE_ISOC99 1
157 #endif
158 #endif
159
160 #ifdef __USE_ISOC99
161 #define FP___PRINTF "%.18Lg"
162 #define FP___TYPE    long double
163 #else
164 #define FP___PRINTF "%.16g"
165 #define FP___TYPE    double
166 #endif
167
168 #ifdef HAVE_COSL
169 #define FUNC_COS   cosl
170 #elif defined(HAVE_COS)
171 #define FUNC_COS        (long double)cos
172 #endif
173
174 #ifdef HAVE_SINL
175 #define FUNC_SIN   sinl
176 #elif defined(HAVE_SIN)
177 #define FUNC_SIN        (long double)sin
178 #endif
179
180 #ifdef HAVE_TANL
181 #define FUNC_TAN   tanl
182 #elif defined(HAVE_TAN)
183 #define FUNC_TAN        (long double)tan
184 #endif
185
186 #ifdef HAVE_ACOSL
187 #define FUNC_ACOS   acosl
188 #elif defined(HAVE_ACOS)
189 #define FUNC_ACOS       (long double)acos
190 #endif
191
192 #ifdef HAVE_ASINL
193 #define FUNC_ASIN   asinl
194 #elif defined(HAVE_ASIN)
195 #define FUNC_ASIN       (long double)asin
196 #endif
197
198 #ifdef HAVE_ATANL
199 #define FUNC_ATAN   atanl
200 #elif defined(HAVE_ATAN)
201 #define FUNC_ATAN       (long double)atan
202 #endif
203
204 #ifdef HAVE_ATAN2L
205 #define FUNC_ATAN2   atan2l
206 #elif defined(HAVE_ATAN2)
207 #define FUNC_ATAN2      (long double)atan2
208 #endif
209
210 #ifdef HAVE_POWL
211 #define FUNC_POW   powl
212 #elif defined(HAVE_POW)
213 #define FUNC_POW        (long double)pow
214 #endif
215
216 #ifdef HAVE_SQRTL
217 #define FUNC_SQRT   sqrtl
218 #elif defined(HAVE_SQRT)
219 #define FUNC_SQRT       (long double)sqrt
220 #endif
221
222 #ifdef HAVE_RINTL
223 #define FUNC_RINT   rintl
224 #elif defined(HAVE_RINT)
225 #define FUNC_RINT       (long double)rint
226 #endif
227
228 #ifdef HAVE_EXPL
229 #define FUNC_EXP   expl
230 #elif defined(HAVE_EXP)
231 #define FUNC_EXP        (long double)exp
232 #endif
233
234 #ifdef HAVE_LOGL
235 #define FUNC_LOG   logl
236 #elif defined(HAVE_LOG)
237 #define FUNC_LOG        (long double)log
238 #endif
239
240 #ifdef HAVE_REMAINDERL
241 #define FUNC_REMAINDER   remainderl
242 #elif defined(HAVE_REMAINDER)
243 #define FUNC_REMAINDER  (long double)remainder
244 #endif
245
246 #ifdef HAVE_FMODL
247 #define FUNC_FMOD   fmodl
248 #elif defined(HAVE_FMOD)
249 #define FUNC_FMOD       (long double)fmod
250 #endif
251
252 #ifdef HAVE_STRTOLD
253 #define FUNC_STRTOD  strtold
254 #elif defined(HAVE_STRTOD)
255 #define FUNC_STRTOD  (long double)strtod
256 #endif
257
258 #ifdef HAVE_FLOORL
259 #define FUNC_FLOOR      floorl
260 #elif defined(HAVE_FLOOR)
261 #define FUNC_FLOOR      (long double)floor
262 #endif
263
264 #ifdef HAVE_CEILL
265 #define FUNC_CEIL      ceill
266 #elif defined(HAVE_CEIL)
267 #define FUNC_CEIL       (long double)ceil
268 #endif
269
270 #ifdef HAVE_ROUNDL
271 #define FUNC_ROUND     roundl
272 #elif defined(HAVE_ROUND)
273 #define FUNC_ROUND     (long double)round
274 #endif
275
276 #ifdef HAVE_TRUNCL
277 #define FUNC_TRUNC     truncl
278 #elif defined(HAVE_TRUNC)
279 #define FUNC_TRUNC     (long double)trunc
280 #endif
281
282 /*! \note
283  * Oddly enough, some platforms have some ISO C99 functions, but not others, so
284  * we define the missing functions in terms of their mathematical identities.
285  */
286 #ifdef HAVE_EXP2L
287 #define FUNC_EXP2       exp2l
288 #elif (defined(HAVE_EXPL) && defined(HAVE_LOGL))
289 #define FUNC_EXP2(x)    expl((x) * logl(2.0))
290 #elif (defined(HAVE_EXP) && defined(HAVE_LOG))
291 #define FUNC_EXP2(x)    (long double)exp((x) * log(2.0))
292 #endif
293
294 #ifdef HAVE_EXP10L
295 #define FUNC_EXP10       exp10l
296 #elif (defined(HAVE_EXPL) && defined(HAVE_LOGL))
297 #define FUNC_EXP10(x)   expl((x) * logl(10.0))
298 #elif (defined(HAVE_EXP) && defined(HAVE_LOG))
299 #define FUNC_EXP10(x)   (long double)exp((x) * log(10.0))
300 #endif
301
302 #ifdef HAVE_LOG2L
303 #define FUNC_LOG2       log2l
304 #elif defined(HAVE_LOGL)
305 #define FUNC_LOG2(x)    (logl(x) / logl(2.0))
306 #elif defined(HAVE_LOG10L)
307 #define FUNC_LOG2(x)    (log10l(x) / log10l(2.0))
308 #elif defined(HAVE_LOG2)
309 #define FUNC_LOG2       (long double)log2
310 #elif defined(HAVE_LOG)
311 #define FUNC_LOG2(x)    ((long double)log(x) / log(2.0))
312 #endif
313
314 #ifdef HAVE_LOG10L
315 #define FUNC_LOG10       log10l
316 #elif defined(HAVE_LOGL)
317 #define FUNC_LOG10(x)   (logl(x) / logl(10.0))
318 #elif defined(HAVE_LOG2L)
319 #define FUNC_LOG10(x)   (log2l(x) / log2l(10.0))
320 #elif defined(HAVE_LOG10)
321 #define FUNC_LOG10(x)   (long double)log10(x)
322 #elif defined(HAVE_LOG)
323 #define FUNC_LOG10(x)   ((long double)log(x) / log(10.0))
324 #endif
325
326
327 #include <stdlib.h>
328 #ifndef _GNU_SOURCE
329 #define _GNU_SOURCE
330 #endif
331 #include <string.h>
332 #include <math.h>
333 #include <locale.h>
334 #include <unistd.h>
335 #include <ctype.h>
336 #if !defined(SOLARIS) && !defined(__CYGWIN__)
337         /* #include <err.h> */
338 #else
339 #define quad_t int64_t
340 #endif
341 #include <errno.h>
342 #include <regex.h>
343 #include <limits.h>
344
345 #include "asterisk/ast_expr.h"
346 #include "asterisk/logger.h"
347 #if !defined(STANDALONE) && !defined(STANDALONE2)
348 #include "asterisk/pbx.h"
349 #endif
350
351 #if defined(LONG_LONG_MIN) && !defined(QUAD_MIN)
352 #define QUAD_MIN LONG_LONG_MIN
353 #endif
354 #if defined(LONG_LONG_MAX) && !defined(QUAD_MAX)
355 #define QUAD_MAX LONG_LONG_MAX
356 #endif
357
358 #  if ! defined(QUAD_MIN)
359 #   define QUAD_MIN     (-0x7fffffffffffffffLL-1)
360 #  endif
361 #  if ! defined(QUAD_MAX)
362 #   define QUAD_MAX     (0x7fffffffffffffffLL)
363 #  endif
364 #define YYENABLE_NLS 0
365 #define YYPARSE_PARAM parseio
366 #define YYLEX_PARAM ((struct parse_io *)parseio)->scanner
367 #define YYERROR_VERBOSE 1
368 extern char extra_error_message[4095];
369 extern int extra_error_message_supplied;
370
371 enum valtype {
372         AST_EXPR_number, AST_EXPR_numeric_string, AST_EXPR_string
373 } ;
374
375 #if defined(STANDALONE) || defined(STANDALONE2)
376 void ast_log(int level, const char *file, int line, const char *function, const char *fmt, ...) __attribute__ ((format (printf,5,6)));
377 #endif
378
379 struct val {
380         enum valtype type;
381         union {
382                 char *s;
383                 FP___TYPE i; /* either long double, or just double, on a bad day */
384         } u;
385 } ;
386
387 enum node_type {
388         AST_EXPR_NODE_COMMA, AST_EXPR_NODE_STRING, AST_EXPR_NODE_VAL
389 } ;
390
391 struct expr_node 
392 {
393         enum node_type type;
394         struct val *val;
395         struct expr_node *left;
396         struct expr_node *right;
397 };
398
399
400 typedef void *yyscan_t;
401
402 struct parse_io
403 {
404         char *string;
405         struct val *val;
406         yyscan_t scanner;
407         struct ast_channel *chan;
408 };
409  
410 static int              chk_div __P((FP___TYPE, FP___TYPE));
411 static int              chk_minus __P((FP___TYPE, FP___TYPE, FP___TYPE));
412 static int              chk_plus __P((FP___TYPE, FP___TYPE, FP___TYPE));
413 static int              chk_times __P((FP___TYPE, FP___TYPE, FP___TYPE));
414 static void             free_value __P((struct val *));
415 static int              is_zero_or_null __P((struct val *));
416 static int              isstring __P((struct val *));
417 static struct val       *make_number __P((FP___TYPE));
418 static struct val       *make_str __P((const char *));
419 static struct val       *op_and __P((struct val *, struct val *));
420 static struct val       *op_colon __P((struct val *, struct val *));
421 static struct val       *op_eqtilde __P((struct val *, struct val *));
422 static struct val       *op_tildetilde __P((struct val *, struct val *));
423 static struct val       *op_div __P((struct val *, struct val *));
424 static struct val       *op_eq __P((struct val *, struct val *));
425 static struct val       *op_ge __P((struct val *, struct val *));
426 static struct val       *op_gt __P((struct val *, struct val *));
427 static struct val       *op_le __P((struct val *, struct val *));
428 static struct val       *op_lt __P((struct val *, struct val *));
429 static struct val       *op_cond __P((struct val *, struct val *, struct val *));
430 static struct val       *op_minus __P((struct val *, struct val *));
431 static struct val       *op_negate __P((struct val *));
432 static struct val       *op_compl __P((struct val *));
433 static struct val       *op_ne __P((struct val *, struct val *));
434 static struct val       *op_or __P((struct val *, struct val *));
435 static struct val       *op_plus __P((struct val *, struct val *));
436 static struct val       *op_rem __P((struct val *, struct val *));
437 static struct val       *op_times __P((struct val *, struct val *));
438 static struct val   *op_func(struct val *funcname, struct expr_node *arglist, struct ast_channel *chan);
439 static int              to_number __P((struct val *));
440 static void             to_string __P((struct val *));
441 static struct expr_node *alloc_expr_node(enum node_type);
442 static void destroy_arglist(struct expr_node *arglist);
443
444 /* uh, if I want to predeclare yylex with a YYLTYPE, I have to predeclare the yyltype... sigh */
445 typedef struct yyltype
446 {
447   int first_line;
448   int first_column;
449
450   int last_line;
451   int last_column;
452 } yyltype;
453
454 # define YYLTYPE yyltype
455 # define YYLTYPE_IS_TRIVIAL 1
456
457 /* we will get warning about no prototype for yylex! But we can't
458    define it here, we have no definition yet for YYSTYPE. */
459
460 int             ast_yyerror(const char *,YYLTYPE *, struct parse_io *);
461  
462 /* I wanted to add args to the yyerror routine, so I could print out
463    some useful info about the error. Not as easy as it looks, but it
464    is possible. */
465 #define ast_yyerror(x) ast_yyerror(x,&yyloc,parseio)
466 #define DESTROY(x) {if((x)->type == AST_EXPR_numeric_string || (x)->type == AST_EXPR_string) free((x)->u.s); (x)->u.s = 0; free(x);}
467
468
469 /* Enabling traces.  */
470 #ifndef YYDEBUG
471 # define YYDEBUG 0
472 #endif
473
474 /* Enabling verbose error messages.  */
475 #ifdef YYERROR_VERBOSE
476 # undef YYERROR_VERBOSE
477 # define YYERROR_VERBOSE 1
478 #else
479 # define YYERROR_VERBOSE 0
480 #endif
481
482 /* Enabling the token table.  */
483 #ifndef YYTOKEN_TABLE
484 # define YYTOKEN_TABLE 0
485 #endif
486
487 #if ! defined YYSTYPE && ! defined YYSTYPE_IS_DECLARED
488 typedef union YYSTYPE
489 #line 345 "ast_expr2.y"
490 {
491         struct val *val;
492         struct expr_node *arglist;
493 }
494 /* Line 187 of yacc.c.  */
495 #line 496 "ast_expr2.c"
496         YYSTYPE;
497 # define yystype YYSTYPE /* obsolescent; will be withdrawn */
498 # define YYSTYPE_IS_DECLARED 1
499 # define YYSTYPE_IS_TRIVIAL 1
500 #endif
501
502 #if ! defined YYLTYPE && ! defined YYLTYPE_IS_DECLARED
503 typedef struct YYLTYPE
504 {
505   int first_line;
506   int first_column;
507   int last_line;
508   int last_column;
509 } YYLTYPE;
510 # define yyltype YYLTYPE /* obsolescent; will be withdrawn */
511 # define YYLTYPE_IS_DECLARED 1
512 # define YYLTYPE_IS_TRIVIAL 1
513 #endif
514
515
516 /* Copy the second part of user declarations.  */
517 #line 350 "ast_expr2.y"
518
519 extern int              ast_yylex __P((YYSTYPE *, YYLTYPE *, yyscan_t));
520
521
522 /* Line 216 of yacc.c.  */
523 #line 524 "ast_expr2.c"
524
525 #ifdef short
526 # undef short
527 #endif
528
529 #ifdef YYTYPE_UINT8
530 typedef YYTYPE_UINT8 yytype_uint8;
531 #else
532 typedef unsigned char yytype_uint8;
533 #endif
534
535 #ifdef YYTYPE_INT8
536 typedef YYTYPE_INT8 yytype_int8;
537 #elif (defined __STDC__ || defined __C99__FUNC__ \
538      || defined __cplusplus || defined _MSC_VER)
539 typedef signed char yytype_int8;
540 #else
541 typedef short int yytype_int8;
542 #endif
543
544 #ifdef YYTYPE_UINT16
545 typedef YYTYPE_UINT16 yytype_uint16;
546 #else
547 typedef unsigned short int yytype_uint16;
548 #endif
549
550 #ifdef YYTYPE_INT16
551 typedef YYTYPE_INT16 yytype_int16;
552 #else
553 typedef short int yytype_int16;
554 #endif
555
556 #ifndef YYSIZE_T
557 # ifdef __SIZE_TYPE__
558 #  define YYSIZE_T __SIZE_TYPE__
559 # elif defined size_t
560 #  define YYSIZE_T size_t
561 # elif ! defined YYSIZE_T && (defined __STDC__ || defined __C99__FUNC__ \
562      || defined __cplusplus || defined _MSC_VER)
563 #  include <stddef.h> /* INFRINGES ON USER NAME SPACE */
564 #  define YYSIZE_T size_t
565 # else
566 #  define YYSIZE_T unsigned int
567 # endif
568 #endif
569
570 #define YYSIZE_MAXIMUM ((YYSIZE_T) -1)
571
572 #ifndef YY_
573 # if YYENABLE_NLS
574 #  if ENABLE_NLS
575 #   include <libintl.h> /* INFRINGES ON USER NAME SPACE */
576 #   define YY_(msgid) dgettext ("bison-runtime", msgid)
577 #  endif
578 # endif
579 # ifndef YY_
580 #  define YY_(msgid) msgid
581 # endif
582 #endif
583
584 /* Suppress unused-variable warnings by "using" E.  */
585 #if ! defined lint || defined __GNUC__
586 # define YYUSE(e) ((void) (e))
587 #else
588 # define YYUSE(e) /* empty */
589 #endif
590
591 /* Identity function, used to suppress warnings about constant conditions.  */
592 #ifndef lint
593 # define YYID(n) (n)
594 #else
595 #if (defined __STDC__ || defined __C99__FUNC__ \
596      || defined __cplusplus || defined _MSC_VER)
597 static int
598 YYID (int i)
599 #else
600 static int
601 YYID (i)
602     int i;
603 #endif
604 {
605   return i;
606 }
607 #endif
608
609 #if ! defined yyoverflow || YYERROR_VERBOSE
610
611 /* The parser invokes alloca or malloc; define the necessary symbols.  */
612
613 # ifdef YYSTACK_USE_ALLOCA
614 #  if YYSTACK_USE_ALLOCA
615 #   ifdef __GNUC__
616 #    define YYSTACK_ALLOC __builtin_alloca
617 #   elif defined __BUILTIN_VA_ARG_INCR
618 #    include <alloca.h> /* INFRINGES ON USER NAME SPACE */
619 #   elif defined _AIX
620 #    define YYSTACK_ALLOC __alloca
621 #   elif defined _MSC_VER
622 #    include <malloc.h> /* INFRINGES ON USER NAME SPACE */
623 #    define alloca _alloca
624 #   else
625 #    define YYSTACK_ALLOC alloca
626 #    if ! defined _ALLOCA_H && ! defined _STDLIB_H && (defined __STDC__ || defined __C99__FUNC__ \
627      || defined __cplusplus || defined _MSC_VER)
628 #     include <stdlib.h> /* INFRINGES ON USER NAME SPACE */
629 #     ifndef _STDLIB_H
630 #      define _STDLIB_H 1
631 #     endif
632 #    endif
633 #   endif
634 #  endif
635 # endif
636
637 # ifdef YYSTACK_ALLOC
638    /* Pacify GCC's `empty if-body' warning.  */
639 #  define YYSTACK_FREE(Ptr) do { /* empty */; } while (YYID (0))
640 #  ifndef YYSTACK_ALLOC_MAXIMUM
641     /* The OS might guarantee only one guard page at the bottom of the stack,
642        and a page size can be as small as 4096 bytes.  So we cannot safely
643        invoke alloca (N) if N exceeds 4096.  Use a slightly smaller number
644        to allow for a few compiler-allocated temporary stack slots.  */
645 #   define YYSTACK_ALLOC_MAXIMUM 4032 /* reasonable circa 2006 */
646 #  endif
647 # else
648 #  define YYSTACK_ALLOC YYMALLOC
649 #  define YYSTACK_FREE YYFREE
650 #  ifndef YYSTACK_ALLOC_MAXIMUM
651 #   define YYSTACK_ALLOC_MAXIMUM YYSIZE_MAXIMUM
652 #  endif
653 #  if (defined __cplusplus && ! defined _STDLIB_H \
654        && ! ((defined YYMALLOC || defined malloc) \
655              && (defined YYFREE || defined free)))
656 #   include <stdlib.h> /* INFRINGES ON USER NAME SPACE */
657 #   ifndef _STDLIB_H
658 #    define _STDLIB_H 1
659 #   endif
660 #  endif
661 #  ifndef YYMALLOC
662 #   define YYMALLOC malloc
663 #   if ! defined malloc && ! defined _STDLIB_H && (defined __STDC__ || defined __C99__FUNC__ \
664      || defined __cplusplus || defined _MSC_VER)
665 void *malloc (YYSIZE_T); /* INFRINGES ON USER NAME SPACE */
666 #   endif
667 #  endif
668 #  ifndef YYFREE
669 #   define YYFREE free
670 #   if ! defined free && ! defined _STDLIB_H && (defined __STDC__ || defined __C99__FUNC__ \
671      || defined __cplusplus || defined _MSC_VER)
672 void free (void *); /* INFRINGES ON USER NAME SPACE */
673 #   endif
674 #  endif
675 # endif
676 #endif /* ! defined yyoverflow || YYERROR_VERBOSE */
677
678
679 #if (! defined yyoverflow \
680      && (! defined __cplusplus \
681          || (defined YYLTYPE_IS_TRIVIAL && YYLTYPE_IS_TRIVIAL \
682              && defined YYSTYPE_IS_TRIVIAL && YYSTYPE_IS_TRIVIAL)))
683
684 /* A type that is properly aligned for any stack member.  */
685 union yyalloc
686 {
687   yytype_int16 yyss;
688   YYSTYPE yyvs;
689     YYLTYPE yyls;
690 };
691
692 /* The size of the maximum gap between one aligned stack and the next.  */
693 # define YYSTACK_GAP_MAXIMUM (sizeof (union yyalloc) - 1)
694
695 /* The size of an array large to enough to hold all stacks, each with
696    N elements.  */
697 # define YYSTACK_BYTES(N) \
698      ((N) * (sizeof (yytype_int16) + sizeof (YYSTYPE) + sizeof (YYLTYPE)) \
699       + 2 * YYSTACK_GAP_MAXIMUM)
700
701 /* Copy COUNT objects from FROM to TO.  The source and destination do
702    not overlap.  */
703 # ifndef YYCOPY
704 #  if defined __GNUC__ && 1 < __GNUC__
705 #   define YYCOPY(To, From, Count) \
706       __builtin_memcpy (To, From, (Count) * sizeof (*(From)))
707 #  else
708 #   define YYCOPY(To, From, Count)              \
709       do                                        \
710         {                                       \
711           YYSIZE_T yyi;                         \
712           for (yyi = 0; yyi < (Count); yyi++)   \
713             (To)[yyi] = (From)[yyi];            \
714         }                                       \
715       while (YYID (0))
716 #  endif
717 # endif
718
719 /* Relocate STACK from its old location to the new one.  The
720    local variables YYSIZE and YYSTACKSIZE give the old and new number of
721    elements in the stack, and YYPTR gives the new location of the
722    stack.  Advance YYPTR to a properly aligned location for the next
723    stack.  */
724 # define YYSTACK_RELOCATE(Stack)                                        \
725     do                                                                  \
726       {                                                                 \
727         YYSIZE_T yynewbytes;                                            \
728         YYCOPY (&yyptr->Stack, Stack, yysize);                          \
729         Stack = &yyptr->Stack;                                          \
730         yynewbytes = yystacksize * sizeof (*Stack) + YYSTACK_GAP_MAXIMUM; \
731         yyptr += yynewbytes / sizeof (*yyptr);                          \
732       }                                                                 \
733     while (YYID (0))
734
735 #endif
736
737 /* YYFINAL -- State number of the termination state.  */
738 #define YYFINAL  11
739 /* YYLAST -- Last index in YYTABLE.  */
740 #define YYLAST   159
741
742 /* YYNTOKENS -- Number of terminals.  */
743 #define YYNTOKENS  26
744 /* YYNNTS -- Number of nonterminals.  */
745 #define YYNNTS  4
746 /* YYNRULES -- Number of rules.  */
747 #define YYNRULES  28
748 /* YYNRULES -- Number of states.  */
749 #define YYNSTATES  54
750
751 /* YYTRANSLATE(YYLEX) -- Bison symbol number corresponding to YYLEX.  */
752 #define YYUNDEFTOK  2
753 #define YYMAXUTOK   280
754
755 #define YYTRANSLATE(YYX)                                                \
756   ((unsigned int) (YYX) <= YYMAXUTOK ? yytranslate[YYX] : YYUNDEFTOK)
757
758 /* YYTRANSLATE[YYLEX] -- Bison symbol number corresponding to YYLEX.  */
759 static const yytype_uint8 yytranslate[] =
760 {
761        0,     2,     2,     2,     2,     2,     2,     2,     2,     2,
762        2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
763        2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
764        2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
765        2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
766        2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
767        2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
768        2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
769        2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
770        2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
771        2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
772        2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
773        2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
774        2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
775        2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
776        2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
777        2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
778        2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
779        2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
780        2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
781        2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
782        2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
783        2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
784        2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
785        2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
786        2,     2,     2,     2,     2,     2,     1,     2,     3,     4,
787        5,     6,     7,     8,     9,    10,    11,    12,    13,    14,
788       15,    16,    17,    18,    19,    20,    21,    22,    23,    24,
789       25
790 };
791
792 #if YYDEBUG
793 /* YYPRHS[YYN] -- Index of the first RHS symbol of rule number YYN in
794    YYRHS.  */
795 static const yytype_uint8 yyprhs[] =
796 {
797        0,     0,     3,     5,     6,     8,    12,    15,    20,    22,
798       26,    30,    34,    38,    42,    46,    50,    54,    58,    62,
799       66,    69,    72,    76,    80,    84,    88,    92,    98
800 };
801
802 /* YYRHS -- A `-1'-separated list of the rules' RHS.  */
803 static const yytype_int8 yyrhs[] =
804 {
805       27,     0,    -1,    29,    -1,    -1,    29,    -1,    28,     3,
806       29,    -1,    28,     3,    -1,    25,    23,    28,    24,    -1,
807       25,    -1,    23,    29,    24,    -1,    29,     6,    29,    -1,
808       29,     7,    29,    -1,    29,    13,    29,    -1,    29,    12,
809       29,    -1,    29,    11,    29,    -1,    29,    10,    29,    -1,
810       29,     9,    29,    -1,    29,     8,    29,    -1,    29,    15,
811       29,    -1,    29,    14,    29,    -1,    14,    29,    -1,    19,
812       29,    -1,    29,    18,    29,    -1,    29,    17,    29,    -1,
813       29,    16,    29,    -1,    29,    22,    29,    -1,    29,    21,
814       29,    -1,    29,     5,    29,     4,    29,    -1,    29,    20,
815       29,    -1
816 };
817
818 /* YYRLINE[YYN] -- source line where rule number YYN was defined.  */
819 static const yytype_uint16 yyrline[] =
820 {
821        0,   374,   374,   382,   389,   390,   396,   405,   411,   412,
822      416,   420,   424,   428,   432,   436,   440,   444,   448,   452,
823      456,   460,   464,   468,   472,   476,   480,   484,   489
824 };
825 #endif
826
827 #if YYDEBUG || YYERROR_VERBOSE || YYTOKEN_TABLE
828 /* YYTNAME[SYMBOL-NUM] -- String name of the symbol SYMBOL-NUM.
829    First, the terminals, then, starting at YYNTOKENS, nonterminals.  */
830 static const char *const yytname[] =
831 {
832   "$end", "error", "$undefined", "TOK_COMMA", "TOK_COLONCOLON",
833   "TOK_COND", "TOK_OR", "TOK_AND", "TOK_NE", "TOK_LE", "TOK_GE", "TOK_LT",
834   "TOK_GT", "TOK_EQ", "TOK_MINUS", "TOK_PLUS", "TOK_MOD", "TOK_DIV",
835   "TOK_MULT", "TOK_COMPL", "TOK_TILDETILDE", "TOK_EQTILDE", "TOK_COLON",
836   "TOK_LP", "TOK_RP", "TOKEN", "$accept", "start", "arglist", "expr", 0
837 };
838 #endif
839
840 # ifdef YYPRINT
841 /* YYTOKNUM[YYLEX-NUM] -- Internal token number corresponding to
842    token YYLEX-NUM.  */
843 static const yytype_uint16 yytoknum[] =
844 {
845        0,   256,   257,   258,   259,   260,   261,   262,   263,   264,
846      265,   266,   267,   268,   269,   270,   271,   272,   273,   274,
847      275,   276,   277,   278,   279,   280
848 };
849 # endif
850
851 /* YYR1[YYN] -- Symbol number of symbol that rule YYN derives.  */
852 static const yytype_uint8 yyr1[] =
853 {
854        0,    26,    27,    27,    28,    28,    28,    29,    29,    29,
855       29,    29,    29,    29,    29,    29,    29,    29,    29,    29,
856       29,    29,    29,    29,    29,    29,    29,    29,    29
857 };
858
859 /* YYR2[YYN] -- Number of symbols composing right hand side of rule YYN.  */
860 static const yytype_uint8 yyr2[] =
861 {
862        0,     2,     1,     0,     1,     3,     2,     4,     1,     3,
863        3,     3,     3,     3,     3,     3,     3,     3,     3,     3,
864        2,     2,     3,     3,     3,     3,     3,     5,     3
865 };
866
867 /* YYDEFACT[STATE-NAME] -- Default rule to reduce with in state
868    STATE-NUM when YYTABLE doesn't specify something else to do.  Zero
869    means the default is an error.  */
870 static const yytype_uint8 yydefact[] =
871 {
872        3,     0,     0,     0,     8,     0,     2,    20,    21,     0,
873        0,     1,     0,     0,     0,     0,     0,     0,     0,     0,
874        0,     0,     0,     0,     0,     0,     0,     0,     0,     9,
875        0,     4,     0,    10,    11,    17,    16,    15,    14,    13,
876       12,    19,    18,    24,    23,    22,    28,    26,    25,     6,
877        7,     0,     5,    27
878 };
879
880 /* YYDEFGOTO[NTERM-NUM].  */
881 static const yytype_int8 yydefgoto[] =
882 {
883       -1,     5,    30,     6
884 };
885
886 /* YYPACT[STATE-NUM] -- Index in YYTABLE of the portion describing
887    STATE-NUM.  */
888 #define YYPACT_NINF -18
889 static const yytype_int16 yypact[] =
890 {
891      118,   118,   118,   118,   -15,     6,    65,   -17,   -17,    25,
892      118,   -18,   118,   118,   118,   118,   118,   118,   118,   118,
893      118,   118,   118,   118,   118,   118,   118,   118,   118,   -18,
894        4,    65,    47,    98,   113,   130,   130,   130,   130,   130,
895      130,   137,   137,   -17,   -17,   -17,   -18,   -18,   -18,   118,
896      -18,   118,    65,    82
897 };
898
899 /* YYPGOTO[NTERM-NUM].  */
900 static const yytype_int8 yypgoto[] =
901 {
902      -18,   -18,   -18,    -1
903 };
904
905 /* YYTABLE[YYPACT[STATE-NUM]].  What to do in state STATE-NUM.  If
906    positive, shift that token.  If negative, reduce the rule which
907    number is the opposite.  If zero, do what YYDEFACT says.
908    If YYTABLE_NINF, syntax error.  */
909 #define YYTABLE_NINF -1
910 static const yytype_uint8 yytable[] =
911 {
912        7,     8,     9,    26,    27,    28,    11,    49,    10,    31,
913        0,    32,    33,    34,    35,    36,    37,    38,    39,    40,
914       41,    42,    43,    44,    45,    46,    47,    48,    50,     0,
915       12,    13,    14,    15,    16,    17,    18,    19,    20,    21,
916       22,    23,    24,    25,     0,    26,    27,    28,    52,    29,
917       53,    51,    12,    13,    14,    15,    16,    17,    18,    19,
918       20,    21,    22,    23,    24,    25,     0,    26,    27,    28,
919       12,    13,    14,    15,    16,    17,    18,    19,    20,    21,
920       22,    23,    24,    25,     0,    26,    27,    28,    13,    14,
921       15,    16,    17,    18,    19,    20,    21,    22,    23,    24,
922       25,     0,    26,    27,    28,    14,    15,    16,    17,    18,
923       19,    20,    21,    22,    23,    24,    25,     0,    26,    27,
924       28,    15,    16,    17,    18,    19,    20,    21,    22,    23,
925       24,    25,     1,    26,    27,    28,     0,     2,     0,     0,
926        0,     3,     0,     4,    21,    22,    23,    24,    25,     0,
927       26,    27,    28,    23,    24,    25,     0,    26,    27,    28
928 };
929
930 static const yytype_int8 yycheck[] =
931 {
932        1,     2,     3,    20,    21,    22,     0,     3,    23,    10,
933       -1,    12,    13,    14,    15,    16,    17,    18,    19,    20,
934       21,    22,    23,    24,    25,    26,    27,    28,    24,    -1,
935        5,     6,     7,     8,     9,    10,    11,    12,    13,    14,
936       15,    16,    17,    18,    -1,    20,    21,    22,    49,    24,
937       51,     4,     5,     6,     7,     8,     9,    10,    11,    12,
938       13,    14,    15,    16,    17,    18,    -1,    20,    21,    22,
939        5,     6,     7,     8,     9,    10,    11,    12,    13,    14,
940       15,    16,    17,    18,    -1,    20,    21,    22,     6,     7,
941        8,     9,    10,    11,    12,    13,    14,    15,    16,    17,
942       18,    -1,    20,    21,    22,     7,     8,     9,    10,    11,
943       12,    13,    14,    15,    16,    17,    18,    -1,    20,    21,
944       22,     8,     9,    10,    11,    12,    13,    14,    15,    16,
945       17,    18,    14,    20,    21,    22,    -1,    19,    -1,    -1,
946       -1,    23,    -1,    25,    14,    15,    16,    17,    18,    -1,
947       20,    21,    22,    16,    17,    18,    -1,    20,    21,    22
948 };
949
950 /* YYSTOS[STATE-NUM] -- The (internal number of the) accessing
951    symbol of state STATE-NUM.  */
952 static const yytype_uint8 yystos[] =
953 {
954        0,    14,    19,    23,    25,    27,    29,    29,    29,    29,
955       23,     0,     5,     6,     7,     8,     9,    10,    11,    12,
956       13,    14,    15,    16,    17,    18,    20,    21,    22,    24,
957       28,    29,    29,    29,    29,    29,    29,    29,    29,    29,
958       29,    29,    29,    29,    29,    29,    29,    29,    29,     3,
959       24,     4,    29,    29
960 };
961
962 #define yyerrok         (yyerrstatus = 0)
963 #define yyclearin       (yychar = YYEMPTY)
964 #define YYEMPTY         (-2)
965 #define YYEOF           0
966
967 #define YYACCEPT        goto yyacceptlab
968 #define YYABORT         goto yyabortlab
969 #define YYERROR         goto yyerrorlab
970
971
972 /* Like YYERROR except do call yyerror.  This remains here temporarily
973    to ease the transition to the new meaning of YYERROR, for GCC.
974    Once GCC version 2 has supplanted version 1, this can go.  */
975
976 #define YYFAIL          goto yyerrlab
977
978 #define YYRECOVERING()  (!!yyerrstatus)
979
980 #define YYBACKUP(Token, Value)                                  \
981 do                                                              \
982   if (yychar == YYEMPTY && yylen == 1)                          \
983     {                                                           \
984       yychar = (Token);                                         \
985       yylval = (Value);                                         \
986       yytoken = YYTRANSLATE (yychar);                           \
987       YYPOPSTACK (1);                                           \
988       goto yybackup;                                            \
989     }                                                           \
990   else                                                          \
991     {                                                           \
992       yyerror (YY_("syntax error: cannot back up")); \
993       YYERROR;                                                  \
994     }                                                           \
995 while (YYID (0))
996
997
998 #define YYTERROR        1
999 #define YYERRCODE       256
1000
1001
1002 /* YYLLOC_DEFAULT -- Set CURRENT to span from RHS[1] to RHS[N].
1003    If N is 0, then set CURRENT to the empty location which ends
1004    the previous symbol: RHS[0] (always defined).  */
1005
1006 #define YYRHSLOC(Rhs, K) ((Rhs)[K])
1007 #ifndef YYLLOC_DEFAULT
1008 # define YYLLOC_DEFAULT(Current, Rhs, N)                                \
1009     do                                                                  \
1010       if (YYID (N))                                                    \
1011         {                                                               \
1012           (Current).first_line   = YYRHSLOC (Rhs, 1).first_line;        \
1013           (Current).first_column = YYRHSLOC (Rhs, 1).first_column;      \
1014           (Current).last_line    = YYRHSLOC (Rhs, N).last_line;         \
1015           (Current).last_column  = YYRHSLOC (Rhs, N).last_column;       \
1016         }                                                               \
1017       else                                                              \
1018         {                                                               \
1019           (Current).first_line   = (Current).last_line   =              \
1020             YYRHSLOC (Rhs, 0).last_line;                                \
1021           (Current).first_column = (Current).last_column =              \
1022             YYRHSLOC (Rhs, 0).last_column;                              \
1023         }                                                               \
1024     while (YYID (0))
1025 #endif
1026
1027
1028 /* YY_LOCATION_PRINT -- Print the location on the stream.
1029    This macro was not mandated originally: define only if we know
1030    we won't break user code: when these are the locations we know.  */
1031
1032 #ifndef YY_LOCATION_PRINT
1033 # if YYLTYPE_IS_TRIVIAL
1034 #  define YY_LOCATION_PRINT(File, Loc)                  \
1035      fprintf (File, "%d.%d-%d.%d",                      \
1036               (Loc).first_line, (Loc).first_column,     \
1037               (Loc).last_line,  (Loc).last_column)
1038 # else
1039 #  define YY_LOCATION_PRINT(File, Loc) ((void) 0)
1040 # endif
1041 #endif
1042
1043
1044 /* YYLEX -- calling `yylex' with the right arguments.  */
1045
1046 #ifdef YYLEX_PARAM
1047 # define YYLEX yylex (&yylval, &yylloc, YYLEX_PARAM)
1048 #else
1049 # define YYLEX yylex (&yylval, &yylloc)
1050 #endif
1051
1052 /* Enable debugging if requested.  */
1053 #if YYDEBUG
1054
1055 # ifndef YYFPRINTF
1056 #  include <stdio.h> /* INFRINGES ON USER NAME SPACE */
1057 #  define YYFPRINTF fprintf
1058 # endif
1059
1060 # define YYDPRINTF(Args)                        \
1061 do {                                            \
1062   if (yydebug)                                  \
1063     YYFPRINTF Args;                             \
1064 } while (YYID (0))
1065
1066 # define YY_SYMBOL_PRINT(Title, Type, Value, Location)                    \
1067 do {                                                                      \
1068   if (yydebug)                                                            \
1069     {                                                                     \
1070       YYFPRINTF (stderr, "%s ", Title);                                   \
1071       yy_symbol_print (stderr,                                            \
1072                   Type, Value, Location); \
1073       YYFPRINTF (stderr, "\n");                                           \
1074     }                                                                     \
1075 } while (YYID (0))
1076
1077
1078 /*--------------------------------.
1079 | Print this symbol on YYOUTPUT.  |
1080 `--------------------------------*/
1081
1082 /*ARGSUSED*/
1083 #if (defined __STDC__ || defined __C99__FUNC__ \
1084      || defined __cplusplus || defined _MSC_VER)
1085 static void
1086 yy_symbol_value_print (FILE *yyoutput, int yytype, YYSTYPE const * const yyvaluep, YYLTYPE const * const yylocationp)
1087 #else
1088 static void
1089 yy_symbol_value_print (yyoutput, yytype, yyvaluep, yylocationp)
1090     FILE *yyoutput;
1091     int yytype;
1092     YYSTYPE const * const yyvaluep;
1093     YYLTYPE const * const yylocationp;
1094 #endif
1095 {
1096   if (!yyvaluep)
1097     return;
1098   YYUSE (yylocationp);
1099 # ifdef YYPRINT
1100   if (yytype < YYNTOKENS)
1101     YYPRINT (yyoutput, yytoknum[yytype], *yyvaluep);
1102 # else
1103   YYUSE (yyoutput);
1104 # endif
1105   switch (yytype)
1106     {
1107       default:
1108         break;
1109     }
1110 }
1111
1112
1113 /*--------------------------------.
1114 | Print this symbol on YYOUTPUT.  |
1115 `--------------------------------*/
1116
1117 #if (defined __STDC__ || defined __C99__FUNC__ \
1118      || defined __cplusplus || defined _MSC_VER)
1119 static void
1120 yy_symbol_print (FILE *yyoutput, int yytype, YYSTYPE const * const yyvaluep, YYLTYPE const * const yylocationp)
1121 #else
1122 static void
1123 yy_symbol_print (yyoutput, yytype, yyvaluep, yylocationp)
1124     FILE *yyoutput;
1125     int yytype;
1126     YYSTYPE const * const yyvaluep;
1127     YYLTYPE const * const yylocationp;
1128 #endif
1129 {
1130   if (yytype < YYNTOKENS)
1131     YYFPRINTF (yyoutput, "token %s (", yytname[yytype]);
1132   else
1133     YYFPRINTF (yyoutput, "nterm %s (", yytname[yytype]);
1134
1135   YY_LOCATION_PRINT (yyoutput, *yylocationp);
1136   YYFPRINTF (yyoutput, ": ");
1137   yy_symbol_value_print (yyoutput, yytype, yyvaluep, yylocationp);
1138   YYFPRINTF (yyoutput, ")");
1139 }
1140
1141 /*------------------------------------------------------------------.
1142 | yy_stack_print -- Print the state stack from its BOTTOM up to its |
1143 | TOP (included).                                                   |
1144 `------------------------------------------------------------------*/
1145
1146 #if (defined __STDC__ || defined __C99__FUNC__ \
1147      || defined __cplusplus || defined _MSC_VER)
1148 static void
1149 yy_stack_print (yytype_int16 *bottom, yytype_int16 *top)
1150 #else
1151 static void
1152 yy_stack_print (bottom, top)
1153     yytype_int16 *bottom;
1154     yytype_int16 *top;
1155 #endif
1156 {
1157   YYFPRINTF (stderr, "Stack now");
1158   for (; bottom <= top; ++bottom)
1159     YYFPRINTF (stderr, " %d", *bottom);
1160   YYFPRINTF (stderr, "\n");
1161 }
1162
1163 # define YY_STACK_PRINT(Bottom, Top)                            \
1164 do {                                                            \
1165   if (yydebug)                                                  \
1166     yy_stack_print ((Bottom), (Top));                           \
1167 } while (YYID (0))
1168
1169
1170 /*------------------------------------------------.
1171 | Report that the YYRULE is going to be reduced.  |
1172 `------------------------------------------------*/
1173
1174 #if (defined __STDC__ || defined __C99__FUNC__ \
1175      || defined __cplusplus || defined _MSC_VER)
1176 static void
1177 yy_reduce_print (YYSTYPE *yyvsp, YYLTYPE *yylsp, int yyrule)
1178 #else
1179 static void
1180 yy_reduce_print (yyvsp, yylsp, yyrule)
1181     YYSTYPE *yyvsp;
1182     YYLTYPE *yylsp;
1183     int yyrule;
1184 #endif
1185 {
1186   int yynrhs = yyr2[yyrule];
1187   int yyi;
1188   unsigned long int yylno = yyrline[yyrule];
1189   YYFPRINTF (stderr, "Reducing stack by rule %d (line %lu):\n",
1190              yyrule - 1, yylno);
1191   /* The symbols being reduced.  */
1192   for (yyi = 0; yyi < yynrhs; yyi++)
1193     {
1194       fprintf (stderr, "   $%d = ", yyi + 1);
1195       yy_symbol_print (stderr, yyrhs[yyprhs[yyrule] + yyi],
1196                        &(yyvsp[(yyi + 1) - (yynrhs)])
1197                        , &(yylsp[(yyi + 1) - (yynrhs)])                );
1198       fprintf (stderr, "\n");
1199     }
1200 }
1201
1202 # define YY_REDUCE_PRINT(Rule)          \
1203 do {                                    \
1204   if (yydebug)                          \
1205     yy_reduce_print (yyvsp, yylsp, Rule); \
1206 } while (YYID (0))
1207
1208 /* Nonzero means print parse trace.  It is left uninitialized so that
1209    multiple parsers can coexist.  */
1210 int yydebug;
1211 #else /* !YYDEBUG */
1212 # define YYDPRINTF(Args)
1213 # define YY_SYMBOL_PRINT(Title, Type, Value, Location)
1214 # define YY_STACK_PRINT(Bottom, Top)
1215 # define YY_REDUCE_PRINT(Rule)
1216 #endif /* !YYDEBUG */
1217
1218
1219 /* YYINITDEPTH -- initial size of the parser's stacks.  */
1220 #ifndef YYINITDEPTH
1221 # define YYINITDEPTH 200
1222 #endif
1223
1224 /* YYMAXDEPTH -- maximum size the stacks can grow to (effective only
1225    if the built-in stack extension method is used).
1226
1227    Do not make this value too large; the results are undefined if
1228    YYSTACK_ALLOC_MAXIMUM < YYSTACK_BYTES (YYMAXDEPTH)
1229    evaluated with infinite-precision integer arithmetic.  */
1230
1231 #ifndef YYMAXDEPTH
1232 # define YYMAXDEPTH 10000
1233 #endif
1234
1235 \f
1236
1237 #if YYERROR_VERBOSE
1238
1239 # ifndef yystrlen
1240 #  if defined __GLIBC__ && defined _STRING_H
1241 #   define yystrlen strlen
1242 #  else
1243 /* Return the length of YYSTR.  */
1244 #if (defined __STDC__ || defined __C99__FUNC__ \
1245      || defined __cplusplus || defined _MSC_VER)
1246 static YYSIZE_T
1247 yystrlen (const char *yystr)
1248 #else
1249 static YYSIZE_T
1250 yystrlen (yystr)
1251     const char *yystr;
1252 #endif
1253 {
1254   YYSIZE_T yylen;
1255   for (yylen = 0; yystr[yylen]; yylen++)
1256     continue;
1257   return yylen;
1258 }
1259 #  endif
1260 # endif
1261
1262 # ifndef yystpcpy
1263 #  if defined __GLIBC__ && defined _STRING_H && defined _GNU_SOURCE
1264 #   define yystpcpy stpcpy
1265 #  else
1266 /* Copy YYSRC to YYDEST, returning the address of the terminating '\0' in
1267    YYDEST.  */
1268 #if (defined __STDC__ || defined __C99__FUNC__ \
1269      || defined __cplusplus || defined _MSC_VER)
1270 static char *
1271 yystpcpy (char *yydest, const char *yysrc)
1272 #else
1273 static char *
1274 yystpcpy (yydest, yysrc)
1275     char *yydest;
1276     const char *yysrc;
1277 #endif
1278 {
1279   char *yyd = yydest;
1280   const char *yys = yysrc;
1281
1282   while ((*yyd++ = *yys++) != '\0')
1283     continue;
1284
1285   return yyd - 1;
1286 }
1287 #  endif
1288 # endif
1289
1290 # ifndef yytnamerr
1291 /* Copy to YYRES the contents of YYSTR after stripping away unnecessary
1292    quotes and backslashes, so that it's suitable for yyerror.  The
1293    heuristic is that double-quoting is unnecessary unless the string
1294    contains an apostrophe, a comma, or backslash (other than
1295    backslash-backslash).  YYSTR is taken from yytname.  If YYRES is
1296    null, do not copy; instead, return the length of what the result
1297    would have been.  */
1298 static YYSIZE_T
1299 yytnamerr (char *yyres, const char *yystr)
1300 {
1301   if (*yystr == '"')
1302     {
1303       YYSIZE_T yyn = 0;
1304       char const *yyp = yystr;
1305
1306       for (;;)
1307         switch (*++yyp)
1308           {
1309           case '\'':
1310           case ',':
1311             goto do_not_strip_quotes;
1312
1313           case '\\':
1314             if (*++yyp != '\\')
1315               goto do_not_strip_quotes;
1316             /* Fall through.  */
1317           default:
1318             if (yyres)
1319               yyres[yyn] = *yyp;
1320             yyn++;
1321             break;
1322
1323           case '"':
1324             if (yyres)
1325               yyres[yyn] = '\0';
1326             return yyn;
1327           }
1328     do_not_strip_quotes: ;
1329     }
1330
1331   if (! yyres)
1332     return yystrlen (yystr);
1333
1334   return yystpcpy (yyres, yystr) - yyres;
1335 }
1336 # endif
1337
1338 /* Copy into YYRESULT an error message about the unexpected token
1339    YYCHAR while in state YYSTATE.  Return the number of bytes copied,
1340    including the terminating null byte.  If YYRESULT is null, do not
1341    copy anything; just return the number of bytes that would be
1342    copied.  As a special case, return 0 if an ordinary "syntax error"
1343    message will do.  Return YYSIZE_MAXIMUM if overflow occurs during
1344    size calculation.  */
1345 static YYSIZE_T
1346 yysyntax_error (char *yyresult, int yystate, int yychar)
1347 {
1348   int yyn = yypact[yystate];
1349
1350   if (! (YYPACT_NINF < yyn && yyn <= YYLAST))
1351     return 0;
1352   else
1353     {
1354       int yytype = YYTRANSLATE (yychar);
1355       YYSIZE_T yysize0 = yytnamerr (0, yytname[yytype]);
1356       YYSIZE_T yysize = yysize0;
1357       YYSIZE_T yysize1;
1358       int yysize_overflow = 0;
1359       enum { YYERROR_VERBOSE_ARGS_MAXIMUM = 5 };
1360       char const *yyarg[YYERROR_VERBOSE_ARGS_MAXIMUM];
1361       int yyx;
1362
1363 # if 0
1364       /* This is so xgettext sees the translatable formats that are
1365          constructed on the fly.  */
1366       YY_("syntax error, unexpected %s");
1367       YY_("syntax error, unexpected %s, expecting %s");
1368       YY_("syntax error, unexpected %s, expecting %s or %s");
1369       YY_("syntax error, unexpected %s, expecting %s or %s or %s");
1370       YY_("syntax error, unexpected %s, expecting %s or %s or %s or %s");
1371 # endif
1372       char *yyfmt;
1373       char const *yyf;
1374       static char const yyunexpected[] = "syntax error, unexpected %s";
1375       static char const yyexpecting[] = ", expecting %s";
1376       static char const yyor[] = " or %s";
1377       char yyformat[sizeof yyunexpected
1378                     + sizeof yyexpecting - 1
1379                     + ((YYERROR_VERBOSE_ARGS_MAXIMUM - 2)
1380                        * (sizeof yyor - 1))];
1381       char const *yyprefix = yyexpecting;
1382
1383       /* Start YYX at -YYN if negative to avoid negative indexes in
1384          YYCHECK.  */
1385       int yyxbegin = yyn < 0 ? -yyn : 0;
1386
1387       /* Stay within bounds of both yycheck and yytname.  */
1388       int yychecklim = YYLAST - yyn + 1;
1389       int yyxend = yychecklim < YYNTOKENS ? yychecklim : YYNTOKENS;
1390       int yycount = 1;
1391
1392       yyarg[0] = yytname[yytype];
1393       yyfmt = yystpcpy (yyformat, yyunexpected);
1394
1395       for (yyx = yyxbegin; yyx < yyxend; ++yyx)
1396         if (yycheck[yyx + yyn] == yyx && yyx != YYTERROR)
1397           {
1398             if (yycount == YYERROR_VERBOSE_ARGS_MAXIMUM)
1399               {
1400                 yycount = 1;
1401                 yysize = yysize0;
1402                 yyformat[sizeof yyunexpected - 1] = '\0';
1403                 break;
1404               }
1405             yyarg[yycount++] = yytname[yyx];
1406             yysize1 = yysize + yytnamerr (0, yytname[yyx]);
1407             yysize_overflow |= (yysize1 < yysize);
1408             yysize = yysize1;
1409             yyfmt = yystpcpy (yyfmt, yyprefix);
1410             yyprefix = yyor;
1411           }
1412
1413       yyf = YY_(yyformat);
1414       yysize1 = yysize + yystrlen (yyf);
1415       yysize_overflow |= (yysize1 < yysize);
1416       yysize = yysize1;
1417
1418       if (yysize_overflow)
1419         return YYSIZE_MAXIMUM;
1420
1421       if (yyresult)
1422         {
1423           /* Avoid sprintf, as that infringes on the user's name space.
1424              Don't have undefined behavior even if the translation
1425              produced a string with the wrong number of "%s"s.  */
1426           char *yyp = yyresult;
1427           int yyi = 0;
1428           while ((*yyp = *yyf) != '\0')
1429             {
1430               if (*yyp == '%' && yyf[1] == 's' && yyi < yycount)
1431                 {
1432                   yyp += yytnamerr (yyp, yyarg[yyi++]);
1433                   yyf += 2;
1434                 }
1435               else
1436                 {
1437                   yyp++;
1438                   yyf++;
1439                 }
1440             }
1441         }
1442       return yysize;
1443     }
1444 }
1445 #endif /* YYERROR_VERBOSE */
1446 \f
1447
1448 /*-----------------------------------------------.
1449 | Release the memory associated to this symbol.  |
1450 `-----------------------------------------------*/
1451
1452 /*ARGSUSED*/
1453 #if (defined __STDC__ || defined __C99__FUNC__ \
1454      || defined __cplusplus || defined _MSC_VER)
1455 static void
1456 yydestruct (const char *yymsg, int yytype, YYSTYPE *yyvaluep, YYLTYPE *yylocationp)
1457 #else
1458 static void
1459 yydestruct (yymsg, yytype, yyvaluep, yylocationp)
1460     const char *yymsg;
1461     int yytype;
1462     YYSTYPE *yyvaluep;
1463     YYLTYPE *yylocationp;
1464 #endif
1465 {
1466   YYUSE (yyvaluep);
1467   YYUSE (yylocationp);
1468
1469   if (!yymsg)
1470     yymsg = "Deleting";
1471   YY_SYMBOL_PRINT (yymsg, yytype, yyvaluep, yylocationp);
1472
1473   switch (yytype)
1474     {
1475       case 4: /* "TOK_COLONCOLON" */
1476 #line 368 "ast_expr2.y"
1477         {  free_value((yyvaluep->val)); };
1478 #line 1479 "ast_expr2.c"
1479         break;
1480       case 5: /* "TOK_COND" */
1481 #line 368 "ast_expr2.y"
1482         {  free_value((yyvaluep->val)); };
1483 #line 1484 "ast_expr2.c"
1484         break;
1485       case 6: /* "TOK_OR" */
1486 #line 368 "ast_expr2.y"
1487         {  free_value((yyvaluep->val)); };
1488 #line 1489 "ast_expr2.c"
1489         break;
1490       case 7: /* "TOK_AND" */
1491 #line 368 "ast_expr2.y"
1492         {  free_value((yyvaluep->val)); };
1493 #line 1494 "ast_expr2.c"
1494         break;
1495       case 8: /* "TOK_NE" */
1496 #line 368 "ast_expr2.y"
1497         {  free_value((yyvaluep->val)); };
1498 #line 1499 "ast_expr2.c"
1499         break;
1500       case 9: /* "TOK_LE" */
1501 #line 368 "ast_expr2.y"
1502         {  free_value((yyvaluep->val)); };
1503 #line 1504 "ast_expr2.c"
1504         break;
1505       case 10: /* "TOK_GE" */
1506 #line 368 "ast_expr2.y"
1507         {  free_value((yyvaluep->val)); };
1508 #line 1509 "ast_expr2.c"
1509         break;
1510       case 11: /* "TOK_LT" */
1511 #line 368 "ast_expr2.y"
1512         {  free_value((yyvaluep->val)); };
1513 #line 1514 "ast_expr2.c"
1514         break;
1515       case 12: /* "TOK_GT" */
1516 #line 368 "ast_expr2.y"
1517         {  free_value((yyvaluep->val)); };
1518 #line 1519 "ast_expr2.c"
1519         break;
1520       case 13: /* "TOK_EQ" */
1521 #line 368 "ast_expr2.y"
1522         {  free_value((yyvaluep->val)); };
1523 #line 1524 "ast_expr2.c"
1524         break;
1525       case 14: /* "TOK_MINUS" */
1526 #line 368 "ast_expr2.y"
1527         {  free_value((yyvaluep->val)); };
1528 #line 1529 "ast_expr2.c"
1529         break;
1530       case 15: /* "TOK_PLUS" */
1531 #line 368 "ast_expr2.y"
1532         {  free_value((yyvaluep->val)); };
1533 #line 1534 "ast_expr2.c"
1534         break;
1535       case 16: /* "TOK_MOD" */
1536 #line 368 "ast_expr2.y"
1537         {  free_value((yyvaluep->val)); };
1538 #line 1539 "ast_expr2.c"
1539         break;
1540       case 17: /* "TOK_DIV" */
1541 #line 368 "ast_expr2.y"
1542         {  free_value((yyvaluep->val)); };
1543 #line 1544 "ast_expr2.c"
1544         break;
1545       case 18: /* "TOK_MULT" */
1546 #line 368 "ast_expr2.y"
1547         {  free_value((yyvaluep->val)); };
1548 #line 1549 "ast_expr2.c"
1549         break;
1550       case 19: /* "TOK_COMPL" */
1551 #line 368 "ast_expr2.y"
1552         {  free_value((yyvaluep->val)); };
1553 #line 1554 "ast_expr2.c"
1554         break;
1555       case 20: /* "TOK_TILDETILDE" */
1556 #line 368 "ast_expr2.y"
1557         {  free_value((yyvaluep->val)); };
1558 #line 1559 "ast_expr2.c"
1559         break;
1560       case 21: /* "TOK_EQTILDE" */
1561 #line 368 "ast_expr2.y"
1562         {  free_value((yyvaluep->val)); };
1563 #line 1564 "ast_expr2.c"
1564         break;
1565       case 22: /* "TOK_COLON" */
1566 #line 368 "ast_expr2.y"
1567         {  free_value((yyvaluep->val)); };
1568 #line 1569 "ast_expr2.c"
1569         break;
1570       case 23: /* "TOK_LP" */
1571 #line 368 "ast_expr2.y"
1572         {  free_value((yyvaluep->val)); };
1573 #line 1574 "ast_expr2.c"
1574         break;
1575       case 24: /* "TOK_RP" */
1576 #line 368 "ast_expr2.y"
1577         {  free_value((yyvaluep->val)); };
1578 #line 1579 "ast_expr2.c"
1579         break;
1580       case 25: /* "TOKEN" */
1581 #line 368 "ast_expr2.y"
1582         {  free_value((yyvaluep->val)); };
1583 #line 1584 "ast_expr2.c"
1584         break;
1585       case 29: /* "expr" */
1586 #line 368 "ast_expr2.y"
1587         {  free_value((yyvaluep->val)); };
1588 #line 1589 "ast_expr2.c"
1589         break;
1590
1591       default:
1592         break;
1593     }
1594 }
1595 \f
1596
1597 /* Prevent warnings from -Wmissing-prototypes.  */
1598
1599 #ifdef YYPARSE_PARAM
1600 #if defined __STDC__ || defined __cplusplus
1601 int yyparse (void *YYPARSE_PARAM);
1602 #else
1603 int yyparse ();
1604 #endif
1605 #else /* ! YYPARSE_PARAM */
1606 #if defined __STDC__ || defined __cplusplus
1607 int yyparse (void);
1608 #else
1609 int yyparse ();
1610 #endif
1611 #endif /* ! YYPARSE_PARAM */
1612
1613
1614
1615
1616
1617
1618 /*----------.
1619 | yyparse.  |
1620 `----------*/
1621
1622 #ifdef YYPARSE_PARAM
1623 #if (defined __STDC__ || defined __C99__FUNC__ \
1624      || defined __cplusplus || defined _MSC_VER)
1625 int
1626 yyparse (void *YYPARSE_PARAM)
1627 #else
1628 int
1629 yyparse (YYPARSE_PARAM)
1630     void *YYPARSE_PARAM;
1631 #endif
1632 #else /* ! YYPARSE_PARAM */
1633 #if (defined __STDC__ || defined __C99__FUNC__ \
1634      || defined __cplusplus || defined _MSC_VER)
1635 int
1636 yyparse (void)
1637 #else
1638 int
1639 yyparse ()
1640
1641 #endif
1642 #endif
1643 {
1644   /* The look-ahead symbol.  */
1645 int yychar;
1646
1647 /* The semantic value of the look-ahead symbol.  */
1648 YYSTYPE yylval;
1649
1650 /* Number of syntax errors so far.  */
1651 int yynerrs;
1652 /* Location data for the look-ahead symbol.  */
1653 YYLTYPE yylloc;
1654
1655   int yystate;
1656   int yyn;
1657   int yyresult;
1658   /* Number of tokens to shift before error messages enabled.  */
1659   int yyerrstatus;
1660   /* Look-ahead token as an internal (translated) token number.  */
1661   int yytoken = 0;
1662 #if YYERROR_VERBOSE
1663   /* Buffer for error messages, and its allocated size.  */
1664   char yymsgbuf[128];
1665   char *yymsg = yymsgbuf;
1666   YYSIZE_T yymsg_alloc = sizeof yymsgbuf;
1667 #endif
1668
1669   /* Three stacks and their tools:
1670      `yyss': related to states,
1671      `yyvs': related to semantic values,
1672      `yyls': related to locations.
1673
1674      Refer to the stacks thru separate pointers, to allow yyoverflow
1675      to reallocate them elsewhere.  */
1676
1677   /* The state stack.  */
1678   yytype_int16 yyssa[YYINITDEPTH];
1679   yytype_int16 *yyss = yyssa;
1680   yytype_int16 *yyssp;
1681
1682   /* The semantic value stack.  */
1683   YYSTYPE yyvsa[YYINITDEPTH];
1684   YYSTYPE *yyvs = yyvsa;
1685   YYSTYPE *yyvsp;
1686
1687   /* The location stack.  */
1688   YYLTYPE yylsa[YYINITDEPTH];
1689   YYLTYPE *yyls = yylsa;
1690   YYLTYPE *yylsp;
1691   /* The locations where the error started and ended.  */
1692   YYLTYPE yyerror_range[2];
1693
1694 #define YYPOPSTACK(N)   (yyvsp -= (N), yyssp -= (N), yylsp -= (N))
1695
1696   YYSIZE_T yystacksize = YYINITDEPTH;
1697
1698   /* The variables used to return semantic value and location from the
1699      action routines.  */
1700   YYSTYPE yyval;
1701   YYLTYPE yyloc;
1702
1703   /* The number of symbols on the RHS of the reduced rule.
1704      Keep to zero when no symbol should be popped.  */
1705   int yylen = 0;
1706
1707   YYDPRINTF ((stderr, "Starting parse\n"));
1708
1709   yystate = 0;
1710   yyerrstatus = 0;
1711   yynerrs = 0;
1712   yychar = YYEMPTY;             /* Cause a token to be read.  */
1713
1714   /* Initialize stack pointers.
1715      Waste one element of value and location stack
1716      so that they stay on the same level as the state stack.
1717      The wasted elements are never initialized.  */
1718
1719   yyssp = yyss;
1720   yyvsp = yyvs;
1721   yylsp = yyls;
1722 #if YYLTYPE_IS_TRIVIAL
1723   /* Initialize the default location before parsing starts.  */
1724   yylloc.first_line   = yylloc.last_line   = 1;
1725   yylloc.first_column = yylloc.last_column = 0;
1726 #endif
1727
1728   goto yysetstate;
1729
1730 /*------------------------------------------------------------.
1731 | yynewstate -- Push a new state, which is found in yystate.  |
1732 `------------------------------------------------------------*/
1733  yynewstate:
1734   /* In all cases, when you get here, the value and location stacks
1735      have just been pushed.  So pushing a state here evens the stacks.  */
1736   yyssp++;
1737
1738  yysetstate:
1739   *yyssp = yystate;
1740
1741   if (yyss + yystacksize - 1 <= yyssp)
1742     {
1743       /* Get the current used size of the three stacks, in elements.  */
1744       YYSIZE_T yysize = yyssp - yyss + 1;
1745
1746 #ifdef yyoverflow
1747       {
1748         /* Give user a chance to reallocate the stack.  Use copies of
1749            these so that the &'s don't force the real ones into
1750            memory.  */
1751         YYSTYPE *yyvs1 = yyvs;
1752         yytype_int16 *yyss1 = yyss;
1753         YYLTYPE *yyls1 = yyls;
1754
1755         /* Each stack pointer address is followed by the size of the
1756            data in use in that stack, in bytes.  This used to be a
1757            conditional around just the two extra args, but that might
1758            be undefined if yyoverflow is a macro.  */
1759         yyoverflow (YY_("memory exhausted"),
1760                     &yyss1, yysize * sizeof (*yyssp),
1761                     &yyvs1, yysize * sizeof (*yyvsp),
1762                     &yyls1, yysize * sizeof (*yylsp),
1763                     &yystacksize);
1764         yyls = yyls1;
1765         yyss = yyss1;
1766         yyvs = yyvs1;
1767       }
1768 #else /* no yyoverflow */
1769 # ifndef YYSTACK_RELOCATE
1770       goto yyexhaustedlab;
1771 # else
1772       /* Extend the stack our own way.  */
1773       if (YYMAXDEPTH <= yystacksize)
1774         goto yyexhaustedlab;
1775       yystacksize *= 2;
1776       if (YYMAXDEPTH < yystacksize)
1777         yystacksize = YYMAXDEPTH;
1778
1779       {
1780         yytype_int16 *yyss1 = yyss;
1781         union yyalloc *yyptr =
1782           (union yyalloc *) YYSTACK_ALLOC (YYSTACK_BYTES (yystacksize));
1783         if (! yyptr)
1784           goto yyexhaustedlab;
1785         YYSTACK_RELOCATE (yyss);
1786         YYSTACK_RELOCATE (yyvs);
1787         YYSTACK_RELOCATE (yyls);
1788 #  undef YYSTACK_RELOCATE
1789         if (yyss1 != yyssa)
1790           YYSTACK_FREE (yyss1);
1791       }
1792 # endif
1793 #endif /* no yyoverflow */
1794
1795       yyssp = yyss + yysize - 1;
1796       yyvsp = yyvs + yysize - 1;
1797       yylsp = yyls + yysize - 1;
1798
1799       YYDPRINTF ((stderr, "Stack size increased to %lu\n",
1800                   (unsigned long int) yystacksize));
1801
1802       if (yyss + yystacksize - 1 <= yyssp)
1803         YYABORT;
1804     }
1805
1806   YYDPRINTF ((stderr, "Entering state %d\n", yystate));
1807
1808   goto yybackup;
1809
1810 /*-----------.
1811 | yybackup.  |
1812 `-----------*/
1813 yybackup:
1814
1815   /* Do appropriate processing given the current state.  Read a
1816      look-ahead token if we need one and don't already have one.  */
1817
1818   /* First try to decide what to do without reference to look-ahead token.  */
1819   yyn = yypact[yystate];
1820   if (yyn == YYPACT_NINF)
1821     goto yydefault;
1822
1823   /* Not known => get a look-ahead token if don't already have one.  */
1824
1825   /* YYCHAR is either YYEMPTY or YYEOF or a valid look-ahead symbol.  */
1826   if (yychar == YYEMPTY)
1827     {
1828       YYDPRINTF ((stderr, "Reading a token: "));
1829       yychar = YYLEX;
1830     }
1831
1832   if (yychar <= YYEOF)
1833     {
1834       yychar = yytoken = YYEOF;
1835       YYDPRINTF ((stderr, "Now at end of input.\n"));
1836     }
1837   else
1838     {
1839       yytoken = YYTRANSLATE (yychar);
1840       YY_SYMBOL_PRINT ("Next token is", yytoken, &yylval, &yylloc);
1841     }
1842
1843   /* If the proper action on seeing token YYTOKEN is to reduce or to
1844      detect an error, take that action.  */
1845   yyn += yytoken;
1846   if (yyn < 0 || YYLAST < yyn || yycheck[yyn] != yytoken)
1847     goto yydefault;
1848   yyn = yytable[yyn];
1849   if (yyn <= 0)
1850     {
1851       if (yyn == 0 || yyn == YYTABLE_NINF)
1852         goto yyerrlab;
1853       yyn = -yyn;
1854       goto yyreduce;
1855     }
1856
1857   if (yyn == YYFINAL)
1858     YYACCEPT;
1859
1860   /* Count tokens shifted since error; after three, turn off error
1861      status.  */
1862   if (yyerrstatus)
1863     yyerrstatus--;
1864
1865   /* Shift the look-ahead token.  */
1866   YY_SYMBOL_PRINT ("Shifting", yytoken, &yylval, &yylloc);
1867
1868   /* Discard the shifted token unless it is eof.  */
1869   if (yychar != YYEOF)
1870     yychar = YYEMPTY;
1871
1872   yystate = yyn;
1873   *++yyvsp = yylval;
1874   *++yylsp = yylloc;
1875   goto yynewstate;
1876
1877
1878 /*-----------------------------------------------------------.
1879 | yydefault -- do the default action for the current state.  |
1880 `-----------------------------------------------------------*/
1881 yydefault:
1882   yyn = yydefact[yystate];
1883   if (yyn == 0)
1884     goto yyerrlab;
1885   goto yyreduce;
1886
1887
1888 /*-----------------------------.
1889 | yyreduce -- Do a reduction.  |
1890 `-----------------------------*/
1891 yyreduce:
1892   /* yyn is the number of a rule to reduce with.  */
1893   yylen = yyr2[yyn];
1894
1895   /* If YYLEN is nonzero, implement the default value of the action:
1896      `$$ = $1'.
1897
1898      Otherwise, the following line sets YYVAL to garbage.
1899      This behavior is undocumented and Bison
1900      users should not rely upon it.  Assigning to YYVAL
1901      unconditionally makes the parser a bit smaller, and it avoids a
1902      GCC warning that YYVAL may be used uninitialized.  */
1903   yyval = yyvsp[1-yylen];
1904
1905   /* Default location.  */
1906   YYLLOC_DEFAULT (yyloc, (yylsp - yylen), yylen);
1907   YY_REDUCE_PRINT (yyn);
1908   switch (yyn)
1909     {
1910         case 2:
1911 #line 374 "ast_expr2.y"
1912     { ((struct parse_io *)parseio)->val = (struct val *)calloc(sizeof(struct val),1);
1913               ((struct parse_io *)parseio)->val->type = (yyvsp[(1) - (1)].val)->type;
1914               if( (yyvsp[(1) - (1)].val)->type == AST_EXPR_number )
1915                                   ((struct parse_io *)parseio)->val->u.i = (yyvsp[(1) - (1)].val)->u.i;
1916               else
1917                                   ((struct parse_io *)parseio)->val->u.s = (yyvsp[(1) - (1)].val)->u.s; 
1918                           free((yyvsp[(1) - (1)].val));
1919                         ;}
1920     break;
1921
1922   case 3:
1923 #line 382 "ast_expr2.y"
1924     {/* nothing */ ((struct parse_io *)parseio)->val = (struct val *)calloc(sizeof(struct val),1);
1925               ((struct parse_io *)parseio)->val->type = AST_EXPR_string;
1926                           ((struct parse_io *)parseio)->val->u.s = strdup(""); 
1927                         ;}
1928     break;
1929
1930   case 4:
1931 #line 389 "ast_expr2.y"
1932     { (yyval.arglist) = alloc_expr_node(AST_EXPR_NODE_VAL); (yyval.arglist)->val = (yyvsp[(1) - (1)].val);;}
1933     break;
1934
1935   case 5:
1936 #line 390 "ast_expr2.y"
1937     {struct expr_node *x = alloc_expr_node(AST_EXPR_NODE_VAL);
1938                                  struct expr_node *t;
1939                                                                  DESTROY((yyvsp[(2) - (3)].val));
1940                                  for (t=(yyvsp[(1) - (3)].arglist);t->right;t=t->right)
1941                                                                   ;
1942                                  (yyval.arglist) = (yyvsp[(1) - (3)].arglist); t->right = x; x->val = (yyvsp[(3) - (3)].val);;}
1943     break;
1944
1945   case 6:
1946 #line 396 "ast_expr2.y"
1947     {struct expr_node *x = alloc_expr_node(AST_EXPR_NODE_VAL);
1948                                  struct expr_node *t;  /* NULL args should OK */
1949                                                                  DESTROY((yyvsp[(2) - (2)].val));
1950                                  for (t=(yyvsp[(1) - (2)].arglist);t->right;t=t->right)
1951                                                                   ;
1952                                  (yyval.arglist) = (yyvsp[(1) - (2)].arglist); t->right = x; x->val = make_str("");;}
1953     break;
1954
1955   case 7:
1956 #line 405 "ast_expr2.y"
1957     { (yyval.val) = op_func((yyvsp[(1) - (4)].val),(yyvsp[(3) - (4)].arglist), ((struct parse_io *)parseio)->chan);
1958                                             DESTROY((yyvsp[(2) - (4)].val));
1959                                                                         DESTROY((yyvsp[(4) - (4)].val));
1960                                                                         DESTROY((yyvsp[(1) - (4)].val));
1961                                                                         destroy_arglist((yyvsp[(3) - (4)].arglist));
1962                                   ;}
1963     break;
1964
1965   case 8:
1966 #line 411 "ast_expr2.y"
1967     {(yyval.val) = (yyvsp[(1) - (1)].val);;}
1968     break;
1969
1970   case 9:
1971 #line 412 "ast_expr2.y"
1972     { (yyval.val) = (yyvsp[(2) - (3)].val);
1973                                (yyloc).first_column = (yylsp[(1) - (3)]).first_column; (yyloc).last_column = (yylsp[(3) - (3)]).last_column; 
1974                                                    (yyloc).first_line=0; (yyloc).last_line=0;
1975                                                         DESTROY((yyvsp[(1) - (3)].val)); DESTROY((yyvsp[(3) - (3)].val)); ;}
1976     break;
1977
1978   case 10:
1979 #line 416 "ast_expr2.y"
1980     { (yyval.val) = op_or ((yyvsp[(1) - (3)].val), (yyvsp[(3) - (3)].val));
1981                                                 DESTROY((yyvsp[(2) - (3)].val));        
1982                          (yyloc).first_column = (yylsp[(1) - (3)]).first_column; (yyloc).last_column = (yylsp[(3) - (3)]).last_column; 
1983                                                  (yyloc).first_line=0; (yyloc).last_line=0;;}
1984     break;
1985
1986   case 11:
1987 #line 420 "ast_expr2.y"
1988     { (yyval.val) = op_and ((yyvsp[(1) - (3)].val), (yyvsp[(3) - (3)].val)); 
1989                                                 DESTROY((yyvsp[(2) - (3)].val));        
1990                               (yyloc).first_column = (yylsp[(1) - (3)]).first_column; (yyloc).last_column = (yylsp[(3) - (3)]).last_column; 
1991                           (yyloc).first_line=0; (yyloc).last_line=0;;}
1992     break;
1993
1994   case 12:
1995 #line 424 "ast_expr2.y"
1996     { (yyval.val) = op_eq ((yyvsp[(1) - (3)].val), (yyvsp[(3) - (3)].val));
1997                                                 DESTROY((yyvsp[(2) - (3)].val));        
1998                              (yyloc).first_column = (yylsp[(1) - (3)]).first_column; (yyloc).last_column = (yylsp[(3) - (3)]).last_column;
1999                                                  (yyloc).first_line=0; (yyloc).last_line=0;;}
2000     break;
2001
2002   case 13:
2003 #line 428 "ast_expr2.y"
2004     { (yyval.val) = op_gt ((yyvsp[(1) - (3)].val), (yyvsp[(3) - (3)].val));
2005                                                 DESTROY((yyvsp[(2) - (3)].val));        
2006                          (yyloc).first_column = (yylsp[(1) - (3)]).first_column; (yyloc).last_column = (yylsp[(3) - (3)]).last_column;
2007                                                  (yyloc).first_line=0; (yyloc).last_line=0;;}
2008     break;
2009
2010   case 14:
2011 #line 432 "ast_expr2.y"
2012     { (yyval.val) = op_lt ((yyvsp[(1) - (3)].val), (yyvsp[(3) - (3)].val)); 
2013                                                 DESTROY((yyvsp[(2) - (3)].val));        
2014                              (yyloc).first_column = (yylsp[(1) - (3)]).first_column; (yyloc).last_column = (yylsp[(3) - (3)]).last_column; 
2015                                                  (yyloc).first_line=0; (yyloc).last_line=0;;}
2016     break;
2017
2018   case 15:
2019 #line 436 "ast_expr2.y"
2020     { (yyval.val) = op_ge ((yyvsp[(1) - (3)].val), (yyvsp[(3) - (3)].val)); 
2021                                                 DESTROY((yyvsp[(2) - (3)].val));        
2022                               (yyloc).first_column = (yylsp[(1) - (3)]).first_column; (yyloc).last_column = (yylsp[(3) - (3)]).last_column; 
2023                                                   (yyloc).first_line=0; (yyloc).last_line=0;;}
2024     break;
2025
2026   case 16:
2027 #line 440 "ast_expr2.y"
2028     { (yyval.val) = op_le ((yyvsp[(1) - (3)].val), (yyvsp[(3) - (3)].val)); 
2029                                                 DESTROY((yyvsp[(2) - (3)].val));        
2030                               (yyloc).first_column = (yylsp[(1) - (3)]).first_column; (yyloc).last_column = (yylsp[(3) - (3)]).last_column; 
2031                                                   (yyloc).first_line=0; (yyloc).last_line=0;;}
2032     break;
2033
2034   case 17:
2035 #line 444 "ast_expr2.y"
2036     { (yyval.val) = op_ne ((yyvsp[(1) - (3)].val), (yyvsp[(3) - (3)].val)); 
2037                                                 DESTROY((yyvsp[(2) - (3)].val));        
2038                               (yyloc).first_column = (yylsp[(1) - (3)]).first_column; (yyloc).last_column = (yylsp[(3) - (3)]).last_column; 
2039                                                   (yyloc).first_line=0; (yyloc).last_line=0;;}
2040     break;
2041
2042   case 18:
2043 #line 448 "ast_expr2.y"
2044     { (yyval.val) = op_plus ((yyvsp[(1) - (3)].val), (yyvsp[(3) - (3)].val)); 
2045                                                 DESTROY((yyvsp[(2) - (3)].val));        
2046                                (yyloc).first_column = (yylsp[(1) - (3)]).first_column; (yyloc).last_column = (yylsp[(3) - (3)]).last_column; 
2047                                                    (yyloc).first_line=0; (yyloc).last_line=0;;}
2048     break;
2049
2050   case 19:
2051 #line 452 "ast_expr2.y"
2052     { (yyval.val) = op_minus ((yyvsp[(1) - (3)].val), (yyvsp[(3) - (3)].val)); 
2053                                                 DESTROY((yyvsp[(2) - (3)].val));        
2054                                 (yyloc).first_column = (yylsp[(1) - (3)]).first_column; (yyloc).last_column = (yylsp[(3) - (3)]).last_column; 
2055                                                         (yyloc).first_line=0; (yyloc).last_line=0;;}
2056     break;
2057
2058   case 20:
2059 #line 456 "ast_expr2.y"
2060     { (yyval.val) = op_negate ((yyvsp[(2) - (2)].val)); 
2061                                                 DESTROY((yyvsp[(1) - (2)].val));        
2062                                 (yyloc).first_column = (yylsp[(1) - (2)]).first_column; (yyloc).last_column = (yylsp[(2) - (2)]).last_column; 
2063                                                         (yyloc).first_line=0; (yyloc).last_line=0;;}
2064     break;
2065
2066   case 21:
2067 #line 460 "ast_expr2.y"
2068     { (yyval.val) = op_compl ((yyvsp[(2) - (2)].val)); 
2069                                                 DESTROY((yyvsp[(1) - (2)].val));        
2070                                 (yyloc).first_column = (yylsp[(1) - (2)]).first_column; (yyloc).last_column = (yylsp[(2) - (2)]).last_column; 
2071                                                         (yyloc).first_line=0; (yyloc).last_line=0;;}
2072     break;
2073
2074   case 22:
2075 #line 464 "ast_expr2.y"
2076     { (yyval.val) = op_times ((yyvsp[(1) - (3)].val), (yyvsp[(3) - (3)].val)); 
2077                                                 DESTROY((yyvsp[(2) - (3)].val));        
2078                                (yyloc).first_column = (yylsp[(1) - (3)]).first_column; (yyloc).last_column = (yylsp[(3) - (3)]).last_column; 
2079                                                    (yyloc).first_line=0; (yyloc).last_line=0;;}
2080     break;
2081
2082   case 23:
2083 #line 468 "ast_expr2.y"
2084     { (yyval.val) = op_div ((yyvsp[(1) - (3)].val), (yyvsp[(3) - (3)].val)); 
2085                                                 DESTROY((yyvsp[(2) - (3)].val));        
2086                               (yyloc).first_column = (yylsp[(1) - (3)]).first_column; (yyloc).last_column = (yylsp[(3) - (3)]).last_column; 
2087                                                   (yyloc).first_line=0; (yyloc).last_line=0;;}
2088     break;
2089
2090   case 24:
2091 #line 472 "ast_expr2.y"
2092     { (yyval.val) = op_rem ((yyvsp[(1) - (3)].val), (yyvsp[(3) - (3)].val)); 
2093                                                 DESTROY((yyvsp[(2) - (3)].val));        
2094                               (yyloc).first_column = (yylsp[(1) - (3)]).first_column; (yyloc).last_column = (yylsp[(3) - (3)]).last_column; 
2095                                                   (yyloc).first_line=0; (yyloc).last_line=0;;}
2096     break;
2097
2098   case 25:
2099 #line 476 "ast_expr2.y"
2100     { (yyval.val) = op_colon ((yyvsp[(1) - (3)].val), (yyvsp[(3) - (3)].val)); 
2101                                                 DESTROY((yyvsp[(2) - (3)].val));        
2102                                 (yyloc).first_column = (yylsp[(1) - (3)]).first_column; (yyloc).last_column = (yylsp[(3) - (3)]).last_column; 
2103                                                         (yyloc).first_line=0; (yyloc).last_line=0;;}
2104     break;
2105
2106   case 26:
2107 #line 480 "ast_expr2.y"
2108     { (yyval.val) = op_eqtilde ((yyvsp[(1) - (3)].val), (yyvsp[(3) - (3)].val)); 
2109                                                 DESTROY((yyvsp[(2) - (3)].val));        
2110                                 (yyloc).first_column = (yylsp[(1) - (3)]).first_column; (yyloc).last_column = (yylsp[(3) - (3)]).last_column; 
2111                                                         (yyloc).first_line=0; (yyloc).last_line=0;;}
2112     break;
2113
2114   case 27:
2115 #line 484 "ast_expr2.y"
2116     { (yyval.val) = op_cond ((yyvsp[(1) - (5)].val), (yyvsp[(3) - (5)].val), (yyvsp[(5) - (5)].val)); 
2117                                                 DESTROY((yyvsp[(2) - (5)].val));        
2118                                                 DESTROY((yyvsp[(4) - (5)].val));        
2119                                 (yyloc).first_column = (yylsp[(1) - (5)]).first_column; (yyloc).last_column = (yylsp[(3) - (5)]).last_column; 
2120                                                         (yyloc).first_line=0; (yyloc).last_line=0;;}
2121     break;
2122
2123   case 28:
2124 #line 489 "ast_expr2.y"
2125     { (yyval.val) = op_tildetilde ((yyvsp[(1) - (3)].val), (yyvsp[(3) - (3)].val)); 
2126                                                 DESTROY((yyvsp[(2) - (3)].val));        
2127                                 (yyloc).first_column = (yylsp[(1) - (3)]).first_column; (yyloc).last_column = (yylsp[(3) - (3)]).last_column; 
2128                                                         (yyloc).first_line=0; (yyloc).last_line=0;;}
2129     break;
2130
2131
2132 /* Line 1267 of yacc.c.  */
2133 #line 2134 "ast_expr2.c"
2134       default: break;
2135     }
2136   YY_SYMBOL_PRINT ("-> $$ =", yyr1[yyn], &yyval, &yyloc);
2137
2138   YYPOPSTACK (yylen);
2139   yylen = 0;
2140   YY_STACK_PRINT (yyss, yyssp);
2141
2142   *++yyvsp = yyval;
2143   *++yylsp = yyloc;
2144
2145   /* Now `shift' the result of the reduction.  Determine what state
2146      that goes to, based on the state we popped back to and the rule
2147      number reduced by.  */
2148
2149   yyn = yyr1[yyn];
2150
2151   yystate = yypgoto[yyn - YYNTOKENS] + *yyssp;
2152   if (0 <= yystate && yystate <= YYLAST && yycheck[yystate] == *yyssp)
2153     yystate = yytable[yystate];
2154   else
2155     yystate = yydefgoto[yyn - YYNTOKENS];
2156
2157   goto yynewstate;
2158
2159
2160 /*------------------------------------.
2161 | yyerrlab -- here on detecting error |
2162 `------------------------------------*/
2163 yyerrlab:
2164   /* If not already recovering from an error, report this error.  */
2165   if (!yyerrstatus)
2166     {
2167       ++yynerrs;
2168 #if ! YYERROR_VERBOSE
2169       yyerror (YY_("syntax error"));
2170 #else
2171       {
2172         YYSIZE_T yysize = yysyntax_error (0, yystate, yychar);
2173         if (yymsg_alloc < yysize && yymsg_alloc < YYSTACK_ALLOC_MAXIMUM)
2174           {
2175             YYSIZE_T yyalloc = 2 * yysize;
2176             if (! (yysize <= yyalloc && yyalloc <= YYSTACK_ALLOC_MAXIMUM))
2177               yyalloc = YYSTACK_ALLOC_MAXIMUM;
2178             if (yymsg != yymsgbuf)
2179               YYSTACK_FREE (yymsg);
2180             yymsg = (char *) YYSTACK_ALLOC (yyalloc);
2181             if (yymsg)
2182               yymsg_alloc = yyalloc;
2183             else
2184               {
2185                 yymsg = yymsgbuf;
2186                 yymsg_alloc = sizeof yymsgbuf;
2187               }
2188           }
2189
2190         if (0 < yysize && yysize <= yymsg_alloc)
2191           {
2192             (void) yysyntax_error (yymsg, yystate, yychar);
2193             yyerror (yymsg);
2194           }
2195         else
2196           {
2197             yyerror (YY_("syntax error"));
2198             if (yysize != 0)
2199               goto yyexhaustedlab;
2200           }
2201       }
2202 #endif
2203     }
2204
2205   yyerror_range[0] = yylloc;
2206
2207   if (yyerrstatus == 3)
2208     {
2209       /* If just tried and failed to reuse look-ahead token after an
2210          error, discard it.  */
2211
2212       if (yychar <= YYEOF)
2213         {
2214           /* Return failure if at end of input.  */
2215           if (yychar == YYEOF)
2216             YYABORT;
2217         }
2218       else
2219         {
2220           yydestruct ("Error: discarding",
2221                       yytoken, &yylval, &yylloc);
2222           yychar = YYEMPTY;
2223         }
2224     }
2225
2226   /* Else will try to reuse look-ahead token after shifting the error
2227      token.  */
2228   goto yyerrlab1;
2229
2230
2231 /*---------------------------------------------------.
2232 | yyerrorlab -- error raised explicitly by YYERROR.  |
2233 `---------------------------------------------------*/
2234 yyerrorlab:
2235
2236   /* Pacify compilers like GCC when the user code never invokes
2237      YYERROR and the label yyerrorlab therefore never appears in user
2238      code.  */
2239   if (/*CONSTCOND*/ 0)
2240      goto yyerrorlab;
2241
2242   yyerror_range[0] = yylsp[1-yylen];
2243   /* Do not reclaim the symbols of the rule which action triggered
2244      this YYERROR.  */
2245   YYPOPSTACK (yylen);
2246   yylen = 0;
2247   YY_STACK_PRINT (yyss, yyssp);
2248   yystate = *yyssp;
2249   goto yyerrlab1;
2250
2251
2252 /*-------------------------------------------------------------.
2253 | yyerrlab1 -- common code for both syntax error and YYERROR.  |
2254 `-------------------------------------------------------------*/
2255 yyerrlab1:
2256   yyerrstatus = 3;      /* Each real token shifted decrements this.  */
2257
2258   for (;;)
2259     {
2260       yyn = yypact[yystate];
2261       if (yyn != YYPACT_NINF)
2262         {
2263           yyn += YYTERROR;
2264           if (0 <= yyn && yyn <= YYLAST && yycheck[yyn] == YYTERROR)
2265             {
2266               yyn = yytable[yyn];
2267               if (0 < yyn)
2268                 break;
2269             }
2270         }
2271
2272       /* Pop the current state because it cannot handle the error token.  */
2273       if (yyssp == yyss)
2274         YYABORT;
2275
2276       yyerror_range[0] = *yylsp;
2277       yydestruct ("Error: popping",
2278                   yystos[yystate], yyvsp, yylsp);
2279       YYPOPSTACK (1);
2280       yystate = *yyssp;
2281       YY_STACK_PRINT (yyss, yyssp);
2282     }
2283
2284   if (yyn == YYFINAL)
2285     YYACCEPT;
2286
2287   *++yyvsp = yylval;
2288
2289   yyerror_range[1] = yylloc;
2290   /* Using YYLLOC is tempting, but would change the location of
2291      the look-ahead.  YYLOC is available though.  */
2292   YYLLOC_DEFAULT (yyloc, (yyerror_range - 1), 2);
2293   *++yylsp = yyloc;
2294
2295   /* Shift the error token.  */
2296   YY_SYMBOL_PRINT ("Shifting", yystos[yyn], yyvsp, yylsp);
2297
2298   yystate = yyn;
2299   goto yynewstate;
2300
2301
2302 /*-------------------------------------.
2303 | yyacceptlab -- YYACCEPT comes here.  |
2304 `-------------------------------------*/
2305 yyacceptlab:
2306   yyresult = 0;
2307   goto yyreturn;
2308
2309 /*-----------------------------------.
2310 | yyabortlab -- YYABORT comes here.  |
2311 `-----------------------------------*/
2312 yyabortlab:
2313   yyresult = 1;
2314   goto yyreturn;
2315
2316 #ifndef yyoverflow
2317 /*-------------------------------------------------.
2318 | yyexhaustedlab -- memory exhaustion comes here.  |
2319 `-------------------------------------------------*/
2320 yyexhaustedlab:
2321   yyerror (YY_("memory exhausted"));
2322   yyresult = 2;
2323   /* Fall through.  */
2324 #endif
2325
2326 yyreturn:
2327   if (yychar != YYEOF && yychar != YYEMPTY)
2328      yydestruct ("Cleanup: discarding lookahead",
2329                  yytoken, &yylval, &yylloc);
2330   /* Do not reclaim the symbols of the rule which action triggered
2331      this YYABORT or YYACCEPT.  */
2332   YYPOPSTACK (yylen);
2333   YY_STACK_PRINT (yyss, yyssp);
2334   while (yyssp != yyss)
2335     {
2336       yydestruct ("Cleanup: popping",
2337                   yystos[*yyssp], yyvsp, yylsp);
2338       YYPOPSTACK (1);
2339     }
2340 #ifndef yyoverflow
2341   if (yyss != yyssa)
2342     YYSTACK_FREE (yyss);
2343 #endif
2344 #if YYERROR_VERBOSE
2345   if (yymsg != yymsgbuf)
2346     YYSTACK_FREE (yymsg);
2347 #endif
2348   /* Make sure YYID is used.  */
2349   return YYID (yyresult);
2350 }
2351
2352
2353 #line 495 "ast_expr2.y"
2354
2355
2356 static struct expr_node *alloc_expr_node(enum node_type nt)
2357 {
2358         struct expr_node *x = calloc(1,sizeof(struct expr_node));
2359         if (!x) {
2360                 ast_log(LOG_ERROR, "Allocation for expr_node FAILED!!\n");
2361                 return 0;
2362         }
2363         x->type = nt;
2364         return x;
2365 }
2366
2367
2368
2369 static struct val *
2370 make_number (FP___TYPE i)
2371 {
2372         struct val *vp;
2373
2374         vp = (struct val *) malloc (sizeof (*vp));
2375         if (vp == NULL) {
2376                 ast_log(LOG_WARNING, "malloc() failed\n");
2377                 return(NULL);
2378         }
2379
2380         vp->type = AST_EXPR_number;
2381         vp->u.i  = i;
2382         return vp; 
2383 }
2384
2385 static struct val *
2386 make_str (const char *s)
2387 {
2388         struct val *vp;
2389         size_t i;
2390         int isint; /* this started out being a test for an integer, but then ended up being a test for a float */
2391
2392         vp = (struct val *) malloc (sizeof (*vp));
2393         if (vp == NULL || ((vp->u.s = strdup (s)) == NULL)) {
2394                 ast_log(LOG_WARNING,"malloc() failed\n");
2395                 return(NULL);
2396         }
2397
2398         for (i = 0, isint = (isdigit(s[0]) || s[0] == '-' || s[0]=='.'); isint && i < strlen(s); i++)
2399         {
2400                 if (!isdigit(s[i]) && s[i] != '.') {
2401                         isint = 0;
2402                         break;
2403                 }
2404         }
2405         if (isint)
2406                 vp->type = AST_EXPR_numeric_string;
2407         else    
2408                 vp->type = AST_EXPR_string;
2409
2410         return vp;
2411 }
2412
2413
2414 static void
2415 free_value (struct val *vp)
2416 {       
2417         if (vp==NULL) {
2418                 return;
2419         }
2420         if (vp->type == AST_EXPR_string || vp->type == AST_EXPR_numeric_string)
2421                 free (vp->u.s); 
2422         free(vp);
2423 }
2424
2425
2426 static int
2427 to_number (struct val *vp)
2428 {
2429         FP___TYPE i;
2430         
2431         if (vp == NULL) {
2432                 ast_log(LOG_WARNING,"vp==NULL in to_number()\n");
2433                 return(0);
2434         }
2435
2436         if (vp->type == AST_EXPR_number)
2437                 return 1;
2438
2439         if (vp->type == AST_EXPR_string)
2440                 return 0;
2441
2442         /* vp->type == AST_EXPR_numeric_string, make it numeric */
2443         errno = 0;
2444         i  = FUNC_STRTOD(vp->u.s, (char**)0); /* either strtod, or strtold on a good day */
2445         if (errno != 0) {
2446                 ast_log(LOG_WARNING,"Conversion of %s to number under/overflowed!\n", vp->u.s);
2447                 free(vp->u.s);
2448                 vp->u.s = 0;
2449                 return(0);
2450         }
2451         free (vp->u.s);
2452         vp->u.i = i;
2453         vp->type = AST_EXPR_number;
2454         return 1;
2455 }
2456
2457 static void
2458 strip_quotes(struct val *vp)
2459 {
2460         if (vp->type != AST_EXPR_string && vp->type != AST_EXPR_numeric_string)
2461                 return;
2462         
2463         if( vp->u.s[0] == '"' && vp->u.s[strlen(vp->u.s)-1] == '"' )
2464         {
2465                 char *f, *t;
2466                 f = vp->u.s;
2467                 t = vp->u.s;
2468                 
2469                 while( *f )
2470                 {
2471                         if( *f  && *f != '"' )
2472                                 *t++ = *f++;
2473                         else
2474                                 f++;
2475                 }
2476                 *t = *f;
2477         }
2478 }
2479
2480 static void
2481 to_string (struct val *vp)
2482 {
2483         char *tmp;
2484
2485         if (vp->type == AST_EXPR_string || vp->type == AST_EXPR_numeric_string)
2486                 return;
2487
2488         tmp = malloc ((size_t)25);
2489         if (tmp == NULL) {
2490                 ast_log(LOG_WARNING,"malloc() failed\n");
2491                 return;
2492         }
2493
2494         sprintf(tmp, FP___PRINTF, vp->u.i);
2495         vp->type = AST_EXPR_string;
2496         vp->u.s  = tmp;
2497 }
2498
2499
2500 static int
2501 isstring (struct val *vp)
2502 {
2503         /* only TRUE if this string is not a valid number */
2504         return (vp->type == AST_EXPR_string);
2505 }
2506
2507
2508 static int
2509 is_zero_or_null (struct val *vp)
2510 {
2511         if (vp->type == AST_EXPR_number) {
2512                 return (vp->u.i == 0);
2513         } else {
2514                 return (*vp->u.s == 0 || (to_number(vp) && vp->u.i == 0));
2515         }
2516         /* NOTREACHED */
2517 }
2518
2519 #ifdef STANDALONE2
2520
2521 void ast_log(int level, const char *file, int line, const char *function, const char *fmt, ...)
2522 {
2523         va_list vars;
2524         va_start(vars,fmt);
2525         
2526         printf("LOG: lev:%d file:%s  line:%d func: %s  ",
2527                    level, file, line, function);
2528         vprintf(fmt, vars);
2529         fflush(stdout);
2530         va_end(vars);
2531 }
2532
2533
2534 int main(int argc,char **argv) {
2535         char s[4096];
2536         char out[4096];
2537         FILE *infile;
2538         
2539         if( !argv[1] )
2540                 exit(20);
2541         
2542         if( access(argv[1],F_OK)== 0 )
2543         {
2544                 int ret;
2545                 
2546                 infile = fopen(argv[1],"r");
2547                 if( !infile )
2548                 {
2549                         printf("Sorry, couldn't open %s for reading!\n", argv[1]);
2550                         exit(10);
2551                 }
2552                 while( fgets(s,sizeof(s),infile) )
2553                 {
2554                         if( s[strlen(s)-1] == '\n' )
2555                                 s[strlen(s)-1] = 0;
2556                         
2557                         ret = ast_expr(s, out, sizeof(out), NULL);
2558                         printf("Expression: %s    Result: [%d] '%s'\n",
2559                                    s, ret, out);
2560                 }
2561                 fclose(infile);
2562         }
2563         else
2564         {
2565                 if (ast_expr(argv[1], s, sizeof(s), NULL))
2566                         printf("=====%s======\n",s);
2567                 else
2568                         printf("No result\n");
2569         }
2570         return 0;
2571 }
2572
2573 #endif
2574
2575 #undef ast_yyerror
2576 #define ast_yyerror(x) ast_yyerror(x, YYLTYPE *yylloc, struct parse_io *parseio)
2577
2578 /* I put the ast_yyerror func in the flex input file,
2579    because it refers to the buffer state. Best to
2580    let it access the BUFFER stuff there and not trying
2581    define all the structs, macros etc. in this file! */
2582
2583 static void destroy_arglist(struct expr_node *arglist)
2584 {
2585         struct expr_node *arglist_next;
2586         
2587         while (arglist)
2588         {
2589                 arglist_next = arglist->right;
2590                 if (arglist->val)
2591                         free_value(arglist->val);
2592                 arglist->val = 0;
2593                 arglist->right = 0;
2594                 free(arglist);
2595                 arglist = arglist_next;
2596         }
2597 }
2598
2599 #if !defined(STANDALONE) && !defined(STANDALONE2)
2600 static char *compose_func_args(struct expr_node *arglist)
2601 {
2602         struct expr_node *t = arglist;
2603         char *argbuf;
2604         int total_len = 0;
2605         
2606         while (t) {
2607                 if (t != arglist)
2608                         total_len += 1; /* for the sep */
2609                 if (t->val) {
2610                         if (t->val->type == AST_EXPR_number)
2611                                 total_len += 25; /* worst case */
2612                         else
2613                                 total_len += strlen(t->val->u.s);
2614                 }
2615                 
2616                 t = t->right;
2617         }
2618         total_len++; /* for the null */
2619         ast_log(LOG_NOTICE,"argbuf allocated %d bytes;\n", total_len);
2620         argbuf = malloc(total_len);
2621         argbuf[0] = 0;
2622         t = arglist;
2623         while (t) {
2624                 char numbuf[30];
2625                 
2626                 if (t != arglist)
2627                         strcat(argbuf,",");
2628                 
2629                 if (t->val) {
2630                         if (t->val->type == AST_EXPR_number) {
2631                                 sprintf(numbuf,FP___PRINTF,t->val->u.i);
2632                                 strcat(argbuf,numbuf);
2633                         } else
2634                                 strcat(argbuf,t->val->u.s);
2635                 }
2636                 t = t->right;
2637         }
2638         ast_log(LOG_NOTICE,"argbuf uses %d bytes;\n", (int) strlen(argbuf));
2639         return argbuf;
2640 }
2641
2642 static int is_really_num(char *str)
2643 {
2644         if ( strspn(str,"-0123456789.   ") == strlen(str))
2645                 return 1;
2646         else
2647                 return 0;
2648 }
2649 #endif
2650
2651 static struct val *op_func(struct val *funcname, struct expr_node *arglist, struct ast_channel *chan)
2652 {
2653         if (strspn(funcname->u.s,"ABCDEFGHIJKLMNOPQRSTUVWXYZ_0123456789") == strlen(funcname->u.s))
2654         {
2655                 struct val *result;
2656                 if (0) {
2657 #ifdef FUNC_COS
2658                 } else if (strcmp(funcname->u.s,"COS") == 0) {
2659                         if (arglist && !arglist->right && arglist->val){
2660                                 to_number(arglist->val);
2661                                 result = make_number(FUNC_COS(arglist->val->u.i));
2662                                 return result;
2663                         } else {
2664                                 ast_log(LOG_WARNING,"Wrong args to %s() function\n",funcname->u.s);
2665                                 return make_number(0.0);
2666                         }
2667 #endif
2668 #ifdef FUNC_SIN
2669                 } else if (strcmp(funcname->u.s,"SIN") == 0) {
2670                         if (arglist && !arglist->right && arglist->val){
2671                                 to_number(arglist->val);
2672                                 result = make_number(FUNC_SIN(arglist->val->u.i));
2673                                 return result;
2674                         } else {
2675                                 ast_log(LOG_WARNING,"Wrong args to %s() function\n",funcname->u.s);
2676                                 return make_number(0.0);
2677                         }
2678 #endif
2679 #ifdef FUNC_TAN
2680                 } else if (strcmp(funcname->u.s,"TAN") == 0) {
2681                         if (arglist && !arglist->right && arglist->val){
2682                                 to_number(arglist->val);
2683                                 result = make_number(FUNC_TAN(arglist->val->u.i));
2684                                 return result;
2685                         } else {
2686                                 ast_log(LOG_WARNING,"Wrong args to %s() function\n",funcname->u.s);
2687                                 return make_number(0.0);
2688                         }
2689 #endif
2690 #ifdef FUNC_ACOS
2691                 } else if (strcmp(funcname->u.s,"ACOS") == 0) {
2692                         if (arglist && !arglist->right && arglist->val){
2693                                 to_number(arglist->val);
2694                                 result = make_number(FUNC_ACOS(arglist->val->u.i));
2695                                 return result;
2696                         } else {
2697                                 ast_log(LOG_WARNING,"Wrong args to %s() function\n",funcname->u.s);
2698                                 return make_number(0.0);
2699                         }
2700 #endif
2701 #ifdef FUNC_ASIN
2702                 } else if (strcmp(funcname->u.s,"ASIN") == 0) {
2703                         if (arglist && !arglist->right && arglist->val){
2704                                 to_number(arglist->val);
2705                                 result = make_number(FUNC_ASIN(arglist->val->u.i));
2706                                 return result;
2707                         } else {
2708                                 ast_log(LOG_WARNING,"Wrong args to %s() function\n",funcname->u.s);
2709                                 return make_number(0.0);
2710                         }
2711 #endif
2712 #ifdef FUNC_ATAN
2713                 } else if (strcmp(funcname->u.s,"ATAN") == 0) {
2714                         if (arglist && !arglist->right && arglist->val){
2715                                 to_number(arglist->val);
2716                                 result = make_number(FUNC_ATAN(arglist->val->u.i));
2717                                 return result;
2718                         } else {
2719                                 ast_log(LOG_WARNING,"Wrong args to %s() function\n",funcname->u.s);
2720                                 return make_number(0.0);
2721                         }
2722 #endif
2723 #ifdef FUNC_ATAN2
2724                 } else if (strcmp(funcname->u.s,"ATAN2") == 0) {
2725                         if (arglist && arglist->right && !arglist->right->right && arglist->val && arglist->right->val){
2726                                 to_number(arglist->val);
2727                                 to_number(arglist->right->val);
2728                                 result = make_number(FUNC_ATAN2(arglist->val->u.i, arglist->right->val->u.i));
2729                                 return result;
2730                         } else {
2731                                 ast_log(LOG_WARNING,"Wrong args to %s() function\n",funcname->u.s);
2732                                 return make_number(0.0);
2733                         }
2734 #endif
2735 #ifdef FUNC_POW
2736                 } else if (strcmp(funcname->u.s,"POW") == 0) {
2737                         if (arglist && arglist->right && !arglist->right->right && arglist->val && arglist->right->val){
2738                                 to_number(arglist->val);
2739                                 to_number(arglist->right->val);
2740                                 result = make_number(FUNC_POW(arglist->val->u.i, arglist->right->val->u.i));
2741                                 return result;
2742                         } else {
2743                                 ast_log(LOG_WARNING,"Wrong args to %s() function\n",funcname->u.s);
2744                                 return make_number(0.0);
2745                         }
2746 #endif
2747 #ifdef FUNC_SQRT
2748                 } else if (strcmp(funcname->u.s,"SQRT") == 0) {
2749                         if (arglist && !arglist->right && arglist->val){
2750                                 to_number(arglist->val);
2751                                 result = make_number(FUNC_SQRT(arglist->val->u.i));
2752                                 return result;
2753                         } else {
2754                                 ast_log(LOG_WARNING,"Wrong args to %s() function\n",funcname->u.s);
2755                                 return make_number(0.0);
2756                         }
2757 #endif
2758 #ifdef FUNC_FLOOR
2759                 } else if (strcmp(funcname->u.s,"FLOOR") == 0) {
2760                         if (arglist && !arglist->right && arglist->val){
2761                                 to_number(arglist->val);
2762                                 result = make_number(FUNC_FLOOR(arglist->val->u.i));
2763                                 return result;
2764                         } else {
2765                                 ast_log(LOG_WARNING,"Wrong args to %s() function\n",funcname->u.s);
2766                                 return make_number(0.0);
2767                         }
2768 #endif
2769 #ifdef FUNC_CEIL
2770                 } else if (strcmp(funcname->u.s,"CEIL") == 0) {
2771                         if (arglist && !arglist->right && arglist->val){
2772                                 to_number(arglist->val);
2773                                 result = make_number(FUNC_CEIL(arglist->val->u.i));
2774                                 return result;
2775                         } else {
2776                                 ast_log(LOG_WARNING,"Wrong args to %s() function\n",funcname->u.s);
2777                                 return make_number(0.0);
2778                         }
2779 #endif
2780 #ifdef FUNC_ROUND
2781                 } else if (strcmp(funcname->u.s,"ROUND") == 0) {
2782                         if (arglist && !arglist->right && arglist->val){
2783                                 to_number(arglist->val);
2784                                 result = make_number(FUNC_ROUND(arglist->val->u.i));
2785                                 return result;
2786                         } else {
2787                                 ast_log(LOG_WARNING,"Wrong args to %s() function\n",funcname->u.s);
2788                                 return make_number(0.0);
2789                         }
2790 #endif /* defined(FUNC_ROUND) */
2791 #ifdef FUNC_RINT
2792                 } else if (strcmp(funcname->u.s,"RINT") == 0) {
2793                         if (arglist && !arglist->right && arglist->val){
2794                                 to_number(arglist->val);
2795                                 result = make_number(FUNC_RINT(arglist->val->u.i));
2796                                 return result;
2797                         } else {
2798                                 ast_log(LOG_WARNING,"Wrong args to %s() function\n",funcname->u.s);
2799                                 return make_number(0.0);
2800                         }
2801 #endif
2802 #ifdef FUNC_TRUNC
2803                 } else if (strcmp(funcname->u.s,"TRUNC") == 0) {
2804                         if (arglist && !arglist->right && arglist->val){
2805                                 to_number(arglist->val);
2806                                 result = make_number(FUNC_TRUNC(arglist->val->u.i));
2807                                 return result;
2808                         } else {
2809                                 ast_log(LOG_WARNING,"Wrong args to %s() function\n",funcname->u.s);
2810                                 return make_number(0.0);
2811                         }
2812 #endif /* defined(FUNC_TRUNC) */
2813 #ifdef FUNC_EXP
2814                 } else if (strcmp(funcname->u.s,"EXP") == 0) {
2815                         if (arglist && !arglist->right && arglist->val){
2816                                 to_number(arglist->val);
2817                                 result = make_number(FUNC_EXP(arglist->val->u.i));
2818                                 return result;
2819                         } else {
2820                                 ast_log(LOG_WARNING,"Wrong args to %s() function\n",funcname->u.s);
2821                                 return make_number(0.0);
2822                         }
2823 #endif
2824 #ifdef FUNC_EXP2
2825                 } else if (strcmp(funcname->u.s,"EXP2") == 0) {
2826                         if (arglist && !arglist->right && arglist->val){
2827                                 to_number(arglist->val);
2828                                 result = make_number(FUNC_EXP2(arglist->val->u.i));
2829                                 return result;
2830                         } else {
2831                                 ast_log(LOG_WARNING,"Wrong args to %s() function\n",funcname->u.s);
2832                                 return make_number(0.0);
2833                         }
2834 #endif
2835 #ifdef FUNC_EXP10
2836                 } else if (strcmp(funcname->u.s,"EXP10") == 0) {
2837                         if (arglist && !arglist->right && arglist->val){
2838                                 to_number(arglist->val);
2839                                 result = make_number(FUNC_EXP10(arglist->val->u.i));
2840                                 return result;
2841                         } else {
2842                                 ast_log(LOG_WARNING,"Wrong args to %s() function\n",funcname->u.s);
2843                                 return make_number(0.0);
2844                         }
2845 #endif
2846 #ifdef FUNC_LOG
2847                 } else if (strcmp(funcname->u.s,"LOG") == 0) {
2848                         if (arglist && !arglist->right && arglist->val){
2849                                 to_number(arglist->val);
2850                                 result = make_number(FUNC_LOG(arglist->val->u.i));
2851                                 return result;
2852                         } else {
2853                                 ast_log(LOG_WARNING,"Wrong args to %s() function\n",funcname->u.s);
2854                                 return make_number(0.0);
2855                         }
2856 #endif
2857 #ifdef FUNC_LOG2
2858                 } else if (strcmp(funcname->u.s,"LOG2") == 0) {
2859                         if (arglist && !arglist->right && arglist->val){
2860                                 to_number(arglist->val);
2861                                 result = make_number(FUNC_LOG2(arglist->val->u.i));
2862                                 return result;
2863                         } else {
2864                                 ast_log(LOG_WARNING,"Wrong args to %s() function\n",funcname->u.s);
2865                                 return make_number(0.0);
2866                         }
2867 #endif
2868 #ifdef FUNC_LOG10
2869                 } else if (strcmp(funcname->u.s,"LOG10") == 0) {
2870                         if (arglist && !arglist->right && arglist->val){
2871                                 to_number(arglist->val);
2872                                 result = make_number(FUNC_LOG10(arglist->val->u.i));
2873                                 return result;
2874                         } else {
2875                                 ast_log(LOG_WARNING,"Wrong args to %s() function\n",funcname->u.s);
2876                                 return make_number(0.0);
2877                         }
2878 #endif
2879 #ifdef FUNC_REMAINDER
2880                 } else if (strcmp(funcname->u.s,"REMAINDER") == 0) {
2881                         if (arglist && arglist->right && !arglist->right->right && arglist->val && arglist->right->val){
2882                                 to_number(arglist->val);
2883                                 to_number(arglist->right->val);
2884                                 result = make_number(FUNC_REMAINDER(arglist->val->u.i, arglist->right->val->u.i));
2885                                 return result;
2886                         } else {
2887                                 ast_log(LOG_WARNING,"Wrong args to %s() function\n",funcname->u.s);
2888                                 return make_number(0.0);
2889                         }
2890 #endif
2891                 } else {
2892                         /* is this a custom function we should execute and collect the results of? */
2893 #if !defined(STANDALONE) && !defined(STANDALONE2)
2894                         struct ast_custom_function *f = ast_custom_function_find(funcname->u.s);
2895                         if (!chan)
2896                                 ast_log(LOG_WARNING,"Hey! chan is NULL.\n");
2897                         if (!f)
2898                                 ast_log(LOG_WARNING,"Hey! could not find func %s.\n", funcname->u.s);
2899                         
2900                         if (f && chan) {
2901                                 if (f->read) {
2902                                         char workspace[512];
2903                                         char *argbuf = compose_func_args(arglist);
2904                                         f->read(chan, funcname->u.s, argbuf, workspace, sizeof(workspace));
2905                                         free(argbuf);
2906                                         if (is_really_num(workspace))
2907                                                 return make_number(FUNC_STRTOD(workspace,(char **)NULL));
2908                                         else
2909                                                 return make_str(workspace);
2910                                 } else {
2911                                         ast_log(LOG_ERROR,"Error! Function '%s' cannot be read!\n", funcname->u.s);
2912                                         return (make_number ((FP___TYPE)0.0));
2913                                 }
2914                                 
2915                         } else {
2916                                 ast_log(LOG_ERROR,"Error! '%s' doesn't appear to be an available function!", funcname->u.s);
2917                                 return (make_number ((FP___TYPE)0.0));
2918                         }
2919 #else
2920                         ast_log(LOG_ERROR,"Error! '%s' is not available in the standalone version!", funcname->u.s);
2921                         return (make_number ((FP___TYPE)0.0));
2922 #endif
2923                 }
2924         }
2925         else
2926         {
2927                 ast_log(LOG_ERROR,"Error! '%s' is not possibly a function name!", funcname->u.s);
2928                 return (make_number ((FP___TYPE)0.0));
2929         }
2930         return (make_number ((FP___TYPE)0.0));
2931 }
2932
2933
2934 static struct val *
2935 op_or (struct val *a, struct val *b)
2936 {
2937         if (is_zero_or_null (a)) {
2938                 free_value (a);
2939                 return (b);
2940         } else {
2941                 free_value (b);
2942                 return (a);
2943         }
2944 }
2945                 
2946 static struct val *
2947 op_and (struct val *a, struct val *b)
2948 {
2949         if (is_zero_or_null (a) || is_zero_or_null (b)) {
2950                 free_value (a);
2951                 free_value (b);
2952                 return (make_number ((FP___TYPE)0.0));
2953         } else {
2954                 free_value (b);
2955                 return (a);
2956         }
2957 }
2958
2959 static struct val *
2960 op_eq (struct val *a, struct val *b)
2961 {
2962         struct val *r; 
2963
2964         if (isstring (a) || isstring (b)) {
2965                 to_string (a);
2966                 to_string (b);  
2967                 r = make_number ((FP___TYPE)(strcoll (a->u.s, b->u.s) == 0));
2968         } else {
2969 #ifdef DEBUG_FOR_CONVERSIONS
2970                 char buffer[2000];
2971                 sprintf(buffer,"Converting '%s' and '%s' ", a->u.s, b->u.s);
2972 #endif
2973                 (void)to_number(a);
2974                 (void)to_number(b);
2975 #ifdef DEBUG_FOR_CONVERSIONS
2976                 ast_log(LOG_WARNING,"%s to '%lld' and '%lld'\n", buffer, a->u.i, b->u.i);
2977 #endif
2978                 r = make_number ((FP___TYPE)(a->u.i == b->u.i));
2979         }
2980
2981         free_value (a);
2982         free_value (b);
2983         return r;
2984 }
2985
2986 static struct val *
2987 op_gt (struct val *a, struct val *b)
2988 {
2989         struct val *r;
2990
2991         if (isstring (a) || isstring (b)) {
2992                 to_string (a);
2993                 to_string (b);
2994                 r = make_number ((FP___TYPE)(strcoll (a->u.s, b->u.s) > 0));
2995         } else {
2996                 (void)to_number(a);
2997                 (void)to_number(b);
2998                 r = make_number ((FP___TYPE)(a->u.i > b->u.i));
2999         }
3000
3001         free_value (a);
3002         free_value (b);
3003         return r;
3004 }
3005
3006 static struct val *
3007 op_lt (struct val *a, struct val *b)
3008 {
3009         struct val *r;
3010
3011         if (isstring (a) || isstring (b)) {
3012                 to_string (a);
3013                 to_string (b);
3014                 r = make_number ((FP___TYPE)(strcoll (a->u.s, b->u.s) < 0));
3015         } else {
3016                 (void)to_number(a);
3017                 (void)to_number(b);
3018                 r = make_number ((FP___TYPE)(a->u.i < b->u.i));
3019         }
3020
3021         free_value (a);
3022         free_value (b);
3023         return r;
3024 }
3025
3026 static struct val *
3027 op_ge (struct val *a, struct val *b)
3028 {
3029         struct val *r;
3030
3031         if (isstring (a) || isstring (b)) {
3032                 to_string (a);
3033                 to_string (b);
3034                 r = make_number ((FP___TYPE)(strcoll (a->u.s, b->u.s) >= 0));
3035         } else {
3036                 (void)to_number(a);
3037                 (void)to_number(b);
3038                 r = make_number ((FP___TYPE)(a->u.i >= b->u.i));
3039         }
3040
3041         free_value (a);
3042         free_value (b);
3043         return r;
3044 }
3045
3046 static struct val *
3047 op_le (struct val *a, struct val *b)
3048 {
3049         struct val *r;
3050
3051         if (isstring (a) || isstring (b)) {
3052                 to_string (a);
3053                 to_string (b);
3054                 r = make_number ((FP___TYPE)(strcoll (a->u.s, b->u.s) <= 0));
3055         } else {
3056                 (void)to_number(a);
3057                 (void)to_number(b);
3058                 r = make_number ((FP___TYPE)(a->u.i <= b->u.i));
3059         }
3060
3061         free_value (a);
3062         free_value (b);
3063         return r;
3064 }
3065
3066 static struct val *
3067 op_cond (struct val *a, struct val *b, struct val *c)
3068 {
3069         struct val *r;
3070
3071         if( isstring(a) )
3072         {
3073                 if( strlen(a->u.s) && strcmp(a->u.s, "\"\"") != 0 && strcmp(a->u.s,"0") != 0 )
3074                 {
3075                         free_value(a);
3076                         free_value(c);
3077                         r = b;
3078                 }
3079                 else
3080                 {
3081                         free_value(a);
3082                         free_value(b);
3083                         r = c;
3084                 }
3085         }
3086         else
3087         {
3088                 (void)to_number(a);
3089                 if( a->u.i )
3090                 {
3091                         free_value(a);
3092                         free_value(c);
3093                         r = b;
3094                 }
3095                 else
3096                 {
3097                         free_value(a);
3098                         free_value(b);
3099                         r = c;
3100                 }
3101         }
3102         return r;
3103 }
3104
3105 static struct val *
3106 op_ne (struct val *a, struct val *b)
3107 {
3108         struct val *r;
3109
3110         if (isstring (a) || isstring (b)) {
3111                 to_string (a);
3112                 to_string (b);
3113                 r = make_number ((FP___TYPE)(strcoll (a->u.s, b->u.s) != 0));
3114         } else {
3115                 (void)to_number(a);
3116                 (void)to_number(b);
3117                 r = make_number ((FP___TYPE)(a->u.i != b->u.i));
3118         }
3119
3120         free_value (a);
3121         free_value (b);
3122         return r;
3123 }
3124
3125 static int
3126 chk_plus (FP___TYPE a, FP___TYPE b, FP___TYPE r)
3127 {
3128         /* sum of two positive numbers must be positive */
3129         if (a > 0 && b > 0 && r <= 0)
3130                 return 1;
3131         /* sum of two negative numbers must be negative */
3132         if (a < 0 && b < 0 && r >= 0)
3133                 return 1;
3134         /* all other cases are OK */
3135         return 0;
3136 }
3137
3138 static struct val *
3139 op_plus (struct val *a, struct val *b)
3140 {
3141         struct val *r;
3142
3143         if (!to_number (a)) {
3144                 if( !extra_error_message_supplied )
3145                         ast_log(LOG_WARNING,"non-numeric argument\n");
3146                 if (!to_number (b)) {
3147                         free_value(a);
3148                         free_value(b);
3149                         return make_number(0);
3150                 } else {
3151                         free_value(a);
3152                         return (b);
3153                 }
3154         } else if (!to_number(b)) {
3155                 free_value(b);
3156                 return (a);
3157         }
3158
3159         r = make_number (a->u.i + b->u.i);
3160         if (chk_plus (a->u.i, b->u.i, r->u.i)) {
3161                 ast_log(LOG_WARNING,"overflow\n");
3162         }
3163         free_value (a);
3164         free_value (b);
3165         return r;
3166 }
3167
3168 static int
3169 chk_minus (FP___TYPE a, FP___TYPE b, FP___TYPE r)
3170 {
3171         /* special case subtraction of QUAD_MIN */
3172         if (b == QUAD_MIN) {
3173                 if (a >= 0)
3174                         return 1;
3175                 else
3176                         return 0;
3177         }
3178         /* this is allowed for b != QUAD_MIN */
3179         return chk_plus (a, -b, r);
3180 }
3181
3182 static struct val *
3183 op_minus (struct val *a, struct val *b)
3184 {
3185         struct val *r;
3186
3187         if (!to_number (a)) {
3188                 if( !extra_error_message_supplied )
3189                         ast_log(LOG_WARNING, "non-numeric argument\n");
3190                 if (!to_number (b)) {
3191                         free_value(a);
3192                         free_value(b);
3193                         return make_number(0);
3194                 } else {
3195                         r = make_number(0 - b->u.i);
3196                         free_value(a);
3197                         free_value(b);
3198                         return (r);
3199                 }
3200         } else if (!to_number(b)) {
3201                 if( !extra_error_message_supplied )
3202                         ast_log(LOG_WARNING, "non-numeric argument\n");
3203                 free_value(b);
3204                 return (a);
3205         }
3206
3207         r = make_number (a->u.i - b->u.i);
3208         if (chk_minus (a->u.i, b->u.i, r->u.i)) {
3209                 ast_log(LOG_WARNING, "overflow\n");
3210         }
3211         free_value (a);
3212         free_value (b);
3213         return r;
3214 }
3215
3216 static struct val *
3217 op_negate (struct val *a)
3218 {
3219         struct val *r;
3220
3221         if (!to_number (a) ) {
3222                 free_value(a);
3223                 if( !extra_error_message_supplied )
3224                         ast_log(LOG_WARNING, "non-numeric argument\n");
3225                 return make_number(0);
3226         }
3227
3228         r = make_number (- a->u.i);
3229         if (chk_minus (0, a->u.i, r->u.i)) {
3230                 ast_log(LOG_WARNING, "overflow\n");
3231         }
3232         free_value (a);
3233         return r;
3234 }
3235
3236 static struct val *
3237 op_compl (struct val *a)
3238 {
3239         int v1 = 1;
3240         struct val *r;
3241         
3242         if( !a )
3243         {
3244                 v1 = 0;
3245         }
3246         else
3247         {
3248                 switch( a->type )
3249                 {
3250                 case AST_EXPR_number:
3251                         if( a->u.i == 0 )
3252                                 v1 = 0;
3253                         break;
3254                         
3255                 case AST_EXPR_string:
3256                         if( a->u.s == 0 )
3257                                 v1 = 0;
3258                         else
3259                         {
3260                                 if( a->u.s[0] == 0 )
3261                                         v1 = 0;
3262                                 else if (strlen(a->u.s) == 1 && a->u.s[0] == '0' )
3263                                         v1 = 0;
3264                         }
3265                         break;
3266                         
3267                 case AST_EXPR_numeric_string:
3268                         if( a->u.s == 0 )
3269                                 v1 = 0;
3270                         else
3271                         {
3272                                 if( a->u.s[0] == 0 )
3273                                         v1 = 0;
3274                                 else if (strlen(a->u.s) == 1 && a->u.s[0] == '0' )
3275                                         v1 = 0;
3276                         }
3277                         break;
3278                 }
3279         }
3280         
3281         r = make_number (!v1);
3282         free_value (a);
3283         return r;
3284 }
3285
3286 static int
3287 chk_times (FP___TYPE a, FP___TYPE b, FP___TYPE r)
3288 {
3289         /* special case: first operand is 0, no overflow possible */
3290         if (a == 0)
3291                 return 0;
3292         /* cerify that result of division matches second operand */
3293         if (r / a != b)
3294                 return 1;
3295         return 0;
3296 }
3297
3298 static struct val *
3299 op_times (struct val *a, struct val *b)
3300 {
3301         struct val *r;
3302
3303         if (!to_number (a) || !to_number (b)) {
3304                 free_value(a);
3305                 free_value(b);
3306                 if( !extra_error_message_supplied )
3307                         ast_log(LOG_WARNING, "non-numeric argument\n");
3308                 return(make_number(0));
3309         }
3310
3311         r = make_number (a->u.i * b->u.i);
3312         if (chk_times (a->u.i, b->u.i, r->u.i)) {
3313                 ast_log(LOG_WARNING, "overflow\n");
3314         }
3315         free_value (a);
3316         free_value (b);
3317         return (r);
3318 }
3319
3320 static int
3321 chk_div (FP___TYPE a, FP___TYPE b)
3322 {
3323         /* div by zero has been taken care of before */
3324         /* only QUAD_MIN / -1 causes overflow */
3325         if (a == QUAD_MIN && b == -1)
3326                 return 1;
3327         /* everything else is OK */
3328         return 0;
3329 }
3330
3331 static struct val *
3332 op_div (struct val *a, struct val *b)
3333 {
3334         struct val *r;
3335
3336         if (!to_number (a)) {
3337                 free_value(a);
3338                 free_value(b);
3339                 if( !extra_error_message_supplied )
3340                         ast_log(LOG_WARNING, "non-numeric argument\n");
3341                 return make_number(0);
3342         } else if (!to_number (b)) {
3343                 free_value(a);
3344                 free_value(b);
3345                 if( !extra_error_message_supplied )
3346                         ast_log(LOG_WARNING, "non-numeric argument\n");
3347                 return make_number(INT_MAX);
3348         }
3349
3350         if (b->u.i == 0) {
3351                 ast_log(LOG_WARNING, "division by zero\n");             
3352                 free_value(a);
3353                 free_value(b);
3354                 return make_number(INT_MAX);
3355         }