1 /* A Bison parser, made by GNU Bison 2.1a. */
3 /* Skeleton parser for Yacc-like parsing with Bison,
4 Copyright (C) 1984, 1989, 1990, 2000, 2001, 2002, 2003, 2004, 2005, 2006 Free Software Foundation, Inc.
6 This program is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2, or (at your option)
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with this program; if not, write to the Free Software
18 Foundation, Inc., 51 Franklin Street, Fifth Floor,
19 Boston, MA 02110-1301, USA. */
21 /* As a special exception, when this file is copied by Bison into a
22 Bison output file, you may use that output file without restriction.
23 This special exception was added by the Free Software Foundation
24 in version 1.24 of Bison. */
26 /* C LALR(1) parser skeleton written by Richard Stallman, by
27 simplifying the original so-called "semantic" parser. */
29 /* All symbols defined below should begin with yy or YY, to avoid
30 infringing on user name space. This should be done even for local
31 variables, as they might otherwise be expanded by user macros.
32 There are some unavoidable exceptions within include files to
33 define necessary library symbols; they are noted "INFRINGES ON
34 USER NAME SPACE" below. */
36 /* Identify Bison output. */
40 #define YYBISON_VERSION "2.1a"
43 #define YYSKELETON_NAME "yacc.c"
48 /* Using locations. */
49 #define YYLSP_NEEDED 1
51 /* Substitute the variable and function names. */
52 #define yyparse ast_yyparse
53 #define yylex ast_yylex
54 #define yyerror ast_yyerror
55 #define yylval ast_yylval
56 #define yychar ast_yychar
57 #define yydebug ast_yydebug
58 #define yynerrs ast_yynerrs
59 #define yylloc ast_yylloc
64 /* Put the tokens into the symbol table, so that GDB and other debuggers
91 #define TOK_COLONCOLON 258
101 #define TOK_MINUS 268
106 #define TOK_COMPL 273
107 #define TOK_EQTILDE 274
108 #define TOK_COLON 275
116 /* Copy the first part of user declarations. */
117 #line 1 "ast_expr2.y"
119 /* Written by Pace Willisson (pace@blitz.com)
120 * and placed in the public domain.
122 * Largely rewritten by J.T. Conklin (jtc@wimsey.com)
124 * And then overhauled twice by Steve Murphy (murf@digium.com)
125 * to add double-quoted strings, allow mult. spaces, improve
126 * error messages, and then to fold in a flex scanner for the
129 * $FreeBSD: src/bin/expr/expr.y,v 1.16 2000/07/22 10:59:36 se Exp $
132 #include <sys/types.h>
135 #ifdef STANDALONE /* I guess somewhere, the feature is set in the asterisk includes */
137 #define __USE_ISOC99 1
142 #define FP___PRINTF "%.16Lg"
143 #define FP___FMOD fmodl
144 #define FP___STRTOD strtold
145 #define FP___TYPE long double
147 #define FP___PRINTF "%.8g"
148 #define FP___FMOD fmod
149 #define FP___STRTOD strtod
150 #define FP___TYPE double
162 #if !defined(SOLARIS) && !defined(__CYGWIN__)
163 /* #include <err.h> */
165 #define quad_t int64_t
171 #include "asterisk.h"
172 #include "asterisk/ast_expr.h"
173 #include "asterisk/logger.h"
175 #if defined(LONG_LONG_MIN) && !defined(QUAD_MIN)
176 #define QUAD_MIN LONG_LONG_MIN
178 #if defined(LONG_LONG_MAX) && !defined(QUAD_MAX)
179 #define QUAD_MAX LONG_LONG_MAX
182 # if ! defined(QUAD_MIN)
183 # define QUAD_MIN (-0x7fffffffffffffffLL-1)
185 # if ! defined(QUAD_MAX)
186 # define QUAD_MAX (0x7fffffffffffffffLL)
188 #define YYENABLE_NLS 0
189 #define YYPARSE_PARAM parseio
190 #define YYLEX_PARAM ((struct parse_io *)parseio)->scanner
191 #define YYERROR_VERBOSE 1
192 extern char extra_error_message[4095];
193 extern int extra_error_message_supplied;
196 AST_EXPR_number, AST_EXPR_numeric_string, AST_EXPR_string
200 void ast_log(int level, const char *file, int line, const char *function, const char *fmt, ...) __attribute__ ((format (printf,5,6)));
207 FP___TYPE i; /* either long double, or just double, on a bad day */
211 typedef void *yyscan_t;
220 static int chk_div __P((FP___TYPE, FP___TYPE));
221 static int chk_minus __P((FP___TYPE, FP___TYPE, FP___TYPE));
222 static int chk_plus __P((FP___TYPE, FP___TYPE, FP___TYPE));
223 static int chk_times __P((FP___TYPE, FP___TYPE, FP___TYPE));
224 static void free_value __P((struct val *));
225 static int is_zero_or_null __P((struct val *));
226 static int isstring __P((struct val *));
227 static struct val *make_number __P((FP___TYPE));
228 static struct val *make_str __P((const char *));
229 static struct val *op_and __P((struct val *, struct val *));
230 static struct val *op_colon __P((struct val *, struct val *));
231 static struct val *op_eqtilde __P((struct val *, struct val *));
232 static struct val *op_div __P((struct val *, struct val *));
233 static struct val *op_eq __P((struct val *, struct val *));
234 static struct val *op_ge __P((struct val *, struct val *));
235 static struct val *op_gt __P((struct val *, struct val *));
236 static struct val *op_le __P((struct val *, struct val *));
237 static struct val *op_lt __P((struct val *, struct val *));
238 static struct val *op_cond __P((struct val *, struct val *, struct val *));
239 static struct val *op_minus __P((struct val *, struct val *));
240 static struct val *op_negate __P((struct val *));
241 static struct val *op_compl __P((struct val *));
242 static struct val *op_ne __P((struct val *, struct val *));
243 static struct val *op_or __P((struct val *, struct val *));
244 static struct val *op_plus __P((struct val *, struct val *));
245 static struct val *op_rem __P((struct val *, struct val *));
246 static struct val *op_times __P((struct val *, struct val *));
247 static int to_number __P((struct val *));
248 static void to_string __P((struct val *));
250 /* uh, if I want to predeclare yylex with a YYLTYPE, I have to predeclare the yyltype... sigh */
251 typedef struct yyltype
260 # define YYLTYPE yyltype
261 # define YYLTYPE_IS_TRIVIAL 1
263 /* we will get warning about no prototype for yylex! But we can't
264 define it here, we have no definition yet for YYSTYPE. */
266 int ast_yyerror(const char *,YYLTYPE *, struct parse_io *);
268 /* I wanted to add args to the yyerror routine, so I could print out
269 some useful info about the error. Not as easy as it looks, but it
271 #define ast_yyerror(x) ast_yyerror(x,&yyloc,parseio)
272 #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);}
275 /* Enabling traces. */
280 /* Enabling verbose error messages. */
281 #ifdef YYERROR_VERBOSE
282 # undef YYERROR_VERBOSE
283 # define YYERROR_VERBOSE 1
285 # define YYERROR_VERBOSE 0
288 /* Enabling the token table. */
289 #ifndef YYTOKEN_TABLE
290 # define YYTOKEN_TABLE 0
293 #if ! defined YYSTYPE && ! defined YYSTYPE_IS_DECLARED
294 typedef union YYSTYPE
295 #line 165 "ast_expr2.y"
299 /* Line 198 of yacc.c. */
300 #line 301 "ast_expr2.c"
302 # define yystype YYSTYPE /* obsolescent; will be withdrawn */
303 # define YYSTYPE_IS_DECLARED 1
304 # define YYSTYPE_IS_TRIVIAL 1
307 #if ! defined YYLTYPE && ! defined YYLTYPE_IS_DECLARED
308 typedef struct YYLTYPE
315 # define yyltype YYLTYPE /* obsolescent; will be withdrawn */
316 # define YYLTYPE_IS_DECLARED 1
317 # define YYLTYPE_IS_TRIVIAL 1
321 /* Copy the second part of user declarations. */
322 #line 169 "ast_expr2.y"
324 extern int ast_yylex __P((YYSTYPE *, YYLTYPE *, yyscan_t));
327 /* Line 221 of yacc.c. */
328 #line 329 "ast_expr2.c"
335 typedef YYTYPE_UINT8 yytype_uint8;
337 typedef unsigned char yytype_uint8;
341 typedef YYTYPE_INT8 yytype_int8;
342 #elif (defined __STDC__ || defined __C99__FUNC__ \
343 || defined __cplusplus || defined _MSC_VER)
344 typedef signed char yytype_int8;
346 typedef short int yytype_int8;
350 typedef YYTYPE_UINT16 yytype_uint16;
352 typedef unsigned short int yytype_uint16;
356 typedef YYTYPE_INT16 yytype_int16;
358 typedef short int yytype_int16;
362 # ifdef __SIZE_TYPE__
363 # define YYSIZE_T __SIZE_TYPE__
364 # elif defined size_t
365 # define YYSIZE_T size_t
366 # elif ! defined YYSIZE_T && (defined __STDC__ || defined __C99__FUNC__ \
367 || defined __cplusplus || defined _MSC_VER)
368 # include <stddef.h> /* INFRINGES ON USER NAME SPACE */
369 # define YYSIZE_T size_t
371 # define YYSIZE_T unsigned int
375 #define YYSIZE_MAXIMUM ((YYSIZE_T) -1)
380 # include <libintl.h> /* INFRINGES ON USER NAME SPACE */
381 # define YY_(msgid) dgettext ("bison-runtime", msgid)
385 # define YY_(msgid) msgid
389 /* Suppress unused-variable warnings by "using" E. */
390 #if ! defined lint || defined __GNUC__
391 # define YYUSE(e) ((void) (e))
393 # define YYUSE(e) /* empty */
396 /* Identity function, used to suppress warnings about constant conditions. */
400 #if (defined __STDC__ || defined __C99__FUNC__ \
401 || defined __cplusplus || defined _MSC_VER)
414 #if ! defined yyoverflow || YYERROR_VERBOSE
416 /* The parser invokes alloca or malloc; define the necessary symbols. */
418 # ifdef YYSTACK_USE_ALLOCA
419 # if YYSTACK_USE_ALLOCA
421 # define YYSTACK_ALLOC __builtin_alloca
422 # elif defined __BUILTIN_VA_ARG_INCR
423 # include <alloca.h> /* INFRINGES ON USER NAME SPACE */
425 # define YYSTACK_ALLOC __alloca
426 # elif defined _MSC_VER
427 # include <malloc.h> /* INFRINGES ON USER NAME SPACE */
428 # define alloca _alloca
430 # define YYSTACK_ALLOC alloca
431 # if ! defined _ALLOCA_H && ! defined _STDLIB_H && (defined __STDC__ || defined __C99__FUNC__ \
432 || defined __cplusplus || defined _MSC_VER)
433 # include <stdlib.h> /* INFRINGES ON USER NAME SPACE */
442 # ifdef YYSTACK_ALLOC
443 /* Pacify GCC's `empty if-body' warning. */
444 # define YYSTACK_FREE(Ptr) do { /* empty */; } while (YYID (0))
445 # ifndef YYSTACK_ALLOC_MAXIMUM
446 /* The OS might guarantee only one guard page at the bottom of the stack,
447 and a page size can be as small as 4096 bytes. So we cannot safely
448 invoke alloca (N) if N exceeds 4096. Use a slightly smaller number
449 to allow for a few compiler-allocated temporary stack slots. */
450 # define YYSTACK_ALLOC_MAXIMUM 4032 /* reasonable circa 2006 */
453 # define YYSTACK_ALLOC YYMALLOC
454 # define YYSTACK_FREE YYFREE
455 # ifndef YYSTACK_ALLOC_MAXIMUM
456 # define YYSTACK_ALLOC_MAXIMUM YYSIZE_MAXIMUM
462 # define YYMALLOC malloc
463 # if ! defined malloc && ! defined _STDLIB_H && (defined __STDC__ || defined __C99__FUNC__ \
464 || defined __cplusplus || defined _MSC_VER)
465 void *malloc (YYSIZE_T); /* INFRINGES ON USER NAME SPACE */
470 # if ! defined free && ! defined _STDLIB_H && (defined __STDC__ || defined __C99__FUNC__ \
471 || defined __cplusplus || defined _MSC_VER)
472 void free (void *); /* INFRINGES ON USER NAME SPACE */
479 #endif /* ! defined yyoverflow || YYERROR_VERBOSE */
482 #if (! defined yyoverflow \
483 && (! defined __cplusplus \
484 || (defined YYLTYPE_IS_TRIVIAL && YYLTYPE_IS_TRIVIAL \
485 && defined YYSTYPE_IS_TRIVIAL && YYSTYPE_IS_TRIVIAL)))
487 /* A type that is properly aligned for any stack member. */
495 /* The size of the maximum gap between one aligned stack and the next. */
496 # define YYSTACK_GAP_MAXIMUM (sizeof (union yyalloc) - 1)
498 /* The size of an array large to enough to hold all stacks, each with
500 # define YYSTACK_BYTES(N) \
501 ((N) * (sizeof (yytype_int16) + sizeof (YYSTYPE) + sizeof (YYLTYPE)) \
502 + 2 * YYSTACK_GAP_MAXIMUM)
504 /* Copy COUNT objects from FROM to TO. The source and destination do
507 # if defined __GNUC__ && 1 < __GNUC__
508 # define YYCOPY(To, From, Count) \
509 __builtin_memcpy (To, From, (Count) * sizeof (*(From)))
511 # define YYCOPY(To, From, Count) \
515 for (yyi = 0; yyi < (Count); yyi++) \
516 (To)[yyi] = (From)[yyi]; \
522 /* Relocate STACK from its old location to the new one. The
523 local variables YYSIZE and YYSTACKSIZE give the old and new number of
524 elements in the stack, and YYPTR gives the new location of the
525 stack. Advance YYPTR to a properly aligned location for the next
527 # define YYSTACK_RELOCATE(Stack) \
530 YYSIZE_T yynewbytes; \
531 YYCOPY (&yyptr->Stack, Stack, yysize); \
532 Stack = &yyptr->Stack; \
533 yynewbytes = yystacksize * sizeof (*Stack) + YYSTACK_GAP_MAXIMUM; \
534 yyptr += yynewbytes / sizeof (*yyptr); \
540 /* YYFINAL -- State number of the termination state. */
542 /* YYLAST -- Last index in YYTABLE. */
545 /* YYNTOKENS -- Number of terminals. */
547 /* YYNNTS -- Number of nonterminals. */
549 /* YYNRULES -- Number of rules. */
551 /* YYNRULES -- Number of states. */
554 /* YYTRANSLATE(YYLEX) -- Bison symbol number corresponding to YYLEX. */
556 #define YYMAXUTOK 278
558 #define YYTRANSLATE(YYX) \
559 ((unsigned int) (YYX) <= YYMAXUTOK ? yytranslate[YYX] : YYUNDEFTOK)
561 /* YYTRANSLATE[YYLEX] -- Bison symbol number corresponding to YYLEX. */
562 static const yytype_uint8 yytranslate[] =
564 0, 2, 2, 2, 2, 2, 2, 2, 2, 2,
565 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
566 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
567 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
568 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
569 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
570 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
571 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
572 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
573 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
574 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
575 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
576 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
577 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
578 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
579 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
580 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
581 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
582 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
583 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
584 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
585 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
586 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
587 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
588 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
589 2, 2, 2, 2, 2, 2, 1, 2, 3, 4,
590 5, 6, 7, 8, 9, 10, 11, 12, 13, 14,
591 15, 16, 17, 18, 19, 20, 21, 22, 23
595 /* YYPRHS[YYN] -- Index of the first RHS symbol of rule number YYN in
597 static const yytype_uint8 yyprhs[] =
599 0, 0, 3, 5, 6, 8, 12, 16, 20, 24,
600 28, 32, 36, 40, 44, 48, 52, 55, 58, 62,
604 /* YYRHS -- A `-1'-separated list of the rules' RHS. */
605 static const yytype_int8 yyrhs[] =
607 25, 0, -1, 26, -1, -1, 23, -1, 21, 26,
608 22, -1, 26, 5, 26, -1, 26, 6, 26, -1,
609 26, 12, 26, -1, 26, 11, 26, -1, 26, 10,
610 26, -1, 26, 9, 26, -1, 26, 8, 26, -1,
611 26, 7, 26, -1, 26, 14, 26, -1, 26, 13,
612 26, -1, 13, 26, -1, 18, 26, -1, 26, 17,
613 26, -1, 26, 16, 26, -1, 26, 15, 26, -1,
614 26, 20, 26, -1, 26, 19, 26, -1, 26, 4,
618 /* YYRLINE[YYN] -- source line where rule number YYN was defined. */
619 static const yytype_uint16 yyrline[] =
621 0, 193, 193, 201, 208, 209, 213, 217, 221, 225,
622 229, 233, 237, 241, 245, 249, 253, 257, 261, 265,
627 #if YYDEBUG || YYERROR_VERBOSE || YYTOKEN_TABLE
628 /* YYTNAME[SYMBOL-NUM] -- String name of the symbol SYMBOL-NUM.
629 First, the terminals, then, starting at YYNTOKENS, nonterminals. */
630 static const char *const yytname[] =
632 "$end", "error", "$undefined", "TOK_COLONCOLON", "TOK_COND", "TOK_OR",
633 "TOK_AND", "TOK_NE", "TOK_LE", "TOK_GE", "TOK_LT", "TOK_GT", "TOK_EQ",
634 "TOK_MINUS", "TOK_PLUS", "TOK_MOD", "TOK_DIV", "TOK_MULT", "TOK_COMPL",
635 "TOK_EQTILDE", "TOK_COLON", "TOK_LP", "TOK_RP", "TOKEN", "$accept",
641 /* YYTOKNUM[YYLEX-NUM] -- Internal token number corresponding to
643 static const yytype_uint16 yytoknum[] =
645 0, 256, 257, 258, 259, 260, 261, 262, 263, 264,
646 265, 266, 267, 268, 269, 270, 271, 272, 273, 274,
651 /* YYR1[YYN] -- Symbol number of symbol that rule YYN derives. */
652 static const yytype_uint8 yyr1[] =
654 0, 24, 25, 25, 26, 26, 26, 26, 26, 26,
655 26, 26, 26, 26, 26, 26, 26, 26, 26, 26,
659 /* YYR2[YYN] -- Number of symbols composing right hand side of rule YYN. */
660 static const yytype_uint8 yyr2[] =
662 0, 2, 1, 0, 1, 3, 3, 3, 3, 3,
663 3, 3, 3, 3, 3, 3, 2, 2, 3, 3,
667 /* YYDEFACT[STATE-NAME] -- Default rule to reduce with in state
668 STATE-NUM when YYTABLE doesn't specify something else to do. Zero
669 means the default is an error. */
670 static const yytype_uint8 yydefact[] =
672 3, 0, 0, 0, 4, 0, 2, 16, 17, 0,
673 1, 0, 0, 0, 0, 0, 0, 0, 0, 0,
674 0, 0, 0, 0, 0, 0, 0, 5, 0, 6,
675 7, 13, 12, 11, 10, 9, 8, 15, 14, 20,
676 19, 18, 22, 21, 0, 23
679 /* YYDEFGOTO[NTERM-NUM]. */
680 static const yytype_int8 yydefgoto[] =
685 /* YYPACT[STATE-NUM] -- Index in YYTABLE of the portion describing
687 #define YYPACT_NINF -13
688 static const yytype_int8 yypact[] =
690 109, 109, 109, 109, -13, 6, 59, 106, 106, 22,
691 -13, 109, 109, 109, 109, 109, 109, 109, 109, 109,
692 109, 109, 109, 109, 109, 109, 109, -13, 42, 90,
693 104, 120, 120, 120, 120, 120, 120, -12, -12, 106,
694 106, 106, -13, -13, 109, 75
697 /* YYPGOTO[NTERM-NUM]. */
698 static const yytype_int8 yypgoto[] =
703 /* YYTABLE[YYPACT[STATE-NUM]]. What to do in state STATE-NUM. If
704 positive, shift that token. If negative, reduce the rule which
705 number is the opposite. If zero, do what YYDEFACT says.
706 If YYTABLE_NINF, syntax error. */
707 #define YYTABLE_NINF -1
708 static const yytype_uint8 yytable[] =
710 7, 8, 9, 22, 23, 24, 10, 25, 26, 0,
711 28, 29, 30, 31, 32, 33, 34, 35, 36, 37,
712 38, 39, 40, 41, 42, 43, 11, 12, 13, 14,
713 15, 16, 17, 18, 19, 20, 21, 22, 23, 24,
714 0, 25, 26, 45, 27, 44, 11, 12, 13, 14,
715 15, 16, 17, 18, 19, 20, 21, 22, 23, 24,
716 0, 25, 26, 11, 12, 13, 14, 15, 16, 17,
717 18, 19, 20, 21, 22, 23, 24, 0, 25, 26,
718 12, 13, 14, 15, 16, 17, 18, 19, 20, 21,
719 22, 23, 24, 0, 25, 26, 13, 14, 15, 16,
720 17, 18, 19, 20, 21, 22, 23, 24, 0, 25,
721 26, 14, 15, 16, 17, 18, 19, 20, 21, 22,
722 23, 24, 1, 25, 26, 25, 26, 2, 0, 0,
723 3, 0, 4, 20, 21, 22, 23, 24, 0, 25,
727 static const yytype_int8 yycheck[] =
729 1, 2, 3, 15, 16, 17, 0, 19, 20, -1,
730 11, 12, 13, 14, 15, 16, 17, 18, 19, 20,
731 21, 22, 23, 24, 25, 26, 4, 5, 6, 7,
732 8, 9, 10, 11, 12, 13, 14, 15, 16, 17,
733 -1, 19, 20, 44, 22, 3, 4, 5, 6, 7,
734 8, 9, 10, 11, 12, 13, 14, 15, 16, 17,
735 -1, 19, 20, 4, 5, 6, 7, 8, 9, 10,
736 11, 12, 13, 14, 15, 16, 17, -1, 19, 20,
737 5, 6, 7, 8, 9, 10, 11, 12, 13, 14,
738 15, 16, 17, -1, 19, 20, 6, 7, 8, 9,
739 10, 11, 12, 13, 14, 15, 16, 17, -1, 19,
740 20, 7, 8, 9, 10, 11, 12, 13, 14, 15,
741 16, 17, 13, 19, 20, 19, 20, 18, -1, -1,
742 21, -1, 23, 13, 14, 15, 16, 17, -1, 19,
746 /* YYSTOS[STATE-NUM] -- The (internal number of the) accessing
747 symbol of state STATE-NUM. */
748 static const yytype_uint8 yystos[] =
750 0, 13, 18, 21, 23, 25, 26, 26, 26, 26,
751 0, 4, 5, 6, 7, 8, 9, 10, 11, 12,
752 13, 14, 15, 16, 17, 19, 20, 22, 26, 26,
753 26, 26, 26, 26, 26, 26, 26, 26, 26, 26,
754 26, 26, 26, 26, 3, 26
757 #define yyerrok (yyerrstatus = 0)
758 #define yyclearin (yychar = YYEMPTY)
762 #define YYACCEPT goto yyacceptlab
763 #define YYABORT goto yyabortlab
764 #define YYERROR goto yyerrorlab
767 /* Like YYERROR except do call yyerror. This remains here temporarily
768 to ease the transition to the new meaning of YYERROR, for GCC.
769 Once GCC version 2 has supplanted version 1, this can go. */
771 #define YYFAIL goto yyerrlab
773 #define YYRECOVERING() (!!yyerrstatus)
775 #define YYBACKUP(Token, Value) \
777 if (yychar == YYEMPTY && yylen == 1) \
781 yytoken = YYTRANSLATE (yychar); \
787 yyerror (YY_("syntax error: cannot back up")); \
794 #define YYERRCODE 256
797 /* YYLLOC_DEFAULT -- Set CURRENT to span from RHS[1] to RHS[N].
798 If N is 0, then set CURRENT to the empty location which ends
799 the previous symbol: RHS[0] (always defined). */
801 #define YYRHSLOC(Rhs, K) ((Rhs)[K])
802 #ifndef YYLLOC_DEFAULT
803 # define YYLLOC_DEFAULT(Current, Rhs, N) \
807 (Current).first_line = YYRHSLOC (Rhs, 1).first_line; \
808 (Current).first_column = YYRHSLOC (Rhs, 1).first_column; \
809 (Current).last_line = YYRHSLOC (Rhs, N).last_line; \
810 (Current).last_column = YYRHSLOC (Rhs, N).last_column; \
814 (Current).first_line = (Current).last_line = \
815 YYRHSLOC (Rhs, 0).last_line; \
816 (Current).first_column = (Current).last_column = \
817 YYRHSLOC (Rhs, 0).last_column; \
823 /* YY_LOCATION_PRINT -- Print the location on the stream.
824 This macro was not mandated originally: define only if we know
825 we won't break user code: when these are the locations we know. */
827 #ifndef YY_LOCATION_PRINT
828 # if YYLTYPE_IS_TRIVIAL
829 # define YY_LOCATION_PRINT(File, Loc) \
830 fprintf (File, "%d.%d-%d.%d", \
831 (Loc).first_line, (Loc).first_column, \
832 (Loc).last_line, (Loc).last_column)
834 # define YY_LOCATION_PRINT(File, Loc) ((void) 0)
839 /* YYLEX -- calling `yylex' with the right arguments. */
842 # define YYLEX yylex (&yylval, &yylloc, YYLEX_PARAM)
844 # define YYLEX yylex (&yylval, &yylloc)
847 /* Enable debugging if requested. */
851 # include <stdio.h> /* INFRINGES ON USER NAME SPACE */
852 # define YYFPRINTF fprintf
855 # define YYDPRINTF(Args) \
861 # define YY_SYMBOL_PRINT(Title, Type, Value, Location) \
865 YYFPRINTF (stderr, "%s ", Title); \
866 yy_symbol_print (stderr, \
867 Type, Value, Location); \
868 YYFPRINTF (stderr, "\n"); \
873 /*--------------------------------.
874 | Print this symbol on YYOUTPUT. |
875 `--------------------------------*/
878 #if (defined __STDC__ || defined __C99__FUNC__ \
879 || defined __cplusplus || defined _MSC_VER)
881 yy_symbol_value_print (FILE *yyoutput, int yytype, const YYSTYPE * const yyvaluep, const YYLTYPE * const yylocationp)
884 yy_symbol_value_print (yyoutput, yytype, yyvaluep, yylocationp)
887 const YYSTYPE * const yyvaluep;
888 const YYLTYPE * const yylocationp;
895 if (yytype < YYNTOKENS)
896 YYPRINT (yyoutput, yytoknum[yytype], *yyvaluep);
908 /*--------------------------------.
909 | Print this symbol on YYOUTPUT. |
910 `--------------------------------*/
912 #if (defined __STDC__ || defined __C99__FUNC__ \
913 || defined __cplusplus || defined _MSC_VER)
915 yy_symbol_print (FILE *yyoutput, int yytype, const YYSTYPE * const yyvaluep, const YYLTYPE * const yylocationp)
918 yy_symbol_print (yyoutput, yytype, yyvaluep, yylocationp)
921 const YYSTYPE * const yyvaluep;
922 const YYLTYPE * const yylocationp;
925 if (yytype < YYNTOKENS)
926 YYFPRINTF (yyoutput, "token %s (", yytname[yytype]);
928 YYFPRINTF (yyoutput, "nterm %s (", yytname[yytype]);
930 YY_LOCATION_PRINT (yyoutput, *yylocationp);
931 YYFPRINTF (yyoutput, ": ");
932 yy_symbol_value_print (yyoutput, yytype, yyvaluep, yylocationp);
933 YYFPRINTF (yyoutput, ")");
936 /*------------------------------------------------------------------.
937 | yy_stack_print -- Print the state stack from its BOTTOM up to its |
939 `------------------------------------------------------------------*/
941 #if (defined __STDC__ || defined __C99__FUNC__ \
942 || defined __cplusplus || defined _MSC_VER)
944 yy_stack_print (yytype_int16 *bottom, yytype_int16 *top)
947 yy_stack_print (bottom, top)
948 yytype_int16 *bottom;
952 YYFPRINTF (stderr, "Stack now");
953 for (; bottom <= top; ++bottom)
954 YYFPRINTF (stderr, " %d", *bottom);
955 YYFPRINTF (stderr, "\n");
958 # define YY_STACK_PRINT(Bottom, Top) \
961 yy_stack_print ((Bottom), (Top)); \
965 /*------------------------------------------------.
966 | Report that the YYRULE is going to be reduced. |
967 `------------------------------------------------*/
969 #if (defined __STDC__ || defined __C99__FUNC__ \
970 || defined __cplusplus || defined _MSC_VER)
972 yy_reduce_print (YYSTYPE *yyvsp, YYLTYPE *yylsp, int yyrule)
975 yy_reduce_print (yyvsp, yylsp, yyrule
982 int yynrhs = yyr2[yyrule];
984 unsigned long int yylno = yyrline[yyrule];
985 YYFPRINTF (stderr, "Reducing stack by rule %d (line %lu):\n",
987 /* The symbols being reduced. */
988 for (yyi = 0; yyi < yynrhs; yyi++)
990 fprintf (stderr, " $%d = ", yyi + 1);
991 yy_symbol_print (stderr, yyrhs[yyprhs[yyrule] + yyi],
992 &(yyvsp[(yyi + 1) - (yynrhs)])
993 , &(yylsp[(yyi + 1) - (yynrhs)]) );
994 fprintf (stderr, "\n");
998 # define YY_REDUCE_PRINT(Rule) \
1001 yy_reduce_print (yyvsp, yylsp, Rule); \
1004 /* Nonzero means print parse trace. It is left uninitialized so that
1005 multiple parsers can coexist. */
1007 #else /* !YYDEBUG */
1008 # define YYDPRINTF(Args)
1009 # define YY_SYMBOL_PRINT(Title, Type, Value, Location)
1010 # define YY_STACK_PRINT(Bottom, Top)
1011 # define YY_REDUCE_PRINT(Rule)
1012 #endif /* !YYDEBUG */
1015 /* YYINITDEPTH -- initial size of the parser's stacks. */
1017 # define YYINITDEPTH 200
1020 /* YYMAXDEPTH -- maximum size the stacks can grow to (effective only
1021 if the built-in stack extension method is used).
1023 Do not make this value too large; the results are undefined if
1024 YYSTACK_ALLOC_MAXIMUM < YYSTACK_BYTES (YYMAXDEPTH)
1025 evaluated with infinite-precision integer arithmetic. */
1028 # define YYMAXDEPTH 10000
1036 # if defined __GLIBC__ && defined _STRING_H
1037 # define yystrlen strlen
1039 /* Return the length of YYSTR. */
1040 #if (defined __STDC__ || defined __C99__FUNC__ \
1041 || defined __cplusplus || defined _MSC_VER)
1043 yystrlen (const char *yystr)
1051 for (yylen = 0; yystr[yylen]; yylen++)
1059 # if defined __GLIBC__ && defined _STRING_H && defined _GNU_SOURCE
1060 # define yystpcpy stpcpy
1062 /* Copy YYSRC to YYDEST, returning the address of the terminating '\0' in
1064 #if (defined __STDC__ || defined __C99__FUNC__ \
1065 || defined __cplusplus || defined _MSC_VER)
1067 yystpcpy (char *yydest, const char *yysrc)
1070 yystpcpy (yydest, yysrc)
1076 const char *yys = yysrc;
1078 while ((*yyd++ = *yys++) != '\0')
1087 /* Copy to YYRES the contents of YYSTR after stripping away unnecessary
1088 quotes and backslashes, so that it's suitable for yyerror. The
1089 heuristic is that double-quoting is unnecessary unless the string
1090 contains an apostrophe, a comma, or backslash (other than
1091 backslash-backslash). YYSTR is taken from yytname. If YYRES is
1092 null, do not copy; instead, return the length of what the result
1095 yytnamerr (char *yyres, const char *yystr)
1100 char const *yyp = yystr;
1107 goto do_not_strip_quotes;
1111 goto do_not_strip_quotes;
1124 do_not_strip_quotes: ;
1128 return yystrlen (yystr);
1130 return yystpcpy (yyres, yystr) - yyres;
1134 /* Copy into YYRESULT an error message about the unexpected token
1135 YYCHAR while in state YYSTATE. Return the number of bytes copied,
1136 including the terminating null byte. If YYRESULT is null, do not
1137 copy anything; just return the number of bytes that would be
1138 copied. As a special case, return 0 if an ordinary "syntax error"
1139 message will do. Return YYSIZE_MAXIMUM if overflow occurs during
1140 size calculation. */
1142 yysyntax_error (char *yyresult, int yystate, int yychar)
1144 int yyn = yypact[yystate];
1146 if (! (YYPACT_NINF < yyn && yyn < YYLAST))
1150 int yytype = YYTRANSLATE (yychar);
1151 YYSIZE_T yysize0 = yytnamerr (0, yytname[yytype]);
1152 YYSIZE_T yysize = yysize0;
1154 int yysize_overflow = 0;
1155 enum { YYERROR_VERBOSE_ARGS_MAXIMUM = 5 };
1156 char const *yyarg[YYERROR_VERBOSE_ARGS_MAXIMUM];
1160 /* This is so xgettext sees the translatable formats that are
1161 constructed on the fly. */
1162 YY_("syntax error, unexpected %s");
1163 YY_("syntax error, unexpected %s, expecting %s");
1164 YY_("syntax error, unexpected %s, expecting %s or %s");
1165 YY_("syntax error, unexpected %s, expecting %s or %s or %s");
1166 YY_("syntax error, unexpected %s, expecting %s or %s or %s or %s");
1170 static char const yyunexpected[] = "syntax error, unexpected %s";
1171 static char const yyexpecting[] = ", expecting %s";
1172 static char const yyor[] = " or %s";
1173 char yyformat[sizeof yyunexpected
1174 + sizeof yyexpecting - 1
1175 + ((YYERROR_VERBOSE_ARGS_MAXIMUM - 2)
1176 * (sizeof yyor - 1))];
1177 char const *yyprefix = yyexpecting;
1179 /* Start YYX at -YYN if negative to avoid negative indexes in
1181 int yyxbegin = yyn < 0 ? -yyn : 0;
1183 /* Stay within bounds of both yycheck and yytname. */
1184 int yychecklim = YYLAST - yyn;
1185 int yyxend = yychecklim < YYNTOKENS ? yychecklim : YYNTOKENS;
1188 yyarg[0] = yytname[yytype];
1189 yyfmt = yystpcpy (yyformat, yyunexpected);
1191 for (yyx = yyxbegin; yyx < yyxend; ++yyx)
1192 if (yycheck[yyx + yyn] == yyx && yyx != YYTERROR)
1194 if (yycount == YYERROR_VERBOSE_ARGS_MAXIMUM)
1198 yyformat[sizeof yyunexpected - 1] = '\0';
1201 yyarg[yycount++] = yytname[yyx];
1202 yysize1 = yysize + yytnamerr (0, yytname[yyx]);
1203 yysize_overflow |= (yysize1 < yysize);
1205 yyfmt = yystpcpy (yyfmt, yyprefix);
1209 yyf = YY_(yyformat);
1210 yysize1 = yysize + yystrlen (yyf);
1211 yysize_overflow |= (yysize1 < yysize);
1214 if (yysize_overflow)
1215 return YYSIZE_MAXIMUM;
1219 /* Avoid sprintf, as that infringes on the user's name space.
1220 Don't have undefined behavior even if the translation
1221 produced a string with the wrong number of "%s"s. */
1222 char *yyp = yyresult;
1224 while ((*yyp = *yyf) != '\0')
1226 if (*yyp == '%' && yyf[1] == 's' && yyi < yycount)
1228 yyp += yytnamerr (yyp, yyarg[yyi++]);
1241 #endif /* YYERROR_VERBOSE */
1244 /*-----------------------------------------------.
1245 | Release the memory associated to this symbol. |
1246 `-----------------------------------------------*/
1249 #if (defined __STDC__ || defined __C99__FUNC__ \
1250 || defined __cplusplus || defined _MSC_VER)
1252 yydestruct (const char *yymsg, int yytype, YYSTYPE *yyvaluep, YYLTYPE *yylocationp)
1255 yydestruct (yymsg, yytype, yyvaluep, yylocationp)
1259 YYLTYPE *yylocationp;
1263 YYUSE (yylocationp);
1267 YY_SYMBOL_PRINT (yymsg, yytype, yyvaluep, yylocationp);
1271 case 3: /* "TOK_COLONCOLON" */
1272 #line 187 "ast_expr2.y"
1273 { free_value((yyvaluep->val)); };
1274 #line 1275 "ast_expr2.c"
1276 case 4: /* "TOK_COND" */
1277 #line 187 "ast_expr2.y"
1278 { free_value((yyvaluep->val)); };
1279 #line 1280 "ast_expr2.c"
1281 case 5: /* "TOK_OR" */
1282 #line 187 "ast_expr2.y"
1283 { free_value((yyvaluep->val)); };
1284 #line 1285 "ast_expr2.c"
1286 case 6: /* "TOK_AND" */
1287 #line 187 "ast_expr2.y"
1288 { free_value((yyvaluep->val)); };
1289 #line 1290 "ast_expr2.c"
1291 case 7: /* "TOK_NE" */
1292 #line 187 "ast_expr2.y"
1293 { free_value((yyvaluep->val)); };
1294 #line 1295 "ast_expr2.c"
1296 case 8: /* "TOK_LE" */
1297 #line 187 "ast_expr2.y"
1298 { free_value((yyvaluep->val)); };
1299 #line 1300 "ast_expr2.c"
1301 case 9: /* "TOK_GE" */
1302 #line 187 "ast_expr2.y"
1303 { free_value((yyvaluep->val)); };
1304 #line 1305 "ast_expr2.c"
1306 case 10: /* "TOK_LT" */
1307 #line 187 "ast_expr2.y"
1308 { free_value((yyvaluep->val)); };
1309 #line 1310 "ast_expr2.c"
1311 case 11: /* "TOK_GT" */
1312 #line 187 "ast_expr2.y"
1313 { free_value((yyvaluep->val)); };
1314 #line 1315 "ast_expr2.c"
1316 case 12: /* "TOK_EQ" */
1317 #line 187 "ast_expr2.y"
1318 { free_value((yyvaluep->val)); };
1319 #line 1320 "ast_expr2.c"
1321 case 13: /* "TOK_MINUS" */
1322 #line 187 "ast_expr2.y"
1323 { free_value((yyvaluep->val)); };
1324 #line 1325 "ast_expr2.c"
1326 case 14: /* "TOK_PLUS" */
1327 #line 187 "ast_expr2.y"
1328 { free_value((yyvaluep->val)); };
1329 #line 1330 "ast_expr2.c"
1331 case 15: /* "TOK_MOD" */
1332 #line 187 "ast_expr2.y"
1333 { free_value((yyvaluep->val)); };
1334 #line 1335 "ast_expr2.c"
1336 case 16: /* "TOK_DIV" */
1337 #line 187 "ast_expr2.y"
1338 { free_value((yyvaluep->val)); };
1339 #line 1340 "ast_expr2.c"
1341 case 17: /* "TOK_MULT" */
1342 #line 187 "ast_expr2.y"
1343 { free_value((yyvaluep->val)); };
1344 #line 1345 "ast_expr2.c"
1346 case 18: /* "TOK_COMPL" */
1347 #line 187 "ast_expr2.y"
1348 { free_value((yyvaluep->val)); };
1349 #line 1350 "ast_expr2.c"
1351 case 19: /* "TOK_EQTILDE" */
1352 #line 187 "ast_expr2.y"
1353 { free_value((yyvaluep->val)); };
1354 #line 1355 "ast_expr2.c"
1356 case 20: /* "TOK_COLON" */
1357 #line 187 "ast_expr2.y"
1358 { free_value((yyvaluep->val)); };
1359 #line 1360 "ast_expr2.c"
1361 case 21: /* "TOK_LP" */
1362 #line 187 "ast_expr2.y"
1363 { free_value((yyvaluep->val)); };
1364 #line 1365 "ast_expr2.c"
1366 case 22: /* "TOK_RP" */
1367 #line 187 "ast_expr2.y"
1368 { free_value((yyvaluep->val)); };
1369 #line 1370 "ast_expr2.c"
1371 case 23: /* "TOKEN" */
1372 #line 187 "ast_expr2.y"
1373 { free_value((yyvaluep->val)); };
1374 #line 1375 "ast_expr2.c"
1376 case 26: /* "expr" */
1377 #line 187 "ast_expr2.y"
1378 { free_value((yyvaluep->val)); };
1379 #line 1380 "ast_expr2.c"
1388 /* Prevent warnings from -Wmissing-prototypes. */
1390 #ifdef YYPARSE_PARAM
1391 #if defined __STDC__ || defined __cplusplus
1392 int yyparse (void *YYPARSE_PARAM);
1396 #else /* ! YYPARSE_PARAM */
1397 #if defined __STDC__ || defined __cplusplus
1402 #endif /* ! YYPARSE_PARAM */
1413 #ifdef YYPARSE_PARAM
1414 #if (defined __STDC__ || defined __C99__FUNC__ \
1415 || defined __cplusplus || defined _MSC_VER)
1417 yyparse (void *YYPARSE_PARAM)
1420 yyparse (YYPARSE_PARAM)
1421 void *YYPARSE_PARAM;
1423 #else /* ! YYPARSE_PARAM */
1424 #if (defined __STDC__ || defined __C99__FUNC__ \
1425 || defined __cplusplus || defined _MSC_VER)
1435 /* The look-ahead symbol. */
1438 /* The semantic value of the look-ahead symbol. */
1441 /* Number of syntax errors so far. */
1443 /* Location data for the look-ahead symbol. */
1449 /* Number of tokens to shift before error messages enabled. */
1451 /* Look-ahead token as an internal (translated) token number. */
1454 /* Buffer for error messages, and its allocated size. */
1456 char *yymsg = yymsgbuf;
1457 YYSIZE_T yymsg_alloc = sizeof yymsgbuf;
1460 /* Three stacks and their tools:
1461 `yyss': related to states,
1462 `yyvs': related to semantic values,
1463 `yyls': related to locations.
1465 Refer to the stacks thru separate pointers, to allow yyoverflow
1466 to reallocate them elsewhere. */
1468 /* The state stack. */
1469 yytype_int16 yyssa[YYINITDEPTH];
1470 yytype_int16 *yyss = yyssa;
1471 yytype_int16 *yyssp;
1473 /* The semantic value stack. */
1474 YYSTYPE yyvsa[YYINITDEPTH];
1475 YYSTYPE *yyvs = yyvsa;
1478 /* The location stack. */
1479 YYLTYPE yylsa[YYINITDEPTH];
1480 YYLTYPE *yyls = yylsa;
1482 /* The locations where the error started and ended. */
1483 YYLTYPE yyerror_range[2];
1485 #define YYPOPSTACK(N) (yyvsp -= (N), yyssp -= (N), yylsp -= (N))
1487 YYSIZE_T yystacksize = YYINITDEPTH;
1489 /* The variables used to return semantic value and location from the
1494 /* The number of symbols on the RHS of the reduced rule.
1495 Keep to zero when no symbol should be popped. */
1498 YYDPRINTF ((stderr, "Starting parse\n"));
1503 yychar = YYEMPTY; /* Cause a token to be read. */
1505 /* Initialize stack pointers.
1506 Waste one element of value and location stack
1507 so that they stay on the same level as the state stack.
1508 The wasted elements are never initialized. */
1513 #if YYLTYPE_IS_TRIVIAL
1514 /* Initialize the default location before parsing starts. */
1515 yylloc.first_line = yylloc.last_line = 1;
1516 yylloc.first_column = yylloc.last_column = 0;
1521 /*------------------------------------------------------------.
1522 | yynewstate -- Push a new state, which is found in yystate. |
1523 `------------------------------------------------------------*/
1525 /* In all cases, when you get here, the value and location stacks
1526 have just been pushed. So pushing a state here evens the stacks. */
1532 if (yyss + yystacksize - 1 <= yyssp)
1534 /* Get the current used size of the three stacks, in elements. */
1535 YYSIZE_T yysize = yyssp - yyss + 1;
1539 /* Give user a chance to reallocate the stack. Use copies of
1540 these so that the &'s don't force the real ones into
1542 YYSTYPE *yyvs1 = yyvs;
1543 yytype_int16 *yyss1 = yyss;
1544 YYLTYPE *yyls1 = yyls;
1546 /* Each stack pointer address is followed by the size of the
1547 data in use in that stack, in bytes. This used to be a
1548 conditional around just the two extra args, but that might
1549 be undefined if yyoverflow is a macro. */
1550 yyoverflow (YY_("memory exhausted"),
1551 &yyss1, yysize * sizeof (*yyssp),
1552 &yyvs1, yysize * sizeof (*yyvsp),
1553 &yyls1, yysize * sizeof (*yylsp),
1559 #else /* no yyoverflow */
1560 # ifndef YYSTACK_RELOCATE
1561 goto yyexhaustedlab;
1563 /* Extend the stack our own way. */
1564 if (YYMAXDEPTH <= yystacksize)
1565 goto yyexhaustedlab;
1567 if (YYMAXDEPTH < yystacksize)
1568 yystacksize = YYMAXDEPTH;
1571 yytype_int16 *yyss1 = yyss;
1572 union yyalloc *yyptr =
1573 (union yyalloc *) YYSTACK_ALLOC (YYSTACK_BYTES (yystacksize));
1575 goto yyexhaustedlab;
1576 YYSTACK_RELOCATE (yyss);
1577 YYSTACK_RELOCATE (yyvs);
1578 YYSTACK_RELOCATE (yyls);
1579 # undef YYSTACK_RELOCATE
1581 YYSTACK_FREE (yyss1);
1584 #endif /* no yyoverflow */
1586 yyssp = yyss + yysize - 1;
1587 yyvsp = yyvs + yysize - 1;
1588 yylsp = yyls + yysize - 1;
1590 YYDPRINTF ((stderr, "Stack size increased to %lu\n",
1591 (unsigned long int) yystacksize));
1593 if (yyss + yystacksize - 1 <= yyssp)
1597 YYDPRINTF ((stderr, "Entering state %d\n", yystate));
1606 /* Do appropriate processing given the current state. Read a
1607 look-ahead token if we need one and don't already have one. */
1609 /* First try to decide what to do without reference to look-ahead token. */
1610 yyn = yypact[yystate];
1611 if (yyn == YYPACT_NINF)
1614 /* Not known => get a look-ahead token if don't already have one. */
1616 /* YYCHAR is either YYEMPTY or YYEOF or a valid look-ahead symbol. */
1617 if (yychar == YYEMPTY)
1619 YYDPRINTF ((stderr, "Reading a token: "));
1623 if (yychar <= YYEOF)
1625 yychar = yytoken = YYEOF;
1626 YYDPRINTF ((stderr, "Now at end of input.\n"));
1630 yytoken = YYTRANSLATE (yychar);
1631 YY_SYMBOL_PRINT ("Next token is", yytoken, &yylval, &yylloc);
1634 /* If the proper action on seeing token YYTOKEN is to reduce or to
1635 detect an error, take that action. */
1637 if (yyn < 0 || YYLAST < yyn || yycheck[yyn] != yytoken)
1642 if (yyn == 0 || yyn == YYTABLE_NINF)
1651 /* Count tokens shifted since error; after three, turn off error
1656 /* Shift the look-ahead token. */
1657 YY_SYMBOL_PRINT ("Shifting", yytoken, &yylval, &yylloc);
1659 /* Discard the shifted token unless it is eof. */
1660 if (yychar != YYEOF)
1669 /*-----------------------------------------------------------.
1670 | yydefault -- do the default action for the current state. |
1671 `-----------------------------------------------------------*/
1673 yyn = yydefact[yystate];
1679 /*-----------------------------.
1680 | yyreduce -- Do a reduction. |
1681 `-----------------------------*/
1683 /* yyn is the number of a rule to reduce with. */
1686 /* If YYLEN is nonzero, implement the default value of the action:
1689 Otherwise, the following line sets YYVAL to garbage.
1690 This behavior is undocumented and Bison
1691 users should not rely upon it. Assigning to YYVAL
1692 unconditionally makes the parser a bit smaller, and it avoids a
1693 GCC warning that YYVAL may be used uninitialized. */
1694 yyval = yyvsp[1-yylen];
1696 /* Default location. */
1697 YYLLOC_DEFAULT (yyloc, (yylsp - yylen), yylen);
1698 YY_REDUCE_PRINT (yyn);
1702 #line 193 "ast_expr2.y"
1703 { ((struct parse_io *)parseio)->val = (struct val *)calloc(sizeof(struct val),1);
1704 ((struct parse_io *)parseio)->val->type = (yyvsp[(1) - (1)].val)->type;
1705 if( (yyvsp[(1) - (1)].val)->type == AST_EXPR_number )
1706 ((struct parse_io *)parseio)->val->u.i = (yyvsp[(1) - (1)].val)->u.i;
1708 ((struct parse_io *)parseio)->val->u.s = (yyvsp[(1) - (1)].val)->u.s;
1709 free((yyvsp[(1) - (1)].val));
1714 #line 201 "ast_expr2.y"
1715 {/* nothing */ ((struct parse_io *)parseio)->val = (struct val *)calloc(sizeof(struct val),1);
1716 ((struct parse_io *)parseio)->val->type = AST_EXPR_string;
1717 ((struct parse_io *)parseio)->val->u.s = strdup("");
1722 #line 208 "ast_expr2.y"
1723 { (yyval.val)= (yyvsp[(1) - (1)].val);;}
1727 #line 209 "ast_expr2.y"
1728 { (yyval.val) = (yyvsp[(2) - (3)].val);
1729 (yyloc).first_column = (yylsp[(1) - (3)]).first_column; (yyloc).last_column = (yylsp[(3) - (3)]).last_column;
1730 (yyloc).first_line=0; (yyloc).last_line=0;
1731 DESTROY((yyvsp[(1) - (3)].val)); DESTROY((yyvsp[(3) - (3)].val)); ;}
1735 #line 213 "ast_expr2.y"
1736 { (yyval.val) = op_or ((yyvsp[(1) - (3)].val), (yyvsp[(3) - (3)].val));
1737 DESTROY((yyvsp[(2) - (3)].val));
1738 (yyloc).first_column = (yylsp[(1) - (3)]).first_column; (yyloc).last_column = (yylsp[(3) - (3)]).last_column;
1739 (yyloc).first_line=0; (yyloc).last_line=0;;}
1743 #line 217 "ast_expr2.y"
1744 { (yyval.val) = op_and ((yyvsp[(1) - (3)].val), (yyvsp[(3) - (3)].val));
1745 DESTROY((yyvsp[(2) - (3)].val));
1746 (yyloc).first_column = (yylsp[(1) - (3)]).first_column; (yyloc).last_column = (yylsp[(3) - (3)]).last_column;
1747 (yyloc).first_line=0; (yyloc).last_line=0;;}
1751 #line 221 "ast_expr2.y"
1752 { (yyval.val) = op_eq ((yyvsp[(1) - (3)].val), (yyvsp[(3) - (3)].val));
1753 DESTROY((yyvsp[(2) - (3)].val));
1754 (yyloc).first_column = (yylsp[(1) - (3)]).first_column; (yyloc).last_column = (yylsp[(3) - (3)]).last_column;
1755 (yyloc).first_line=0; (yyloc).last_line=0;;}
1759 #line 225 "ast_expr2.y"
1760 { (yyval.val) = op_gt ((yyvsp[(1) - (3)].val), (yyvsp[(3) - (3)].val));
1761 DESTROY((yyvsp[(2) - (3)].val));
1762 (yyloc).first_column = (yylsp[(1) - (3)]).first_column; (yyloc).last_column = (yylsp[(3) - (3)]).last_column;
1763 (yyloc).first_line=0; (yyloc).last_line=0;;}
1767 #line 229 "ast_expr2.y"
1768 { (yyval.val) = op_lt ((yyvsp[(1) - (3)].val), (yyvsp[(3) - (3)].val));
1769 DESTROY((yyvsp[(2) - (3)].val));
1770 (yyloc).first_column = (yylsp[(1) - (3)]).first_column; (yyloc).last_column = (yylsp[(3) - (3)]).last_column;
1771 (yyloc).first_line=0; (yyloc).last_line=0;;}
1775 #line 233 "ast_expr2.y"
1776 { (yyval.val) = op_ge ((yyvsp[(1) - (3)].val), (yyvsp[(3) - (3)].val));
1777 DESTROY((yyvsp[(2) - (3)].val));
1778 (yyloc).first_column = (yylsp[(1) - (3)]).first_column; (yyloc).last_column = (yylsp[(3) - (3)]).last_column;
1779 (yyloc).first_line=0; (yyloc).last_line=0;;}
1783 #line 237 "ast_expr2.y"
1784 { (yyval.val) = op_le ((yyvsp[(1) - (3)].val), (yyvsp[(3) - (3)].val));
1785 DESTROY((yyvsp[(2) - (3)].val));
1786 (yyloc).first_column = (yylsp[(1) - (3)]).first_column; (yyloc).last_column = (yylsp[(3) - (3)]).last_column;
1787 (yyloc).first_line=0; (yyloc).last_line=0;;}
1791 #line 241 "ast_expr2.y"
1792 { (yyval.val) = op_ne ((yyvsp[(1) - (3)].val), (yyvsp[(3) - (3)].val));
1793 DESTROY((yyvsp[(2) - (3)].val));
1794 (yyloc).first_column = (yylsp[(1) - (3)]).first_column; (yyloc).last_column = (yylsp[(3) - (3)]).last_column;
1795 (yyloc).first_line=0; (yyloc).last_line=0;;}
1799 #line 245 "ast_expr2.y"
1800 { (yyval.val) = op_plus ((yyvsp[(1) - (3)].val), (yyvsp[(3) - (3)].val));
1801 DESTROY((yyvsp[(2) - (3)].val));
1802 (yyloc).first_column = (yylsp[(1) - (3)]).first_column; (yyloc).last_column = (yylsp[(3) - (3)]).last_column;
1803 (yyloc).first_line=0; (yyloc).last_line=0;;}
1807 #line 249 "ast_expr2.y"
1808 { (yyval.val) = op_minus ((yyvsp[(1) - (3)].val), (yyvsp[(3) - (3)].val));
1809 DESTROY((yyvsp[(2) - (3)].val));
1810 (yyloc).first_column = (yylsp[(1) - (3)]).first_column; (yyloc).last_column = (yylsp[(3) - (3)]).last_column;
1811 (yyloc).first_line=0; (yyloc).last_line=0;;}
1815 #line 253 "ast_expr2.y"
1816 { (yyval.val) = op_negate ((yyvsp[(2) - (2)].val));
1817 DESTROY((yyvsp[(1) - (2)].val));
1818 (yyloc).first_column = (yylsp[(1) - (2)]).first_column; (yyloc).last_column = (yylsp[(2) - (2)]).last_column;
1819 (yyloc).first_line=0; (yyloc).last_line=0;;}
1823 #line 257 "ast_expr2.y"
1824 { (yyval.val) = op_compl ((yyvsp[(2) - (2)].val));
1825 DESTROY((yyvsp[(1) - (2)].val));
1826 (yyloc).first_column = (yylsp[(1) - (2)]).first_column; (yyloc).last_column = (yylsp[(2) - (2)]).last_column;
1827 (yyloc).first_line=0; (yyloc).last_line=0;;}
1831 #line 261 "ast_expr2.y"
1832 { (yyval.val) = op_times ((yyvsp[(1) - (3)].val), (yyvsp[(3) - (3)].val));
1833 DESTROY((yyvsp[(2) - (3)].val));
1834 (yyloc).first_column = (yylsp[(1) - (3)]).first_column; (yyloc).last_column = (yylsp[(3) - (3)]).last_column;
1835 (yyloc).first_line=0; (yyloc).last_line=0;;}
1839 #line 265 "ast_expr2.y"
1840 { (yyval.val) = op_div ((yyvsp[(1) - (3)].val), (yyvsp[(3) - (3)].val));
1841 DESTROY((yyvsp[(2) - (3)].val));
1842 (yyloc).first_column = (yylsp[(1) - (3)]).first_column; (yyloc).last_column = (yylsp[(3) - (3)]).last_column;
1843 (yyloc).first_line=0; (yyloc).last_line=0;;}
1847 #line 269 "ast_expr2.y"
1848 { (yyval.val) = op_rem ((yyvsp[(1) - (3)].val), (yyvsp[(3) - (3)].val));
1849 DESTROY((yyvsp[(2) - (3)].val));
1850 (yyloc).first_column = (yylsp[(1) - (3)]).first_column; (yyloc).last_column = (yylsp[(3) - (3)]).last_column;
1851 (yyloc).first_line=0; (yyloc).last_line=0;;}
1855 #line 273 "ast_expr2.y"
1856 { (yyval.val) = op_colon ((yyvsp[(1) - (3)].val), (yyvsp[(3) - (3)].val));
1857 DESTROY((yyvsp[(2) - (3)].val));
1858 (yyloc).first_column = (yylsp[(1) - (3)]).first_column; (yyloc).last_column = (yylsp[(3) - (3)]).last_column;
1859 (yyloc).first_line=0; (yyloc).last_line=0;;}
1863 #line 277 "ast_expr2.y"
1864 { (yyval.val) = op_eqtilde ((yyvsp[(1) - (3)].val), (yyvsp[(3) - (3)].val));
1865 DESTROY((yyvsp[(2) - (3)].val));
1866 (yyloc).first_column = (yylsp[(1) - (3)]).first_column; (yyloc).last_column = (yylsp[(3) - (3)]).last_column;
1867 (yyloc).first_line=0; (yyloc).last_line=0;;}
1871 #line 281 "ast_expr2.y"
1872 { (yyval.val) = op_cond ((yyvsp[(1) - (5)].val), (yyvsp[(3) - (5)].val), (yyvsp[(5) - (5)].val));
1873 DESTROY((yyvsp[(2) - (5)].val));
1874 DESTROY((yyvsp[(4) - (5)].val));
1875 (yyloc).first_column = (yylsp[(1) - (5)]).first_column; (yyloc).last_column = (yylsp[(3) - (5)]).last_column;
1876 (yyloc).first_line=0; (yyloc).last_line=0;;}
1880 /* Line 1270 of yacc.c. */
1881 #line 1882 "ast_expr2.c"
1884 YY_SYMBOL_PRINT ("-> $$ =", yyr1[yyn], &yyval, &yyloc);
1888 YY_STACK_PRINT (yyss, yyssp);
1893 /* Now `shift' the result of the reduction. Determine what state
1894 that goes to, based on the state we popped back to and the rule
1895 number reduced by. */
1899 yystate = yypgoto[yyn - YYNTOKENS] + *yyssp;
1900 if (0 <= yystate && yystate <= YYLAST && yycheck[yystate] == *yyssp)
1901 yystate = yytable[yystate];
1903 yystate = yydefgoto[yyn - YYNTOKENS];
1908 /*------------------------------------.
1909 | yyerrlab -- here on detecting error |
1910 `------------------------------------*/
1912 /* If not already recovering from an error, report this error. */
1916 #if ! YYERROR_VERBOSE
1917 yyerror (YY_("syntax error"));
1920 YYSIZE_T yysize = yysyntax_error (0, yystate, yychar);
1921 if (yymsg_alloc < yysize && yymsg_alloc < YYSTACK_ALLOC_MAXIMUM)
1923 YYSIZE_T yyalloc = 2 * yysize;
1924 if (! (yysize <= yyalloc && yyalloc <= YYSTACK_ALLOC_MAXIMUM))
1925 yyalloc = YYSTACK_ALLOC_MAXIMUM;
1926 if (yymsg != yymsgbuf)
1927 YYSTACK_FREE (yymsg);
1928 yymsg = (char *) YYSTACK_ALLOC (yyalloc);
1930 yymsg_alloc = yyalloc;
1934 yymsg_alloc = sizeof yymsgbuf;
1938 if (0 < yysize && yysize <= yymsg_alloc)
1940 (void) yysyntax_error (yymsg, yystate, yychar);
1945 yyerror (YY_("syntax error"));
1947 goto yyexhaustedlab;
1953 yyerror_range[0] = yylloc;
1955 if (yyerrstatus == 3)
1957 /* If just tried and failed to reuse look-ahead token after an
1958 error, discard it. */
1960 if (yychar <= YYEOF)
1962 /* Return failure if at end of input. */
1963 if (yychar == YYEOF)
1968 yydestruct ("Error: discarding",
1969 yytoken, &yylval, &yylloc);
1974 /* Else will try to reuse look-ahead token after shifting the error
1979 /*---------------------------------------------------.
1980 | yyerrorlab -- error raised explicitly by YYERROR. |
1981 `---------------------------------------------------*/
1984 /* Pacify compilers like GCC when the user code never invokes
1985 YYERROR and the label yyerrorlab therefore never appears in user
1987 if (/*CONSTCOND*/ 0)
1990 yyerror_range[0] = yylsp[1-yylen];
1991 /* Do not reclaim the symbols of the rule which action triggered
1995 YY_STACK_PRINT (yyss, yyssp);
2000 /*-------------------------------------------------------------.
2001 | yyerrlab1 -- common code for both syntax error and YYERROR. |
2002 `-------------------------------------------------------------*/
2004 yyerrstatus = 3; /* Each real token shifted decrements this. */
2008 yyn = yypact[yystate];
2009 if (yyn != YYPACT_NINF)
2012 if (0 <= yyn && yyn <= YYLAST && yycheck[yyn] == YYTERROR)
2020 /* Pop the current state because it cannot handle the error token. */
2024 yyerror_range[0] = *yylsp;
2025 yydestruct ("Error: popping",
2026 yystos[yystate], yyvsp, yylsp);
2029 YY_STACK_PRINT (yyss, yyssp);
2037 yyerror_range[1] = yylloc;
2038 /* Using YYLLOC is tempting, but would change the location of
2039 the look-ahead. YYLOC is available though. */
2040 YYLLOC_DEFAULT (yyloc, (yyerror_range - 1), 2);
2043 /* Shift the error token. */
2044 YY_SYMBOL_PRINT ("Shifting", yystos[yyn], yyvsp, yylsp);
2050 /*-------------------------------------.
2051 | yyacceptlab -- YYACCEPT comes here. |
2052 `-------------------------------------*/
2057 /*-----------------------------------.
2058 | yyabortlab -- YYABORT comes here. |
2059 `-----------------------------------*/
2065 /*-------------------------------------------------.
2066 | yyexhaustedlab -- memory exhaustion comes here. |
2067 `-------------------------------------------------*/
2069 yyerror (YY_("memory exhausted"));
2075 if (yychar != YYEOF && yychar != YYEMPTY)
2076 yydestruct ("Cleanup: discarding lookahead",
2077 yytoken, &yylval, &yylloc);
2078 /* Do not reclaim the symbols of the rule which action triggered
2079 this YYABORT or YYACCEPT. */
2081 YY_STACK_PRINT (yyss, yyssp);
2082 while (yyssp != yyss)
2084 yydestruct ("Cleanup: popping",
2085 yystos[*yyssp], yyvsp, yylsp);
2090 YYSTACK_FREE (yyss);
2093 if (yymsg != yymsgbuf)
2094 YYSTACK_FREE (yymsg);
2100 #line 288 "ast_expr2.y"
2104 make_number (FP___TYPE i)
2108 vp = (struct val *) malloc (sizeof (*vp));
2110 ast_log(LOG_WARNING, "malloc() failed\n");
2114 vp->type = AST_EXPR_number;
2120 make_str (const char *s)
2124 int isint; /* this started out being a test for an integer, but then ended up being a test for a float */
2126 vp = (struct val *) malloc (sizeof (*vp));
2127 if (vp == NULL || ((vp->u.s = strdup (s)) == NULL)) {
2128 ast_log(LOG_WARNING,"malloc() failed\n");
2132 for (i = 0, isint = (isdigit(s[0]) || s[0] == '-' || s[0]=='.'); isint && i < strlen(s); i++)
2134 if (!isdigit(s[i]) && s[i] != '.') {
2140 vp->type = AST_EXPR_numeric_string;
2142 vp->type = AST_EXPR_string;
2149 free_value (struct val *vp)
2154 if (vp->type == AST_EXPR_string || vp->type == AST_EXPR_numeric_string)
2161 to_number (struct val *vp)
2166 ast_log(LOG_WARNING,"vp==NULL in to_number()\n");
2170 if (vp->type == AST_EXPR_number)
2173 if (vp->type == AST_EXPR_string)
2176 /* vp->type == AST_EXPR_numeric_string, make it numeric */
2178 i = FP___STRTOD(vp->u.s, (char**)0); /* either strtod, or strtold on a good day */
2180 ast_log(LOG_WARNING,"Conversion of %s to number under/overflowed!\n", vp->u.s);
2187 vp->type = AST_EXPR_number;
2192 strip_quotes(struct val *vp)
2194 if (vp->type != AST_EXPR_string && vp->type != AST_EXPR_numeric_string)
2197 if( vp->u.s[0] == '"' && vp->u.s[strlen(vp->u.s)-1] == '"' )
2205 if( *f && *f != '"' )
2215 to_string (struct val *vp)
2219 if (vp->type == AST_EXPR_string || vp->type == AST_EXPR_numeric_string)
2222 tmp = malloc ((size_t)25);
2224 ast_log(LOG_WARNING,"malloc() failed\n");
2228 sprintf(tmp, FP___PRINTF, vp->u.i);
2229 vp->type = AST_EXPR_string;
2235 isstring (struct val *vp)
2237 /* only TRUE if this string is not a valid number */
2238 return (vp->type == AST_EXPR_string);
2243 is_zero_or_null (struct val *vp)
2245 if (vp->type == AST_EXPR_number) {
2246 return (vp->u.i == 0);
2248 return (*vp->u.s == 0 || (to_number(vp) && vp->u.i == 0));
2255 void ast_log(int level, const char *file, int line, const char *function, const char *fmt, ...)
2260 printf("LOG: lev:%d file:%s line:%d func: %s ",
2261 level, file, line, function);
2268 int main(int argc,char **argv) {
2276 if( access(argv[1],F_OK)== 0 )
2280 infile = fopen(argv[1],"r");
2283 printf("Sorry, couldn't open %s for reading!\n", argv[1]);
2286 while( fgets(s,sizeof(s),infile) )
2288 if( s[strlen(s)-1] == '\n' )
2291 ret = ast_expr(s, out, sizeof(out));
2292 printf("Expression: %s Result: [%d] '%s'\n",
2299 if (ast_expr(argv[1], s, sizeof(s)))
2300 printf("=====%s======\n",s);
2302 printf("No result\n");
2309 #define ast_yyerror(x) ast_yyerror(x, YYLTYPE *yylloc, struct parse_io *parseio)
2311 /* I put the ast_yyerror func in the flex input file,
2312 because it refers to the buffer state. Best to
2313 let it access the BUFFER stuff there and not trying
2314 define all the structs, macros etc. in this file! */
2318 op_or (struct val *a, struct val *b)
2320 if (is_zero_or_null (a)) {
2330 op_and (struct val *a, struct val *b)
2332 if (is_zero_or_null (a) || is_zero_or_null (b)) {
2335 return (make_number ((double)0.0));
2343 op_eq (struct val *a, struct val *b)
2347 if (isstring (a) || isstring (b)) {
2350 r = make_number ((FP___TYPE)(strcoll (a->u.s, b->u.s) == 0));
2352 #ifdef DEBUG_FOR_CONVERSIONS
2354 sprintf(buffer,"Converting '%s' and '%s' ", a->u.s, b->u.s);
2358 #ifdef DEBUG_FOR_CONVERSIONS
2359 ast_log(LOG_WARNING,"%s to '%lld' and '%lld'\n", buffer, a->u.i, b->u.i);
2361 r = make_number ((FP___TYPE)(a->u.i == b->u.i));
2370 op_gt (struct val *a, struct val *b)
2374 if (isstring (a) || isstring (b)) {
2377 r = make_number ((FP___TYPE)(strcoll (a->u.s, b->u.s) > 0));
2381 r = make_number ((FP___TYPE)(a->u.i > b->u.i));
2390 op_lt (struct val *a, struct val *b)
2394 if (isstring (a) || isstring (b)) {
2397 r = make_number ((FP___TYPE)(strcoll (a->u.s, b->u.s) < 0));
2401 r = make_number ((FP___TYPE)(a->u.i < b->u.i));
2410 op_ge (struct val *a, struct val *b)
2414 if (isstring (a) || isstring (b)) {
2417 r = make_number ((FP___TYPE)(strcoll (a->u.s, b->u.s) >= 0));
2421 r = make_number ((FP___TYPE)(a->u.i >= b->u.i));
2430 op_le (struct val *a, struct val *b)
2434 if (isstring (a) || isstring (b)) {
2437 r = make_number ((FP___TYPE)(strcoll (a->u.s, b->u.s) <= 0));
2441 r = make_number ((FP___TYPE)(a->u.i <= b->u.i));
2450 op_cond (struct val *a, struct val *b, struct val *c)
2456 if( strlen(a->u.s) && strcmp(a->u.s, "\"\"") != 0 && strcmp(a->u.s,"0") != 0 )
2489 op_ne (struct val *a, struct val *b)
2493 if (isstring (a) || isstring (b)) {
2496 r = make_number ((FP___TYPE)(strcoll (a->u.s, b->u.s) != 0));
2500 r = make_number ((FP___TYPE)(a->u.i != b->u.i));
2509 chk_plus (FP___TYPE a, FP___TYPE b, FP___TYPE r)
2511 /* sum of two positive numbers must be positive */
2512 if (a > 0 && b > 0 && r <= 0)
2514 /* sum of two negative numbers must be negative */
2515 if (a < 0 && b < 0 && r >= 0)
2517 /* all other cases are OK */
2522 op_plus (struct val *a, struct val *b)
2526 if (!to_number (a)) {
2527 if( !extra_error_message_supplied )
2528 ast_log(LOG_WARNING,"non-numeric argument\n");
2529 if (!to_number (b)) {
2532 return make_number(0);
2537 } else if (!to_number(b)) {
2542 r = make_number (a->u.i + b->u.i);
2543 if (chk_plus (a->u.i, b->u.i, r->u.i)) {
2544 ast_log(LOG_WARNING,"overflow\n");
2552 chk_minus (FP___TYPE a, FP___TYPE b, FP___TYPE r)
2554 /* special case subtraction of QUAD_MIN */
2555 if (b == QUAD_MIN) {
2561 /* this is allowed for b != QUAD_MIN */
2562 return chk_plus (a, -b, r);
2566 op_minus (struct val *a, struct val *b)
2570 if (!to_number (a)) {
2571 if( !extra_error_message_supplied )
2572 ast_log(LOG_WARNING, "non-numeric argument\n");
2573 if (!to_number (b)) {
2576 return make_number(0);
2578 r = make_number(0 - b->u.i);
2583 } else if (!to_number(b)) {
2584 if( !extra_error_message_supplied )
2585 ast_log(LOG_WARNING, "non-numeric argument\n");
2590 r = make_number (a->u.i - b->u.i);
2591 if (chk_minus (a->u.i, b->u.i, r->u.i)) {
2592 ast_log(LOG_WARNING, "overflow\n");
2600 op_negate (struct val *a)
2604 if (!to_number (a) ) {
2606 if( !extra_error_message_supplied )
2607 ast_log(LOG_WARNING, "non-numeric argument\n");
2608 return make_number(0);
2611 r = make_number (- a->u.i);
2612 if (chk_minus (0, a->u.i, r->u.i)) {
2613 ast_log(LOG_WARNING, "overflow\n");
2620 op_compl (struct val *a)
2633 case AST_EXPR_number:
2638 case AST_EXPR_string:
2643 if( a->u.s[0] == 0 )
2645 else if (strlen(a->u.s) == 1 && a->u.s[0] == '0' )
2650 case AST_EXPR_numeric_string:
2655 if( a->u.s[0] == 0 )
2657 else if (strlen(a->u.s) == 1 && a->u.s[0] == '0' )
2664 r = make_number (!v1);
2670 chk_times (FP___TYPE a, FP___TYPE b, FP___TYPE r)
2672 /* special case: first operand is 0, no overflow possible */
2675 /* cerify that result of division matches second operand */
2682 op_times (struct val *a, struct val *b)
2686 if (!to_number (a) || !to_number (b)) {
2689 if( !extra_error_message_supplied )
2690 ast_log(LOG_WARNING, "non-numeric argument\n");
2691 return(make_number(0));
2694 r = make_number (a->u.i * b->u.i);
2695 if (chk_times (a->u.i, b->u.i, r->u.i)) {
2696 ast_log(LOG_WARNING, "overflow\n");
2704 chk_div (FP___TYPE a, FP___TYPE b)
2706 /* div by zero has been taken care of before */
2707 /* only QUAD_MIN / -1 causes overflow */
2708 if (a == QUAD_MIN && b == -1)
2710 /* everything else is OK */
2715 op_div (struct val *a, struct val *b)
2719 if (!to_number (a)) {
2722 if( !extra_error_message_supplied )
2723 ast_log(LOG_WARNING, "non-numeric argument\n");
2724 return make_number(0);
2725 } else if (!to_number (b)) {
2728 if( !extra_error_message_supplied )
2729 ast_log(LOG_WARNING, "non-numeric argument\n");
2730 return make_number(INT_MAX);
2734 ast_log(LOG_WARNING, "division by zero\n");
2737 return make_number(INT_MAX);
2740 r = make_number (a->u.i / b->u.i);
2741 if (chk_div (a->u.i, b->u.i)) {
2742 ast_log(LOG_WARNING, "overflow\n");
2750 op_rem (struct val *a, struct val *b)
2754 if (!to_number (a) || !to_number (b)) {
2755 if( !extra_error_message_supplied )
2756 ast_log(LOG_WARNING, "non-numeric argument\n");
2759 return make_number(0);
2763 ast_log(LOG_WARNING, "div by zero\n");
2768 r = make_number (FP___FMOD(a->u.i, b->u.i)); /* either fmod or fmodl if FP___TYPE is available */
2769 /* chk_rem necessary ??? */
2777 op_colon (struct val *a, struct val *b)
2785 /* coerce to both arguments to strings */
2788 /* strip double quotes from both -- they'll screw up the pattern, and the search string starting at ^ */
2791 /* compile regular expression */
2792 if ((eval = regcomp (&rp, b->u.s, REG_EXTENDED)) != 0) {
2793 regerror (eval, &rp, errbuf, sizeof(errbuf));
2794 ast_log(LOG_WARNING,"regcomp() error : %s",errbuf);
2797 return make_str("");
2800 /* compare string against pattern */
2801 /* remember that patterns are anchored to the beginning of the line */
2802 if (regexec(&rp, a->u.s, (size_t)2, rm, 0) == 0 && rm[0].rm_so == 0) {
2803 if (rm[1].rm_so >= 0) {
2804 *(a->u.s + rm[1].rm_eo) = '\0';
2805 v = make_str (a->u.s + rm[1].rm_so);
2808 v = make_number ((FP___TYPE)(rm[0].rm_eo - rm[0].rm_so));
2811 if (rp.re_nsub == 0) {
2812 v = make_number ((FP___TYPE)0);
2818 /* free arguments and pattern buffer */
2828 op_eqtilde (struct val *a, struct val *b)
2836 /* coerce to both arguments to strings */
2839 /* strip double quotes from both -- they'll screw up the pattern, and the search string starting at ^ */
2842 /* compile regular expression */
2843 if ((eval = regcomp (&rp, b->u.s, REG_EXTENDED)) != 0) {
2844 regerror (eval, &rp, errbuf, sizeof(errbuf));
2845 ast_log(LOG_WARNING,"regcomp() error : %s",errbuf);
2848 return make_str("");
2851 /* compare string against pattern */
2852 /* remember that patterns are anchored to the beginning of the line */
2853 if (regexec(&rp, a->u.s, (size_t)2, rm, 0) == 0 ) {
2854 if (rm[1].rm_so >= 0) {
2855 *(a->u.s + rm[1].rm_eo) = '\0';
2856 v = make_str (a->u.s + rm[1].rm_so);
2859 v = make_number ((FP___TYPE)(rm[0].rm_eo - rm[0].rm_so));
2862 if (rp.re_nsub == 0) {
2863 v = make_number ((FP___TYPE)0.0);
2869 /* free arguments and pattern buffer */