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 "asterisk.h"
135 ASTERISK_FILE_VERSION(__FILE__
, "$Revision$")
138 #include <sys/types.h>
145 #if !defined(SOLARIS) && !defined(__CYGWIN__)
146 /* #include <err.h> */
148 #define quad_t int64_t
154 #include "asterisk/ast_expr.h"
155 #include "asterisk/logger.h"
157 #if defined(LONG_LONG_MIN) && !defined(QUAD_MIN)
158 #define QUAD_MIN LONG_LONG_MIN
160 #if defined(LONG_LONG_MAX) && !defined(QUAD_MAX)
161 #define QUAD_MAX LONG_LONG_MAX
164 # if ! defined(QUAD_MIN)
165 # define QUAD_MIN (-0x7fffffffffffffffLL-1)
167 # if ! defined(QUAD_MAX)
168 # define QUAD_MAX (0x7fffffffffffffffLL)
171 #define YYPARSE_PARAM parseio
172 #define YYLEX_PARAM ((struct parse_io *)parseio)->scanner
173 #define YYERROR_VERBOSE 1
174 extern char extra_error_message
[4095];
175 extern int extra_error_message_supplied
;
178 AST_EXPR_integer
, AST_EXPR_numeric_string
, AST_EXPR_string
182 void ast_log(int level
, const char *file
, int line
, const char *function
, const char *fmt
, ...) __attribute__ ((format (printf
,5,6)));
193 typedef void *yyscan_t
;
202 static int chk_div
__P((quad_t
, quad_t
));
203 static int chk_minus
__P((quad_t
, quad_t
, quad_t
));
204 static int chk_plus
__P((quad_t
, quad_t
, quad_t
));
205 static int chk_times
__P((quad_t
, quad_t
, quad_t
));
206 static void free_value
__P((struct val
*));
207 static int is_zero_or_null
__P((struct val
*));
208 static int isstring
__P((struct val
*));
209 static struct val
*make_integer
__P((quad_t
));
210 static struct val
*make_str
__P((const char *));
211 static struct val
*op_and
__P((struct val
*, struct val
*));
212 static struct val
*op_colon
__P((struct val
*, struct val
*));
213 static struct val
*op_eqtilde
__P((struct val
*, struct val
*));
214 static struct val
*op_div
__P((struct val
*, struct val
*));
215 static struct val
*op_eq
__P((struct val
*, struct val
*));
216 static struct val
*op_ge
__P((struct val
*, struct val
*));
217 static struct val
*op_gt
__P((struct val
*, struct val
*));
218 static struct val
*op_le
__P((struct val
*, struct val
*));
219 static struct val
*op_lt
__P((struct val
*, struct val
*));
220 static struct val
*op_cond
__P((struct val
*, struct val
*, struct val
*));
221 static struct val
*op_minus
__P((struct val
*, struct val
*));
222 static struct val
*op_negate
__P((struct val
*));
223 static struct val
*op_compl
__P((struct val
*));
224 static struct val
*op_ne
__P((struct val
*, struct val
*));
225 static struct val
*op_or
__P((struct val
*, struct val
*));
226 static struct val
*op_plus
__P((struct val
*, struct val
*));
227 static struct val
*op_rem
__P((struct val
*, struct val
*));
228 static struct val
*op_times
__P((struct val
*, struct val
*));
229 static quad_t to_integer
__P((struct val
*));
230 static void to_string
__P((struct val
*));
232 /* uh, if I want to predeclare yylex with a YYLTYPE, I have to predeclare the yyltype... sigh */
233 typedef struct yyltype
242 # define YYLTYPE yyltype
243 # define YYLTYPE_IS_TRIVIAL 1
245 /* we will get warning about no prototype for yylex! But we can't
246 define it here, we have no definition yet for YYSTYPE. */
248 int ast_yyerror(const char *,YYLTYPE
*, struct parse_io
*);
250 /* I wanted to add args to the yyerror routine, so I could print out
251 some useful info about the error. Not as easy as it looks, but it
253 #define ast_yyerror(x) ast_yyerror(x,&yyloc,parseio)
254 #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);}
257 /* Enabling traces. */
262 /* Enabling verbose error messages. */
263 #ifdef YYERROR_VERBOSE
264 # undef YYERROR_VERBOSE
265 # define YYERROR_VERBOSE 1
267 # define YYERROR_VERBOSE 0
270 /* Enabling the token table. */
271 #ifndef YYTOKEN_TABLE
272 # define YYTOKEN_TABLE 0
275 #if ! defined YYSTYPE && ! defined YYSTYPE_IS_DECLARED
276 typedef union YYSTYPE
277 #line 147 "ast_expr2.y"
281 /* Line 198 of yacc.c. */
282 #line 283 "ast_expr2.c"
284 # define yystype YYSTYPE /* obsolescent; will be withdrawn */
285 # define YYSTYPE_IS_DECLARED 1
286 # define YYSTYPE_IS_TRIVIAL 1
289 #if ! defined YYLTYPE && ! defined YYLTYPE_IS_DECLARED
290 typedef struct YYLTYPE
297 # define yyltype YYLTYPE /* obsolescent; will be withdrawn */
298 # define YYLTYPE_IS_DECLARED 1
299 # define YYLTYPE_IS_TRIVIAL 1
303 /* Copy the second part of user declarations. */
304 #line 151 "ast_expr2.y"
306 extern int ast_yylex
__P((YYSTYPE
*, YYLTYPE
*, yyscan_t
));
309 /* Line 221 of yacc.c. */
310 #line 311 "ast_expr2.c"
317 typedef YYTYPE_UINT8 yytype_uint8
;
319 typedef unsigned char yytype_uint8
;
323 typedef YYTYPE_INT8 yytype_int8
;
324 #elif (defined __STDC__ || defined __C99__FUNC__ \
325 || defined __cplusplus || defined _MSC_VER)
326 typedef signed char yytype_int8
;
328 typedef short int yytype_int8
;
332 typedef YYTYPE_UINT16 yytype_uint16
;
334 typedef unsigned short int yytype_uint16
;
338 typedef YYTYPE_INT16 yytype_int16
;
340 typedef short int yytype_int16
;
344 # ifdef __SIZE_TYPE__
345 # define YYSIZE_T __SIZE_TYPE__
346 # elif defined size_t
347 # define YYSIZE_T size_t
348 # elif ! defined YYSIZE_T && (defined __STDC__ || defined __C99__FUNC__ \
349 || defined __cplusplus || defined _MSC_VER)
350 # include <stddef.h> /* INFRINGES ON USER NAME SPACE */
351 # define YYSIZE_T size_t
353 # define YYSIZE_T unsigned int
357 #define YYSIZE_MAXIMUM ((YYSIZE_T) -1)
362 # include <libintl.h> /* INFRINGES ON USER NAME SPACE */
363 # define YY_(msgid) dgettext ("bison-runtime", msgid)
367 # define YY_(msgid) msgid
371 /* Suppress unused-variable warnings by "using" E. */
372 #if ! defined lint || defined __GNUC__
373 # define YYUSE(e) ((void) (e))
375 # define YYUSE(e) /* empty */
378 /* Identity function, used to suppress warnings about constant conditions. */
382 #if (defined __STDC__ || defined __C99__FUNC__ \
383 || defined __cplusplus || defined _MSC_VER)
396 #if ! defined yyoverflow || YYERROR_VERBOSE
398 /* The parser invokes alloca or malloc; define the necessary symbols. */
400 # ifdef YYSTACK_USE_ALLOCA
401 # if YYSTACK_USE_ALLOCA
403 # define YYSTACK_ALLOC __builtin_alloca
404 # elif defined __BUILTIN_VA_ARG_INCR
405 # include <alloca.h> /* INFRINGES ON USER NAME SPACE */
407 # define YYSTACK_ALLOC __alloca
408 # elif defined _MSC_VER
409 # include <malloc.h> /* INFRINGES ON USER NAME SPACE */
410 # define alloca _alloca
412 # define YYSTACK_ALLOC alloca
413 # if ! defined _ALLOCA_H && ! defined _STDLIB_H && (defined __STDC__ || defined __C99__FUNC__ \
414 || defined __cplusplus || defined _MSC_VER)
415 # include <stdlib.h> /* INFRINGES ON USER NAME SPACE */
424 # ifdef YYSTACK_ALLOC
425 /* Pacify GCC's `empty if-body' warning. */
426 # define YYSTACK_FREE(Ptr) do { /* empty */; } while (YYID (0))
427 # ifndef YYSTACK_ALLOC_MAXIMUM
428 /* The OS might guarantee only one guard page at the bottom of the stack,
429 and a page size can be as small as 4096 bytes. So we cannot safely
430 invoke alloca (N) if N exceeds 4096. Use a slightly smaller number
431 to allow for a few compiler-allocated temporary stack slots. */
432 # define YYSTACK_ALLOC_MAXIMUM 4032 /* reasonable circa 2006 */
435 # define YYSTACK_ALLOC YYMALLOC
436 # define YYSTACK_FREE YYFREE
437 # ifndef YYSTACK_ALLOC_MAXIMUM
438 # define YYSTACK_ALLOC_MAXIMUM YYSIZE_MAXIMUM
444 # define YYMALLOC malloc
445 # if ! defined malloc && ! defined _STDLIB_H && (defined __STDC__ || defined __C99__FUNC__ \
446 || defined __cplusplus || defined _MSC_VER)
447 void *malloc (YYSIZE_T
); /* INFRINGES ON USER NAME SPACE */
452 # if ! defined free && ! defined _STDLIB_H && (defined __STDC__ || defined __C99__FUNC__ \
453 || defined __cplusplus || defined _MSC_VER)
454 void free (void *); /* INFRINGES ON USER NAME SPACE */
461 #endif /* ! defined yyoverflow || YYERROR_VERBOSE */
464 #if (! defined yyoverflow \
465 && (! defined __cplusplus \
466 || (defined YYLTYPE_IS_TRIVIAL && YYLTYPE_IS_TRIVIAL \
467 && defined YYSTYPE_IS_TRIVIAL && YYSTYPE_IS_TRIVIAL)))
469 /* A type that is properly aligned for any stack member. */
477 /* The size of the maximum gap between one aligned stack and the next. */
478 # define YYSTACK_GAP_MAXIMUM (sizeof (union yyalloc) - 1)
480 /* The size of an array large to enough to hold all stacks, each with
482 # define YYSTACK_BYTES(N) \
483 ((N) * (sizeof (yytype_int16) + sizeof (YYSTYPE) + sizeof (YYLTYPE)) \
484 + 2 * YYSTACK_GAP_MAXIMUM)
486 /* Copy COUNT objects from FROM to TO. The source and destination do
489 # if defined __GNUC__ && 1 < __GNUC__
490 # define YYCOPY(To, From, Count) \
491 __builtin_memcpy (To, From, (Count) * sizeof (*(From)))
493 # define YYCOPY(To, From, Count) \
497 for (yyi = 0; yyi < (Count); yyi++) \
498 (To)[yyi] = (From)[yyi]; \
504 /* Relocate STACK from its old location to the new one. The
505 local variables YYSIZE and YYSTACKSIZE give the old and new number of
506 elements in the stack, and YYPTR gives the new location of the
507 stack. Advance YYPTR to a properly aligned location for the next
509 # define YYSTACK_RELOCATE(Stack) \
512 YYSIZE_T yynewbytes; \
513 YYCOPY (&yyptr->Stack, Stack, yysize); \
514 Stack = &yyptr->Stack; \
515 yynewbytes = yystacksize * sizeof (*Stack) + YYSTACK_GAP_MAXIMUM; \
516 yyptr += yynewbytes / sizeof (*yyptr); \
522 /* YYFINAL -- State number of the termination state. */
524 /* YYLAST -- Last index in YYTABLE. */
527 /* YYNTOKENS -- Number of terminals. */
529 /* YYNNTS -- Number of nonterminals. */
531 /* YYNRULES -- Number of rules. */
533 /* YYNRULES -- Number of states. */
536 /* YYTRANSLATE(YYLEX) -- Bison symbol number corresponding to YYLEX. */
538 #define YYMAXUTOK 278
540 #define YYTRANSLATE(YYX) \
541 ((unsigned int) (YYX) <= YYMAXUTOK ? yytranslate[YYX] : YYUNDEFTOK)
543 /* YYTRANSLATE[YYLEX] -- Bison symbol number corresponding to YYLEX. */
544 static const yytype_uint8 yytranslate
[] =
546 0, 2, 2, 2, 2, 2, 2, 2, 2, 2,
547 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
548 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
549 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
550 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
551 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
552 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
553 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
554 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
555 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
556 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
557 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
558 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
559 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
560 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
561 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
562 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
563 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
564 2, 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, 1, 2, 3, 4,
572 5, 6, 7, 8, 9, 10, 11, 12, 13, 14,
573 15, 16, 17, 18, 19, 20, 21, 22, 23
577 /* YYPRHS[YYN] -- Index of the first RHS symbol of rule number YYN in
579 static const yytype_uint8 yyprhs
[] =
581 0, 0, 3, 5, 6, 8, 12, 16, 20, 24,
582 28, 32, 36, 40, 44, 48, 52, 55, 58, 62,
586 /* YYRHS -- A `-1'-separated list of the rules' RHS. */
587 static const yytype_int8 yyrhs
[] =
589 25, 0, -1, 26, -1, -1, 23, -1, 21, 26,
590 22, -1, 26, 5, 26, -1, 26, 6, 26, -1,
591 26, 12, 26, -1, 26, 11, 26, -1, 26, 10,
592 26, -1, 26, 9, 26, -1, 26, 8, 26, -1,
593 26, 7, 26, -1, 26, 14, 26, -1, 26, 13,
594 26, -1, 13, 26, -1, 18, 26, -1, 26, 17,
595 26, -1, 26, 16, 26, -1, 26, 15, 26, -1,
596 26, 20, 26, -1, 26, 19, 26, -1, 26, 4,
600 /* YYRLINE[YYN] -- source line where rule number YYN was defined. */
601 static const yytype_uint16 yyrline
[] =
603 0, 175, 175, 183, 190, 191, 195, 199, 203, 207,
604 211, 215, 219, 223, 227, 231, 235, 239, 243, 247,
609 #if YYDEBUG || YYERROR_VERBOSE || YYTOKEN_TABLE
610 /* YYTNAME[SYMBOL-NUM] -- String name of the symbol SYMBOL-NUM.
611 First, the terminals, then, starting at YYNTOKENS, nonterminals. */
612 static const char *const yytname
[] =
614 "$end", "error", "$undefined", "TOK_COLONCOLON", "TOK_COND", "TOK_OR",
615 "TOK_AND", "TOK_NE", "TOK_LE", "TOK_GE", "TOK_LT", "TOK_GT", "TOK_EQ",
616 "TOK_MINUS", "TOK_PLUS", "TOK_MOD", "TOK_DIV", "TOK_MULT", "TOK_COMPL",
617 "TOK_EQTILDE", "TOK_COLON", "TOK_LP", "TOK_RP", "TOKEN", "$accept",
623 /* YYTOKNUM[YYLEX-NUM] -- Internal token number corresponding to
625 static const yytype_uint16 yytoknum
[] =
627 0, 256, 257, 258, 259, 260, 261, 262, 263, 264,
628 265, 266, 267, 268, 269, 270, 271, 272, 273, 274,
633 /* YYR1[YYN] -- Symbol number of symbol that rule YYN derives. */
634 static const yytype_uint8 yyr1
[] =
636 0, 24, 25, 25, 26, 26, 26, 26, 26, 26,
637 26, 26, 26, 26, 26, 26, 26, 26, 26, 26,
641 /* YYR2[YYN] -- Number of symbols composing right hand side of rule YYN. */
642 static const yytype_uint8 yyr2
[] =
644 0, 2, 1, 0, 1, 3, 3, 3, 3, 3,
645 3, 3, 3, 3, 3, 3, 2, 2, 3, 3,
649 /* YYDEFACT[STATE-NAME] -- Default rule to reduce with in state
650 STATE-NUM when YYTABLE doesn't specify something else to do. Zero
651 means the default is an error. */
652 static const yytype_uint8 yydefact
[] =
654 3, 0, 0, 0, 4, 0, 2, 16, 17, 0,
655 1, 0, 0, 0, 0, 0, 0, 0, 0, 0,
656 0, 0, 0, 0, 0, 0, 0, 5, 0, 6,
657 7, 13, 12, 11, 10, 9, 8, 15, 14, 20,
658 19, 18, 22, 21, 0, 23
661 /* YYDEFGOTO[NTERM-NUM]. */
662 static const yytype_int8 yydefgoto
[] =
667 /* YYPACT[STATE-NUM] -- Index in YYTABLE of the portion describing
669 #define YYPACT_NINF -13
670 static const yytype_int8 yypact
[] =
672 109, 109, 109, 109, -13, 6, 59, 106, 106, 22,
673 -13, 109, 109, 109, 109, 109, 109, 109, 109, 109,
674 109, 109, 109, 109, 109, 109, 109, -13, 42, 90,
675 104, 120, 120, 120, 120, 120, 120, -12, -12, 106,
676 106, 106, -13, -13, 109, 75
679 /* YYPGOTO[NTERM-NUM]. */
680 static const yytype_int8 yypgoto
[] =
685 /* YYTABLE[YYPACT[STATE-NUM]]. What to do in state STATE-NUM. If
686 positive, shift that token. If negative, reduce the rule which
687 number is the opposite. If zero, do what YYDEFACT says.
688 If YYTABLE_NINF, syntax error. */
689 #define YYTABLE_NINF -1
690 static const yytype_uint8 yytable
[] =
692 7, 8, 9, 22, 23, 24, 10, 25, 26, 0,
693 28, 29, 30, 31, 32, 33, 34, 35, 36, 37,
694 38, 39, 40, 41, 42, 43, 11, 12, 13, 14,
695 15, 16, 17, 18, 19, 20, 21, 22, 23, 24,
696 0, 25, 26, 45, 27, 44, 11, 12, 13, 14,
697 15, 16, 17, 18, 19, 20, 21, 22, 23, 24,
698 0, 25, 26, 11, 12, 13, 14, 15, 16, 17,
699 18, 19, 20, 21, 22, 23, 24, 0, 25, 26,
700 12, 13, 14, 15, 16, 17, 18, 19, 20, 21,
701 22, 23, 24, 0, 25, 26, 13, 14, 15, 16,
702 17, 18, 19, 20, 21, 22, 23, 24, 0, 25,
703 26, 14, 15, 16, 17, 18, 19, 20, 21, 22,
704 23, 24, 1, 25, 26, 25, 26, 2, 0, 0,
705 3, 0, 4, 20, 21, 22, 23, 24, 0, 25,
709 static const yytype_int8 yycheck
[] =
711 1, 2, 3, 15, 16, 17, 0, 19, 20, -1,
712 11, 12, 13, 14, 15, 16, 17, 18, 19, 20,
713 21, 22, 23, 24, 25, 26, 4, 5, 6, 7,
714 8, 9, 10, 11, 12, 13, 14, 15, 16, 17,
715 -1, 19, 20, 44, 22, 3, 4, 5, 6, 7,
716 8, 9, 10, 11, 12, 13, 14, 15, 16, 17,
717 -1, 19, 20, 4, 5, 6, 7, 8, 9, 10,
718 11, 12, 13, 14, 15, 16, 17, -1, 19, 20,
719 5, 6, 7, 8, 9, 10, 11, 12, 13, 14,
720 15, 16, 17, -1, 19, 20, 6, 7, 8, 9,
721 10, 11, 12, 13, 14, 15, 16, 17, -1, 19,
722 20, 7, 8, 9, 10, 11, 12, 13, 14, 15,
723 16, 17, 13, 19, 20, 19, 20, 18, -1, -1,
724 21, -1, 23, 13, 14, 15, 16, 17, -1, 19,
728 /* YYSTOS[STATE-NUM] -- The (internal number of the) accessing
729 symbol of state STATE-NUM. */
730 static const yytype_uint8 yystos
[] =
732 0, 13, 18, 21, 23, 25, 26, 26, 26, 26,
733 0, 4, 5, 6, 7, 8, 9, 10, 11, 12,
734 13, 14, 15, 16, 17, 19, 20, 22, 26, 26,
735 26, 26, 26, 26, 26, 26, 26, 26, 26, 26,
736 26, 26, 26, 26, 3, 26
739 #define yyerrok (yyerrstatus = 0)
740 #define yyclearin (yychar = YYEMPTY)
744 #define YYACCEPT goto yyacceptlab
745 #define YYABORT goto yyabortlab
746 #define YYERROR goto yyerrorlab
749 /* Like YYERROR except do call yyerror. This remains here temporarily
750 to ease the transition to the new meaning of YYERROR, for GCC.
751 Once GCC version 2 has supplanted version 1, this can go. */
753 #define YYFAIL goto yyerrlab
755 #define YYRECOVERING() (!!yyerrstatus)
757 #define YYBACKUP(Token, Value) \
759 if (yychar == YYEMPTY && yylen == 1) \
763 yytoken = YYTRANSLATE (yychar); \
769 yyerror (YY_("syntax error: cannot back up")); \
776 #define YYERRCODE 256
779 /* YYLLOC_DEFAULT -- Set CURRENT to span from RHS[1] to RHS[N].
780 If N is 0, then set CURRENT to the empty location which ends
781 the previous symbol: RHS[0] (always defined). */
783 #define YYRHSLOC(Rhs, K) ((Rhs)[K])
784 #ifndef YYLLOC_DEFAULT
785 # define YYLLOC_DEFAULT(Current, Rhs, N) \
789 (Current).first_line = YYRHSLOC (Rhs, 1).first_line; \
790 (Current).first_column = YYRHSLOC (Rhs, 1).first_column; \
791 (Current).last_line = YYRHSLOC (Rhs, N).last_line; \
792 (Current).last_column = YYRHSLOC (Rhs, N).last_column; \
796 (Current).first_line = (Current).last_line = \
797 YYRHSLOC (Rhs, 0).last_line; \
798 (Current).first_column = (Current).last_column = \
799 YYRHSLOC (Rhs, 0).last_column; \
805 /* YY_LOCATION_PRINT -- Print the location on the stream.
806 This macro was not mandated originally: define only if we know
807 we won't break user code: when these are the locations we know. */
809 #ifndef YY_LOCATION_PRINT
810 # if YYLTYPE_IS_TRIVIAL
811 # define YY_LOCATION_PRINT(File, Loc) \
812 fprintf (File, "%d.%d-%d.%d", \
813 (Loc).first_line, (Loc).first_column, \
814 (Loc).last_line, (Loc).last_column)
816 # define YY_LOCATION_PRINT(File, Loc) ((void) 0)
821 /* YYLEX -- calling `yylex' with the right arguments. */
824 # define YYLEX yylex (&yylval, &yylloc, YYLEX_PARAM)
826 # define YYLEX yylex (&yylval, &yylloc)
829 /* Enable debugging if requested. */
833 # include <stdio.h> /* INFRINGES ON USER NAME SPACE */
834 # define YYFPRINTF fprintf
837 # define YYDPRINTF(Args) \
843 # define YY_SYMBOL_PRINT(Title, Type, Value, Location) \
847 YYFPRINTF (stderr, "%s ", Title); \
848 yy_symbol_print (stderr, \
849 Type, Value, Location); \
850 YYFPRINTF (stderr, "\n"); \
855 /*--------------------------------.
856 | Print this symbol on YYOUTPUT. |
857 `--------------------------------*/
860 #if (defined __STDC__ || defined __C99__FUNC__ \
861 || defined __cplusplus || defined _MSC_VER)
863 yy_symbol_value_print (FILE *yyoutput
, int yytype
, const YYSTYPE
* const yyvaluep
, const YYLTYPE
* const yylocationp
)
866 yy_symbol_value_print (yyoutput
, yytype
, yyvaluep
, yylocationp
)
869 const YYSTYPE
* const yyvaluep
;
870 const YYLTYPE
* const yylocationp
;
877 if (yytype
< YYNTOKENS
)
878 YYPRINT (yyoutput
, yytoknum
[yytype
], *yyvaluep
);
890 /*--------------------------------.
891 | Print this symbol on YYOUTPUT. |
892 `--------------------------------*/
894 #if (defined __STDC__ || defined __C99__FUNC__ \
895 || defined __cplusplus || defined _MSC_VER)
897 yy_symbol_print (FILE *yyoutput
, int yytype
, const YYSTYPE
* const yyvaluep
, const YYLTYPE
* const yylocationp
)
900 yy_symbol_print (yyoutput
, yytype
, yyvaluep
, yylocationp
)
903 const YYSTYPE
* const yyvaluep
;
904 const YYLTYPE
* const yylocationp
;
907 if (yytype
< YYNTOKENS
)
908 YYFPRINTF (yyoutput
, "token %s (", yytname
[yytype
]);
910 YYFPRINTF (yyoutput
, "nterm %s (", yytname
[yytype
]);
912 YY_LOCATION_PRINT (yyoutput
, *yylocationp
);
913 YYFPRINTF (yyoutput
, ": ");
914 yy_symbol_value_print (yyoutput
, yytype
, yyvaluep
, yylocationp
);
915 YYFPRINTF (yyoutput
, ")");
918 /*------------------------------------------------------------------.
919 | yy_stack_print -- Print the state stack from its BOTTOM up to its |
921 `------------------------------------------------------------------*/
923 #if (defined __STDC__ || defined __C99__FUNC__ \
924 || defined __cplusplus || defined _MSC_VER)
926 yy_stack_print (yytype_int16
*bottom
, yytype_int16
*top
)
929 yy_stack_print (bottom
, top
)
930 yytype_int16
*bottom
;
934 YYFPRINTF (stderr
, "Stack now");
935 for (; bottom
<= top
; ++bottom
)
936 YYFPRINTF (stderr
, " %d", *bottom
);
937 YYFPRINTF (stderr
, "\n");
940 # define YY_STACK_PRINT(Bottom, Top) \
943 yy_stack_print ((Bottom), (Top)); \
947 /*------------------------------------------------.
948 | Report that the YYRULE is going to be reduced. |
949 `------------------------------------------------*/
951 #if (defined __STDC__ || defined __C99__FUNC__ \
952 || defined __cplusplus || defined _MSC_VER)
954 yy_reduce_print (YYSTYPE
*yyvsp
, YYLTYPE
*yylsp
, int yyrule
)
957 yy_reduce_print (yyvsp
, yylsp
, yyrule
964 int yynrhs
= yyr2
[yyrule
];
966 unsigned long int yylno
= yyrline
[yyrule
];
967 YYFPRINTF (stderr
, "Reducing stack by rule %d (line %lu):\n",
969 /* The symbols being reduced. */
970 for (yyi
= 0; yyi
< yynrhs
; yyi
++)
972 fprintf (stderr
, " $%d = ", yyi
+ 1);
973 yy_symbol_print (stderr
, yyrhs
[yyprhs
[yyrule
] + yyi
],
974 &(yyvsp
[(yyi
+ 1) - (yynrhs
)])
975 , &(yylsp
[(yyi
+ 1) - (yynrhs
)]) );
976 fprintf (stderr
, "\n");
980 # define YY_REDUCE_PRINT(Rule) \
983 yy_reduce_print (yyvsp, yylsp, Rule); \
986 /* Nonzero means print parse trace. It is left uninitialized so that
987 multiple parsers can coexist. */
990 # define YYDPRINTF(Args)
991 # define YY_SYMBOL_PRINT(Title, Type, Value, Location)
992 # define YY_STACK_PRINT(Bottom, Top)
993 # define YY_REDUCE_PRINT(Rule)
994 #endif /* !YYDEBUG */
997 /* YYINITDEPTH -- initial size of the parser's stacks. */
999 # define YYINITDEPTH 200
1002 /* YYMAXDEPTH -- maximum size the stacks can grow to (effective only
1003 if the built-in stack extension method is used).
1005 Do not make this value too large; the results are undefined if
1006 YYSTACK_ALLOC_MAXIMUM < YYSTACK_BYTES (YYMAXDEPTH)
1007 evaluated with infinite-precision integer arithmetic. */
1010 # define YYMAXDEPTH 10000
1018 # if defined __GLIBC__ && defined _STRING_H
1019 # define yystrlen strlen
1021 /* Return the length of YYSTR. */
1022 #if (defined __STDC__ || defined __C99__FUNC__ \
1023 || defined __cplusplus || defined _MSC_VER)
1025 yystrlen (const char *yystr
)
1033 for (yylen
= 0; yystr
[yylen
]; yylen
++)
1041 # if defined __GLIBC__ && defined _STRING_H && defined _GNU_SOURCE
1042 # define yystpcpy stpcpy
1044 /* Copy YYSRC to YYDEST, returning the address of the terminating '\0' in
1046 #if (defined __STDC__ || defined __C99__FUNC__ \
1047 || defined __cplusplus || defined _MSC_VER)
1049 yystpcpy (char *yydest
, const char *yysrc
)
1052 yystpcpy (yydest
, yysrc
)
1058 const char *yys
= yysrc
;
1060 while ((*yyd
++ = *yys
++) != '\0')
1069 /* Copy to YYRES the contents of YYSTR after stripping away unnecessary
1070 quotes and backslashes, so that it's suitable for yyerror. The
1071 heuristic is that double-quoting is unnecessary unless the string
1072 contains an apostrophe, a comma, or backslash (other than
1073 backslash-backslash). YYSTR is taken from yytname. If YYRES is
1074 null, do not copy; instead, return the length of what the result
1077 yytnamerr (char *yyres
, const char *yystr
)
1082 char const *yyp
= yystr
;
1089 goto do_not_strip_quotes
;
1093 goto do_not_strip_quotes
;
1106 do_not_strip_quotes
: ;
1110 return yystrlen (yystr
);
1112 return yystpcpy (yyres
, yystr
) - yyres
;
1116 /* Copy into YYRESULT an error message about the unexpected token
1117 YYCHAR while in state YYSTATE. Return the number of bytes copied,
1118 including the terminating null byte. If YYRESULT is null, do not
1119 copy anything; just return the number of bytes that would be
1120 copied. As a special case, return 0 if an ordinary "syntax error"
1121 message will do. Return YYSIZE_MAXIMUM if overflow occurs during
1122 size calculation. */
1124 yysyntax_error (char *yyresult
, int yystate
, int yychar
)
1126 int yyn
= yypact
[yystate
];
1128 if (! (YYPACT_NINF
< yyn
&& yyn
< YYLAST
))
1132 int yytype
= YYTRANSLATE (yychar
);
1133 YYSIZE_T yysize0
= yytnamerr (0, yytname
[yytype
]);
1134 YYSIZE_T yysize
= yysize0
;
1136 int yysize_overflow
= 0;
1137 enum { YYERROR_VERBOSE_ARGS_MAXIMUM
= 5 };
1138 char const *yyarg
[YYERROR_VERBOSE_ARGS_MAXIMUM
];
1142 /* This is so xgettext sees the translatable formats that are
1143 constructed on the fly. */
1144 YY_("syntax error, unexpected %s");
1145 YY_("syntax error, unexpected %s, expecting %s");
1146 YY_("syntax error, unexpected %s, expecting %s or %s");
1147 YY_("syntax error, unexpected %s, expecting %s or %s or %s");
1148 YY_("syntax error, unexpected %s, expecting %s or %s or %s or %s");
1152 static char const yyunexpected
[] = "syntax error, unexpected %s";
1153 static char const yyexpecting
[] = ", expecting %s";
1154 static char const yyor
[] = " or %s";
1155 char yyformat
[sizeof yyunexpected
1156 + sizeof yyexpecting
- 1
1157 + ((YYERROR_VERBOSE_ARGS_MAXIMUM
- 2)
1158 * (sizeof yyor
- 1))];
1159 char const *yyprefix
= yyexpecting
;
1161 /* Start YYX at -YYN if negative to avoid negative indexes in
1163 int yyxbegin
= yyn
< 0 ? -yyn
: 0;
1165 /* Stay within bounds of both yycheck and yytname. */
1166 int yychecklim
= YYLAST
- yyn
;
1167 int yyxend
= yychecklim
< YYNTOKENS
? yychecklim
: YYNTOKENS
;
1170 yyarg
[0] = yytname
[yytype
];
1171 yyfmt
= yystpcpy (yyformat
, yyunexpected
);
1173 for (yyx
= yyxbegin
; yyx
< yyxend
; ++yyx
)
1174 if (yycheck
[yyx
+ yyn
] == yyx
&& yyx
!= YYTERROR
)
1176 if (yycount
== YYERROR_VERBOSE_ARGS_MAXIMUM
)
1180 yyformat
[sizeof yyunexpected
- 1] = '\0';
1183 yyarg
[yycount
++] = yytname
[yyx
];
1184 yysize1
= yysize
+ yytnamerr (0, yytname
[yyx
]);
1185 yysize_overflow
|= (yysize1
< yysize
);
1187 yyfmt
= yystpcpy (yyfmt
, yyprefix
);
1191 yyf
= YY_(yyformat
);
1192 yysize1
= yysize
+ yystrlen (yyf
);
1193 yysize_overflow
|= (yysize1
< yysize
);
1196 if (yysize_overflow
)
1197 return YYSIZE_MAXIMUM
;
1201 /* Avoid sprintf, as that infringes on the user's name space.
1202 Don't have undefined behavior even if the translation
1203 produced a string with the wrong number of "%s"s. */
1204 char *yyp
= yyresult
;
1206 while ((*yyp
= *yyf
) != '\0')
1208 if (*yyp
== '%' && yyf
[1] == 's' && yyi
< yycount
)
1210 yyp
+= yytnamerr (yyp
, yyarg
[yyi
++]);
1223 #endif /* YYERROR_VERBOSE */
1226 /*-----------------------------------------------.
1227 | Release the memory associated to this symbol. |
1228 `-----------------------------------------------*/
1231 #if (defined __STDC__ || defined __C99__FUNC__ \
1232 || defined __cplusplus || defined _MSC_VER)
1234 yydestruct (const char *yymsg
, int yytype
, YYSTYPE
*yyvaluep
, YYLTYPE
*yylocationp
)
1237 yydestruct (yymsg
, yytype
, yyvaluep
, yylocationp
)
1241 YYLTYPE
*yylocationp
;
1245 YYUSE (yylocationp
);
1249 YY_SYMBOL_PRINT (yymsg
, yytype
, yyvaluep
, yylocationp
);
1253 case 3: /* "TOK_COLONCOLON" */
1254 #line 169 "ast_expr2.y"
1255 { free_value((yyvaluep
->val
)); };
1256 #line 1257 "ast_expr2.c"
1258 case 4: /* "TOK_COND" */
1259 #line 169 "ast_expr2.y"
1260 { free_value((yyvaluep
->val
)); };
1261 #line 1262 "ast_expr2.c"
1263 case 5: /* "TOK_OR" */
1264 #line 169 "ast_expr2.y"
1265 { free_value((yyvaluep
->val
)); };
1266 #line 1267 "ast_expr2.c"
1268 case 6: /* "TOK_AND" */
1269 #line 169 "ast_expr2.y"
1270 { free_value((yyvaluep
->val
)); };
1271 #line 1272 "ast_expr2.c"
1273 case 7: /* "TOK_NE" */
1274 #line 169 "ast_expr2.y"
1275 { free_value((yyvaluep
->val
)); };
1276 #line 1277 "ast_expr2.c"
1278 case 8: /* "TOK_LE" */
1279 #line 169 "ast_expr2.y"
1280 { free_value((yyvaluep
->val
)); };
1281 #line 1282 "ast_expr2.c"
1283 case 9: /* "TOK_GE" */
1284 #line 169 "ast_expr2.y"
1285 { free_value((yyvaluep
->val
)); };
1286 #line 1287 "ast_expr2.c"
1288 case 10: /* "TOK_LT" */
1289 #line 169 "ast_expr2.y"
1290 { free_value((yyvaluep
->val
)); };
1291 #line 1292 "ast_expr2.c"
1293 case 11: /* "TOK_GT" */
1294 #line 169 "ast_expr2.y"
1295 { free_value((yyvaluep
->val
)); };
1296 #line 1297 "ast_expr2.c"
1298 case 12: /* "TOK_EQ" */
1299 #line 169 "ast_expr2.y"
1300 { free_value((yyvaluep
->val
)); };
1301 #line 1302 "ast_expr2.c"
1303 case 13: /* "TOK_MINUS" */
1304 #line 169 "ast_expr2.y"
1305 { free_value((yyvaluep
->val
)); };
1306 #line 1307 "ast_expr2.c"
1308 case 14: /* "TOK_PLUS" */
1309 #line 169 "ast_expr2.y"
1310 { free_value((yyvaluep
->val
)); };
1311 #line 1312 "ast_expr2.c"
1313 case 15: /* "TOK_MOD" */
1314 #line 169 "ast_expr2.y"
1315 { free_value((yyvaluep
->val
)); };
1316 #line 1317 "ast_expr2.c"
1318 case 16: /* "TOK_DIV" */
1319 #line 169 "ast_expr2.y"
1320 { free_value((yyvaluep
->val
)); };
1321 #line 1322 "ast_expr2.c"
1323 case 17: /* "TOK_MULT" */
1324 #line 169 "ast_expr2.y"
1325 { free_value((yyvaluep
->val
)); };
1326 #line 1327 "ast_expr2.c"
1328 case 18: /* "TOK_COMPL" */
1329 #line 169 "ast_expr2.y"
1330 { free_value((yyvaluep
->val
)); };
1331 #line 1332 "ast_expr2.c"
1333 case 19: /* "TOK_EQTILDE" */
1334 #line 169 "ast_expr2.y"
1335 { free_value((yyvaluep
->val
)); };
1336 #line 1337 "ast_expr2.c"
1338 case 20: /* "TOK_COLON" */
1339 #line 169 "ast_expr2.y"
1340 { free_value((yyvaluep
->val
)); };
1341 #line 1342 "ast_expr2.c"
1343 case 21: /* "TOK_LP" */
1344 #line 169 "ast_expr2.y"
1345 { free_value((yyvaluep
->val
)); };
1346 #line 1347 "ast_expr2.c"
1348 case 22: /* "TOK_RP" */
1349 #line 169 "ast_expr2.y"
1350 { free_value((yyvaluep
->val
)); };
1351 #line 1352 "ast_expr2.c"
1353 case 23: /* "TOKEN" */
1354 #line 169 "ast_expr2.y"
1355 { free_value((yyvaluep
->val
)); };
1356 #line 1357 "ast_expr2.c"
1358 case 26: /* "expr" */
1359 #line 169 "ast_expr2.y"
1360 { free_value((yyvaluep
->val
)); };
1361 #line 1362 "ast_expr2.c"
1370 /* Prevent warnings from -Wmissing-prototypes. */
1372 #ifdef YYPARSE_PARAM
1373 #if defined __STDC__ || defined __cplusplus
1374 int yyparse (void *YYPARSE_PARAM
);
1378 #else /* ! YYPARSE_PARAM */
1379 #if defined __STDC__ || defined __cplusplus
1384 #endif /* ! YYPARSE_PARAM */
1395 #ifdef YYPARSE_PARAM
1396 #if (defined __STDC__ || defined __C99__FUNC__ \
1397 || defined __cplusplus || defined _MSC_VER)
1399 yyparse (void *YYPARSE_PARAM
)
1402 yyparse (YYPARSE_PARAM
)
1403 void *YYPARSE_PARAM
;
1405 #else /* ! YYPARSE_PARAM */
1406 #if (defined __STDC__ || defined __C99__FUNC__ \
1407 || defined __cplusplus || defined _MSC_VER)
1417 /* The look-ahead symbol. */
1420 /* The semantic value of the look-ahead symbol. */
1423 /* Number of syntax errors so far. */
1425 /* Location data for the look-ahead symbol. */
1431 /* Number of tokens to shift before error messages enabled. */
1433 /* Look-ahead token as an internal (translated) token number. */
1436 /* Buffer for error messages, and its allocated size. */
1438 char *yymsg
= yymsgbuf
;
1439 YYSIZE_T yymsg_alloc
= sizeof yymsgbuf
;
1442 /* Three stacks and their tools:
1443 `yyss': related to states,
1444 `yyvs': related to semantic values,
1445 `yyls': related to locations.
1447 Refer to the stacks thru separate pointers, to allow yyoverflow
1448 to reallocate them elsewhere. */
1450 /* The state stack. */
1451 yytype_int16 yyssa
[YYINITDEPTH
];
1452 yytype_int16
*yyss
= yyssa
;
1453 yytype_int16
*yyssp
;
1455 /* The semantic value stack. */
1456 YYSTYPE yyvsa
[YYINITDEPTH
];
1457 YYSTYPE
*yyvs
= yyvsa
;
1460 /* The location stack. */
1461 YYLTYPE yylsa
[YYINITDEPTH
];
1462 YYLTYPE
*yyls
= yylsa
;
1464 /* The locations where the error started and ended. */
1465 YYLTYPE yyerror_range
[2];
1467 #define YYPOPSTACK(N) (yyvsp -= (N), yyssp -= (N), yylsp -= (N))
1469 YYSIZE_T yystacksize
= YYINITDEPTH
;
1471 /* The variables used to return semantic value and location from the
1476 /* The number of symbols on the RHS of the reduced rule.
1477 Keep to zero when no symbol should be popped. */
1480 YYDPRINTF ((stderr
, "Starting parse\n"));
1485 yychar
= YYEMPTY
; /* Cause a token to be read. */
1487 /* Initialize stack pointers.
1488 Waste one element of value and location stack
1489 so that they stay on the same level as the state stack.
1490 The wasted elements are never initialized. */
1495 #if YYLTYPE_IS_TRIVIAL
1496 /* Initialize the default location before parsing starts. */
1497 yylloc
.first_line
= yylloc
.last_line
= 1;
1498 yylloc
.first_column
= yylloc
.last_column
= 0;
1503 /*------------------------------------------------------------.
1504 | yynewstate -- Push a new state, which is found in yystate. |
1505 `------------------------------------------------------------*/
1507 /* In all cases, when you get here, the value and location stacks
1508 have just been pushed. So pushing a state here evens the stacks. */
1514 if (yyss
+ yystacksize
- 1 <= yyssp
)
1516 /* Get the current used size of the three stacks, in elements. */
1517 YYSIZE_T yysize
= yyssp
- yyss
+ 1;
1521 /* Give user a chance to reallocate the stack. Use copies of
1522 these so that the &'s don't force the real ones into
1524 YYSTYPE
*yyvs1
= yyvs
;
1525 yytype_int16
*yyss1
= yyss
;
1526 YYLTYPE
*yyls1
= yyls
;
1528 /* Each stack pointer address is followed by the size of the
1529 data in use in that stack, in bytes. This used to be a
1530 conditional around just the two extra args, but that might
1531 be undefined if yyoverflow is a macro. */
1532 yyoverflow (YY_("memory exhausted"),
1533 &yyss1
, yysize
* sizeof (*yyssp
),
1534 &yyvs1
, yysize
* sizeof (*yyvsp
),
1535 &yyls1
, yysize
* sizeof (*yylsp
),
1541 #else /* no yyoverflow */
1542 # ifndef YYSTACK_RELOCATE
1543 goto yyexhaustedlab
;
1545 /* Extend the stack our own way. */
1546 if (YYMAXDEPTH
<= yystacksize
)
1547 goto yyexhaustedlab
;
1549 if (YYMAXDEPTH
< yystacksize
)
1550 yystacksize
= YYMAXDEPTH
;
1553 yytype_int16
*yyss1
= yyss
;
1554 union yyalloc
*yyptr
=
1555 (union yyalloc
*) YYSTACK_ALLOC (YYSTACK_BYTES (yystacksize
));
1557 goto yyexhaustedlab
;
1558 YYSTACK_RELOCATE (yyss
);
1559 YYSTACK_RELOCATE (yyvs
);
1560 YYSTACK_RELOCATE (yyls
);
1561 # undef YYSTACK_RELOCATE
1563 YYSTACK_FREE (yyss1
);
1566 #endif /* no yyoverflow */
1568 yyssp
= yyss
+ yysize
- 1;
1569 yyvsp
= yyvs
+ yysize
- 1;
1570 yylsp
= yyls
+ yysize
- 1;
1572 YYDPRINTF ((stderr
, "Stack size increased to %lu\n",
1573 (unsigned long int) yystacksize
));
1575 if (yyss
+ yystacksize
- 1 <= yyssp
)
1579 YYDPRINTF ((stderr
, "Entering state %d\n", yystate
));
1588 /* Do appropriate processing given the current state. Read a
1589 look-ahead token if we need one and don't already have one. */
1591 /* First try to decide what to do without reference to look-ahead token. */
1592 yyn
= yypact
[yystate
];
1593 if (yyn
== YYPACT_NINF
)
1596 /* Not known => get a look-ahead token if don't already have one. */
1598 /* YYCHAR is either YYEMPTY or YYEOF or a valid look-ahead symbol. */
1599 if (yychar
== YYEMPTY
)
1601 YYDPRINTF ((stderr
, "Reading a token: "));
1605 if (yychar
<= YYEOF
)
1607 yychar
= yytoken
= YYEOF
;
1608 YYDPRINTF ((stderr
, "Now at end of input.\n"));
1612 yytoken
= YYTRANSLATE (yychar
);
1613 YY_SYMBOL_PRINT ("Next token is", yytoken
, &yylval
, &yylloc
);
1616 /* If the proper action on seeing token YYTOKEN is to reduce or to
1617 detect an error, take that action. */
1619 if (yyn
< 0 || YYLAST
< yyn
|| yycheck
[yyn
] != yytoken
)
1624 if (yyn
== 0 || yyn
== YYTABLE_NINF
)
1633 /* Count tokens shifted since error; after three, turn off error
1638 /* Shift the look-ahead token. */
1639 YY_SYMBOL_PRINT ("Shifting", yytoken
, &yylval
, &yylloc
);
1641 /* Discard the shifted token unless it is eof. */
1642 if (yychar
!= YYEOF
)
1651 /*-----------------------------------------------------------.
1652 | yydefault -- do the default action for the current state. |
1653 `-----------------------------------------------------------*/
1655 yyn
= yydefact
[yystate
];
1661 /*-----------------------------.
1662 | yyreduce -- Do a reduction. |
1663 `-----------------------------*/
1665 /* yyn is the number of a rule to reduce with. */
1668 /* If YYLEN is nonzero, implement the default value of the action:
1671 Otherwise, the following line sets YYVAL to garbage.
1672 This behavior is undocumented and Bison
1673 users should not rely upon it. Assigning to YYVAL
1674 unconditionally makes the parser a bit smaller, and it avoids a
1675 GCC warning that YYVAL may be used uninitialized. */
1676 yyval
= yyvsp
[1-yylen
];
1678 /* Default location. */
1679 YYLLOC_DEFAULT (yyloc
, (yylsp
- yylen
), yylen
);
1680 YY_REDUCE_PRINT (yyn
);
1684 #line 175 "ast_expr2.y"
1685 { ((struct parse_io
*)parseio
)->val
= (struct val
*)calloc(sizeof(struct val
),1);
1686 ((struct parse_io
*)parseio
)->val
->type
= (yyvsp
[(1) - (1)].val
)->type
;
1687 if( (yyvsp
[(1) - (1)].val
)->type
== AST_EXPR_integer
)
1688 ((struct parse_io
*)parseio
)->val
->u
.i
= (yyvsp
[(1) - (1)].val
)->u
.i
;
1690 ((struct parse_io
*)parseio
)->val
->u
.s
= (yyvsp
[(1) - (1)].val
)->u
.s
;
1691 free((yyvsp
[(1) - (1)].val
));
1696 #line 183 "ast_expr2.y"
1697 {/* nothing */ ((struct parse_io
*)parseio
)->val
= (struct val
*)calloc(sizeof(struct val
),1);
1698 ((struct parse_io
*)parseio
)->val
->type
= AST_EXPR_string
;
1699 ((struct parse_io
*)parseio
)->val
->u
.s
= strdup("");
1704 #line 190 "ast_expr2.y"
1705 { (yyval
.val
)= (yyvsp
[(1) - (1)].val
);;}
1709 #line 191 "ast_expr2.y"
1710 { (yyval
.val
) = (yyvsp
[(2) - (3)].val
);
1711 (yyloc
).first_column
= (yylsp
[(1) - (3)]).first_column
; (yyloc
).last_column
= (yylsp
[(3) - (3)]).last_column
;
1712 (yyloc
).first_line
=0; (yyloc
).last_line
=0;
1713 DESTROY((yyvsp
[(1) - (3)].val
)); DESTROY((yyvsp
[(3) - (3)].val
)); ;}
1717 #line 195 "ast_expr2.y"
1718 { (yyval
.val
) = op_or ((yyvsp
[(1) - (3)].val
), (yyvsp
[(3) - (3)].val
));
1719 DESTROY((yyvsp
[(2) - (3)].val
));
1720 (yyloc
).first_column
= (yylsp
[(1) - (3)]).first_column
; (yyloc
).last_column
= (yylsp
[(3) - (3)]).last_column
;
1721 (yyloc
).first_line
=0; (yyloc
).last_line
=0;;}
1725 #line 199 "ast_expr2.y"
1726 { (yyval
.val
) = op_and ((yyvsp
[(1) - (3)].val
), (yyvsp
[(3) - (3)].val
));
1727 DESTROY((yyvsp
[(2) - (3)].val
));
1728 (yyloc
).first_column
= (yylsp
[(1) - (3)]).first_column
; (yyloc
).last_column
= (yylsp
[(3) - (3)]).last_column
;
1729 (yyloc
).first_line
=0; (yyloc
).last_line
=0;;}
1733 #line 203 "ast_expr2.y"
1734 { (yyval
.val
) = op_eq ((yyvsp
[(1) - (3)].val
), (yyvsp
[(3) - (3)].val
));
1735 DESTROY((yyvsp
[(2) - (3)].val
));
1736 (yyloc
).first_column
= (yylsp
[(1) - (3)]).first_column
; (yyloc
).last_column
= (yylsp
[(3) - (3)]).last_column
;
1737 (yyloc
).first_line
=0; (yyloc
).last_line
=0;;}
1741 #line 207 "ast_expr2.y"
1742 { (yyval
.val
) = op_gt ((yyvsp
[(1) - (3)].val
), (yyvsp
[(3) - (3)].val
));
1743 DESTROY((yyvsp
[(2) - (3)].val
));
1744 (yyloc
).first_column
= (yylsp
[(1) - (3)]).first_column
; (yyloc
).last_column
= (yylsp
[(3) - (3)]).last_column
;
1745 (yyloc
).first_line
=0; (yyloc
).last_line
=0;;}
1749 #line 211 "ast_expr2.y"
1750 { (yyval
.val
) = op_lt ((yyvsp
[(1) - (3)].val
), (yyvsp
[(3) - (3)].val
));
1751 DESTROY((yyvsp
[(2) - (3)].val
));
1752 (yyloc
).first_column
= (yylsp
[(1) - (3)]).first_column
; (yyloc
).last_column
= (yylsp
[(3) - (3)]).last_column
;
1753 (yyloc
).first_line
=0; (yyloc
).last_line
=0;;}
1757 #line 215 "ast_expr2.y"
1758 { (yyval
.val
) = op_ge ((yyvsp
[(1) - (3)].val
), (yyvsp
[(3) - (3)].val
));
1759 DESTROY((yyvsp
[(2) - (3)].val
));
1760 (yyloc
).first_column
= (yylsp
[(1) - (3)]).first_column
; (yyloc
).last_column
= (yylsp
[(3) - (3)]).last_column
;
1761 (yyloc
).first_line
=0; (yyloc
).last_line
=0;;}
1765 #line 219 "ast_expr2.y"
1766 { (yyval
.val
) = op_le ((yyvsp
[(1) - (3)].val
), (yyvsp
[(3) - (3)].val
));
1767 DESTROY((yyvsp
[(2) - (3)].val
));
1768 (yyloc
).first_column
= (yylsp
[(1) - (3)]).first_column
; (yyloc
).last_column
= (yylsp
[(3) - (3)]).last_column
;
1769 (yyloc
).first_line
=0; (yyloc
).last_line
=0;;}
1773 #line 223 "ast_expr2.y"
1774 { (yyval
.val
) = op_ne ((yyvsp
[(1) - (3)].val
), (yyvsp
[(3) - (3)].val
));
1775 DESTROY((yyvsp
[(2) - (3)].val
));
1776 (yyloc
).first_column
= (yylsp
[(1) - (3)]).first_column
; (yyloc
).last_column
= (yylsp
[(3) - (3)]).last_column
;
1777 (yyloc
).first_line
=0; (yyloc
).last_line
=0;;}
1781 #line 227 "ast_expr2.y"
1782 { (yyval
.val
) = op_plus ((yyvsp
[(1) - (3)].val
), (yyvsp
[(3) - (3)].val
));
1783 DESTROY((yyvsp
[(2) - (3)].val
));
1784 (yyloc
).first_column
= (yylsp
[(1) - (3)]).first_column
; (yyloc
).last_column
= (yylsp
[(3) - (3)]).last_column
;
1785 (yyloc
).first_line
=0; (yyloc
).last_line
=0;;}
1789 #line 231 "ast_expr2.y"
1790 { (yyval
.val
) = op_minus ((yyvsp
[(1) - (3)].val
), (yyvsp
[(3) - (3)].val
));
1791 DESTROY((yyvsp
[(2) - (3)].val
));
1792 (yyloc
).first_column
= (yylsp
[(1) - (3)]).first_column
; (yyloc
).last_column
= (yylsp
[(3) - (3)]).last_column
;
1793 (yyloc
).first_line
=0; (yyloc
).last_line
=0;;}
1797 #line 235 "ast_expr2.y"
1798 { (yyval
.val
) = op_negate ((yyvsp
[(2) - (2)].val
));
1799 DESTROY((yyvsp
[(1) - (2)].val
));
1800 (yyloc
).first_column
= (yylsp
[(1) - (2)]).first_column
; (yyloc
).last_column
= (yylsp
[(2) - (2)]).last_column
;
1801 (yyloc
).first_line
=0; (yyloc
).last_line
=0;;}
1805 #line 239 "ast_expr2.y"
1806 { (yyval
.val
) = op_compl ((yyvsp
[(2) - (2)].val
));
1807 DESTROY((yyvsp
[(1) - (2)].val
));
1808 (yyloc
).first_column
= (yylsp
[(1) - (2)]).first_column
; (yyloc
).last_column
= (yylsp
[(2) - (2)]).last_column
;
1809 (yyloc
).first_line
=0; (yyloc
).last_line
=0;;}
1813 #line 243 "ast_expr2.y"
1814 { (yyval
.val
) = op_times ((yyvsp
[(1) - (3)].val
), (yyvsp
[(3) - (3)].val
));
1815 DESTROY((yyvsp
[(2) - (3)].val
));
1816 (yyloc
).first_column
= (yylsp
[(1) - (3)]).first_column
; (yyloc
).last_column
= (yylsp
[(3) - (3)]).last_column
;
1817 (yyloc
).first_line
=0; (yyloc
).last_line
=0;;}
1821 #line 247 "ast_expr2.y"
1822 { (yyval
.val
) = op_div ((yyvsp
[(1) - (3)].val
), (yyvsp
[(3) - (3)].val
));
1823 DESTROY((yyvsp
[(2) - (3)].val
));
1824 (yyloc
).first_column
= (yylsp
[(1) - (3)]).first_column
; (yyloc
).last_column
= (yylsp
[(3) - (3)]).last_column
;
1825 (yyloc
).first_line
=0; (yyloc
).last_line
=0;;}
1829 #line 251 "ast_expr2.y"
1830 { (yyval
.val
) = op_rem ((yyvsp
[(1) - (3)].val
), (yyvsp
[(3) - (3)].val
));
1831 DESTROY((yyvsp
[(2) - (3)].val
));
1832 (yyloc
).first_column
= (yylsp
[(1) - (3)]).first_column
; (yyloc
).last_column
= (yylsp
[(3) - (3)]).last_column
;
1833 (yyloc
).first_line
=0; (yyloc
).last_line
=0;;}
1837 #line 255 "ast_expr2.y"
1838 { (yyval
.val
) = op_colon ((yyvsp
[(1) - (3)].val
), (yyvsp
[(3) - (3)].val
));
1839 DESTROY((yyvsp
[(2) - (3)].val
));
1840 (yyloc
).first_column
= (yylsp
[(1) - (3)]).first_column
; (yyloc
).last_column
= (yylsp
[(3) - (3)]).last_column
;
1841 (yyloc
).first_line
=0; (yyloc
).last_line
=0;;}
1845 #line 259 "ast_expr2.y"
1846 { (yyval
.val
) = op_eqtilde ((yyvsp
[(1) - (3)].val
), (yyvsp
[(3) - (3)].val
));
1847 DESTROY((yyvsp
[(2) - (3)].val
));
1848 (yyloc
).first_column
= (yylsp
[(1) - (3)]).first_column
; (yyloc
).last_column
= (yylsp
[(3) - (3)]).last_column
;
1849 (yyloc
).first_line
=0; (yyloc
).last_line
=0;;}
1853 #line 263 "ast_expr2.y"
1854 { (yyval
.val
) = op_cond ((yyvsp
[(1) - (5)].val
), (yyvsp
[(3) - (5)].val
), (yyvsp
[(5) - (5)].val
));
1855 DESTROY((yyvsp
[(2) - (5)].val
));
1856 DESTROY((yyvsp
[(4) - (5)].val
));
1857 (yyloc
).first_column
= (yylsp
[(1) - (5)]).first_column
; (yyloc
).last_column
= (yylsp
[(3) - (5)]).last_column
;
1858 (yyloc
).first_line
=0; (yyloc
).last_line
=0;;}
1862 /* Line 1270 of yacc.c. */
1863 #line 1864 "ast_expr2.c"
1866 YY_SYMBOL_PRINT ("-> $$ =", yyr1
[yyn
], &yyval
, &yyloc
);
1870 YY_STACK_PRINT (yyss
, yyssp
);
1875 /* Now `shift' the result of the reduction. Determine what state
1876 that goes to, based on the state we popped back to and the rule
1877 number reduced by. */
1881 yystate
= yypgoto
[yyn
- YYNTOKENS
] + *yyssp
;
1882 if (0 <= yystate
&& yystate
<= YYLAST
&& yycheck
[yystate
] == *yyssp
)
1883 yystate
= yytable
[yystate
];
1885 yystate
= yydefgoto
[yyn
- YYNTOKENS
];
1890 /*------------------------------------.
1891 | yyerrlab -- here on detecting error |
1892 `------------------------------------*/
1894 /* If not already recovering from an error, report this error. */
1898 #if ! YYERROR_VERBOSE
1899 yyerror (YY_("syntax error"));
1902 YYSIZE_T yysize
= yysyntax_error (0, yystate
, yychar
);
1903 if (yymsg_alloc
< yysize
&& yymsg_alloc
< YYSTACK_ALLOC_MAXIMUM
)
1905 YYSIZE_T yyalloc
= 2 * yysize
;
1906 if (! (yysize
<= yyalloc
&& yyalloc
<= YYSTACK_ALLOC_MAXIMUM
))
1907 yyalloc
= YYSTACK_ALLOC_MAXIMUM
;
1908 if (yymsg
!= yymsgbuf
)
1909 YYSTACK_FREE (yymsg
);
1910 yymsg
= (char *) YYSTACK_ALLOC (yyalloc
);
1912 yymsg_alloc
= yyalloc
;
1916 yymsg_alloc
= sizeof yymsgbuf
;
1920 if (0 < yysize
&& yysize
<= yymsg_alloc
)
1922 (void) yysyntax_error (yymsg
, yystate
, yychar
);
1927 yyerror (YY_("syntax error"));
1929 goto yyexhaustedlab
;
1935 yyerror_range
[0] = yylloc
;
1937 if (yyerrstatus
== 3)
1939 /* If just tried and failed to reuse look-ahead token after an
1940 error, discard it. */
1942 if (yychar
<= YYEOF
)
1944 /* Return failure if at end of input. */
1945 if (yychar
== YYEOF
)
1950 yydestruct ("Error: discarding",
1951 yytoken
, &yylval
, &yylloc
);
1956 /* Else will try to reuse look-ahead token after shifting the error
1961 /*---------------------------------------------------.
1962 | yyerrorlab -- error raised explicitly by YYERROR. |
1963 `---------------------------------------------------*/
1966 /* Pacify compilers like GCC when the user code never invokes
1967 YYERROR and the label yyerrorlab therefore never appears in user
1969 if (/*CONSTCOND*/ 0)
1972 yyerror_range
[0] = yylsp
[1-yylen
];
1973 /* Do not reclaim the symbols of the rule which action triggered
1977 YY_STACK_PRINT (yyss
, yyssp
);
1982 /*-------------------------------------------------------------.
1983 | yyerrlab1 -- common code for both syntax error and YYERROR. |
1984 `-------------------------------------------------------------*/
1986 yyerrstatus
= 3; /* Each real token shifted decrements this. */
1990 yyn
= yypact
[yystate
];
1991 if (yyn
!= YYPACT_NINF
)
1994 if (0 <= yyn
&& yyn
<= YYLAST
&& yycheck
[yyn
] == YYTERROR
)
2002 /* Pop the current state because it cannot handle the error token. */
2006 yyerror_range
[0] = *yylsp
;
2007 yydestruct ("Error: popping",
2008 yystos
[yystate
], yyvsp
, yylsp
);
2011 YY_STACK_PRINT (yyss
, yyssp
);
2019 yyerror_range
[1] = yylloc
;
2020 /* Using YYLLOC is tempting, but would change the location of
2021 the look-ahead. YYLOC is available though. */
2022 YYLLOC_DEFAULT (yyloc
, (yyerror_range
- 1), 2);
2025 /* Shift the error token. */
2026 YY_SYMBOL_PRINT ("Shifting", yystos
[yyn
], yyvsp
, yylsp
);
2032 /*-------------------------------------.
2033 | yyacceptlab -- YYACCEPT comes here. |
2034 `-------------------------------------*/
2039 /*-----------------------------------.
2040 | yyabortlab -- YYABORT comes here. |
2041 `-----------------------------------*/
2047 /*-------------------------------------------------.
2048 | yyexhaustedlab -- memory exhaustion comes here. |
2049 `-------------------------------------------------*/
2051 yyerror (YY_("memory exhausted"));
2057 if (yychar
!= YYEOF
&& yychar
!= YYEMPTY
)
2058 yydestruct ("Cleanup: discarding lookahead",
2059 yytoken
, &yylval
, &yylloc
);
2060 /* Do not reclaim the symbols of the rule which action triggered
2061 this YYABORT or YYACCEPT. */
2063 YY_STACK_PRINT (yyss
, yyssp
);
2064 while (yyssp
!= yyss
)
2066 yydestruct ("Cleanup: popping",
2067 yystos
[*yyssp
], yyvsp
, yylsp
);
2072 YYSTACK_FREE (yyss
);
2075 if (yymsg
!= yymsgbuf
)
2076 YYSTACK_FREE (yymsg
);
2082 #line 270 "ast_expr2.y"
2086 make_integer (quad_t i
)
2090 vp
= (struct val
*) malloc (sizeof (*vp
));
2092 ast_log(LOG_WARNING
, "malloc() failed\n");
2096 vp
->type
= AST_EXPR_integer
;
2102 make_str (const char *s
)
2108 vp
= (struct val
*) malloc (sizeof (*vp
));
2109 if (vp
== NULL
|| ((vp
->u
.s
= strdup (s
)) == NULL
)) {
2110 ast_log(LOG_WARNING
,"malloc() failed\n");
2114 for(i
= 1, isint
= isdigit(s
[0]) || s
[0] == '-';
2115 isint
&& i
< strlen(s
);
2123 vp
->type
= AST_EXPR_numeric_string
;
2125 vp
->type
= AST_EXPR_string
;
2132 free_value (struct val
*vp
)
2137 if (vp
->type
== AST_EXPR_string
|| vp
->type
== AST_EXPR_numeric_string
)
2144 to_integer (struct val
*vp
)
2149 ast_log(LOG_WARNING
,"vp==NULL in to_integer()\n");
2153 if (vp
->type
== AST_EXPR_integer
)
2156 if (vp
->type
== AST_EXPR_string
)
2159 /* vp->type == AST_EXPR_numeric_string, make it numeric */
2161 i
= strtoll(vp
->u
.s
, (char**)NULL
, 10);
2163 ast_log(LOG_WARNING
,"Conversion of %s to integer under/overflowed!\n", vp
->u
.s
);
2170 vp
->type
= AST_EXPR_integer
;
2175 strip_quotes(struct val
*vp
)
2177 if (vp
->type
!= AST_EXPR_string
&& vp
->type
!= AST_EXPR_numeric_string
)
2180 if( vp
->u
.s
[0] == '"' && vp
->u
.s
[strlen(vp
->u
.s
)-1] == '"' )
2188 if( *f
&& *f
!= '"' )
2198 to_string (struct val
*vp
)
2202 if (vp
->type
== AST_EXPR_string
|| vp
->type
== AST_EXPR_numeric_string
)
2205 tmp
= malloc ((size_t)25);
2207 ast_log(LOG_WARNING
,"malloc() failed\n");
2211 sprintf(tmp
, "%ld", (long int) vp
->u
.i
);
2212 vp
->type
= AST_EXPR_string
;
2218 isstring (struct val
*vp
)
2220 /* only TRUE if this string is not a valid integer */
2221 return (vp
->type
== AST_EXPR_string
);
2226 is_zero_or_null (struct val
*vp
)
2228 if (vp
->type
== AST_EXPR_integer
) {
2229 return (vp
->u
.i
== 0);
2231 return (*vp
->u
.s
== 0 || (to_integer (vp
) && vp
->u
.i
== 0));
2238 void ast_log(int level
, const char *file
, int line
, const char *function
, const char *fmt
, ...)
2243 printf("LOG: lev:%d file:%s line:%d func: %s ",
2244 level
, file
, line
, function
);
2251 int main(int argc
,char **argv
) {
2259 if( access(argv
[1],F_OK
)== 0 )
2263 infile
= fopen(argv
[1],"r");
2266 printf("Sorry, couldn't open %s for reading!\n", argv
[1]);
2269 while( fgets(s
,sizeof(s
),infile
) )
2271 if( s
[strlen(s
)-1] == '\n' )
2274 ret
= ast_expr(s
, out
, sizeof(out
));
2275 printf("Expression: %s Result: [%d] '%s'\n",
2282 if (ast_expr(argv
[1], s
, sizeof(s
)))
2283 printf("=====%s======\n",s
);
2285 printf("No result\n");
2292 #define ast_yyerror(x) ast_yyerror(x, YYLTYPE *yylloc, struct parse_io *parseio)
2294 /* I put the ast_yyerror func in the flex input file,
2295 because it refers to the buffer state. Best to
2296 let it access the BUFFER stuff there and not trying
2297 define all the structs, macros etc. in this file! */
2301 op_or (struct val
*a
, struct val
*b
)
2303 if (is_zero_or_null (a
)) {
2313 op_and (struct val
*a
, struct val
*b
)
2315 if (is_zero_or_null (a
) || is_zero_or_null (b
)) {
2318 return (make_integer ((quad_t
)0));
2326 op_eq (struct val
*a
, struct val
*b
)
2330 if (isstring (a
) || isstring (b
)) {
2333 r
= make_integer ((quad_t
)(strcoll (a
->u
.s
, b
->u
.s
) == 0));
2335 #ifdef DEBUG_FOR_CONVERSIONS
2337 sprintf(buffer
,"Converting '%s' and '%s' ", a
->u
.s
, b
->u
.s
);
2339 (void)to_integer(a
);
2340 (void)to_integer(b
);
2341 #ifdef DEBUG_FOR_CONVERSIONS
2342 ast_log(LOG_WARNING
,"%s to '%lld' and '%lld'\n", buffer
, a
->u
.i
, b
->u
.i
);
2344 r
= make_integer ((quad_t
)(a
->u
.i
== b
->u
.i
));
2353 op_gt (struct val
*a
, struct val
*b
)
2357 if (isstring (a
) || isstring (b
)) {
2360 r
= make_integer ((quad_t
)(strcoll (a
->u
.s
, b
->u
.s
) > 0));
2362 (void)to_integer(a
);
2363 (void)to_integer(b
);
2364 r
= make_integer ((quad_t
)(a
->u
.i
> b
->u
.i
));
2373 op_lt (struct val
*a
, struct val
*b
)
2377 if (isstring (a
) || isstring (b
)) {
2380 r
= make_integer ((quad_t
)(strcoll (a
->u
.s
, b
->u
.s
) < 0));
2382 (void)to_integer(a
);
2383 (void)to_integer(b
);
2384 r
= make_integer ((quad_t
)(a
->u
.i
< b
->u
.i
));
2393 op_ge (struct val
*a
, struct val
*b
)
2397 if (isstring (a
) || isstring (b
)) {
2400 r
= make_integer ((quad_t
)(strcoll (a
->u
.s
, b
->u
.s
) >= 0));
2402 (void)to_integer(a
);
2403 (void)to_integer(b
);
2404 r
= make_integer ((quad_t
)(a
->u
.i
>= b
->u
.i
));
2413 op_le (struct val
*a
, struct val
*b
)
2417 if (isstring (a
) || isstring (b
)) {
2420 r
= make_integer ((quad_t
)(strcoll (a
->u
.s
, b
->u
.s
) <= 0));
2422 (void)to_integer(a
);
2423 (void)to_integer(b
);
2424 r
= make_integer ((quad_t
)(a
->u
.i
<= b
->u
.i
));
2433 op_cond (struct val
*a
, struct val
*b
, struct val
*c
)
2439 if( strlen(a
->u
.s
) && strcmp(a
->u
.s
, "\"\"") != 0 && strcmp(a
->u
.s
,"0") != 0 )
2454 (void)to_integer(a
);
2472 op_ne (struct val
*a
, struct val
*b
)
2476 if (isstring (a
) || isstring (b
)) {
2479 r
= make_integer ((quad_t
)(strcoll (a
->u
.s
, b
->u
.s
) != 0));
2481 (void)to_integer(a
);
2482 (void)to_integer(b
);
2483 r
= make_integer ((quad_t
)(a
->u
.i
!= b
->u
.i
));
2492 chk_plus (quad_t a
, quad_t b
, quad_t r
)
2494 /* sum of two positive numbers must be positive */
2495 if (a
> 0 && b
> 0 && r
<= 0)
2497 /* sum of two negative numbers must be negative */
2498 if (a
< 0 && b
< 0 && r
>= 0)
2500 /* all other cases are OK */
2505 op_plus (struct val
*a
, struct val
*b
)
2509 if (!to_integer (a
)) {
2510 if( !extra_error_message_supplied
)
2511 ast_log(LOG_WARNING
,"non-numeric argument\n");
2512 if (!to_integer (b
)) {
2515 return make_integer(0);
2520 } else if (!to_integer(b
)) {
2525 r
= make_integer (/*(quad_t)*/(a
->u
.i
+ b
->u
.i
));
2526 if (chk_plus (a
->u
.i
, b
->u
.i
, r
->u
.i
)) {
2527 ast_log(LOG_WARNING
,"overflow\n");
2535 chk_minus (quad_t a
, quad_t b
, quad_t r
)
2537 /* special case subtraction of QUAD_MIN */
2538 if (b
== QUAD_MIN
) {
2544 /* this is allowed for b != QUAD_MIN */
2545 return chk_plus (a
, -b
, r
);
2549 op_minus (struct val
*a
, struct val
*b
)
2553 if (!to_integer (a
)) {
2554 if( !extra_error_message_supplied
)
2555 ast_log(LOG_WARNING
, "non-numeric argument\n");
2556 if (!to_integer (b
)) {
2559 return make_integer(0);
2561 r
= make_integer(0 - b
->u
.i
);
2566 } else if (!to_integer(b
)) {
2567 if( !extra_error_message_supplied
)
2568 ast_log(LOG_WARNING
, "non-numeric argument\n");
2573 r
= make_integer (/*(quad_t)*/(a
->u
.i
- b
->u
.i
));
2574 if (chk_minus (a
->u
.i
, b
->u
.i
, r
->u
.i
)) {
2575 ast_log(LOG_WARNING
, "overflow\n");
2583 op_negate (struct val
*a
)
2587 if (!to_integer (a
) ) {
2589 if( !extra_error_message_supplied
)
2590 ast_log(LOG_WARNING
, "non-numeric argument\n");
2591 return make_integer(0);
2594 r
= make_integer (/*(quad_t)*/(- a
->u
.i
));
2595 if (chk_minus (0, a
->u
.i
, r
->u
.i
)) {
2596 ast_log(LOG_WARNING
, "overflow\n");
2603 op_compl (struct val
*a
)
2616 case AST_EXPR_integer
:
2621 case AST_EXPR_string
:
2626 if( a
->u
.s
[0] == 0 )
2628 else if (strlen(a
->u
.s
) == 1 && a
->u
.s
[0] == '0' )
2633 case AST_EXPR_numeric_string
:
2638 if( a
->u
.s
[0] == 0 )
2640 else if (strlen(a
->u
.s
) == 1 && a
->u
.s
[0] == '0' )
2647 r
= make_integer (!v1
);
2653 chk_times (quad_t a
, quad_t b
, quad_t r
)
2655 /* special case: first operand is 0, no overflow possible */
2658 /* cerify that result of division matches second operand */
2665 op_times (struct val
*a
, struct val
*b
)
2669 if (!to_integer (a
) || !to_integer (b
)) {
2672 if( !extra_error_message_supplied
)
2673 ast_log(LOG_WARNING
, "non-numeric argument\n");
2674 return(make_integer(0));
2677 r
= make_integer (/*(quad_t)*/(a
->u
.i
* b
->u
.i
));
2678 if (chk_times (a
->u
.i
, b
->u
.i
, r
->u
.i
)) {
2679 ast_log(LOG_WARNING
, "overflow\n");
2687 chk_div (quad_t a
, quad_t b
)
2689 /* div by zero has been taken care of before */
2690 /* only QUAD_MIN / -1 causes overflow */
2691 if (a
== QUAD_MIN
&& b
== -1)
2693 /* everything else is OK */
2698 op_div (struct val
*a
, struct val
*b
)
2702 if (!to_integer (a
)) {
2705 if( !extra_error_message_supplied
)
2706 ast_log(LOG_WARNING
, "non-numeric argument\n");
2707 return make_integer(0);
2708 } else if (!to_integer (b
)) {
2711 if( !extra_error_message_supplied
)
2712 ast_log(LOG_WARNING
, "non-numeric argument\n");
2713 return make_integer(INT_MAX
);
2717 ast_log(LOG_WARNING
, "division by zero\n");
2720 return make_integer(INT_MAX
);
2723 r
= make_integer (/*(quad_t)*/(a
->u
.i
/ b
->u
.i
));
2724 if (chk_div (a
->u
.i
, b
->u
.i
)) {
2725 ast_log(LOG_WARNING
, "overflow\n");
2733 op_rem (struct val
*a
, struct val
*b
)
2737 if (!to_integer (a
) || !to_integer (b
)) {
2738 if( !extra_error_message_supplied
)
2739 ast_log(LOG_WARNING
, "non-numeric argument\n");
2742 return make_integer(0);
2746 ast_log(LOG_WARNING
, "div by zero\n");
2751 r
= make_integer (/*(quad_t)*/(a
->u
.i
% b
->u
.i
));
2752 /* chk_rem necessary ??? */
2760 op_colon (struct val
*a
, struct val
*b
)
2768 /* coerce to both arguments to strings */
2771 /* strip double quotes from both -- they'll screw up the pattern, and the search string starting at ^ */
2774 /* compile regular expression */
2775 if ((eval
= regcomp (&rp
, b
->u
.s
, REG_EXTENDED
)) != 0) {
2776 regerror (eval
, &rp
, errbuf
, sizeof(errbuf
));
2777 ast_log(LOG_WARNING
,"regcomp() error : %s",errbuf
);
2780 return make_str("");
2783 /* compare string against pattern */
2784 /* remember that patterns are anchored to the beginning of the line */
2785 if (regexec(&rp
, a
->u
.s
, (size_t)2, rm
, 0) == 0 && rm
[0].rm_so
== 0) {
2786 if (rm
[1].rm_so
>= 0) {
2787 *(a
->u
.s
+ rm
[1].rm_eo
) = '\0';
2788 v
= make_str (a
->u
.s
+ rm
[1].rm_so
);
2791 v
= make_integer ((quad_t
)(rm
[0].rm_eo
- rm
[0].rm_so
));
2794 if (rp
.re_nsub
== 0) {
2795 v
= make_integer ((quad_t
)0);
2801 /* free arguments and pattern buffer */
2811 op_eqtilde (struct val
*a
, struct val
*b
)
2819 /* coerce to both arguments to strings */
2822 /* strip double quotes from both -- they'll screw up the pattern, and the search string starting at ^ */
2825 /* compile regular expression */
2826 if ((eval
= regcomp (&rp
, b
->u
.s
, REG_EXTENDED
)) != 0) {
2827 regerror (eval
, &rp
, errbuf
, sizeof(errbuf
));
2828 ast_log(LOG_WARNING
,"regcomp() error : %s",errbuf
);
2831 return make_str("");
2834 /* compare string against pattern */
2835 /* remember that patterns are anchored to the beginning of the line */
2836 if (regexec(&rp
, a
->u
.s
, (size_t)2, rm
, 0) == 0 ) {
2837 if (rm
[1].rm_so
>= 0) {
2838 *(a
->u
.s
+ rm
[1].rm_eo
) = '\0';
2839 v
= make_str (a
->u
.s
+ rm
[1].rm_so
);
2842 v
= make_integer ((quad_t
)(rm
[0].rm_eo
- rm
[0].rm_so
));
2845 if (rp
.re_nsub
== 0) {
2846 v
= make_integer ((quad_t
)0);
2852 /* free arguments and pattern buffer */