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
103 #define TOK_COMMA 258
104 #define TOK_COLONCOLON 259
114 #define TOK_MINUS 269
119 #define TOK_COMPL 274
120 #define TOK_TILDETILDE 275
121 #define TOK_EQTILDE 276
122 #define TOK_COLON 277
130 /* Copy the first part of user declarations. */
131 #line 1 "ast_expr2.y"
133 /* Written by Pace Willisson (pace@blitz.com)
134 * and placed in the public domain.
136 * Largely rewritten by J.T. Conklin (jtc@wimsey.com)
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
143 * $FreeBSD: src/bin/expr/expr.y,v 1.16 2000/07/22 10:59:36 se Exp $
146 #include "asterisk.h"
148 #include <sys/types.h>
151 #if !defined(STANDALONE) && !defined(STANDALONE2) \
153 ASTERISK_FILE_VERSION(__FILE__, "$Revision$")
156 #define __USE_ISOC99 1
161 #define FP___PRINTF "%.18Lg"
162 #define FP___TYPE long double
164 #define FP___PRINTF "%.16g"
165 #define FP___TYPE double
169 #define FUNC_COS cosl
170 #elif defined(HAVE_COS)
171 #define FUNC_COS (long double)cos
175 #define FUNC_SIN sinl
176 #elif defined(HAVE_SIN)
177 #define FUNC_SIN (long double)sin
181 #define FUNC_TAN tanl
182 #elif defined(HAVE_TAN)
183 #define FUNC_TAN (long double)tan
187 #define FUNC_ACOS acosl
188 #elif defined(HAVE_ACOS)
189 #define FUNC_ACOS (long double)acos
193 #define FUNC_ASIN asinl
194 #elif defined(HAVE_ASIN)
195 #define FUNC_ASIN (long double)asin
199 #define FUNC_ATAN atanl
200 #elif defined(HAVE_ATAN)
201 #define FUNC_ATAN (long double)atan
205 #define FUNC_ATAN2 atan2l
206 #elif defined(HAVE_ATAN2)
207 #define FUNC_ATAN2 (long double)atan2
211 #define FUNC_POW powl
212 #elif defined(HAVE_POW)
213 #define FUNC_POW (long double)pow
217 #define FUNC_SQRT sqrtl
218 #elif defined(HAVE_SQRT)
219 #define FUNC_SQRT (long double)sqrt
223 #define FUNC_RINT rintl
224 #elif defined(HAVE_RINT)
225 #define FUNC_RINT (long double)rint
229 #define FUNC_EXP expl
230 #elif defined(HAVE_EXP)
231 #define FUNC_EXP (long double)exp
235 #define FUNC_LOG logl
236 #elif defined(HAVE_LOG)
237 #define FUNC_LOG (long double)log
240 #ifdef HAVE_REMAINDERL
241 #define FUNC_REMAINDER remainderl
242 #elif defined(HAVE_REMAINDER)
243 #define FUNC_REMAINDER (long double)remainder
247 #define FUNC_FMOD fmodl
248 #elif defined(HAVE_FMOD)
249 #define FUNC_FMOD (long double)fmod
253 #define FUNC_STRTOD strtold
254 #elif defined(HAVE_STRTOD)
255 #define FUNC_STRTOD (long double)strtod
259 #define FUNC_FLOOR floorl
260 #elif defined(HAVE_FLOOR)
261 #define FUNC_FLOOR (long double)floor
265 #define FUNC_CEIL ceill
266 #elif defined(HAVE_CEIL)
267 #define FUNC_CEIL (long double)ceil
271 #define FUNC_ROUND roundl
272 #elif defined(HAVE_ROUND)
273 #define FUNC_ROUND (long double)round
277 #define FUNC_TRUNC truncl
278 #elif defined(HAVE_TRUNC)
279 #define FUNC_TRUNC (long double)trunc
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.
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))
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))
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))
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))
336 #if !defined(SOLARIS) && !defined(__CYGWIN__)
337 /* #include <err.h> */
339 #define quad_t int64_t
345 #include "asterisk/ast_expr.h"
346 #include "asterisk/logger.h"
347 #if !defined(STANDALONE) && !defined(STANDALONE2)
348 #include "asterisk/pbx.h"
351 #if defined(LONG_LONG_MIN) && !defined(QUAD_MIN)
352 #define QUAD_MIN LONG_LONG_MIN
354 #if defined(LONG_LONG_MAX) && !defined(QUAD_MAX)
355 #define QUAD_MAX LONG_LONG_MAX
358 # if ! defined(QUAD_MIN)
359 # define QUAD_MIN (-0x7fffffffffffffffLL-1)
361 # if ! defined(QUAD_MAX)
362 # define QUAD_MAX (0x7fffffffffffffffLL)
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;
372 AST_EXPR_number, AST_EXPR_numeric_string, AST_EXPR_string
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)));
383 FP___TYPE i; /* either long double, or just double, on a bad day */
388 AST_EXPR_NODE_COMMA, AST_EXPR_NODE_STRING, AST_EXPR_NODE_VAL
395 struct expr_node *left;
396 struct expr_node *right;
400 typedef void *yyscan_t;
407 struct ast_channel *chan;
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);
444 /* uh, if I want to predeclare yylex with a YYLTYPE, I have to predeclare the yyltype... sigh */
445 typedef struct yyltype
454 # define YYLTYPE yyltype
455 # define YYLTYPE_IS_TRIVIAL 1
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. */
460 int ast_yyerror(const char *,YYLTYPE *, struct parse_io *);
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
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);}
469 /* Enabling traces. */
474 /* Enabling verbose error messages. */
475 #ifdef YYERROR_VERBOSE
476 # undef YYERROR_VERBOSE
477 # define YYERROR_VERBOSE 1
479 # define YYERROR_VERBOSE 0
482 /* Enabling the token table. */
483 #ifndef YYTOKEN_TABLE
484 # define YYTOKEN_TABLE 0
487 #if ! defined YYSTYPE && ! defined YYSTYPE_IS_DECLARED
488 typedef union YYSTYPE
489 #line 345 "ast_expr2.y"
492 struct expr_node *arglist;
494 /* Line 187 of yacc.c. */
495 #line 496 "ast_expr2.c"
497 # define yystype YYSTYPE /* obsolescent; will be withdrawn */
498 # define YYSTYPE_IS_DECLARED 1
499 # define YYSTYPE_IS_TRIVIAL 1
502 #if ! defined YYLTYPE && ! defined YYLTYPE_IS_DECLARED
503 typedef struct YYLTYPE
510 # define yyltype YYLTYPE /* obsolescent; will be withdrawn */
511 # define YYLTYPE_IS_DECLARED 1
512 # define YYLTYPE_IS_TRIVIAL 1
516 /* Copy the second part of user declarations. */
517 #line 350 "ast_expr2.y"
519 extern int ast_yylex __P((YYSTYPE *, YYLTYPE *, yyscan_t));
522 /* Line 216 of yacc.c. */
523 #line 524 "ast_expr2.c"
530 typedef YYTYPE_UINT8 yytype_uint8;
532 typedef unsigned char yytype_uint8;
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;
541 typedef short int yytype_int8;
545 typedef YYTYPE_UINT16 yytype_uint16;
547 typedef unsigned short int yytype_uint16;
551 typedef YYTYPE_INT16 yytype_int16;
553 typedef short int yytype_int16;
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
566 # define YYSIZE_T unsigned int
570 #define YYSIZE_MAXIMUM ((YYSIZE_T) -1)
575 # include <libintl.h> /* INFRINGES ON USER NAME SPACE */
576 # define YY_(msgid) dgettext ("bison-runtime", msgid)
580 # define YY_(msgid) msgid
584 /* Suppress unused-variable warnings by "using" E. */
585 #if ! defined lint || defined __GNUC__
586 # define YYUSE(e) ((void) (e))
588 # define YYUSE(e) /* empty */
591 /* Identity function, used to suppress warnings about constant conditions. */
595 #if (defined __STDC__ || defined __C99__FUNC__ \
596 || defined __cplusplus || defined _MSC_VER)
609 #if ! defined yyoverflow || YYERROR_VERBOSE
611 /* The parser invokes alloca or malloc; define the necessary symbols. */
613 # ifdef YYSTACK_USE_ALLOCA
614 # if YYSTACK_USE_ALLOCA
616 # define YYSTACK_ALLOC __builtin_alloca
617 # elif defined __BUILTIN_VA_ARG_INCR
618 # include <alloca.h> /* INFRINGES ON USER NAME SPACE */
620 # define YYSTACK_ALLOC __alloca
621 # elif defined _MSC_VER
622 # include <malloc.h> /* INFRINGES ON USER NAME SPACE */
623 # define alloca _alloca
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 */
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 */
648 # define YYSTACK_ALLOC YYMALLOC
649 # define YYSTACK_FREE YYFREE
650 # ifndef YYSTACK_ALLOC_MAXIMUM
651 # define YYSTACK_ALLOC_MAXIMUM YYSIZE_MAXIMUM
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 */
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 */
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 */
676 #endif /* ! defined yyoverflow || YYERROR_VERBOSE */
679 #if (! defined yyoverflow \
680 && (! defined __cplusplus \
681 || (defined YYLTYPE_IS_TRIVIAL && YYLTYPE_IS_TRIVIAL \
682 && defined YYSTYPE_IS_TRIVIAL && YYSTYPE_IS_TRIVIAL)))
684 /* A type that is properly aligned for any stack member. */
692 /* The size of the maximum gap between one aligned stack and the next. */
693 # define YYSTACK_GAP_MAXIMUM (sizeof (union yyalloc) - 1)
695 /* The size of an array large to enough to hold all stacks, each with
697 # define YYSTACK_BYTES(N) \
698 ((N) * (sizeof (yytype_int16) + sizeof (YYSTYPE) + sizeof (YYLTYPE)) \
699 + 2 * YYSTACK_GAP_MAXIMUM)
701 /* Copy COUNT objects from FROM to TO. The source and destination do
704 # if defined __GNUC__ && 1 < __GNUC__
705 # define YYCOPY(To, From, Count) \
706 __builtin_memcpy (To, From, (Count) * sizeof (*(From)))
708 # define YYCOPY(To, From, Count) \
712 for (yyi = 0; yyi < (Count); yyi++) \
713 (To)[yyi] = (From)[yyi]; \
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
724 # define YYSTACK_RELOCATE(Stack) \
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); \
737 /* YYFINAL -- State number of the termination state. */
739 /* YYLAST -- Last index in YYTABLE. */
742 /* YYNTOKENS -- Number of terminals. */
744 /* YYNNTS -- Number of nonterminals. */
746 /* YYNRULES -- Number of rules. */
748 /* YYNRULES -- Number of states. */
751 /* YYTRANSLATE(YYLEX) -- Bison symbol number corresponding to YYLEX. */
753 #define YYMAXUTOK 280
755 #define YYTRANSLATE(YYX) \
756 ((unsigned int) (YYX) <= YYMAXUTOK ? yytranslate[YYX] : YYUNDEFTOK)
758 /* YYTRANSLATE[YYLEX] -- Bison symbol number corresponding to YYLEX. */
759 static const yytype_uint8 yytranslate[] =
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,
793 /* YYPRHS[YYN] -- Index of the first RHS symbol of rule number YYN in
795 static const yytype_uint8 yyprhs[] =
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
802 /* YYRHS -- A `-1'-separated list of the rules' RHS. */
803 static const yytype_int8 yyrhs[] =
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,
818 /* YYRLINE[YYN] -- source line where rule number YYN was defined. */
819 static const yytype_uint16 yyrline[] =
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
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[] =
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
841 /* YYTOKNUM[YYLEX-NUM] -- Internal token number corresponding to
843 static const yytype_uint16 yytoknum[] =
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
851 /* YYR1[YYN] -- Symbol number of symbol that rule YYN derives. */
852 static const yytype_uint8 yyr1[] =
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
859 /* YYR2[YYN] -- Number of symbols composing right hand side of rule YYN. */
860 static const yytype_uint8 yyr2[] =
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
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[] =
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,
880 /* YYDEFGOTO[NTERM-NUM]. */
881 static const yytype_int8 yydefgoto[] =
886 /* YYPACT[STATE-NUM] -- Index in YYTABLE of the portion describing
888 #define YYPACT_NINF -18
889 static const yytype_int16 yypact[] =
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,
899 /* YYPGOTO[NTERM-NUM]. */
900 static const yytype_int8 yypgoto[] =
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[] =
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
930 static const yytype_int8 yycheck[] =
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
950 /* YYSTOS[STATE-NUM] -- The (internal number of the) accessing
951 symbol of state STATE-NUM. */
952 static const yytype_uint8 yystos[] =
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,
962 #define yyerrok (yyerrstatus = 0)
963 #define yyclearin (yychar = YYEMPTY)
967 #define YYACCEPT goto yyacceptlab
968 #define YYABORT goto yyabortlab
969 #define YYERROR goto yyerrorlab
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. */
976 #define YYFAIL goto yyerrlab
978 #define YYRECOVERING() (!!yyerrstatus)
980 #define YYBACKUP(Token, Value) \
982 if (yychar == YYEMPTY && yylen == 1) \
986 yytoken = YYTRANSLATE (yychar); \
992 yyerror (YY_("syntax error: cannot back up")); \
999 #define YYERRCODE 256
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). */
1006 #define YYRHSLOC(Rhs, K) ((Rhs)[K])
1007 #ifndef YYLLOC_DEFAULT
1008 # define YYLLOC_DEFAULT(Current, Rhs, N) \
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; \
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; \
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. */
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)
1039 # define YY_LOCATION_PRINT(File, Loc) ((void) 0)
1044 /* YYLEX -- calling `yylex' with the right arguments. */
1047 # define YYLEX yylex (&yylval, &yylloc, YYLEX_PARAM)
1049 # define YYLEX yylex (&yylval, &yylloc)
1052 /* Enable debugging if requested. */
1056 # include <stdio.h> /* INFRINGES ON USER NAME SPACE */
1057 # define YYFPRINTF fprintf
1060 # define YYDPRINTF(Args) \
1066 # define YY_SYMBOL_PRINT(Title, Type, Value, Location) \
1070 YYFPRINTF (stderr, "%s ", Title); \
1071 yy_symbol_print (stderr, \
1072 Type, Value, Location); \
1073 YYFPRINTF (stderr, "\n"); \
1078 /*--------------------------------.
1079 | Print this symbol on YYOUTPUT. |
1080 `--------------------------------*/
1083 #if (defined __STDC__ || defined __C99__FUNC__ \
1084 || defined __cplusplus || defined _MSC_VER)
1086 yy_symbol_value_print (FILE *yyoutput, int yytype, YYSTYPE const * const yyvaluep, YYLTYPE const * const yylocationp)
1089 yy_symbol_value_print (yyoutput, yytype, yyvaluep, yylocationp)
1092 YYSTYPE const * const yyvaluep;
1093 YYLTYPE const * const yylocationp;
1098 YYUSE (yylocationp);
1100 if (yytype < YYNTOKENS)
1101 YYPRINT (yyoutput, yytoknum[yytype], *yyvaluep);
1113 /*--------------------------------.
1114 | Print this symbol on YYOUTPUT. |
1115 `--------------------------------*/
1117 #if (defined __STDC__ || defined __C99__FUNC__ \
1118 || defined __cplusplus || defined _MSC_VER)
1120 yy_symbol_print (FILE *yyoutput, int yytype, YYSTYPE const * const yyvaluep, YYLTYPE const * const yylocationp)
1123 yy_symbol_print (yyoutput, yytype, yyvaluep, yylocationp)
1126 YYSTYPE const * const yyvaluep;
1127 YYLTYPE const * const yylocationp;
1130 if (yytype < YYNTOKENS)
1131 YYFPRINTF (yyoutput, "token %s (", yytname[yytype]);
1133 YYFPRINTF (yyoutput, "nterm %s (", yytname[yytype]);
1135 YY_LOCATION_PRINT (yyoutput, *yylocationp);
1136 YYFPRINTF (yyoutput, ": ");
1137 yy_symbol_value_print (yyoutput, yytype, yyvaluep, yylocationp);
1138 YYFPRINTF (yyoutput, ")");
1141 /*------------------------------------------------------------------.
1142 | yy_stack_print -- Print the state stack from its BOTTOM up to its |
1144 `------------------------------------------------------------------*/
1146 #if (defined __STDC__ || defined __C99__FUNC__ \
1147 || defined __cplusplus || defined _MSC_VER)
1149 yy_stack_print (yytype_int16 *bottom, yytype_int16 *top)
1152 yy_stack_print (bottom, top)
1153 yytype_int16 *bottom;
1157 YYFPRINTF (stderr, "Stack now");
1158 for (; bottom <= top; ++bottom)
1159 YYFPRINTF (stderr, " %d", *bottom);
1160 YYFPRINTF (stderr, "\n");
1163 # define YY_STACK_PRINT(Bottom, Top) \
1166 yy_stack_print ((Bottom), (Top)); \
1170 /*------------------------------------------------.
1171 | Report that the YYRULE is going to be reduced. |
1172 `------------------------------------------------*/
1174 #if (defined __STDC__ || defined __C99__FUNC__ \
1175 || defined __cplusplus || defined _MSC_VER)
1177 yy_reduce_print (YYSTYPE *yyvsp, YYLTYPE *yylsp, int yyrule)
1180 yy_reduce_print (yyvsp, yylsp, yyrule)
1186 int yynrhs = yyr2[yyrule];
1188 unsigned long int yylno = yyrline[yyrule];
1189 YYFPRINTF (stderr, "Reducing stack by rule %d (line %lu):\n",
1191 /* The symbols being reduced. */
1192 for (yyi = 0; yyi < yynrhs; yyi++)
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");
1202 # define YY_REDUCE_PRINT(Rule) \
1205 yy_reduce_print (yyvsp, yylsp, Rule); \
1208 /* Nonzero means print parse trace. It is left uninitialized so that
1209 multiple parsers can coexist. */
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 */
1219 /* YYINITDEPTH -- initial size of the parser's stacks. */
1221 # define YYINITDEPTH 200
1224 /* YYMAXDEPTH -- maximum size the stacks can grow to (effective only
1225 if the built-in stack extension method is used).
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. */
1232 # define YYMAXDEPTH 10000
1240 # if defined __GLIBC__ && defined _STRING_H
1241 # define yystrlen strlen
1243 /* Return the length of YYSTR. */
1244 #if (defined __STDC__ || defined __C99__FUNC__ \
1245 || defined __cplusplus || defined _MSC_VER)
1247 yystrlen (const char *yystr)
1255 for (yylen = 0; yystr[yylen]; yylen++)
1263 # if defined __GLIBC__ && defined _STRING_H && defined _GNU_SOURCE
1264 # define yystpcpy stpcpy
1266 /* Copy YYSRC to YYDEST, returning the address of the terminating '\0' in
1268 #if (defined __STDC__ || defined __C99__FUNC__ \
1269 || defined __cplusplus || defined _MSC_VER)
1271 yystpcpy (char *yydest, const char *yysrc)
1274 yystpcpy (yydest, yysrc)
1280 const char *yys = yysrc;
1282 while ((*yyd++ = *yys++) != '\0')
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
1299 yytnamerr (char *yyres, const char *yystr)
1304 char const *yyp = yystr;
1311 goto do_not_strip_quotes;
1315 goto do_not_strip_quotes;
1328 do_not_strip_quotes: ;
1332 return yystrlen (yystr);
1334 return yystpcpy (yyres, yystr) - yyres;
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. */
1346 yysyntax_error (char *yyresult, int yystate, int yychar)
1348 int yyn = yypact[yystate];
1350 if (! (YYPACT_NINF < yyn && yyn <= YYLAST))
1354 int yytype = YYTRANSLATE (yychar);
1355 YYSIZE_T yysize0 = yytnamerr (0, yytname[yytype]);
1356 YYSIZE_T yysize = yysize0;
1358 int yysize_overflow = 0;
1359 enum { YYERROR_VERBOSE_ARGS_MAXIMUM = 5 };
1360 char const *yyarg[YYERROR_VERBOSE_ARGS_MAXIMUM];
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");
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;
1383 /* Start YYX at -YYN if negative to avoid negative indexes in
1385 int yyxbegin = yyn < 0 ? -yyn : 0;
1387 /* Stay within bounds of both yycheck and yytname. */
1388 int yychecklim = YYLAST - yyn + 1;
1389 int yyxend = yychecklim < YYNTOKENS ? yychecklim : YYNTOKENS;
1392 yyarg[0] = yytname[yytype];
1393 yyfmt = yystpcpy (yyformat, yyunexpected);
1395 for (yyx = yyxbegin; yyx < yyxend; ++yyx)
1396 if (yycheck[yyx + yyn] == yyx && yyx != YYTERROR)
1398 if (yycount == YYERROR_VERBOSE_ARGS_MAXIMUM)
1402 yyformat[sizeof yyunexpected - 1] = '\0';
1405 yyarg[yycount++] = yytname[yyx];
1406 yysize1 = yysize + yytnamerr (0, yytname[yyx]);
1407 yysize_overflow |= (yysize1 < yysize);
1409 yyfmt = yystpcpy (yyfmt, yyprefix);
1413 yyf = YY_(yyformat);
1414 yysize1 = yysize + yystrlen (yyf);
1415 yysize_overflow |= (yysize1 < yysize);
1418 if (yysize_overflow)
1419 return YYSIZE_MAXIMUM;
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;
1428 while ((*yyp = *yyf) != '\0')
1430 if (*yyp == '%' && yyf[1] == 's' && yyi < yycount)
1432 yyp += yytnamerr (yyp, yyarg[yyi++]);
1445 #endif /* YYERROR_VERBOSE */
1448 /*-----------------------------------------------.
1449 | Release the memory associated to this symbol. |
1450 `-----------------------------------------------*/
1453 #if (defined __STDC__ || defined __C99__FUNC__ \
1454 || defined __cplusplus || defined _MSC_VER)
1456 yydestruct (const char *yymsg, int yytype, YYSTYPE *yyvaluep, YYLTYPE *yylocationp)
1459 yydestruct (yymsg, yytype, yyvaluep, yylocationp)
1463 YYLTYPE *yylocationp;
1467 YYUSE (yylocationp);
1471 YY_SYMBOL_PRINT (yymsg, yytype, yyvaluep, yylocationp);
1475 case 4: /* "TOK_COLONCOLON" */
1476 #line 368 "ast_expr2.y"
1477 { free_value((yyvaluep->val)); };
1478 #line 1479 "ast_expr2.c"
1480 case 5: /* "TOK_COND" */
1481 #line 368 "ast_expr2.y"
1482 { free_value((yyvaluep->val)); };
1483 #line 1484 "ast_expr2.c"
1485 case 6: /* "TOK_OR" */
1486 #line 368 "ast_expr2.y"
1487 { free_value((yyvaluep->val)); };
1488 #line 1489 "ast_expr2.c"
1490 case 7: /* "TOK_AND" */
1491 #line 368 "ast_expr2.y"
1492 { free_value((yyvaluep->val)); };
1493 #line 1494 "ast_expr2.c"
1495 case 8: /* "TOK_NE" */
1496 #line 368 "ast_expr2.y"
1497 { free_value((yyvaluep->val)); };
1498 #line 1499 "ast_expr2.c"
1500 case 9: /* "TOK_LE" */
1501 #line 368 "ast_expr2.y"
1502 { free_value((yyvaluep->val)); };
1503 #line 1504 "ast_expr2.c"
1505 case 10: /* "TOK_GE" */
1506 #line 368 "ast_expr2.y"
1507 { free_value((yyvaluep->val)); };
1508 #line 1509 "ast_expr2.c"
1510 case 11: /* "TOK_LT" */
1511 #line 368 "ast_expr2.y"
1512 { free_value((yyvaluep->val)); };
1513 #line 1514 "ast_expr2.c"
1515 case 12: /* "TOK_GT" */
1516 #line 368 "ast_expr2.y"
1517 { free_value((yyvaluep->val)); };
1518 #line 1519 "ast_expr2.c"
1520 case 13: /* "TOK_EQ" */
1521 #line 368 "ast_expr2.y"
1522 { free_value((yyvaluep->val)); };
1523 #line 1524 "ast_expr2.c"
1525 case 14: /* "TOK_MINUS" */
1526 #line 368 "ast_expr2.y"
1527 { free_value((yyvaluep->val)); };
1528 #line 1529 "ast_expr2.c"
1530 case 15: /* "TOK_PLUS" */
1531 #line 368 "ast_expr2.y"
1532 { free_value((yyvaluep->val)); };
1533 #line 1534 "ast_expr2.c"
1535 case 16: /* "TOK_MOD" */
1536 #line 368 "ast_expr2.y"
1537 { free_value((yyvaluep->val)); };
1538 #line 1539 "ast_expr2.c"
1540 case 17: /* "TOK_DIV" */
1541 #line 368 "ast_expr2.y"
1542 { free_value((yyvaluep->val)); };
1543 #line 1544 "ast_expr2.c"
1545 case 18: /* "TOK_MULT" */
1546 #line 368 "ast_expr2.y"
1547 { free_value((yyvaluep->val)); };
1548 #line 1549 "ast_expr2.c"
1550 case 19: /* "TOK_COMPL" */
1551 #line 368 "ast_expr2.y"
1552 { free_value((yyvaluep->val)); };
1553 #line 1554 "ast_expr2.c"
1555 case 20: /* "TOK_TILDETILDE" */
1556 #line 368 "ast_expr2.y"
1557 { free_value((yyvaluep->val)); };
1558 #line 1559 "ast_expr2.c"
1560 case 21: /* "TOK_EQTILDE" */
1561 #line 368 "ast_expr2.y"
1562 { free_value((yyvaluep->val)); };
1563 #line 1564 "ast_expr2.c"
1565 case 22: /* "TOK_COLON" */
1566 #line 368 "ast_expr2.y"
1567 { free_value((yyvaluep->val)); };
1568 #line 1569 "ast_expr2.c"
1570 case 23: /* "TOK_LP" */
1571 #line 368 "ast_expr2.y"
1572 { free_value((yyvaluep->val)); };
1573 #line 1574 "ast_expr2.c"
1575 case 24: /* "TOK_RP" */
1576 #line 368 "ast_expr2.y"
1577 { free_value((yyvaluep->val)); };
1578 #line 1579 "ast_expr2.c"
1580 case 25: /* "TOKEN" */
1581 #line 368 "ast_expr2.y"
1582 { free_value((yyvaluep->val)); };
1583 #line 1584 "ast_expr2.c"
1585 case 29: /* "expr" */
1586 #line 368 "ast_expr2.y"
1587 { free_value((yyvaluep->val)); };
1588 #line 1589 "ast_expr2.c"
1597 /* Prevent warnings from -Wmissing-prototypes. */
1599 #ifdef YYPARSE_PARAM
1600 #if defined __STDC__ || defined __cplusplus
1601 int yyparse (void *YYPARSE_PARAM);
1605 #else /* ! YYPARSE_PARAM */
1606 #if defined __STDC__ || defined __cplusplus
1611 #endif /* ! YYPARSE_PARAM */
1622 #ifdef YYPARSE_PARAM
1623 #if (defined __STDC__ || defined __C99__FUNC__ \
1624 || defined __cplusplus || defined _MSC_VER)
1626 yyparse (void *YYPARSE_PARAM)
1629 yyparse (YYPARSE_PARAM)
1630 void *YYPARSE_PARAM;
1632 #else /* ! YYPARSE_PARAM */
1633 #if (defined __STDC__ || defined __C99__FUNC__ \
1634 || defined __cplusplus || defined _MSC_VER)
1644 /* The look-ahead symbol. */
1647 /* The semantic value of the look-ahead symbol. */
1650 /* Number of syntax errors so far. */
1652 /* Location data for the look-ahead symbol. */
1658 /* Number of tokens to shift before error messages enabled. */
1660 /* Look-ahead token as an internal (translated) token number. */
1663 /* Buffer for error messages, and its allocated size. */
1665 char *yymsg = yymsgbuf;
1666 YYSIZE_T yymsg_alloc = sizeof yymsgbuf;
1669 /* Three stacks and their tools:
1670 `yyss': related to states,
1671 `yyvs': related to semantic values,
1672 `yyls': related to locations.
1674 Refer to the stacks thru separate pointers, to allow yyoverflow
1675 to reallocate them elsewhere. */
1677 /* The state stack. */
1678 yytype_int16 yyssa[YYINITDEPTH];
1679 yytype_int16 *yyss = yyssa;
1680 yytype_int16 *yyssp;
1682 /* The semantic value stack. */
1683 YYSTYPE yyvsa[YYINITDEPTH];
1684 YYSTYPE *yyvs = yyvsa;
1687 /* The location stack. */
1688 YYLTYPE yylsa[YYINITDEPTH];
1689 YYLTYPE *yyls = yylsa;
1691 /* The locations where the error started and ended. */
1692 YYLTYPE yyerror_range[2];
1694 #define YYPOPSTACK(N) (yyvsp -= (N), yyssp -= (N), yylsp -= (N))
1696 YYSIZE_T yystacksize = YYINITDEPTH;
1698 /* The variables used to return semantic value and location from the
1703 /* The number of symbols on the RHS of the reduced rule.
1704 Keep to zero when no symbol should be popped. */
1707 YYDPRINTF ((stderr, "Starting parse\n"));
1712 yychar = YYEMPTY; /* Cause a token to be read. */
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. */
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;
1730 /*------------------------------------------------------------.
1731 | yynewstate -- Push a new state, which is found in yystate. |
1732 `------------------------------------------------------------*/
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. */
1741 if (yyss + yystacksize - 1 <= yyssp)
1743 /* Get the current used size of the three stacks, in elements. */
1744 YYSIZE_T yysize = yyssp - yyss + 1;
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
1751 YYSTYPE *yyvs1 = yyvs;
1752 yytype_int16 *yyss1 = yyss;
1753 YYLTYPE *yyls1 = yyls;
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),
1768 #else /* no yyoverflow */
1769 # ifndef YYSTACK_RELOCATE
1770 goto yyexhaustedlab;
1772 /* Extend the stack our own way. */
1773 if (YYMAXDEPTH <= yystacksize)
1774 goto yyexhaustedlab;
1776 if (YYMAXDEPTH < yystacksize)
1777 yystacksize = YYMAXDEPTH;
1780 yytype_int16 *yyss1 = yyss;
1781 union yyalloc *yyptr =
1782 (union yyalloc *) YYSTACK_ALLOC (YYSTACK_BYTES (yystacksize));
1784 goto yyexhaustedlab;
1785 YYSTACK_RELOCATE (yyss);
1786 YYSTACK_RELOCATE (yyvs);
1787 YYSTACK_RELOCATE (yyls);
1788 # undef YYSTACK_RELOCATE
1790 YYSTACK_FREE (yyss1);
1793 #endif /* no yyoverflow */
1795 yyssp = yyss + yysize - 1;
1796 yyvsp = yyvs + yysize - 1;
1797 yylsp = yyls + yysize - 1;
1799 YYDPRINTF ((stderr, "Stack size increased to %lu\n",
1800 (unsigned long int) yystacksize));
1802 if (yyss + yystacksize - 1 <= yyssp)
1806 YYDPRINTF ((stderr, "Entering state %d\n", yystate));
1815 /* Do appropriate processing given the current state. Read a
1816 look-ahead token if we need one and don't already have one. */
1818 /* First try to decide what to do without reference to look-ahead token. */
1819 yyn = yypact[yystate];
1820 if (yyn == YYPACT_NINF)
1823 /* Not known => get a look-ahead token if don't already have one. */
1825 /* YYCHAR is either YYEMPTY or YYEOF or a valid look-ahead symbol. */
1826 if (yychar == YYEMPTY)
1828 YYDPRINTF ((stderr, "Reading a token: "));
1832 if (yychar <= YYEOF)
1834 yychar = yytoken = YYEOF;
1835 YYDPRINTF ((stderr, "Now at end of input.\n"));
1839 yytoken = YYTRANSLATE (yychar);
1840 YY_SYMBOL_PRINT ("Next token is", yytoken, &yylval, &yylloc);
1843 /* If the proper action on seeing token YYTOKEN is to reduce or to
1844 detect an error, take that action. */
1846 if (yyn < 0 || YYLAST < yyn || yycheck[yyn] != yytoken)
1851 if (yyn == 0 || yyn == YYTABLE_NINF)
1860 /* Count tokens shifted since error; after three, turn off error
1865 /* Shift the look-ahead token. */
1866 YY_SYMBOL_PRINT ("Shifting", yytoken, &yylval, &yylloc);
1868 /* Discard the shifted token unless it is eof. */
1869 if (yychar != YYEOF)
1878 /*-----------------------------------------------------------.
1879 | yydefault -- do the default action for the current state. |
1880 `-----------------------------------------------------------*/
1882 yyn = yydefact[yystate];
1888 /*-----------------------------.
1889 | yyreduce -- Do a reduction. |
1890 `-----------------------------*/
1892 /* yyn is the number of a rule to reduce with. */
1895 /* If YYLEN is nonzero, implement the default value of the action:
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];
1905 /* Default location. */
1906 YYLLOC_DEFAULT (yyloc, (yylsp - yylen), yylen);
1907 YY_REDUCE_PRINT (yyn);
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;
1917 ((struct parse_io *)parseio)->val->u.s = (yyvsp[(1) - (1)].val)->u.s;
1918 free((yyvsp[(1) - (1)].val));
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("");
1931 #line 389 "ast_expr2.y"
1932 { (yyval.arglist) = alloc_expr_node(AST_EXPR_NODE_VAL); (yyval.arglist)->val = (yyvsp[(1) - (1)].val);;}
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)
1942 (yyval.arglist) = (yyvsp[(1) - (3)].arglist); t->right = x; x->val = (yyvsp[(3) - (3)].val);;}
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)
1952 (yyval.arglist) = (yyvsp[(1) - (2)].arglist); t->right = x; x->val = make_str("");;}
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));
1966 #line 411 "ast_expr2.y"
1967 {(yyval.val) = (yyvsp[(1) - (1)].val);;}
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)); ;}
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;;}
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;;}
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;;}
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;;}
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;;}
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;;}
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;;}
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;;}
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;;}
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;;}
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;;}
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;;}
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;;}
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;;}
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;;}
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;;}
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;;}
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;;}
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;;}
2132 /* Line 1267 of yacc.c. */
2133 #line 2134 "ast_expr2.c"
2136 YY_SYMBOL_PRINT ("-> $$ =", yyr1[yyn], &yyval, &yyloc);
2140 YY_STACK_PRINT (yyss, yyssp);
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. */
2151 yystate = yypgoto[yyn - YYNTOKENS] + *yyssp;
2152 if (0 <= yystate && yystate <= YYLAST && yycheck[yystate] == *yyssp)
2153 yystate = yytable[yystate];
2155 yystate = yydefgoto[yyn - YYNTOKENS];
2160 /*------------------------------------.
2161 | yyerrlab -- here on detecting error |
2162 `------------------------------------*/
2164 /* If not already recovering from an error, report this error. */
2168 #if ! YYERROR_VERBOSE
2169 yyerror (YY_("syntax error"));
2172 YYSIZE_T yysize = yysyntax_error (0, yystate, yychar);
2173 if (yymsg_alloc < yysize && yymsg_alloc < YYSTACK_ALLOC_MAXIMUM)
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);
2182 yymsg_alloc = yyalloc;
2186 yymsg_alloc = sizeof yymsgbuf;
2190 if (0 < yysize && yysize <= yymsg_alloc)
2192 (void) yysyntax_error (yymsg, yystate, yychar);
2197 yyerror (YY_("syntax error"));
2199 goto yyexhaustedlab;
2205 yyerror_range[0] = yylloc;
2207 if (yyerrstatus == 3)
2209 /* If just tried and failed to reuse look-ahead token after an
2210 error, discard it. */
2212 if (yychar <= YYEOF)
2214 /* Return failure if at end of input. */
2215 if (yychar == YYEOF)
2220 yydestruct ("Error: discarding",
2221 yytoken, &yylval, &yylloc);
2226 /* Else will try to reuse look-ahead token after shifting the error
2231 /*---------------------------------------------------.
2232 | yyerrorlab -- error raised explicitly by YYERROR. |
2233 `---------------------------------------------------*/
2236 /* Pacify compilers like GCC when the user code never invokes
2237 YYERROR and the label yyerrorlab therefore never appears in user
2239 if (/*CONSTCOND*/ 0)
2242 yyerror_range[0] = yylsp[1-yylen];
2243 /* Do not reclaim the symbols of the rule which action triggered
2247 YY_STACK_PRINT (yyss, yyssp);
2252 /*-------------------------------------------------------------.
2253 | yyerrlab1 -- common code for both syntax error and YYERROR. |
2254 `-------------------------------------------------------------*/
2256 yyerrstatus = 3; /* Each real token shifted decrements this. */
2260 yyn = yypact[yystate];
2261 if (yyn != YYPACT_NINF)
2264 if (0 <= yyn && yyn <= YYLAST && yycheck[yyn] == YYTERROR)
2272 /* Pop the current state because it cannot handle the error token. */
2276 yyerror_range[0] = *yylsp;
2277 yydestruct ("Error: popping",
2278 yystos[yystate], yyvsp, yylsp);
2281 YY_STACK_PRINT (yyss, yyssp);
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);
2295 /* Shift the error token. */
2296 YY_SYMBOL_PRINT ("Shifting", yystos[yyn], yyvsp, yylsp);
2302 /*-------------------------------------.
2303 | yyacceptlab -- YYACCEPT comes here. |
2304 `-------------------------------------*/
2309 /*-----------------------------------.
2310 | yyabortlab -- YYABORT comes here. |
2311 `-----------------------------------*/
2317 /*-------------------------------------------------.
2318 | yyexhaustedlab -- memory exhaustion comes here. |
2319 `-------------------------------------------------*/
2321 yyerror (YY_("memory exhausted"));
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. */
2333 YY_STACK_PRINT (yyss, yyssp);
2334 while (yyssp != yyss)
2336 yydestruct ("Cleanup: popping",
2337 yystos[*yyssp], yyvsp, yylsp);
2342 YYSTACK_FREE (yyss);
2345 if (yymsg != yymsgbuf)
2346 YYSTACK_FREE (yymsg);
2348 /* Make sure YYID is used. */
2349 return YYID (yyresult);
2353 #line 495 "ast_expr2.y"
2356 static struct expr_node *alloc_expr_node(enum node_type nt)
2358 struct expr_node *x = calloc(1,sizeof(struct expr_node));
2360 ast_log(LOG_ERROR, "Allocation for expr_node FAILED!!\n");
2370 make_number (FP___TYPE i)
2374 vp = (struct val *) malloc (sizeof (*vp));
2376 ast_log(LOG_WARNING, "malloc() failed\n");
2380 vp->type = AST_EXPR_number;
2386 make_str (const char *s)
2390 int isint; /* this started out being a test for an integer, but then ended up being a test for a float */
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");
2398 for (i = 0, isint = (isdigit(s[0]) || s[0] == '-' || s[0]=='.'); isint && i < strlen(s); i++)
2400 if (!isdigit(s[i]) && s[i] != '.') {
2406 vp->type = AST_EXPR_numeric_string;
2408 vp->type = AST_EXPR_string;
2415 free_value (struct val *vp)
2420 if (vp->type == AST_EXPR_string || vp->type == AST_EXPR_numeric_string)
2427 to_number (struct val *vp)
2432 ast_log(LOG_WARNING,"vp==NULL in to_number()\n");
2436 if (vp->type == AST_EXPR_number)
2439 if (vp->type == AST_EXPR_string)
2442 /* vp->type == AST_EXPR_numeric_string, make it numeric */
2444 i = FUNC_STRTOD(vp->u.s, (char**)0); /* either strtod, or strtold on a good day */
2446 ast_log(LOG_WARNING,"Conversion of %s to number under/overflowed!\n", vp->u.s);
2453 vp->type = AST_EXPR_number;
2458 strip_quotes(struct val *vp)
2460 if (vp->type != AST_EXPR_string && vp->type != AST_EXPR_numeric_string)
2463 if( vp->u.s[0] == '"' && vp->u.s[strlen(vp->u.s)-1] == '"' )
2471 if( *f && *f != '"' )
2481 to_string (struct val *vp)
2485 if (vp->type == AST_EXPR_string || vp->type == AST_EXPR_numeric_string)
2488 tmp = malloc ((size_t)25);
2490 ast_log(LOG_WARNING,"malloc() failed\n");
2494 sprintf(tmp, FP___PRINTF, vp->u.i);
2495 vp->type = AST_EXPR_string;
2501 isstring (struct val *vp)
2503 /* only TRUE if this string is not a valid number */
2504 return (vp->type == AST_EXPR_string);
2509 is_zero_or_null (struct val *vp)
2511 if (vp->type == AST_EXPR_number) {
2512 return (vp->u.i == 0);
2514 return (*vp->u.s == 0 || (to_number(vp) && vp->u.i == 0));
2521 void ast_log(int level, const char *file, int line, const char *function, const char *fmt, ...)
2526 printf("LOG: lev:%d file:%s line:%d func: %s ",
2527 level, file, line, function);
2534 int main(int argc,char **argv) {
2542 if( access(argv[1],F_OK)== 0 )
2546 infile = fopen(argv[1],"r");
2549 printf("Sorry, couldn't open %s for reading!\n", argv[1]);
2552 while( fgets(s,sizeof(s),infile) )
2554 if( s[strlen(s)-1] == '\n' )
2557 ret = ast_expr(s, out, sizeof(out), NULL);
2558 printf("Expression: %s Result: [%d] '%s'\n",
2565 if (ast_expr(argv[1], s, sizeof(s), NULL))
2566 printf("=====%s======\n",s);
2568 printf("No result\n");
2576 #define ast_yyerror(x) ast_yyerror(x, YYLTYPE *yylloc, struct parse_io *parseio)
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! */
2583 static void destroy_arglist(struct expr_node *arglist)
2585 struct expr_node *arglist_next;
2589 arglist_next = arglist->right;
2591 free_value(arglist->val);
2595 arglist = arglist_next;
2599 #if !defined(STANDALONE) && !defined(STANDALONE2)
2600 static char *compose_func_args(struct expr_node *arglist)
2602 struct expr_node *t = arglist;
2608 total_len += 1; /* for the sep */
2610 if (t->val->type == AST_EXPR_number)
2611 total_len += 25; /* worst case */
2613 total_len += strlen(t->val->u.s);
2618 total_len++; /* for the null */
2619 ast_log(LOG_NOTICE,"argbuf allocated %d bytes;\n", total_len);
2620 argbuf = malloc(total_len);
2630 if (t->val->type == AST_EXPR_number) {
2631 sprintf(numbuf,FP___PRINTF,t->val->u.i);
2632 strcat(argbuf,numbuf);
2634 strcat(argbuf,t->val->u.s);
2638 ast_log(LOG_NOTICE,"argbuf uses %d bytes;\n", (int) strlen(argbuf));
2642 static int is_really_num(char *str)
2644 if ( strspn(str,"-0123456789. ") == strlen(str))
2651 static struct val *op_func(struct val *funcname, struct expr_node *arglist, struct ast_channel *chan)
2653 if (strspn(funcname->u.s,"ABCDEFGHIJKLMNOPQRSTUVWXYZ_0123456789") == strlen(funcname->u.s))
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));
2664 ast_log(LOG_WARNING,"Wrong args to %s() function\n",funcname->u.s);
2665 return make_number(0.0);
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));
2675 ast_log(LOG_WARNING,"Wrong args to %s() function\n",funcname->u.s);
2676 return make_number(0.0);
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));
2686 ast_log(LOG_WARNING,"Wrong args to %s() function\n",funcname->u.s);
2687 return make_number(0.0);
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));
2697 ast_log(LOG_WARNING,"Wrong args to %s() function\n",funcname->u.s);
2698 return make_number(0.0);
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));
2708 ast_log(LOG_WARNING,"Wrong args to %s() function\n",funcname->u.s);
2709 return make_number(0.0);
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));
2719 ast_log(LOG_WARNING,"Wrong args to %s() function\n",funcname->u.s);
2720 return make_number(0.0);
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));
2731 ast_log(LOG_WARNING,"Wrong args to %s() function\n",funcname->u.s);
2732 return make_number(0.0);
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));
2743 ast_log(LOG_WARNING,"Wrong args to %s() function\n",funcname->u.s);
2744 return make_number(0.0);
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));
2754 ast_log(LOG_WARNING,"Wrong args to %s() function\n",funcname->u.s);
2755 return make_number(0.0);
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));
2765 ast_log(LOG_WARNING,"Wrong args to %s() function\n",funcname->u.s);
2766 return make_number(0.0);
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));
2776 ast_log(LOG_WARNING,"Wrong args to %s() function\n",funcname->u.s);
2777 return make_number(0.0);
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));
2787 ast_log(LOG_WARNING,"Wrong args to %s() function\n",funcname->u.s);
2788 return make_number(0.0);
2790 #endif /* defined(FUNC_ROUND) */
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));
2798 ast_log(LOG_WARNING,"Wrong args to %s() function\n",funcname->u.s);
2799 return make_number(0.0);
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));
2809 ast_log(LOG_WARNING,"Wrong args to %s() function\n",funcname->u.s);
2810 return make_number(0.0);
2812 #endif /* defined(FUNC_TRUNC) */
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));
2820 ast_log(LOG_WARNING,"Wrong args to %s() function\n",funcname->u.s);
2821 return make_number(0.0);
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));
2831 ast_log(LOG_WARNING,"Wrong args to %s() function\n",funcname->u.s);
2832 return make_number(0.0);
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));
2842 ast_log(LOG_WARNING,"Wrong args to %s() function\n",funcname->u.s);
2843 return make_number(0.0);
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));
2853 ast_log(LOG_WARNING,"Wrong args to %s() function\n",funcname->u.s);
2854 return make_number(0.0);
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));
2864 ast_log(LOG_WARNING,"Wrong args to %s() function\n",funcname->u.s);
2865 return make_number(0.0);
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));
2875 ast_log(LOG_WARNING,"Wrong args to %s() function\n",funcname->u.s);
2876 return make_number(0.0);
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));
2887 ast_log(LOG_WARNING,"Wrong args to %s() function\n",funcname->u.s);
2888 return make_number(0.0);
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);
2896 ast_log(LOG_WARNING,"Hey! chan is NULL.\n");
2898 ast_log(LOG_WARNING,"Hey! could not find func %s.\n", funcname->u.s);
2902 char workspace[512];
2903 char *argbuf = compose_func_args(arglist);
2904 f->read(chan, funcname->u.s, argbuf, workspace, sizeof(workspace));
2906 if (is_really_num(workspace))
2907 return make_number(FUNC_STRTOD(workspace,(char **)NULL));
2909 return make_str(workspace);
2911 ast_log(LOG_ERROR,"Error! Function '%s' cannot be read!\n", funcname->u.s);
2912 return (make_number ((FP___TYPE)0.0));
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));
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));
2927 ast_log(LOG_ERROR,"Error! '%s' is not possibly a function name!", funcname->u.s);
2928 return (make_number ((FP___TYPE)0.0));
2930 return (make_number ((FP___TYPE)0.0));
2935 op_or (struct val *a, struct val *b)
2937 if (is_zero_or_null (a)) {
2947 op_and (struct val *a, struct val *b)
2949 if (is_zero_or_null (a) || is_zero_or_null (b)) {
2952 return (make_number ((FP___TYPE)0.0));
2960 op_eq (struct val *a, struct val *b)
2964 if (isstring (a) || isstring (b)) {
2967 r = make_number ((FP___TYPE)(strcoll (a->u.s, b->u.s) == 0));
2969 #ifdef DEBUG_FOR_CONVERSIONS
2971 sprintf(buffer,"Converting '%s' and '%s' ", a->u.s, b->u.s);
2975 #ifdef DEBUG_FOR_CONVERSIONS
2976 ast_log(LOG_WARNING,"%s to '%lld' and '%lld'\n", buffer, a->u.i, b->u.i);
2978 r = make_number ((FP___TYPE)(a->u.i == b->u.i));
2987 op_gt (struct val *a, struct val *b)
2991 if (isstring (a) || isstring (b)) {
2994 r = make_number ((FP___TYPE)(strcoll (a->u.s, b->u.s) > 0));
2998 r = make_number ((FP___TYPE)(a->u.i > b->u.i));
3007 op_lt (struct val *a, struct val *b)
3011 if (isstring (a) || isstring (b)) {
3014 r = make_number ((FP___TYPE)(strcoll (a->u.s, b->u.s) < 0));
3018 r = make_number ((FP___TYPE)(a->u.i < b->u.i));
3027 op_ge (struct val *a, struct val *b)
3031 if (isstring (a) || isstring (b)) {
3034 r = make_number ((FP___TYPE)(strcoll (a->u.s, b->u.s) >= 0));
3038 r = make_number ((FP___TYPE)(a->u.i >= b->u.i));
3047 op_le (struct val *a, struct val *b)
3051 if (isstring (a) || isstring (b)) {
3054 r = make_number ((FP___TYPE)(strcoll (a->u.s, b->u.s) <= 0));
3058 r = make_number ((FP___TYPE)(a->u.i <= b->u.i));
3067 op_cond (struct val *a, struct val *b, struct val *c)
3073 if( strlen(a->u.s) && strcmp(a->u.s, "\"\"") != 0 && strcmp(a->u.s,"0") != 0 )
3106 op_ne (struct val *a, struct val *b)
3110 if (isstring (a) || isstring (b)) {
3113 r = make_number ((FP___TYPE)(strcoll (a->u.s, b->u.s) != 0));
3117 r = make_number ((FP___TYPE)(a->u.i != b->u.i));
3126 chk_plus (FP___TYPE a, FP___TYPE b, FP___TYPE r)
3128 /* sum of two positive numbers must be positive */
3129 if (a > 0 && b > 0 && r <= 0)
3131 /* sum of two negative numbers must be negative */
3132 if (a < 0 && b < 0 && r >= 0)
3134 /* all other cases are OK */
3139 op_plus (struct val *a, struct val *b)
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)) {
3149 return make_number(0);
3154 } else if (!to_number(b)) {
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");
3169 chk_minus (FP___TYPE a, FP___TYPE b, FP___TYPE r)
3171 /* special case subtraction of QUAD_MIN */
3172 if (b == QUAD_MIN) {
3178 /* this is allowed for b != QUAD_MIN */
3179 return chk_plus (a, -b, r);
3183 op_minus (struct val *a, struct val *b)
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)) {
3193 return make_number(0);
3195 r = make_number(0 - b->u.i);
3200 } else if (!to_number(b)) {
3201 if( !extra_error_message_supplied )
3202 ast_log(LOG_WARNING, "non-numeric argument\n");
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");
3217 op_negate (struct val *a)
3221 if (!to_number (a) ) {
3223 if( !extra_error_message_supplied )
3224 ast_log(LOG_WARNING, "non-numeric argument\n");
3225 return make_number(0);
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");
3237 op_compl (struct val *a)
3250 case AST_EXPR_number:
3255 case AST_EXPR_string:
3260 if( a->u.s[0] == 0 )
3262 else if (strlen(a->u.s) == 1 && a->u.s[0] == '0' )
3267 case AST_EXPR_numeric_string:
3272 if( a->u.s[0] == 0 )
3274 else if (strlen(a->u.s) == 1 && a->u.s[0] == '0' )
3281 r = make_number (!v1);
3287 chk_times (FP___TYPE a, FP___TYPE b, FP___TYPE r)
3289 /* special case: first operand is 0, no overflow possible */
3292 /* cerify that result of division matches second operand */
3299 op_times (struct val *a, struct val *b)
3303 if (!to_number (a) || !to_number (b)) {
3306 if( !extra_error_message_supplied )
3307 ast_log(LOG_WARNING, "non-numeric argument\n");
3308 return(make_number(0));
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");
3321 chk_div (FP___TYPE a, FP___TYPE b)
3323 /* div by zero has been taken care of before */
3324 /* only QUAD_MIN / -1 causes overflow */
3325 if (a == QUAD_MIN && b == -1)
3327 /* everything else is OK */
3332 op_div (struct val *a, struct val *b)
3336 if (!to_number (a)) {
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)) {
3345 if( !extra_error_message_supplied )
3346 ast_log(LOG_WARNING, "non-numeric argument\n");
3347 return make_number(INT_MAX);
3351 ast_log(LOG_WARNING, "division by zero\n");
3354 return make_number(INT_MAX);