1 /* A Bison parser, made by GNU Bison 2.3. */
3 /* Skeleton implementation for Bison's Yacc-like parsers in C
5 Copyright (C) 1984, 1989, 1990, 2000, 2001, 2002, 2003, 2004, 2005, 2006
6 Free Software Foundation, Inc.
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)
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.
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. */
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.
33 This special exception was added by the Free Software Foundation in
34 version 2.2 of Bison. */
36 /* C LALR(1) parser skeleton written by Richard Stallman, by
37 simplifying the original so-called "semantic" parser. */
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. */
46 /* Identify Bison output. */
50 #define YYBISON_VERSION "2.3"
53 #define YYSKELETON_NAME "yacc.c"
58 /* Using locations. */
59 #define YYLSP_NEEDED 1
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
74 /* Put the tokens into the symbol table, so that GDB and other debuggers
102 #define TOK_COMMA 258
103 #define TOK_COLONCOLON 259
113 #define TOK_MINUS 269
118 #define TOK_COMPL 274
119 #define TOK_EQTILDE 275
120 #define TOK_COLON 276
128 /* Copy the first part of user declarations. */
129 #line 1 "../main/ast_expr2.y"
131 /* Written by Pace Willisson (pace@blitz.com)
132 * and placed in the public domain.
134 * Largely rewritten by J.T. Conklin (jtc@wimsey.com)
136 * And then overhauled twice by Steve Murphy (murf@digium.com)
137 * to add double-quoted strings, allow mult. spaces, improve
138 * error messages, and then to fold in a flex scanner for the
141 * $FreeBSD: src/bin/expr/expr.y,v 1.16 2000/07/22 10:59:36 se Exp $
144 #include <sys/types.h>
147 #ifdef STANDALONE /* I guess somewhere, the feature is set in the asterisk includes */
149 #define __USE_ISOC99 1
154 #define FP___PRINTF "%.18Lg"
155 #define FP___FMOD fmodl
156 #define FP___STRTOD strtold
157 #define FP___TYPE long double
158 #define FUNC_COS cosl
159 #define FUNC_SIN sinl
160 #define FUNC_TAN tanl
161 #define FUNC_ACOS acosl
162 #define FUNC_ASIN asinl
163 #define FUNC_ATAN atanl
164 #define FUNC_ATAN2 atan2l
165 #define FUNC_POW powl
166 #define FUNC_SQRT sqrtl
167 #define FUNC_FLOOR floorl
168 #define FUNC_CEIL ceill
169 #define FUNC_ROUND roundl
170 #define FUNC_RINT rintl
171 #define FUNC_TRUNC truncl
172 #define FUNC_EXP expl
174 #define FUNC_EXP2 exp2l
176 #define FUNC_EXP2(x) expl((x) * logl(2))
179 #define FUNC_EXP10 exp10l
181 #define FUNC_EXP10(x) expl((x) * logl(10))
183 #define FUNC_LOG logl
185 #define FUNC_LOG2 log2l
187 #define FUNC_LOG2(x) (logl(x) / logl(2))
190 #define FUNC_LOG10 log10l
192 #define FUNC_LOG10(x) (logl(x) / logl(10))
194 #define FUNC_REMAINDER remainderl
196 #define FP___PRINTF "%.16g"
197 #define FP___FMOD fmod
198 #define FP___STRTOD strtod
199 #define FP___TYPE double
203 #define FUNC_ACOS acos
204 #define FUNC_ASIN asin
205 #define FUNC_ATAN atan
206 #define FUNC_ATAN2 atan2
208 #define FUNC_SQRT sqrt
209 #define FUNC_FLOOR floor
210 #define FUNC_CEIL ceil
211 #define FUNC_ROUND round
212 #define FUNC_RINT rint
213 #define FUNC_TRUNC trunc
216 #define FUNC_EXP2 exp2
218 #define FUNC_EXP2(x) exp((x) * log(2))
221 #define FUNC_EXP10 exp10
223 #define FUNC_EXP10(x) exp((x) * log(10))
227 #define FUNC_LOG2 log2
229 #define FUNC_LOG2(x) (log(x) / log(2))
232 #define FUNC_LOG10 log10
234 #define FUNC_LOG10(x) (log(x) / log(10))
236 #define FUNC_REMAINDER remainder
248 #if !defined(SOLARIS) && !defined(__CYGWIN__)
249 /* #include <err.h> */
251 #define quad_t int64_t
257 #include "asterisk.h"
258 #include "asterisk/ast_expr.h"
259 #include "asterisk/logger.h"
261 #include "asterisk/pbx.h"
264 #if defined(LONG_LONG_MIN) && !defined(QUAD_MIN)
265 #define QUAD_MIN LONG_LONG_MIN
267 #if defined(LONG_LONG_MAX) && !defined(QUAD_MAX)
268 #define QUAD_MAX LONG_LONG_MAX
271 # if ! defined(QUAD_MIN)
272 # define QUAD_MIN (-0x7fffffffffffffffLL-1)
274 # if ! defined(QUAD_MAX)
275 # define QUAD_MAX (0x7fffffffffffffffLL)
277 #define YYENABLE_NLS 0
278 #define YYPARSE_PARAM parseio
279 #define YYLEX_PARAM ((struct parse_io *)parseio)->scanner
280 #define YYERROR_VERBOSE 1
281 extern char extra_error_message[4095];
282 extern int extra_error_message_supplied;
285 AST_EXPR_number, AST_EXPR_numeric_string, AST_EXPR_string
289 void ast_log(int level, const char *file, int line, const char *function, const char *fmt, ...) __attribute__ ((format (printf,5,6)));
296 FP___TYPE i; /* either long double, or just double, on a bad day */
301 AST_EXPR_NODE_COMMA, AST_EXPR_NODE_STRING, AST_EXPR_NODE_VAL
308 struct expr_node *left;
309 struct expr_node *right;
313 typedef void *yyscan_t;
320 struct ast_channel *chan;
323 static int chk_div __P((FP___TYPE, FP___TYPE));
324 static int chk_minus __P((FP___TYPE, FP___TYPE, FP___TYPE));
325 static int chk_plus __P((FP___TYPE, FP___TYPE, FP___TYPE));
326 static int chk_times __P((FP___TYPE, FP___TYPE, FP___TYPE));
327 static void free_value __P((struct val *));
328 static int is_zero_or_null __P((struct val *));
329 static int isstring __P((struct val *));
330 static struct val *make_number __P((FP___TYPE));
331 static struct val *make_str __P((const char *));
332 static struct val *op_and __P((struct val *, struct val *));
333 static struct val *op_colon __P((struct val *, struct val *));
334 static struct val *op_eqtilde __P((struct val *, struct val *));
335 static struct val *op_div __P((struct val *, struct val *));
336 static struct val *op_eq __P((struct val *, struct val *));
337 static struct val *op_ge __P((struct val *, struct val *));
338 static struct val *op_gt __P((struct val *, struct val *));
339 static struct val *op_le __P((struct val *, struct val *));
340 static struct val *op_lt __P((struct val *, struct val *));
341 static struct val *op_cond __P((struct val *, struct val *, struct val *));
342 static struct val *op_minus __P((struct val *, struct val *));
343 static struct val *op_negate __P((struct val *));
344 static struct val *op_compl __P((struct val *));
345 static struct val *op_ne __P((struct val *, struct val *));
346 static struct val *op_or __P((struct val *, struct val *));
347 static struct val *op_plus __P((struct val *, struct val *));
348 static struct val *op_rem __P((struct val *, struct val *));
349 static struct val *op_times __P((struct val *, struct val *));
350 static struct val *op_func(struct val *funcname, struct expr_node *arglist, struct ast_channel *chan);
351 static int to_number __P((struct val *));
352 static void to_string __P((struct val *));
353 static struct expr_node *alloc_expr_node(enum node_type);
354 static void destroy_arglist(struct expr_node *arglist);
355 static int is_really_num(char *str);
357 /* uh, if I want to predeclare yylex with a YYLTYPE, I have to predeclare the yyltype... sigh */
358 typedef struct yyltype
367 # define YYLTYPE yyltype
368 # define YYLTYPE_IS_TRIVIAL 1
370 /* we will get warning about no prototype for yylex! But we can't
371 define it here, we have no definition yet for YYSTYPE. */
373 int ast_yyerror(const char *,YYLTYPE *, struct parse_io *);
375 /* I wanted to add args to the yyerror routine, so I could print out
376 some useful info about the error. Not as easy as it looks, but it
378 #define ast_yyerror(x) ast_yyerror(x,&yyloc,parseio)
379 #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);}
382 /* Enabling traces. */
387 /* Enabling verbose error messages. */
388 #ifdef YYERROR_VERBOSE
389 # undef YYERROR_VERBOSE
390 # define YYERROR_VERBOSE 1
392 # define YYERROR_VERBOSE 0
395 /* Enabling the token table. */
396 #ifndef YYTOKEN_TABLE
397 # define YYTOKEN_TABLE 0
400 #if ! defined YYSTYPE && ! defined YYSTYPE_IS_DECLARED
401 typedef union YYSTYPE
402 #line 260 "../main/ast_expr2.y"
405 struct expr_node *arglist;
407 /* Line 187 of yacc.c. */
408 #line 409 "../main/ast_expr2.c"
410 # define yystype YYSTYPE /* obsolescent; will be withdrawn */
411 # define YYSTYPE_IS_DECLARED 1
412 # define YYSTYPE_IS_TRIVIAL 1
415 #if ! defined YYLTYPE && ! defined YYLTYPE_IS_DECLARED
416 typedef struct YYLTYPE
423 # define yyltype YYLTYPE /* obsolescent; will be withdrawn */
424 # define YYLTYPE_IS_DECLARED 1
425 # define YYLTYPE_IS_TRIVIAL 1
429 /* Copy the second part of user declarations. */
430 #line 265 "../main/ast_expr2.y"
432 extern int ast_yylex __P((YYSTYPE *, YYLTYPE *, yyscan_t));
435 /* Line 216 of yacc.c. */
436 #line 437 "../main/ast_expr2.c"
443 typedef YYTYPE_UINT8 yytype_uint8;
445 typedef unsigned char yytype_uint8;
449 typedef YYTYPE_INT8 yytype_int8;
450 #elif (defined __STDC__ || defined __C99__FUNC__ \
451 || defined __cplusplus || defined _MSC_VER)
452 typedef signed char yytype_int8;
454 typedef short int yytype_int8;
458 typedef YYTYPE_UINT16 yytype_uint16;
460 typedef unsigned short int yytype_uint16;
464 typedef YYTYPE_INT16 yytype_int16;
466 typedef short int yytype_int16;
470 # ifdef __SIZE_TYPE__
471 # define YYSIZE_T __SIZE_TYPE__
472 # elif defined size_t
473 # define YYSIZE_T size_t
474 # elif ! defined YYSIZE_T && (defined __STDC__ || defined __C99__FUNC__ \
475 || defined __cplusplus || defined _MSC_VER)
476 # include <stddef.h> /* INFRINGES ON USER NAME SPACE */
477 # define YYSIZE_T size_t
479 # define YYSIZE_T unsigned int
483 #define YYSIZE_MAXIMUM ((YYSIZE_T) -1)
488 # include <libintl.h> /* INFRINGES ON USER NAME SPACE */
489 # define YY_(msgid) dgettext ("bison-runtime", msgid)
493 # define YY_(msgid) msgid
497 /* Suppress unused-variable warnings by "using" E. */
498 #if ! defined lint || defined __GNUC__
499 # define YYUSE(e) ((void) (e))
501 # define YYUSE(e) /* empty */
504 /* Identity function, used to suppress warnings about constant conditions. */
508 #if (defined __STDC__ || defined __C99__FUNC__ \
509 || defined __cplusplus || defined _MSC_VER)
522 #if ! defined yyoverflow || YYERROR_VERBOSE
524 /* The parser invokes alloca or malloc; define the necessary symbols. */
526 # ifdef YYSTACK_USE_ALLOCA
527 # if YYSTACK_USE_ALLOCA
529 # define YYSTACK_ALLOC __builtin_alloca
530 # elif defined __BUILTIN_VA_ARG_INCR
531 # include <alloca.h> /* INFRINGES ON USER NAME SPACE */
533 # define YYSTACK_ALLOC __alloca
534 # elif defined _MSC_VER
535 # include <malloc.h> /* INFRINGES ON USER NAME SPACE */
536 # define alloca _alloca
538 # define YYSTACK_ALLOC alloca
539 # if ! defined _ALLOCA_H && ! defined _STDLIB_H && (defined __STDC__ || defined __C99__FUNC__ \
540 || defined __cplusplus || defined _MSC_VER)
541 # include <stdlib.h> /* INFRINGES ON USER NAME SPACE */
550 # ifdef YYSTACK_ALLOC
551 /* Pacify GCC's `empty if-body' warning. */
552 # define YYSTACK_FREE(Ptr) do { /* empty */; } while (YYID (0))
553 # ifndef YYSTACK_ALLOC_MAXIMUM
554 /* The OS might guarantee only one guard page at the bottom of the stack,
555 and a page size can be as small as 4096 bytes. So we cannot safely
556 invoke alloca (N) if N exceeds 4096. Use a slightly smaller number
557 to allow for a few compiler-allocated temporary stack slots. */
558 # define YYSTACK_ALLOC_MAXIMUM 4032 /* reasonable circa 2006 */
561 # define YYSTACK_ALLOC YYMALLOC
562 # define YYSTACK_FREE YYFREE
563 # ifndef YYSTACK_ALLOC_MAXIMUM
564 # define YYSTACK_ALLOC_MAXIMUM YYSIZE_MAXIMUM
566 # if (defined __cplusplus && ! defined _STDLIB_H \
567 && ! ((defined YYMALLOC || defined malloc) \
568 && (defined YYFREE || defined free)))
569 # include <stdlib.h> /* INFRINGES ON USER NAME SPACE */
575 # define YYMALLOC malloc
576 # if ! defined malloc && ! defined _STDLIB_H && (defined __STDC__ || defined __C99__FUNC__ \
577 || defined __cplusplus || defined _MSC_VER)
578 void *malloc (YYSIZE_T); /* INFRINGES ON USER NAME SPACE */
583 # if ! defined free && ! defined _STDLIB_H && (defined __STDC__ || defined __C99__FUNC__ \
584 || defined __cplusplus || defined _MSC_VER)
585 void free (void *); /* INFRINGES ON USER NAME SPACE */
589 #endif /* ! defined yyoverflow || YYERROR_VERBOSE */
592 #if (! defined yyoverflow \
593 && (! defined __cplusplus \
594 || (defined YYLTYPE_IS_TRIVIAL && YYLTYPE_IS_TRIVIAL \
595 && defined YYSTYPE_IS_TRIVIAL && YYSTYPE_IS_TRIVIAL)))
597 /* A type that is properly aligned for any stack member. */
605 /* The size of the maximum gap between one aligned stack and the next. */
606 # define YYSTACK_GAP_MAXIMUM (sizeof (union yyalloc) - 1)
608 /* The size of an array large to enough to hold all stacks, each with
610 # define YYSTACK_BYTES(N) \
611 ((N) * (sizeof (yytype_int16) + sizeof (YYSTYPE) + sizeof (YYLTYPE)) \
612 + 2 * YYSTACK_GAP_MAXIMUM)
614 /* Copy COUNT objects from FROM to TO. The source and destination do
617 # if defined __GNUC__ && 1 < __GNUC__
618 # define YYCOPY(To, From, Count) \
619 __builtin_memcpy (To, From, (Count) * sizeof (*(From)))
621 # define YYCOPY(To, From, Count) \
625 for (yyi = 0; yyi < (Count); yyi++) \
626 (To)[yyi] = (From)[yyi]; \
632 /* Relocate STACK from its old location to the new one. The
633 local variables YYSIZE and YYSTACKSIZE give the old and new number of
634 elements in the stack, and YYPTR gives the new location of the
635 stack. Advance YYPTR to a properly aligned location for the next
637 # define YYSTACK_RELOCATE(Stack) \
640 YYSIZE_T yynewbytes; \
641 YYCOPY (&yyptr->Stack, Stack, yysize); \
642 Stack = &yyptr->Stack; \
643 yynewbytes = yystacksize * sizeof (*Stack) + YYSTACK_GAP_MAXIMUM; \
644 yyptr += yynewbytes / sizeof (*yyptr); \
650 /* YYFINAL -- State number of the termination state. */
652 /* YYLAST -- Last index in YYTABLE. */
655 /* YYNTOKENS -- Number of terminals. */
657 /* YYNNTS -- Number of nonterminals. */
659 /* YYNRULES -- Number of rules. */
661 /* YYNRULES -- Number of states. */
664 /* YYTRANSLATE(YYLEX) -- Bison symbol number corresponding to YYLEX. */
666 #define YYMAXUTOK 279
668 #define YYTRANSLATE(YYX) \
669 ((unsigned int) (YYX) <= YYMAXUTOK ? yytranslate[YYX] : YYUNDEFTOK)
671 /* YYTRANSLATE[YYLEX] -- Bison symbol number corresponding to YYLEX. */
672 static const yytype_uint8 yytranslate[] =
674 0, 2, 2, 2, 2, 2, 2, 2, 2, 2,
675 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
676 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
677 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
678 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
679 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
680 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
681 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
682 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
683 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
684 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
685 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
686 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
687 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
688 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
689 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
690 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
691 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
692 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
693 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
694 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
695 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
696 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
697 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
698 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
699 2, 2, 2, 2, 2, 2, 1, 2, 3, 4,
700 5, 6, 7, 8, 9, 10, 11, 12, 13, 14,
701 15, 16, 17, 18, 19, 20, 21, 22, 23, 24
705 /* YYPRHS[YYN] -- Index of the first RHS symbol of rule number YYN in
707 static const yytype_uint8 yyprhs[] =
709 0, 0, 3, 5, 6, 8, 12, 17, 19, 23,
710 27, 31, 35, 39, 43, 47, 51, 55, 59, 63,
711 66, 69, 73, 77, 81, 85, 89
714 /* YYRHS -- A `-1'-separated list of the rules' RHS. */
715 static const yytype_int8 yyrhs[] =
717 26, 0, -1, 28, -1, -1, 28, -1, 27, 3,
718 28, -1, 24, 22, 27, 23, -1, 24, -1, 22,
719 28, 23, -1, 28, 6, 28, -1, 28, 7, 28,
720 -1, 28, 13, 28, -1, 28, 12, 28, -1, 28,
721 11, 28, -1, 28, 10, 28, -1, 28, 9, 28,
722 -1, 28, 8, 28, -1, 28, 15, 28, -1, 28,
723 14, 28, -1, 14, 28, -1, 19, 28, -1, 28,
724 18, 28, -1, 28, 17, 28, -1, 28, 16, 28,
725 -1, 28, 21, 28, -1, 28, 20, 28, -1, 28,
729 /* YYRLINE[YYN] -- source line where rule number YYN was defined. */
730 static const yytype_uint16 yyrline[] =
732 0, 291, 291, 299, 306, 307, 316, 322, 323, 327,
733 331, 335, 339, 343, 347, 351, 355, 359, 363, 367,
734 371, 375, 379, 383, 387, 391, 395
738 #if YYDEBUG || YYERROR_VERBOSE || YYTOKEN_TABLE
739 /* YYTNAME[SYMBOL-NUM] -- String name of the symbol SYMBOL-NUM.
740 First, the terminals, then, starting at YYNTOKENS, nonterminals. */
741 static const char *const yytname[] =
743 "$end", "error", "$undefined", "TOK_COMMA", "TOK_COLONCOLON",
744 "TOK_COND", "TOK_OR", "TOK_AND", "TOK_NE", "TOK_LE", "TOK_GE", "TOK_LT",
745 "TOK_GT", "TOK_EQ", "TOK_MINUS", "TOK_PLUS", "TOK_MOD", "TOK_DIV",
746 "TOK_MULT", "TOK_COMPL", "TOK_EQTILDE", "TOK_COLON", "TOK_LP", "TOK_RP",
747 "TOKEN", "$accept", "start", "arglist", "expr", 0
752 /* YYTOKNUM[YYLEX-NUM] -- Internal token number corresponding to
754 static const yytype_uint16 yytoknum[] =
756 0, 256, 257, 258, 259, 260, 261, 262, 263, 264,
757 265, 266, 267, 268, 269, 270, 271, 272, 273, 274,
758 275, 276, 277, 278, 279
762 /* YYR1[YYN] -- Symbol number of symbol that rule YYN derives. */
763 static const yytype_uint8 yyr1[] =
765 0, 25, 26, 26, 27, 27, 28, 28, 28, 28,
766 28, 28, 28, 28, 28, 28, 28, 28, 28, 28,
767 28, 28, 28, 28, 28, 28, 28
770 /* YYR2[YYN] -- Number of symbols composing right hand side of rule YYN. */
771 static const yytype_uint8 yyr2[] =
773 0, 2, 1, 0, 1, 3, 4, 1, 3, 3,
774 3, 3, 3, 3, 3, 3, 3, 3, 3, 2,
778 /* YYDEFACT[STATE-NAME] -- Default rule to reduce with in state
779 STATE-NUM when YYTABLE doesn't specify something else to do. Zero
780 means the default is an error. */
781 static const yytype_uint8 yydefact[] =
783 3, 0, 0, 0, 7, 0, 2, 19, 20, 0,
784 0, 1, 0, 0, 0, 0, 0, 0, 0, 0,
785 0, 0, 0, 0, 0, 0, 0, 0, 8, 0,
786 4, 0, 9, 10, 16, 15, 14, 13, 12, 11,
787 18, 17, 23, 22, 21, 25, 24, 0, 6, 0,
791 /* YYDEFGOTO[NTERM-NUM]. */
792 static const yytype_int8 yydefgoto[] =
797 /* YYPACT[STATE-NUM] -- Index in YYTABLE of the portion describing
799 #define YYPACT_NINF -18
800 static const yytype_int16 yypact[] =
802 112, 112, 112, 112, -16, 5, 62, -17, -17, 24,
803 112, -18, 112, 112, 112, 112, 112, 112, 112, 112,
804 112, 112, 112, 112, 112, 112, 112, 112, -18, 4,
805 62, 45, 93, 107, 123, 123, 123, 123, 123, 123,
806 129, 129, -17, -17, -17, -18, -18, 112, -18, 112,
810 /* YYPGOTO[NTERM-NUM]. */
811 static const yytype_int8 yypgoto[] =
816 /* YYTABLE[YYPACT[STATE-NUM]]. What to do in state STATE-NUM. If
817 positive, shift that token. If negative, reduce the rule which
818 number is the opposite. If zero, do what YYDEFACT says.
819 If YYTABLE_NINF, syntax error. */
820 #define YYTABLE_NINF -1
821 static const yytype_uint8 yytable[] =
823 7, 8, 9, 26, 27, 11, 10, 47, 0, 30,
824 0, 31, 32, 33, 34, 35, 36, 37, 38, 39,
825 40, 41, 42, 43, 44, 45, 46, 48, 0, 12,
826 13, 14, 15, 16, 17, 18, 19, 20, 21, 22,
827 23, 24, 25, 0, 26, 27, 50, 28, 51, 49,
828 12, 13, 14, 15, 16, 17, 18, 19, 20, 21,
829 22, 23, 24, 25, 0, 26, 27, 12, 13, 14,
830 15, 16, 17, 18, 19, 20, 21, 22, 23, 24,
831 25, 0, 26, 27, 13, 14, 15, 16, 17, 18,
832 19, 20, 21, 22, 23, 24, 25, 0, 26, 27,
833 14, 15, 16, 17, 18, 19, 20, 21, 22, 23,
834 24, 25, 0, 26, 27, 15, 16, 17, 18, 19,
835 20, 21, 22, 23, 24, 25, 1, 26, 27, 0,
836 0, 2, 0, 0, 3, 0, 4, 21, 22, 23,
837 24, 25, 0, 26, 27, 23, 24, 25, 0, 26,
841 static const yytype_int8 yycheck[] =
843 1, 2, 3, 20, 21, 0, 22, 3, -1, 10,
844 -1, 12, 13, 14, 15, 16, 17, 18, 19, 20,
845 21, 22, 23, 24, 25, 26, 27, 23, -1, 5,
846 6, 7, 8, 9, 10, 11, 12, 13, 14, 15,
847 16, 17, 18, -1, 20, 21, 47, 23, 49, 4,
848 5, 6, 7, 8, 9, 10, 11, 12, 13, 14,
849 15, 16, 17, 18, -1, 20, 21, 5, 6, 7,
850 8, 9, 10, 11, 12, 13, 14, 15, 16, 17,
851 18, -1, 20, 21, 6, 7, 8, 9, 10, 11,
852 12, 13, 14, 15, 16, 17, 18, -1, 20, 21,
853 7, 8, 9, 10, 11, 12, 13, 14, 15, 16,
854 17, 18, -1, 20, 21, 8, 9, 10, 11, 12,
855 13, 14, 15, 16, 17, 18, 14, 20, 21, -1,
856 -1, 19, -1, -1, 22, -1, 24, 14, 15, 16,
857 17, 18, -1, 20, 21, 16, 17, 18, -1, 20,
861 /* YYSTOS[STATE-NUM] -- The (internal number of the) accessing
862 symbol of state STATE-NUM. */
863 static const yytype_uint8 yystos[] =
865 0, 14, 19, 22, 24, 26, 28, 28, 28, 28,
866 22, 0, 5, 6, 7, 8, 9, 10, 11, 12,
867 13, 14, 15, 16, 17, 18, 20, 21, 23, 27,
868 28, 28, 28, 28, 28, 28, 28, 28, 28, 28,
869 28, 28, 28, 28, 28, 28, 28, 3, 23, 4,
873 #define yyerrok (yyerrstatus = 0)
874 #define yyclearin (yychar = YYEMPTY)
878 #define YYACCEPT goto yyacceptlab
879 #define YYABORT goto yyabortlab
880 #define YYERROR goto yyerrorlab
883 /* Like YYERROR except do call yyerror. This remains here temporarily
884 to ease the transition to the new meaning of YYERROR, for GCC.
885 Once GCC version 2 has supplanted version 1, this can go. */
887 #define YYFAIL goto yyerrlab
889 #define YYRECOVERING() (!!yyerrstatus)
891 #define YYBACKUP(Token, Value) \
893 if (yychar == YYEMPTY && yylen == 1) \
897 yytoken = YYTRANSLATE (yychar); \
903 yyerror (YY_("syntax error: cannot back up")); \
910 #define YYERRCODE 256
913 /* YYLLOC_DEFAULT -- Set CURRENT to span from RHS[1] to RHS[N].
914 If N is 0, then set CURRENT to the empty location which ends
915 the previous symbol: RHS[0] (always defined). */
917 #define YYRHSLOC(Rhs, K) ((Rhs)[K])
918 #ifndef YYLLOC_DEFAULT
919 # define YYLLOC_DEFAULT(Current, Rhs, N) \
923 (Current).first_line = YYRHSLOC (Rhs, 1).first_line; \
924 (Current).first_column = YYRHSLOC (Rhs, 1).first_column; \
925 (Current).last_line = YYRHSLOC (Rhs, N).last_line; \
926 (Current).last_column = YYRHSLOC (Rhs, N).last_column; \
930 (Current).first_line = (Current).last_line = \
931 YYRHSLOC (Rhs, 0).last_line; \
932 (Current).first_column = (Current).last_column = \
933 YYRHSLOC (Rhs, 0).last_column; \
939 /* YY_LOCATION_PRINT -- Print the location on the stream.
940 This macro was not mandated originally: define only if we know
941 we won't break user code: when these are the locations we know. */
943 #ifndef YY_LOCATION_PRINT
944 # if YYLTYPE_IS_TRIVIAL
945 # define YY_LOCATION_PRINT(File, Loc) \
946 fprintf (File, "%d.%d-%d.%d", \
947 (Loc).first_line, (Loc).first_column, \
948 (Loc).last_line, (Loc).last_column)
950 # define YY_LOCATION_PRINT(File, Loc) ((void) 0)
955 /* YYLEX -- calling `yylex' with the right arguments. */
958 # define YYLEX yylex (&yylval, &yylloc, YYLEX_PARAM)
960 # define YYLEX yylex (&yylval, &yylloc)
963 /* Enable debugging if requested. */
967 # include <stdio.h> /* INFRINGES ON USER NAME SPACE */
968 # define YYFPRINTF fprintf
971 # define YYDPRINTF(Args) \
977 # define YY_SYMBOL_PRINT(Title, Type, Value, Location) \
981 YYFPRINTF (stderr, "%s ", Title); \
982 yy_symbol_print (stderr, \
983 Type, Value, Location); \
984 YYFPRINTF (stderr, "\n"); \
989 /*--------------------------------.
990 | Print this symbol on YYOUTPUT. |
991 `--------------------------------*/
994 #if (defined __STDC__ || defined __C99__FUNC__ \
995 || defined __cplusplus || defined _MSC_VER)
997 yy_symbol_value_print (FILE *yyoutput, int yytype, YYSTYPE const * const yyvaluep, YYLTYPE const * const yylocationp)
1000 yy_symbol_value_print (yyoutput, yytype, yyvaluep, yylocationp)
1003 YYSTYPE const * const yyvaluep;
1004 YYLTYPE const * const yylocationp;
1009 YYUSE (yylocationp);
1011 if (yytype < YYNTOKENS)
1012 YYPRINT (yyoutput, yytoknum[yytype], *yyvaluep);
1024 /*--------------------------------.
1025 | Print this symbol on YYOUTPUT. |
1026 `--------------------------------*/
1028 #if (defined __STDC__ || defined __C99__FUNC__ \
1029 || defined __cplusplus || defined _MSC_VER)
1031 yy_symbol_print (FILE *yyoutput, int yytype, YYSTYPE const * const yyvaluep, YYLTYPE const * const yylocationp)
1034 yy_symbol_print (yyoutput, yytype, yyvaluep, yylocationp)
1037 YYSTYPE const * const yyvaluep;
1038 YYLTYPE const * const yylocationp;
1041 if (yytype < YYNTOKENS)
1042 YYFPRINTF (yyoutput, "token %s (", yytname[yytype]);
1044 YYFPRINTF (yyoutput, "nterm %s (", yytname[yytype]);
1046 YY_LOCATION_PRINT (yyoutput, *yylocationp);
1047 YYFPRINTF (yyoutput, ": ");
1048 yy_symbol_value_print (yyoutput, yytype, yyvaluep, yylocationp);
1049 YYFPRINTF (yyoutput, ")");
1052 /*------------------------------------------------------------------.
1053 | yy_stack_print -- Print the state stack from its BOTTOM up to its |
1055 `------------------------------------------------------------------*/
1057 #if (defined __STDC__ || defined __C99__FUNC__ \
1058 || defined __cplusplus || defined _MSC_VER)
1060 yy_stack_print (yytype_int16 *bottom, yytype_int16 *top)
1063 yy_stack_print (bottom, top)
1064 yytype_int16 *bottom;
1068 YYFPRINTF (stderr, "Stack now");
1069 for (; bottom <= top; ++bottom)
1070 YYFPRINTF (stderr, " %d", *bottom);
1071 YYFPRINTF (stderr, "\n");
1074 # define YY_STACK_PRINT(Bottom, Top) \
1077 yy_stack_print ((Bottom), (Top)); \
1081 /*------------------------------------------------.
1082 | Report that the YYRULE is going to be reduced. |
1083 `------------------------------------------------*/
1085 #if (defined __STDC__ || defined __C99__FUNC__ \
1086 || defined __cplusplus || defined _MSC_VER)
1088 yy_reduce_print (YYSTYPE *yyvsp, YYLTYPE *yylsp, int yyrule)
1091 yy_reduce_print (yyvsp, yylsp, yyrule)
1097 int yynrhs = yyr2[yyrule];
1099 unsigned long int yylno = yyrline[yyrule];
1100 YYFPRINTF (stderr, "Reducing stack by rule %d (line %lu):\n",
1102 /* The symbols being reduced. */
1103 for (yyi = 0; yyi < yynrhs; yyi++)
1105 fprintf (stderr, " $%d = ", yyi + 1);
1106 yy_symbol_print (stderr, yyrhs[yyprhs[yyrule] + yyi],
1107 &(yyvsp[(yyi + 1) - (yynrhs)])
1108 , &(yylsp[(yyi + 1) - (yynrhs)]) );
1109 fprintf (stderr, "\n");
1113 # define YY_REDUCE_PRINT(Rule) \
1116 yy_reduce_print (yyvsp, yylsp, Rule); \
1119 /* Nonzero means print parse trace. It is left uninitialized so that
1120 multiple parsers can coexist. */
1122 #else /* !YYDEBUG */
1123 # define YYDPRINTF(Args)
1124 # define YY_SYMBOL_PRINT(Title, Type, Value, Location)
1125 # define YY_STACK_PRINT(Bottom, Top)
1126 # define YY_REDUCE_PRINT(Rule)
1127 #endif /* !YYDEBUG */
1130 /* YYINITDEPTH -- initial size of the parser's stacks. */
1132 # define YYINITDEPTH 200
1135 /* YYMAXDEPTH -- maximum size the stacks can grow to (effective only
1136 if the built-in stack extension method is used).
1138 Do not make this value too large; the results are undefined if
1139 YYSTACK_ALLOC_MAXIMUM < YYSTACK_BYTES (YYMAXDEPTH)
1140 evaluated with infinite-precision integer arithmetic. */
1143 # define YYMAXDEPTH 10000
1151 # if defined __GLIBC__ && defined _STRING_H
1152 # define yystrlen strlen
1154 /* Return the length of YYSTR. */
1155 #if (defined __STDC__ || defined __C99__FUNC__ \
1156 || defined __cplusplus || defined _MSC_VER)
1158 yystrlen (const char *yystr)
1166 for (yylen = 0; yystr[yylen]; yylen++)
1174 # if defined __GLIBC__ && defined _STRING_H && defined _GNU_SOURCE
1175 # define yystpcpy stpcpy
1177 /* Copy YYSRC to YYDEST, returning the address of the terminating '\0' in
1179 #if (defined __STDC__ || defined __C99__FUNC__ \
1180 || defined __cplusplus || defined _MSC_VER)
1182 yystpcpy (char *yydest, const char *yysrc)
1185 yystpcpy (yydest, yysrc)
1191 const char *yys = yysrc;
1193 while ((*yyd++ = *yys++) != '\0')
1202 /* Copy to YYRES the contents of YYSTR after stripping away unnecessary
1203 quotes and backslashes, so that it's suitable for yyerror. The
1204 heuristic is that double-quoting is unnecessary unless the string
1205 contains an apostrophe, a comma, or backslash (other than
1206 backslash-backslash). YYSTR is taken from yytname. If YYRES is
1207 null, do not copy; instead, return the length of what the result
1210 yytnamerr (char *yyres, const char *yystr)
1215 char const *yyp = yystr;
1222 goto do_not_strip_quotes;
1226 goto do_not_strip_quotes;
1239 do_not_strip_quotes: ;
1243 return yystrlen (yystr);
1245 return yystpcpy (yyres, yystr) - yyres;
1249 /* Copy into YYRESULT an error message about the unexpected token
1250 YYCHAR while in state YYSTATE. Return the number of bytes copied,
1251 including the terminating null byte. If YYRESULT is null, do not
1252 copy anything; just return the number of bytes that would be
1253 copied. As a special case, return 0 if an ordinary "syntax error"
1254 message will do. Return YYSIZE_MAXIMUM if overflow occurs during
1255 size calculation. */
1257 yysyntax_error (char *yyresult, int yystate, int yychar)
1259 int yyn = yypact[yystate];
1261 if (! (YYPACT_NINF < yyn && yyn <= YYLAST))
1265 int yytype = YYTRANSLATE (yychar);
1266 YYSIZE_T yysize0 = yytnamerr (0, yytname[yytype]);
1267 YYSIZE_T yysize = yysize0;
1269 int yysize_overflow = 0;
1270 enum { YYERROR_VERBOSE_ARGS_MAXIMUM = 5 };
1271 char const *yyarg[YYERROR_VERBOSE_ARGS_MAXIMUM];
1275 /* This is so xgettext sees the translatable formats that are
1276 constructed on the fly. */
1277 YY_("syntax error, unexpected %s");
1278 YY_("syntax error, unexpected %s, expecting %s");
1279 YY_("syntax error, unexpected %s, expecting %s or %s");
1280 YY_("syntax error, unexpected %s, expecting %s or %s or %s");
1281 YY_("syntax error, unexpected %s, expecting %s or %s or %s or %s");
1285 static char const yyunexpected[] = "syntax error, unexpected %s";
1286 static char const yyexpecting[] = ", expecting %s";
1287 static char const yyor[] = " or %s";
1288 char yyformat[sizeof yyunexpected
1289 + sizeof yyexpecting - 1
1290 + ((YYERROR_VERBOSE_ARGS_MAXIMUM - 2)
1291 * (sizeof yyor - 1))];
1292 char const *yyprefix = yyexpecting;
1294 /* Start YYX at -YYN if negative to avoid negative indexes in
1296 int yyxbegin = yyn < 0 ? -yyn : 0;
1298 /* Stay within bounds of both yycheck and yytname. */
1299 int yychecklim = YYLAST - yyn + 1;
1300 int yyxend = yychecklim < YYNTOKENS ? yychecklim : YYNTOKENS;
1303 yyarg[0] = yytname[yytype];
1304 yyfmt = yystpcpy (yyformat, yyunexpected);
1306 for (yyx = yyxbegin; yyx < yyxend; ++yyx)
1307 if (yycheck[yyx + yyn] == yyx && yyx != YYTERROR)
1309 if (yycount == YYERROR_VERBOSE_ARGS_MAXIMUM)
1313 yyformat[sizeof yyunexpected - 1] = '\0';
1316 yyarg[yycount++] = yytname[yyx];
1317 yysize1 = yysize + yytnamerr (0, yytname[yyx]);
1318 yysize_overflow |= (yysize1 < yysize);
1320 yyfmt = yystpcpy (yyfmt, yyprefix);
1324 yyf = YY_(yyformat);
1325 yysize1 = yysize + yystrlen (yyf);
1326 yysize_overflow |= (yysize1 < yysize);
1329 if (yysize_overflow)
1330 return YYSIZE_MAXIMUM;
1334 /* Avoid sprintf, as that infringes on the user's name space.
1335 Don't have undefined behavior even if the translation
1336 produced a string with the wrong number of "%s"s. */
1337 char *yyp = yyresult;
1339 while ((*yyp = *yyf) != '\0')
1341 if (*yyp == '%' && yyf[1] == 's' && yyi < yycount)
1343 yyp += yytnamerr (yyp, yyarg[yyi++]);
1356 #endif /* YYERROR_VERBOSE */
1359 /*-----------------------------------------------.
1360 | Release the memory associated to this symbol. |
1361 `-----------------------------------------------*/
1364 #if (defined __STDC__ || defined __C99__FUNC__ \
1365 || defined __cplusplus || defined _MSC_VER)
1367 yydestruct (const char *yymsg, int yytype, YYSTYPE *yyvaluep, YYLTYPE *yylocationp)
1370 yydestruct (yymsg, yytype, yyvaluep, yylocationp)
1374 YYLTYPE *yylocationp;
1378 YYUSE (yylocationp);
1382 YY_SYMBOL_PRINT (yymsg, yytype, yyvaluep, yylocationp);
1386 case 4: /* "TOK_COLONCOLON" */
1387 #line 285 "../main/ast_expr2.y"
1388 { free_value((yyvaluep->val)); };
1389 #line 1390 "../main/ast_expr2.c"
1391 case 5: /* "TOK_COND" */
1392 #line 285 "../main/ast_expr2.y"
1393 { free_value((yyvaluep->val)); };
1394 #line 1395 "../main/ast_expr2.c"
1396 case 6: /* "TOK_OR" */
1397 #line 285 "../main/ast_expr2.y"
1398 { free_value((yyvaluep->val)); };
1399 #line 1400 "../main/ast_expr2.c"
1401 case 7: /* "TOK_AND" */
1402 #line 285 "../main/ast_expr2.y"
1403 { free_value((yyvaluep->val)); };
1404 #line 1405 "../main/ast_expr2.c"
1406 case 8: /* "TOK_NE" */
1407 #line 285 "../main/ast_expr2.y"
1408 { free_value((yyvaluep->val)); };
1409 #line 1410 "../main/ast_expr2.c"
1411 case 9: /* "TOK_LE" */
1412 #line 285 "../main/ast_expr2.y"
1413 { free_value((yyvaluep->val)); };
1414 #line 1415 "../main/ast_expr2.c"
1416 case 10: /* "TOK_GE" */
1417 #line 285 "../main/ast_expr2.y"
1418 { free_value((yyvaluep->val)); };
1419 #line 1420 "../main/ast_expr2.c"
1421 case 11: /* "TOK_LT" */
1422 #line 285 "../main/ast_expr2.y"
1423 { free_value((yyvaluep->val)); };
1424 #line 1425 "../main/ast_expr2.c"
1426 case 12: /* "TOK_GT" */
1427 #line 285 "../main/ast_expr2.y"
1428 { free_value((yyvaluep->val)); };
1429 #line 1430 "../main/ast_expr2.c"
1431 case 13: /* "TOK_EQ" */
1432 #line 285 "../main/ast_expr2.y"
1433 { free_value((yyvaluep->val)); };
1434 #line 1435 "../main/ast_expr2.c"
1436 case 14: /* "TOK_MINUS" */
1437 #line 285 "../main/ast_expr2.y"
1438 { free_value((yyvaluep->val)); };
1439 #line 1440 "../main/ast_expr2.c"
1441 case 15: /* "TOK_PLUS" */
1442 #line 285 "../main/ast_expr2.y"
1443 { free_value((yyvaluep->val)); };
1444 #line 1445 "../main/ast_expr2.c"
1446 case 16: /* "TOK_MOD" */
1447 #line 285 "../main/ast_expr2.y"
1448 { free_value((yyvaluep->val)); };
1449 #line 1450 "../main/ast_expr2.c"
1451 case 17: /* "TOK_DIV" */
1452 #line 285 "../main/ast_expr2.y"
1453 { free_value((yyvaluep->val)); };
1454 #line 1455 "../main/ast_expr2.c"
1456 case 18: /* "TOK_MULT" */
1457 #line 285 "../main/ast_expr2.y"
1458 { free_value((yyvaluep->val)); };
1459 #line 1460 "../main/ast_expr2.c"
1461 case 19: /* "TOK_COMPL" */
1462 #line 285 "../main/ast_expr2.y"
1463 { free_value((yyvaluep->val)); };
1464 #line 1465 "../main/ast_expr2.c"
1466 case 20: /* "TOK_EQTILDE" */
1467 #line 285 "../main/ast_expr2.y"
1468 { free_value((yyvaluep->val)); };
1469 #line 1470 "../main/ast_expr2.c"
1471 case 21: /* "TOK_COLON" */
1472 #line 285 "../main/ast_expr2.y"
1473 { free_value((yyvaluep->val)); };
1474 #line 1475 "../main/ast_expr2.c"
1476 case 22: /* "TOK_LP" */
1477 #line 285 "../main/ast_expr2.y"
1478 { free_value((yyvaluep->val)); };
1479 #line 1480 "../main/ast_expr2.c"
1481 case 23: /* "TOK_RP" */
1482 #line 285 "../main/ast_expr2.y"
1483 { free_value((yyvaluep->val)); };
1484 #line 1485 "../main/ast_expr2.c"
1486 case 24: /* "TOKEN" */
1487 #line 285 "../main/ast_expr2.y"
1488 { free_value((yyvaluep->val)); };
1489 #line 1490 "../main/ast_expr2.c"
1491 case 28: /* "expr" */
1492 #line 285 "../main/ast_expr2.y"
1493 { free_value((yyvaluep->val)); };
1494 #line 1495 "../main/ast_expr2.c"
1503 /* Prevent warnings from -Wmissing-prototypes. */
1505 #ifdef YYPARSE_PARAM
1506 #if defined __STDC__ || defined __cplusplus
1507 int yyparse (void *YYPARSE_PARAM);
1511 #else /* ! YYPARSE_PARAM */
1512 #if defined __STDC__ || defined __cplusplus
1517 #endif /* ! YYPARSE_PARAM */
1528 #ifdef YYPARSE_PARAM
1529 #if (defined __STDC__ || defined __C99__FUNC__ \
1530 || defined __cplusplus || defined _MSC_VER)
1532 yyparse (void *YYPARSE_PARAM)
1535 yyparse (YYPARSE_PARAM)
1536 void *YYPARSE_PARAM;
1538 #else /* ! YYPARSE_PARAM */
1539 #if (defined __STDC__ || defined __C99__FUNC__ \
1540 || defined __cplusplus || defined _MSC_VER)
1550 /* The look-ahead symbol. */
1553 /* The semantic value of the look-ahead symbol. */
1556 /* Number of syntax errors so far. */
1558 /* Location data for the look-ahead symbol. */
1564 /* Number of tokens to shift before error messages enabled. */
1566 /* Look-ahead token as an internal (translated) token number. */
1569 /* Buffer for error messages, and its allocated size. */
1571 char *yymsg = yymsgbuf;
1572 YYSIZE_T yymsg_alloc = sizeof yymsgbuf;
1575 /* Three stacks and their tools:
1576 `yyss': related to states,
1577 `yyvs': related to semantic values,
1578 `yyls': related to locations.
1580 Refer to the stacks thru separate pointers, to allow yyoverflow
1581 to reallocate them elsewhere. */
1583 /* The state stack. */
1584 yytype_int16 yyssa[YYINITDEPTH];
1585 yytype_int16 *yyss = yyssa;
1586 yytype_int16 *yyssp;
1588 /* The semantic value stack. */
1589 YYSTYPE yyvsa[YYINITDEPTH];
1590 YYSTYPE *yyvs = yyvsa;
1593 /* The location stack. */
1594 YYLTYPE yylsa[YYINITDEPTH];
1595 YYLTYPE *yyls = yylsa;
1597 /* The locations where the error started and ended. */
1598 YYLTYPE yyerror_range[2];
1600 #define YYPOPSTACK(N) (yyvsp -= (N), yyssp -= (N), yylsp -= (N))
1602 YYSIZE_T yystacksize = YYINITDEPTH;
1604 /* The variables used to return semantic value and location from the
1609 /* The number of symbols on the RHS of the reduced rule.
1610 Keep to zero when no symbol should be popped. */
1613 YYDPRINTF ((stderr, "Starting parse\n"));
1618 yychar = YYEMPTY; /* Cause a token to be read. */
1620 /* Initialize stack pointers.
1621 Waste one element of value and location stack
1622 so that they stay on the same level as the state stack.
1623 The wasted elements are never initialized. */
1628 #if YYLTYPE_IS_TRIVIAL
1629 /* Initialize the default location before parsing starts. */
1630 yylloc.first_line = yylloc.last_line = 1;
1631 yylloc.first_column = yylloc.last_column = 0;
1636 /*------------------------------------------------------------.
1637 | yynewstate -- Push a new state, which is found in yystate. |
1638 `------------------------------------------------------------*/
1640 /* In all cases, when you get here, the value and location stacks
1641 have just been pushed. So pushing a state here evens the stacks. */
1647 if (yyss + yystacksize - 1 <= yyssp)
1649 /* Get the current used size of the three stacks, in elements. */
1650 YYSIZE_T yysize = yyssp - yyss + 1;
1654 /* Give user a chance to reallocate the stack. Use copies of
1655 these so that the &'s don't force the real ones into
1657 YYSTYPE *yyvs1 = yyvs;
1658 yytype_int16 *yyss1 = yyss;
1659 YYLTYPE *yyls1 = yyls;
1661 /* Each stack pointer address is followed by the size of the
1662 data in use in that stack, in bytes. This used to be a
1663 conditional around just the two extra args, but that might
1664 be undefined if yyoverflow is a macro. */
1665 yyoverflow (YY_("memory exhausted"),
1666 &yyss1, yysize * sizeof (*yyssp),
1667 &yyvs1, yysize * sizeof (*yyvsp),
1668 &yyls1, yysize * sizeof (*yylsp),
1674 #else /* no yyoverflow */
1675 # ifndef YYSTACK_RELOCATE
1676 goto yyexhaustedlab;
1678 /* Extend the stack our own way. */
1679 if (YYMAXDEPTH <= yystacksize)
1680 goto yyexhaustedlab;
1682 if (YYMAXDEPTH < yystacksize)
1683 yystacksize = YYMAXDEPTH;
1686 yytype_int16 *yyss1 = yyss;
1687 union yyalloc *yyptr =
1688 (union yyalloc *) YYSTACK_ALLOC (YYSTACK_BYTES (yystacksize));
1690 goto yyexhaustedlab;
1691 YYSTACK_RELOCATE (yyss);
1692 YYSTACK_RELOCATE (yyvs);
1693 YYSTACK_RELOCATE (yyls);
1694 # undef YYSTACK_RELOCATE
1696 YYSTACK_FREE (yyss1);
1699 #endif /* no yyoverflow */
1701 yyssp = yyss + yysize - 1;
1702 yyvsp = yyvs + yysize - 1;
1703 yylsp = yyls + yysize - 1;
1705 YYDPRINTF ((stderr, "Stack size increased to %lu\n",
1706 (unsigned long int) yystacksize));
1708 if (yyss + yystacksize - 1 <= yyssp)
1712 YYDPRINTF ((stderr, "Entering state %d\n", yystate));
1721 /* Do appropriate processing given the current state. Read a
1722 look-ahead token if we need one and don't already have one. */
1724 /* First try to decide what to do without reference to look-ahead token. */
1725 yyn = yypact[yystate];
1726 if (yyn == YYPACT_NINF)
1729 /* Not known => get a look-ahead token if don't already have one. */
1731 /* YYCHAR is either YYEMPTY or YYEOF or a valid look-ahead symbol. */
1732 if (yychar == YYEMPTY)
1734 YYDPRINTF ((stderr, "Reading a token: "));
1738 if (yychar <= YYEOF)
1740 yychar = yytoken = YYEOF;
1741 YYDPRINTF ((stderr, "Now at end of input.\n"));
1745 yytoken = YYTRANSLATE (yychar);
1746 YY_SYMBOL_PRINT ("Next token is", yytoken, &yylval, &yylloc);
1749 /* If the proper action on seeing token YYTOKEN is to reduce or to
1750 detect an error, take that action. */
1752 if (yyn < 0 || YYLAST < yyn || yycheck[yyn] != yytoken)
1757 if (yyn == 0 || yyn == YYTABLE_NINF)
1766 /* Count tokens shifted since error; after three, turn off error
1771 /* Shift the look-ahead token. */
1772 YY_SYMBOL_PRINT ("Shifting", yytoken, &yylval, &yylloc);
1774 /* Discard the shifted token unless it is eof. */
1775 if (yychar != YYEOF)
1784 /*-----------------------------------------------------------.
1785 | yydefault -- do the default action for the current state. |
1786 `-----------------------------------------------------------*/
1788 yyn = yydefact[yystate];
1794 /*-----------------------------.
1795 | yyreduce -- Do a reduction. |
1796 `-----------------------------*/
1798 /* yyn is the number of a rule to reduce with. */
1801 /* If YYLEN is nonzero, implement the default value of the action:
1804 Otherwise, the following line sets YYVAL to garbage.
1805 This behavior is undocumented and Bison
1806 users should not rely upon it. Assigning to YYVAL
1807 unconditionally makes the parser a bit smaller, and it avoids a
1808 GCC warning that YYVAL may be used uninitialized. */
1809 yyval = yyvsp[1-yylen];
1811 /* Default location. */
1812 YYLLOC_DEFAULT (yyloc, (yylsp - yylen), yylen);
1813 YY_REDUCE_PRINT (yyn);
1817 #line 291 "../main/ast_expr2.y"
1818 { ((struct parse_io *)parseio)->val = (struct val *)calloc(sizeof(struct val),1);
1819 ((struct parse_io *)parseio)->val->type = (yyvsp[(1) - (1)].val)->type;
1820 if( (yyvsp[(1) - (1)].val)->type == AST_EXPR_number )
1821 ((struct parse_io *)parseio)->val->u.i = (yyvsp[(1) - (1)].val)->u.i;
1823 ((struct parse_io *)parseio)->val->u.s = (yyvsp[(1) - (1)].val)->u.s;
1824 free((yyvsp[(1) - (1)].val));
1829 #line 299 "../main/ast_expr2.y"
1830 {/* nothing */ ((struct parse_io *)parseio)->val = (struct val *)calloc(sizeof(struct val),1);
1831 ((struct parse_io *)parseio)->val->type = AST_EXPR_string;
1832 ((struct parse_io *)parseio)->val->u.s = strdup("");
1837 #line 306 "../main/ast_expr2.y"
1838 { (yyval.arglist) = alloc_expr_node(AST_EXPR_NODE_VAL); (yyval.arglist)->val = (yyvsp[(1) - (1)].val);;}
1842 #line 307 "../main/ast_expr2.y"
1843 {struct expr_node *x = alloc_expr_node(AST_EXPR_NODE_VAL);
1844 struct expr_node *t;
1845 DESTROY((yyvsp[(2) - (3)].val));
1846 for (t=(yyvsp[(1) - (3)].arglist);t->right;t=t->right)
1848 (yyval.arglist) = (yyvsp[(1) - (3)].arglist); t->right = x; x->val = (yyvsp[(3) - (3)].val);;}
1852 #line 316 "../main/ast_expr2.y"
1853 { (yyval.val) = op_func((yyvsp[(1) - (4)].val),(yyvsp[(3) - (4)].arglist), ((struct parse_io *)parseio)->chan);
1854 DESTROY((yyvsp[(2) - (4)].val));
1855 DESTROY((yyvsp[(4) - (4)].val));
1856 DESTROY((yyvsp[(1) - (4)].val));
1857 destroy_arglist((yyvsp[(3) - (4)].arglist));
1862 #line 322 "../main/ast_expr2.y"
1863 {(yyval.val) = (yyvsp[(1) - (1)].val);;}
1867 #line 323 "../main/ast_expr2.y"
1868 { (yyval.val) = (yyvsp[(2) - (3)].val);
1869 (yyloc).first_column = (yylsp[(1) - (3)]).first_column; (yyloc).last_column = (yylsp[(3) - (3)]).last_column;
1870 (yyloc).first_line=0; (yyloc).last_line=0;
1871 DESTROY((yyvsp[(1) - (3)].val)); DESTROY((yyvsp[(3) - (3)].val)); ;}
1875 #line 327 "../main/ast_expr2.y"
1876 { (yyval.val) = op_or ((yyvsp[(1) - (3)].val), (yyvsp[(3) - (3)].val));
1877 DESTROY((yyvsp[(2) - (3)].val));
1878 (yyloc).first_column = (yylsp[(1) - (3)]).first_column; (yyloc).last_column = (yylsp[(3) - (3)]).last_column;
1879 (yyloc).first_line=0; (yyloc).last_line=0;;}
1883 #line 331 "../main/ast_expr2.y"
1884 { (yyval.val) = op_and ((yyvsp[(1) - (3)].val), (yyvsp[(3) - (3)].val));
1885 DESTROY((yyvsp[(2) - (3)].val));
1886 (yyloc).first_column = (yylsp[(1) - (3)]).first_column; (yyloc).last_column = (yylsp[(3) - (3)]).last_column;
1887 (yyloc).first_line=0; (yyloc).last_line=0;;}
1891 #line 335 "../main/ast_expr2.y"
1892 { (yyval.val) = op_eq ((yyvsp[(1) - (3)].val), (yyvsp[(3) - (3)].val));
1893 DESTROY((yyvsp[(2) - (3)].val));
1894 (yyloc).first_column = (yylsp[(1) - (3)]).first_column; (yyloc).last_column = (yylsp[(3) - (3)]).last_column;
1895 (yyloc).first_line=0; (yyloc).last_line=0;;}
1899 #line 339 "../main/ast_expr2.y"
1900 { (yyval.val) = op_gt ((yyvsp[(1) - (3)].val), (yyvsp[(3) - (3)].val));
1901 DESTROY((yyvsp[(2) - (3)].val));
1902 (yyloc).first_column = (yylsp[(1) - (3)]).first_column; (yyloc).last_column = (yylsp[(3) - (3)]).last_column;
1903 (yyloc).first_line=0; (yyloc).last_line=0;;}
1907 #line 343 "../main/ast_expr2.y"
1908 { (yyval.val) = op_lt ((yyvsp[(1) - (3)].val), (yyvsp[(3) - (3)].val));
1909 DESTROY((yyvsp[(2) - (3)].val));
1910 (yyloc).first_column = (yylsp[(1) - (3)]).first_column; (yyloc).last_column = (yylsp[(3) - (3)]).last_column;
1911 (yyloc).first_line=0; (yyloc).last_line=0;;}
1915 #line 347 "../main/ast_expr2.y"
1916 { (yyval.val) = op_ge ((yyvsp[(1) - (3)].val), (yyvsp[(3) - (3)].val));
1917 DESTROY((yyvsp[(2) - (3)].val));
1918 (yyloc).first_column = (yylsp[(1) - (3)]).first_column; (yyloc).last_column = (yylsp[(3) - (3)]).last_column;
1919 (yyloc).first_line=0; (yyloc).last_line=0;;}
1923 #line 351 "../main/ast_expr2.y"
1924 { (yyval.val) = op_le ((yyvsp[(1) - (3)].val), (yyvsp[(3) - (3)].val));
1925 DESTROY((yyvsp[(2) - (3)].val));
1926 (yyloc).first_column = (yylsp[(1) - (3)]).first_column; (yyloc).last_column = (yylsp[(3) - (3)]).last_column;
1927 (yyloc).first_line=0; (yyloc).last_line=0;;}
1931 #line 355 "../main/ast_expr2.y"
1932 { (yyval.val) = op_ne ((yyvsp[(1) - (3)].val), (yyvsp[(3) - (3)].val));
1933 DESTROY((yyvsp[(2) - (3)].val));
1934 (yyloc).first_column = (yylsp[(1) - (3)]).first_column; (yyloc).last_column = (yylsp[(3) - (3)]).last_column;
1935 (yyloc).first_line=0; (yyloc).last_line=0;;}
1939 #line 359 "../main/ast_expr2.y"
1940 { (yyval.val) = op_plus ((yyvsp[(1) - (3)].val), (yyvsp[(3) - (3)].val));
1941 DESTROY((yyvsp[(2) - (3)].val));
1942 (yyloc).first_column = (yylsp[(1) - (3)]).first_column; (yyloc).last_column = (yylsp[(3) - (3)]).last_column;
1943 (yyloc).first_line=0; (yyloc).last_line=0;;}
1947 #line 363 "../main/ast_expr2.y"
1948 { (yyval.val) = op_minus ((yyvsp[(1) - (3)].val), (yyvsp[(3) - (3)].val));
1949 DESTROY((yyvsp[(2) - (3)].val));
1950 (yyloc).first_column = (yylsp[(1) - (3)]).first_column; (yyloc).last_column = (yylsp[(3) - (3)]).last_column;
1951 (yyloc).first_line=0; (yyloc).last_line=0;;}
1955 #line 367 "../main/ast_expr2.y"
1956 { (yyval.val) = op_negate ((yyvsp[(2) - (2)].val));
1957 DESTROY((yyvsp[(1) - (2)].val));
1958 (yyloc).first_column = (yylsp[(1) - (2)]).first_column; (yyloc).last_column = (yylsp[(2) - (2)]).last_column;
1959 (yyloc).first_line=0; (yyloc).last_line=0;;}
1963 #line 371 "../main/ast_expr2.y"
1964 { (yyval.val) = op_compl ((yyvsp[(2) - (2)].val));
1965 DESTROY((yyvsp[(1) - (2)].val));
1966 (yyloc).first_column = (yylsp[(1) - (2)]).first_column; (yyloc).last_column = (yylsp[(2) - (2)]).last_column;
1967 (yyloc).first_line=0; (yyloc).last_line=0;;}
1971 #line 375 "../main/ast_expr2.y"
1972 { (yyval.val) = op_times ((yyvsp[(1) - (3)].val), (yyvsp[(3) - (3)].val));
1973 DESTROY((yyvsp[(2) - (3)].val));
1974 (yyloc).first_column = (yylsp[(1) - (3)]).first_column; (yyloc).last_column = (yylsp[(3) - (3)]).last_column;
1975 (yyloc).first_line=0; (yyloc).last_line=0;;}
1979 #line 379 "../main/ast_expr2.y"
1980 { (yyval.val) = op_div ((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;;}
1987 #line 383 "../main/ast_expr2.y"
1988 { (yyval.val) = op_rem ((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;;}
1995 #line 387 "../main/ast_expr2.y"
1996 { (yyval.val) = op_colon ((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;;}
2003 #line 391 "../main/ast_expr2.y"
2004 { (yyval.val) = op_eqtilde ((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;;}
2011 #line 395 "../main/ast_expr2.y"
2012 { (yyval.val) = op_cond ((yyvsp[(1) - (5)].val), (yyvsp[(3) - (5)].val), (yyvsp[(5) - (5)].val));
2013 DESTROY((yyvsp[(2) - (5)].val));
2014 DESTROY((yyvsp[(4) - (5)].val));
2015 (yyloc).first_column = (yylsp[(1) - (5)]).first_column; (yyloc).last_column = (yylsp[(3) - (5)]).last_column;
2016 (yyloc).first_line=0; (yyloc).last_line=0;;}
2020 /* Line 1267 of yacc.c. */
2021 #line 2022 "../main/ast_expr2.c"
2024 YY_SYMBOL_PRINT ("-> $$ =", yyr1[yyn], &yyval, &yyloc);
2028 YY_STACK_PRINT (yyss, yyssp);
2033 /* Now `shift' the result of the reduction. Determine what state
2034 that goes to, based on the state we popped back to and the rule
2035 number reduced by. */
2039 yystate = yypgoto[yyn - YYNTOKENS] + *yyssp;
2040 if (0 <= yystate && yystate <= YYLAST && yycheck[yystate] == *yyssp)
2041 yystate = yytable[yystate];
2043 yystate = yydefgoto[yyn - YYNTOKENS];
2048 /*------------------------------------.
2049 | yyerrlab -- here on detecting error |
2050 `------------------------------------*/
2052 /* If not already recovering from an error, report this error. */
2056 #if ! YYERROR_VERBOSE
2057 yyerror (YY_("syntax error"));
2060 YYSIZE_T yysize = yysyntax_error (0, yystate, yychar);
2061 if (yymsg_alloc < yysize && yymsg_alloc < YYSTACK_ALLOC_MAXIMUM)
2063 YYSIZE_T yyalloc = 2 * yysize;
2064 if (! (yysize <= yyalloc && yyalloc <= YYSTACK_ALLOC_MAXIMUM))
2065 yyalloc = YYSTACK_ALLOC_MAXIMUM;
2066 if (yymsg != yymsgbuf)
2067 YYSTACK_FREE (yymsg);
2068 yymsg = (char *) YYSTACK_ALLOC (yyalloc);
2070 yymsg_alloc = yyalloc;
2074 yymsg_alloc = sizeof yymsgbuf;
2078 if (0 < yysize && yysize <= yymsg_alloc)
2080 (void) yysyntax_error (yymsg, yystate, yychar);
2085 yyerror (YY_("syntax error"));
2087 goto yyexhaustedlab;
2093 yyerror_range[0] = yylloc;
2095 if (yyerrstatus == 3)
2097 /* If just tried and failed to reuse look-ahead token after an
2098 error, discard it. */
2100 if (yychar <= YYEOF)
2102 /* Return failure if at end of input. */
2103 if (yychar == YYEOF)
2108 yydestruct ("Error: discarding",
2109 yytoken, &yylval, &yylloc);
2114 /* Else will try to reuse look-ahead token after shifting the error
2119 /*---------------------------------------------------.
2120 | yyerrorlab -- error raised explicitly by YYERROR. |
2121 `---------------------------------------------------*/
2124 /* Pacify compilers like GCC when the user code never invokes
2125 YYERROR and the label yyerrorlab therefore never appears in user
2127 if (/*CONSTCOND*/ 0)
2130 yyerror_range[0] = yylsp[1-yylen];
2131 /* Do not reclaim the symbols of the rule which action triggered
2135 YY_STACK_PRINT (yyss, yyssp);
2140 /*-------------------------------------------------------------.
2141 | yyerrlab1 -- common code for both syntax error and YYERROR. |
2142 `-------------------------------------------------------------*/
2144 yyerrstatus = 3; /* Each real token shifted decrements this. */
2148 yyn = yypact[yystate];
2149 if (yyn != YYPACT_NINF)
2152 if (0 <= yyn && yyn <= YYLAST && yycheck[yyn] == YYTERROR)
2160 /* Pop the current state because it cannot handle the error token. */
2164 yyerror_range[0] = *yylsp;
2165 yydestruct ("Error: popping",
2166 yystos[yystate], yyvsp, yylsp);
2169 YY_STACK_PRINT (yyss, yyssp);
2177 yyerror_range[1] = yylloc;
2178 /* Using YYLLOC is tempting, but would change the location of
2179 the look-ahead. YYLOC is available though. */
2180 YYLLOC_DEFAULT (yyloc, (yyerror_range - 1), 2);
2183 /* Shift the error token. */
2184 YY_SYMBOL_PRINT ("Shifting", yystos[yyn], yyvsp, yylsp);
2190 /*-------------------------------------.
2191 | yyacceptlab -- YYACCEPT comes here. |
2192 `-------------------------------------*/
2197 /*-----------------------------------.
2198 | yyabortlab -- YYABORT comes here. |
2199 `-----------------------------------*/
2205 /*-------------------------------------------------.
2206 | yyexhaustedlab -- memory exhaustion comes here. |
2207 `-------------------------------------------------*/
2209 yyerror (YY_("memory exhausted"));
2215 if (yychar != YYEOF && yychar != YYEMPTY)
2216 yydestruct ("Cleanup: discarding lookahead",
2217 yytoken, &yylval, &yylloc);
2218 /* Do not reclaim the symbols of the rule which action triggered
2219 this YYABORT or YYACCEPT. */
2221 YY_STACK_PRINT (yyss, yyssp);
2222 while (yyssp != yyss)
2224 yydestruct ("Cleanup: popping",
2225 yystos[*yyssp], yyvsp, yylsp);
2230 YYSTACK_FREE (yyss);
2233 if (yymsg != yymsgbuf)
2234 YYSTACK_FREE (yymsg);
2236 /* Make sure YYID is used. */
2237 return YYID (yyresult);
2241 #line 402 "../main/ast_expr2.y"
2244 static struct expr_node *alloc_expr_node(enum node_type nt)
2246 struct expr_node *x = calloc(1,sizeof(struct expr_node));
2248 ast_log(LOG_ERROR, "Allocation for expr_node FAILED!!\n");
2258 make_number (FP___TYPE i)
2262 vp = (struct val *) malloc (sizeof (*vp));
2264 ast_log(LOG_WARNING, "malloc() failed\n");
2268 vp->type = AST_EXPR_number;
2274 make_str (const char *s)
2278 int isint; /* this started out being a test for an integer, but then ended up being a test for a float */
2280 vp = (struct val *) malloc (sizeof (*vp));
2281 if (vp == NULL || ((vp->u.s = strdup (s)) == NULL)) {
2282 ast_log(LOG_WARNING,"malloc() failed\n");
2286 for (i = 0, isint = (isdigit(s[0]) || s[0] == '-' || s[0]=='.'); isint && i < strlen(s); i++)
2288 if (!isdigit(s[i]) && s[i] != '.') {
2294 vp->type = AST_EXPR_numeric_string;
2296 vp->type = AST_EXPR_string;
2303 free_value (struct val *vp)
2308 if (vp->type == AST_EXPR_string || vp->type == AST_EXPR_numeric_string)
2315 to_number (struct val *vp)
2320 ast_log(LOG_WARNING,"vp==NULL in to_number()\n");
2324 if (vp->type == AST_EXPR_number)
2327 if (vp->type == AST_EXPR_string)
2330 /* vp->type == AST_EXPR_numeric_string, make it numeric */
2332 i = FP___STRTOD(vp->u.s, (char**)0); /* either strtod, or strtold on a good day */
2334 ast_log(LOG_WARNING,"Conversion of %s to number under/overflowed!\n", vp->u.s);
2341 vp->type = AST_EXPR_number;
2346 strip_quotes(struct val *vp)
2348 if (vp->type != AST_EXPR_string && vp->type != AST_EXPR_numeric_string)
2351 if( vp->u.s[0] == '"' && vp->u.s[strlen(vp->u.s)-1] == '"' )
2359 if( *f && *f != '"' )
2369 to_string (struct val *vp)
2373 if (vp->type == AST_EXPR_string || vp->type == AST_EXPR_numeric_string)
2376 tmp = malloc ((size_t)25);
2378 ast_log(LOG_WARNING,"malloc() failed\n");
2382 sprintf(tmp, FP___PRINTF, vp->u.i);
2383 vp->type = AST_EXPR_string;
2389 isstring (struct val *vp)
2391 /* only TRUE if this string is not a valid number */
2392 return (vp->type == AST_EXPR_string);
2397 is_zero_or_null (struct val *vp)
2399 if (vp->type == AST_EXPR_number) {
2400 return (vp->u.i == 0);
2402 return (*vp->u.s == 0 || (to_number(vp) && vp->u.i == 0));
2409 void ast_log(int level, const char *file, int line, const char *function, const char *fmt, ...)
2414 printf("LOG: lev:%d file:%s line:%d func: %s ",
2415 level, file, line, function);
2422 int main(int argc,char **argv) {
2430 if( access(argv[1],F_OK)== 0 )
2434 infile = fopen(argv[1],"r");
2437 printf("Sorry, couldn't open %s for reading!\n", argv[1]);
2440 while( fgets(s,sizeof(s),infile) )
2442 if( s[strlen(s)-1] == '\n' )
2445 ret = ast_expr(s, out, sizeof(out),NULL);
2446 printf("Expression: %s Result: [%d] '%s'\n",
2453 if (ast_expr(argv[1], s, sizeof(s), NULL))
2454 printf("=====%s======\n",s);
2456 printf("No result\n");
2463 #define ast_yyerror(x) ast_yyerror(x, YYLTYPE *yylloc, struct parse_io *parseio)
2465 /* I put the ast_yyerror func in the flex input file,
2466 because it refers to the buffer state. Best to
2467 let it access the BUFFER stuff there and not trying
2468 define all the structs, macros etc. in this file! */
2470 static void destroy_arglist(struct expr_node *arglist)
2472 struct expr_node *arglist_next;
2476 arglist_next = arglist->right;
2478 free_value(arglist->val);
2482 arglist = arglist_next;
2486 static char *compose_func_args(struct expr_node *arglist)
2488 struct expr_node *t = arglist;
2494 total_len += 1; /* for the sep */
2496 if (t->val->type == AST_EXPR_number)
2497 total_len += 25; /* worst case */
2499 total_len += strlen(t->val->u.s);
2504 total_len++; /* for the null */
2505 ast_log(LOG_NOTICE,"argbuf allocated %d bytes;\n", total_len);
2506 argbuf = malloc(total_len);
2516 if (t->val->type == AST_EXPR_number) {
2517 sprintf(numbuf,FP___PRINTF,t->val->u.i);
2518 strcat(argbuf,numbuf);
2520 strcat(argbuf,t->val->u.s);
2524 ast_log(LOG_NOTICE,"argbuf uses %d bytes;\n", (int) strlen(argbuf));
2528 static int is_really_num(char *str)
2530 if ( strspn(str,"-0123456789. ") == strlen(str))
2537 static struct val *op_func(struct val *funcname, struct expr_node *arglist, struct ast_channel *chan)
2539 if (strspn(funcname->u.s,"ABCDEFGHIJKLMNOPQRSTUVWXYZ_0123456789") == strlen(funcname->u.s))
2543 if (strcmp(funcname->u.s,"COS") == 0) {
2544 if (arglist && !arglist->right && arglist->val){
2545 to_number(arglist->val);
2546 result = make_number(FUNC_COS(arglist->val->u.i));
2549 ast_log(LOG_WARNING,"Wrong args to %s() function\n",funcname->u.s);
2550 return make_number(0.0);
2552 } else if (strcmp(funcname->u.s,"SIN") == 0) {
2553 if (arglist && !arglist->right && arglist->val){
2554 to_number(arglist->val);
2555 result = make_number(FUNC_SIN(arglist->val->u.i));
2558 ast_log(LOG_WARNING,"Wrong args to %s() function\n",funcname->u.s);
2559 return make_number(0.0);
2561 } else if (strcmp(funcname->u.s,"TAN") == 0) {
2562 if (arglist && !arglist->right && arglist->val){
2563 to_number(arglist->val);
2564 result = make_number(FUNC_TAN(arglist->val->u.i));
2567 ast_log(LOG_WARNING,"Wrong args to %s() function\n",funcname->u.s);
2568 return make_number(0.0);
2570 } else if (strcmp(funcname->u.s,"ACOS") == 0) {
2571 if (arglist && !arglist->right && arglist->val){
2572 to_number(arglist->val);
2573 result = make_number(FUNC_ACOS(arglist->val->u.i));
2576 ast_log(LOG_WARNING,"Wrong args to %s() function\n",funcname->u.s);
2577 return make_number(0.0);
2579 } else if (strcmp(funcname->u.s,"ASIN") == 0) {
2580 if (arglist && !arglist->right && arglist->val){
2581 to_number(arglist->val);
2582 result = make_number(FUNC_ASIN(arglist->val->u.i));
2585 ast_log(LOG_WARNING,"Wrong args to %s() function\n",funcname->u.s);
2586 return make_number(0.0);
2588 } else if (strcmp(funcname->u.s,"ATAN") == 0) {
2589 if (arglist && !arglist->right && arglist->val){
2590 to_number(arglist->val);
2591 result = make_number(FUNC_ATAN(arglist->val->u.i));
2594 ast_log(LOG_WARNING,"Wrong args to %s() function\n",funcname->u.s);
2595 return make_number(0.0);
2597 } else if (strcmp(funcname->u.s,"ATAN2") == 0) {
2598 if (arglist && arglist->right && !arglist->right->right && arglist->val && arglist->right->val){
2599 to_number(arglist->val);
2600 to_number(arglist->right->val);
2601 result = make_number(FUNC_ATAN2(arglist->val->u.i, arglist->right->val->u.i));
2604 ast_log(LOG_WARNING,"Wrong args to %s() function\n",funcname->u.s);
2605 return make_number(0.0);
2607 } else if (strcmp(funcname->u.s,"POW") == 0) {
2608 if (arglist && arglist->right && !arglist->right->right && arglist->val && arglist->right->val){
2609 to_number(arglist->val);
2610 to_number(arglist->right->val);
2611 result = make_number(FUNC_POW(arglist->val->u.i, arglist->right->val->u.i));
2614 ast_log(LOG_WARNING,"Wrong args to %s() function\n",funcname->u.s);
2615 return make_number(0.0);
2617 } else if (strcmp(funcname->u.s,"SQRT") == 0) {
2618 if (arglist && !arglist->right && arglist->val){
2619 to_number(arglist->val);
2620 result = make_number(FUNC_SQRT(arglist->val->u.i));
2623 ast_log(LOG_WARNING,"Wrong args to %s() function\n",funcname->u.s);
2624 return make_number(0.0);
2626 } else if (strcmp(funcname->u.s,"FLOOR") == 0) {
2627 if (arglist && !arglist->right && arglist->val){
2628 to_number(arglist->val);
2629 result = make_number(FUNC_FLOOR(arglist->val->u.i));
2632 ast_log(LOG_WARNING,"Wrong args to %s() function\n",funcname->u.s);
2633 return make_number(0.0);
2635 } else if (strcmp(funcname->u.s,"CEIL") == 0) {
2636 if (arglist && !arglist->right && arglist->val){
2637 to_number(arglist->val);
2638 result = make_number(FUNC_CEIL(arglist->val->u.i));
2641 ast_log(LOG_WARNING,"Wrong args to %s() function\n",funcname->u.s);
2642 return make_number(0.0);
2644 } else if (strcmp(funcname->u.s,"ROUND") == 0) {
2645 if (arglist && !arglist->right && arglist->val){
2646 to_number(arglist->val);
2647 result = make_number(FUNC_ROUND(arglist->val->u.i));
2650 ast_log(LOG_WARNING,"Wrong args to %s() function\n",funcname->u.s);
2651 return make_number(0.0);
2653 } else if (strcmp(funcname->u.s,"RINT") == 0) {
2654 if (arglist && !arglist->right && arglist->val){
2655 to_number(arglist->val);
2656 result = make_number(FUNC_RINT(arglist->val->u.i));
2659 ast_log(LOG_WARNING,"Wrong args to %s() function\n",funcname->u.s);
2660 return make_number(0.0);
2662 } else if (strcmp(funcname->u.s,"TRUNC") == 0) {
2663 if (arglist && !arglist->right && arglist->val){
2664 to_number(arglist->val);
2665 result = make_number(FUNC_TRUNC(arglist->val->u.i));
2668 ast_log(LOG_WARNING,"Wrong args to %s() function\n",funcname->u.s);
2669 return make_number(0.0);
2671 } else if (strcmp(funcname->u.s,"EXP") == 0) {
2672 if (arglist && !arglist->right && arglist->val){
2673 to_number(arglist->val);
2674 result = make_number(FUNC_EXP(arglist->val->u.i));
2677 ast_log(LOG_WARNING,"Wrong args to %s() function\n",funcname->u.s);
2678 return make_number(0.0);
2680 } else if (strcmp(funcname->u.s,"EXP2") == 0) {
2681 if (arglist && !arglist->right && arglist->val){
2682 to_number(arglist->val);
2683 result = make_number(FUNC_EXP2(arglist->val->u.i));
2686 ast_log(LOG_WARNING,"Wrong args to %s() function\n",funcname->u.s);
2687 return make_number(0.0);
2689 } else if (strcmp(funcname->u.s,"EXP10") == 0) {
2690 if (arglist && !arglist->right && arglist->val){
2691 to_number(arglist->val);
2692 result = make_number(FUNC_EXP10(arglist->val->u.i));
2695 ast_log(LOG_WARNING,"Wrong args to %s() function\n",funcname->u.s);
2696 return make_number(0.0);
2698 } else if (strcmp(funcname->u.s,"LOG") == 0) {
2699 if (arglist && !arglist->right && arglist->val){
2700 to_number(arglist->val);
2701 result = make_number(FUNC_LOG(arglist->val->u.i));
2704 ast_log(LOG_WARNING,"Wrong args to %s() function\n",funcname->u.s);
2705 return make_number(0.0);
2707 } else if (strcmp(funcname->u.s,"LOG2") == 0) {
2708 if (arglist && !arglist->right && arglist->val){
2709 to_number(arglist->val);
2710 result = make_number(FUNC_LOG2(arglist->val->u.i));
2713 ast_log(LOG_WARNING,"Wrong args to %s() function\n",funcname->u.s);
2714 return make_number(0.0);
2716 } else if (strcmp(funcname->u.s,"LOG10") == 0) {
2717 if (arglist && !arglist->right && arglist->val){
2718 to_number(arglist->val);
2719 result = make_number(FUNC_LOG10(arglist->val->u.i));
2722 ast_log(LOG_WARNING,"Wrong args to %s() function\n",funcname->u.s);
2723 return make_number(0.0);
2725 } else if (strcmp(funcname->u.s,"REMAINDER") == 0) {
2726 if (arglist && arglist->right && !arglist->right->right && arglist->val && arglist->right->val){
2727 to_number(arglist->val);
2728 to_number(arglist->right->val);
2729 result = make_number(FUNC_REMAINDER(arglist->val->u.i, arglist->right->val->u.i));
2732 ast_log(LOG_WARNING,"Wrong args to %s() function\n",funcname->u.s);
2733 return make_number(0.0);
2736 /* is this a custom function we should execute and collect the results of? */
2738 struct ast_custom_function *f = ast_custom_function_find(funcname->u.s);
2740 ast_log(LOG_WARNING,"Hey! chan is NULL.\n");
2742 ast_log(LOG_WARNING,"Hey! could not find func %s.\n", funcname->u.s);
2746 char workspace[512];
2747 char *argbuf = compose_func_args(arglist);
2748 f->read(chan, funcname->u.s, argbuf, workspace, sizeof(workspace));
2750 if (is_really_num(workspace))
2751 return make_number(FP___STRTOD(workspace,(char **)NULL));
2753 return make_str(workspace);
2755 ast_log(LOG_ERROR,"Error! Function '%s' cannot be read!\n", funcname->u.s);
2756 return (make_number ((FP___TYPE)0.0));
2760 ast_log(LOG_ERROR,"Error! '%s' doesn't appear to be an available function!", funcname->u.s);
2761 return (make_number ((FP___TYPE)0.0));
2764 ast_log(LOG_ERROR,"Error! '%s' is not available in the standalone version!", funcname->u.s);
2765 return (make_number ((FP___TYPE)0.0));
2771 ast_log(LOG_ERROR,"Error! '%s' is not possibly a function name!", funcname->u.s);
2772 return (make_number ((FP___TYPE)0.0));
2774 return (make_number ((FP___TYPE)0.0));
2779 op_or (struct val *a, struct val *b)
2781 if (is_zero_or_null (a)) {
2791 op_and (struct val *a, struct val *b)
2793 if (is_zero_or_null (a) || is_zero_or_null (b)) {
2796 return (make_number ((FP___TYPE)0.0));
2804 op_eq (struct val *a, struct val *b)
2808 if (isstring (a) || isstring (b)) {
2811 r = make_number ((FP___TYPE)(strcoll (a->u.s, b->u.s) == 0));
2813 #ifdef DEBUG_FOR_CONVERSIONS
2815 sprintf(buffer,"Converting '%s' and '%s' ", a->u.s, b->u.s);
2819 #ifdef DEBUG_FOR_CONVERSIONS
2820 ast_log(LOG_WARNING,"%s to '%lld' and '%lld'\n", buffer, a->u.i, b->u.i);
2822 r = make_number ((FP___TYPE)(a->u.i == b->u.i));
2831 op_gt (struct val *a, struct val *b)
2835 if (isstring (a) || isstring (b)) {
2838 r = make_number ((FP___TYPE)(strcoll (a->u.s, b->u.s) > 0));
2842 r = make_number ((FP___TYPE)(a->u.i > b->u.i));
2851 op_lt (struct val *a, struct val *b)
2855 if (isstring (a) || isstring (b)) {
2858 r = make_number ((FP___TYPE)(strcoll (a->u.s, b->u.s) < 0));
2862 r = make_number ((FP___TYPE)(a->u.i < b->u.i));
2871 op_ge (struct val *a, struct val *b)
2875 if (isstring (a) || isstring (b)) {
2878 r = make_number ((FP___TYPE)(strcoll (a->u.s, b->u.s) >= 0));
2882 r = make_number ((FP___TYPE)(a->u.i >= b->u.i));
2891 op_le (struct val *a, struct val *b)
2895 if (isstring (a) || isstring (b)) {
2898 r = make_number ((FP___TYPE)(strcoll (a->u.s, b->u.s) <= 0));
2902 r = make_number ((FP___TYPE)(a->u.i <= b->u.i));
2911 op_cond (struct val *a, struct val *b, struct val *c)
2917 if( strlen(a->u.s) && strcmp(a->u.s, "\"\"") != 0 && strcmp(a->u.s,"0") != 0 )
2950 op_ne (struct val *a, struct val *b)
2954 if (isstring (a) || isstring (b)) {
2957 r = make_number ((FP___TYPE)(strcoll (a->u.s, b->u.s) != 0));
2961 r = make_number ((FP___TYPE)(a->u.i != b->u.i));
2970 chk_plus (FP___TYPE a, FP___TYPE b, FP___TYPE r)
2972 /* sum of two positive numbers must be positive */
2973 if (a > 0 && b > 0 && r <= 0)
2975 /* sum of two negative numbers must be negative */
2976 if (a < 0 && b < 0 && r >= 0)
2978 /* all other cases are OK */
2983 op_plus (struct val *a, struct val *b)
2987 if (!to_number (a)) {
2988 if( !extra_error_message_supplied )
2989 ast_log(LOG_WARNING,"non-numeric argument\n");
2990 if (!to_number (b)) {
2993 return make_number(0);
2998 } else if (!to_number(b)) {
3003 r = make_number (a->u.i + b->u.i);
3004 if (chk_plus (a->u.i, b->u.i, r->u.i)) {
3005 ast_log(LOG_WARNING,"overflow\n");
3013 chk_minus (FP___TYPE a, FP___TYPE b, FP___TYPE r)
3015 /* special case subtraction of QUAD_MIN */
3016 if (b == QUAD_MIN) {
3022 /* this is allowed for b != QUAD_MIN */
3023 return chk_plus (a, -b, r);
3027 op_minus (struct val *a, struct val *b)
3031 if (!to_number (a)) {
3032 if( !extra_error_message_supplied )
3033 ast_log(LOG_WARNING, "non-numeric argument\n");
3034 if (!to_number (b)) {
3037 return make_number(0);
3039 r = make_number(0 - b->u.i);
3044 } else if (!to_number(b)) {
3045 if( !extra_error_message_supplied )
3046 ast_log(LOG_WARNING, "non-numeric argument\n");
3051 r = make_number (a->u.i - b->u.i);
3052 if (chk_minus (a->u.i, b->u.i, r->u.i)) {
3053 ast_log(LOG_WARNING, "overflow\n");
3061 op_negate (struct val *a)
3065 if (!to_number (a) ) {
3067 if( !extra_error_message_supplied )
3068 ast_log(LOG_WARNING, "non-numeric argument\n");
3069 return make_number(0);
3072 r = make_number (- a->u.i);
3073 if (chk_minus (0, a->u.i, r->u.i)) {
3074 ast_log(LOG_WARNING, "overflow\n");
3081 op_compl (struct val *a)
3094 case AST_EXPR_number:
3099 case AST_EXPR_string:
3104 if( a->u.s[0] == 0 )
3106 else if (strlen(a->u.s) == 1 && a->u.s[0] == '0' )
3111 case AST_EXPR_numeric_string:
3116 if( a->u.s[0] == 0 )
3118 else if (strlen(a->u.s) == 1 && a->u.s[0] == '0' )
3125 r = make_number (!v1);
3131 chk_times (FP___TYPE a, FP___TYPE b, FP___TYPE r)
3133 /* special case: first operand is 0, no overflow possible */
3136 /* cerify that result of division matches second operand */
3143 op_times (struct val *a, struct val *b)
3147 if (!to_number (a) || !to_number (b)) {
3150 if( !extra_error_message_supplied )
3151 ast_log(LOG_WARNING, "non-numeric argument\n");
3152 return(make_number(0));
3155 r = make_number (a->u.i * b->u.i);
3156 if (chk_times (a->u.i, b->u.i, r->u.i)) {
3157 ast_log(LOG_WARNING, "overflow\n");
3165 chk_div (FP___TYPE a, FP___TYPE b)
3167 /* div by zero has been taken care of before */
3168 /* only QUAD_MIN / -1 causes overflow */
3169 if (a == QUAD_MIN && b == -1)
3171 /* everything else is OK */
3176 op_div (struct val *a, struct val *b)
3180 if (!to_number (a)) {
3183 if( !extra_error_message_supplied )
3184 ast_log(LOG_WARNING, "non-numeric argument\n");
3185 return make_number(0);
3186 } else if (!to_number (b)) {
3189 if( !extra_error_message_supplied )
3190 ast_log(LOG_WARNING, "non-numeric argument\n");
3191 return make_number(INT_MAX);
3195 ast_log(LOG_WARNING, "division by zero\n");
3198 return make_number(INT_MAX);
3201 r = make_number (a->u.i / b->u.i);
3202 if (chk_div (a->u.i, b->u.i)) {
3203 ast_log(LOG_WARNING, "overflow\n");
3211 op_rem (struct val *a, struct val *b)
3215 if (!to_number (a) || !to_number (b)) {
3216 if( !extra_error_message_supplied )
3217 ast_log(LOG_WARNING, "non-numeric argument\n");
3220 return make_number(0);
3224 ast_log(LOG_WARNING, "div by zero\n");
3229 r = make_number (FP___FMOD(a->u.i, b->u.i)); /* either fmod or fmodl if FP___TYPE is available */
3230 /* chk_rem necessary ??? */
3238 op_colon (struct val *a, struct val *b)
3246 /* coerce to both arguments to strings */
3249 /* strip double quotes from both -- they'll screw up the pattern, and the search string starting at ^ */
3252 /* compile regular expression */
3253 if ((eval = regcomp (&rp, b->u.s, REG_EXTENDED)) != 0) {
3254 regerror (eval, &rp, errbuf, sizeof(errbuf));
3255 ast_log(LOG_WARNING,"regcomp() error : %s",errbuf);
3258 return make_str("");
3261 /* compare string against pattern */
3262 /* remember that patterns are anchored to the beginning of the line */
3263 if (regexec(&rp, a->u.s, (size_t)2, rm, 0) == 0 && rm[0].rm_so == 0) {
3264 if (rm[1].rm_so >= 0) {
3265 *(a->u.s + rm[1].rm_eo) = '\0';
3266 v = make_str (a->u.s + rm[1].rm_so);
3269 v = make_number ((FP___TYPE)(rm[0].rm_eo - rm[0].rm_so));
3272 if (rp.re_nsub == 0) {
3273 v = make_number ((FP___TYPE)0);
3279 /* free arguments and pattern buffer */
3289 op_eqtilde (struct val *a, struct val *b)
3297 /* coerce to both arguments to strings */
3300 /* strip double quotes from both -- they'll screw up the pattern, and the search string starting at ^ */
3303 /* compile regular expression */
3304 if ((eval = regcomp (&rp, b->u.s, REG_EXTENDED)) != 0) {
3305 regerror (eval, &rp, errbuf, sizeof(errbuf));
3306 ast_log(LOG_WARNING,"regcomp() error : %s",errbuf);
3309 return make_str("");
3312 /* compare string against pattern */
3313 /* remember that patterns are anchored to the beginning of the line */
3314 if (regexec(&rp, a->u.s, (size_t)2, rm, 0) == 0 ) {
3315 if (rm[1].rm_so >= 0) {
3316 *(a->u.s + rm[1].rm_eo) = '\0';
3317 v = make_str (a->u.s + rm[1].rm_so);
3320 v = make_number ((FP___TYPE)(rm[0].rm_eo - rm[0].rm_so));
3323 if (rp.re_nsub == 0) {
3324 v = make_number ((FP___TYPE)0.0);
3330 /* free arguments and pattern buffer */