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@e-tools.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>
139 #if !defined(SOLARIS) && !defined(__CYGWIN__)
142 #define quad_t int64_t
148 #include "asterisk.h"
150 ASTERISK_FILE_VERSION(__FILE__
, "$Revision$")
152 #include "asterisk/ast_expr.h"
153 #include "asterisk/logger.h"
155 #if defined(LONG_LONG_MIN) && !defined(QUAD_MIN)
156 #define QUAD_MIN LONG_LONG_MIN
158 #if defined(LONG_LONG_MAX) && !defined(QUAD_MAX)
159 #define QUAD_MAX LONG_LONG_MAX
162 # if ! defined(QUAD_MIN)
163 # define QUAD_MIN (-0x7fffffffffffffffLL-1)
165 # if ! defined(QUAD_MAX)
166 # define QUAD_MAX (0x7fffffffffffffffLL)
169 #define YYPARSE_PARAM parseio
170 #define YYLEX_PARAM ((struct parse_io *)parseio)->scanner
171 #define YYERROR_VERBOSE 1
172 extern char extra_error_message
[4095];
173 extern int extra_error_message_supplied
;
176 AST_EXPR_integer
, AST_EXPR_numeric_string
, AST_EXPR_string
180 void ast_log(int level
, const char *file
, int line
, const char *function
, const char *fmt
, ...) __attribute__ ((format (printf
,5,6)));
191 typedef void *yyscan_t
;
200 static int chk_div
__P((quad_t
, quad_t
));
201 static int chk_minus
__P((quad_t
, quad_t
, quad_t
));
202 static int chk_plus
__P((quad_t
, quad_t
, quad_t
));
203 static int chk_times
__P((quad_t
, quad_t
, quad_t
));
204 static void free_value
__P((struct val
*));
205 static int is_zero_or_null
__P((struct val
*));
206 static int isstring
__P((struct val
*));
207 static struct val
*make_integer
__P((quad_t
));
208 static struct val
*make_str
__P((const char *));
209 static struct val
*op_and
__P((struct val
*, struct val
*));
210 static struct val
*op_colon
__P((struct val
*, struct val
*));
211 static struct val
*op_eqtilde
__P((struct val
*, struct val
*));
212 static struct val
*op_div
__P((struct val
*, struct val
*));
213 static struct val
*op_eq
__P((struct val
*, struct val
*));
214 static struct val
*op_ge
__P((struct val
*, struct val
*));
215 static struct val
*op_gt
__P((struct val
*, struct val
*));
216 static struct val
*op_le
__P((struct val
*, struct val
*));
217 static struct val
*op_lt
__P((struct val
*, struct val
*));
218 static struct val
*op_cond
__P((struct val
*, struct val
*, struct val
*));
219 static struct val
*op_minus
__P((struct val
*, struct val
*));
220 static struct val
*op_negate
__P((struct val
*));
221 static struct val
*op_compl
__P((struct val
*));
222 static struct val
*op_ne
__P((struct val
*, struct val
*));
223 static struct val
*op_or
__P((struct val
*, struct val
*));
224 static struct val
*op_plus
__P((struct val
*, struct val
*));
225 static struct val
*op_rem
__P((struct val
*, struct val
*));
226 static struct val
*op_times
__P((struct val
*, struct val
*));
227 static quad_t to_integer
__P((struct val
*));
228 static void to_string
__P((struct val
*));
230 /* uh, if I want to predeclare yylex with a YYLTYPE, I have to predeclare the yyltype... sigh */
231 typedef struct yyltype
240 # define YYLTYPE yyltype
241 # define YYLTYPE_IS_TRIVIAL 1
243 /* we will get warning about no prototype for yylex! But we can't
244 define it here, we have no definition yet for YYSTYPE. */
246 int ast_yyerror(const char *,YYLTYPE
*, struct parse_io
*);
248 /* I wanted to add args to the yyerror routine, so I could print out
249 some useful info about the error. Not as easy as it looks, but it
251 #define ast_yyerror(x) ast_yyerror(x,&yyloc,parseio)
252 #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);}
255 /* Enabling traces. */
260 /* Enabling verbose error messages. */
261 #ifdef YYERROR_VERBOSE
262 # undef YYERROR_VERBOSE
263 # define YYERROR_VERBOSE 1
265 # define YYERROR_VERBOSE 0
268 /* Enabling the token table. */
269 #ifndef YYTOKEN_TABLE
270 # define YYTOKEN_TABLE 0
273 #if ! defined YYSTYPE && ! defined YYSTYPE_IS_DECLARED
274 typedef union YYSTYPE
275 #line 140 "ast_expr2.y"
279 /* Line 198 of yacc.c. */
280 #line 276 "ast_expr2.c"
282 # define yystype YYSTYPE /* obsolescent; will be withdrawn */
283 # define YYSTYPE_IS_DECLARED 1
284 # define YYSTYPE_IS_TRIVIAL 1
287 #if ! defined YYLTYPE && ! defined YYLTYPE_IS_DECLARED
288 typedef struct YYLTYPE
295 # define yyltype YYLTYPE /* obsolescent; will be withdrawn */
296 # define YYLTYPE_IS_DECLARED 1
297 # define YYLTYPE_IS_TRIVIAL 1
301 /* Copy the second part of user declarations. */
302 #line 144 "ast_expr2.y"
304 extern int ast_yylex
__P((YYSTYPE
*, YYLTYPE
*, yyscan_t
));
307 /* Line 221 of yacc.c. */
308 #line 304 "ast_expr2.c"
315 typedef YYTYPE_UINT8 yytype_uint8
;
317 typedef unsigned char yytype_uint8
;
321 typedef YYTYPE_INT8 yytype_int8
;
322 #elif (defined __STDC__ || defined __C99__FUNC__ \
323 || defined __cplusplus || defined _MSC_VER)
324 typedef signed char yytype_int8
;
326 typedef short int yytype_int8
;
330 typedef YYTYPE_UINT16 yytype_uint16
;
332 typedef unsigned short int yytype_uint16
;
336 typedef YYTYPE_INT16 yytype_int16
;
338 typedef short int yytype_int16
;
342 # ifdef __SIZE_TYPE__
343 # define YYSIZE_T __SIZE_TYPE__
344 # elif defined size_t
345 # define YYSIZE_T size_t
346 # elif ! defined YYSIZE_T && (defined __STDC__ || defined __C99__FUNC__ \
347 || defined __cplusplus || defined _MSC_VER)
348 # include <stddef.h> /* INFRINGES ON USER NAME SPACE */
349 # define YYSIZE_T size_t
351 # define YYSIZE_T unsigned int
355 #define YYSIZE_MAXIMUM ((YYSIZE_T) -1)
360 # include <libintl.h> /* INFRINGES ON USER NAME SPACE */
361 # define YY_(msgid) dgettext ("bison-runtime", msgid)
365 # define YY_(msgid) msgid
369 /* Suppress unused-variable warnings by "using" E. */
370 #if ! defined lint || defined __GNUC__
371 # define YYUSE(e) ((void) (e))
373 # define YYUSE(e) /* empty */
376 /* Identity function, used to suppress warnings about constant conditions. */
380 #if (defined __STDC__ || defined __C99__FUNC__ \
381 || defined __cplusplus || defined _MSC_VER)
394 #if ! defined yyoverflow || YYERROR_VERBOSE
396 /* The parser invokes alloca or malloc; define the necessary symbols. */
398 # ifdef YYSTACK_USE_ALLOCA
399 # if YYSTACK_USE_ALLOCA
401 # define YYSTACK_ALLOC __builtin_alloca
402 # elif defined __BUILTIN_VA_ARG_INCR
403 # include <alloca.h> /* INFRINGES ON USER NAME SPACE */
405 # define YYSTACK_ALLOC __alloca
406 # elif defined _MSC_VER
407 # include <malloc.h> /* INFRINGES ON USER NAME SPACE */
408 # define alloca _alloca
410 # define YYSTACK_ALLOC alloca
411 # if ! defined _ALLOCA_H && ! defined _STDLIB_H && (defined __STDC__ || defined __C99__FUNC__ \
412 || defined __cplusplus || defined _MSC_VER)
413 # include <stdlib.h> /* INFRINGES ON USER NAME SPACE */
422 # ifdef YYSTACK_ALLOC
423 /* Pacify GCC's `empty if-body' warning. */
424 # define YYSTACK_FREE(Ptr) do { /* empty */; } while (YYID (0))
425 # ifndef YYSTACK_ALLOC_MAXIMUM
426 /* The OS might guarantee only one guard page at the bottom of the stack,
427 and a page size can be as small as 4096 bytes. So we cannot safely
428 invoke alloca (N) if N exceeds 4096. Use a slightly smaller number
429 to allow for a few compiler-allocated temporary stack slots. */
430 # define YYSTACK_ALLOC_MAXIMUM 4032 /* reasonable circa 2006 */
433 # define YYSTACK_ALLOC YYMALLOC
434 # define YYSTACK_FREE YYFREE
435 # ifndef YYSTACK_ALLOC_MAXIMUM
436 # define YYSTACK_ALLOC_MAXIMUM YYSIZE_MAXIMUM
442 # define YYMALLOC malloc
443 # if ! defined malloc && ! defined _STDLIB_H && (defined __STDC__ || defined __C99__FUNC__ \
444 || defined __cplusplus || defined _MSC_VER)
445 void *malloc (YYSIZE_T
); /* INFRINGES ON USER NAME SPACE */
450 # if ! defined free && ! defined _STDLIB_H && (defined __STDC__ || defined __C99__FUNC__ \
451 || defined __cplusplus || defined _MSC_VER)
452 void free (void *); /* INFRINGES ON USER NAME SPACE */
459 #endif /* ! defined yyoverflow || YYERROR_VERBOSE */
462 #if (! defined yyoverflow \
463 && (! defined __cplusplus \
464 || (defined YYLTYPE_IS_TRIVIAL && YYLTYPE_IS_TRIVIAL \
465 && defined YYSTYPE_IS_TRIVIAL && YYSTYPE_IS_TRIVIAL)))
467 /* A type that is properly aligned for any stack member. */
475 /* The size of the maximum gap between one aligned stack and the next. */
476 # define YYSTACK_GAP_MAXIMUM (sizeof (union yyalloc) - 1)
478 /* The size of an array large to enough to hold all stacks, each with
480 # define YYSTACK_BYTES(N) \
481 ((N) * (sizeof (yytype_int16) + sizeof (YYSTYPE) + sizeof (YYLTYPE)) \
482 + 2 * YYSTACK_GAP_MAXIMUM)
484 /* Copy COUNT objects from FROM to TO. The source and destination do
487 # if defined __GNUC__ && 1 < __GNUC__
488 # define YYCOPY(To, From, Count) \
489 __builtin_memcpy (To, From, (Count) * sizeof (*(From)))
491 # define YYCOPY(To, From, Count) \
495 for (yyi = 0; yyi < (Count); yyi++) \
496 (To)[yyi] = (From)[yyi]; \
502 /* Relocate STACK from its old location to the new one. The
503 local variables YYSIZE and YYSTACKSIZE give the old and new number of
504 elements in the stack, and YYPTR gives the new location of the
505 stack. Advance YYPTR to a properly aligned location for the next
507 # define YYSTACK_RELOCATE(Stack) \
510 YYSIZE_T yynewbytes; \
511 YYCOPY (&yyptr->Stack, Stack, yysize); \
512 Stack = &yyptr->Stack; \
513 yynewbytes = yystacksize * sizeof (*Stack) + YYSTACK_GAP_MAXIMUM; \
514 yyptr += yynewbytes / sizeof (*yyptr); \
520 /* YYFINAL -- State number of the termination state. */
522 /* YYLAST -- Last index in YYTABLE. */
525 /* YYNTOKENS -- Number of terminals. */
527 /* YYNNTS -- Number of nonterminals. */
529 /* YYNRULES -- Number of rules. */
531 /* YYNRULES -- Number of states. */
534 /* YYTRANSLATE(YYLEX) -- Bison symbol number corresponding to YYLEX. */
536 #define YYMAXUTOK 278
538 #define YYTRANSLATE(YYX) \
539 ((unsigned int) (YYX) <= YYMAXUTOK ? yytranslate[YYX] : YYUNDEFTOK)
541 /* YYTRANSLATE[YYLEX] -- Bison symbol number corresponding to YYLEX. */
542 static const yytype_uint8 yytranslate
[] =
544 0, 2, 2, 2, 2, 2, 2, 2, 2, 2,
545 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
546 2, 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, 1, 2, 3, 4,
570 5, 6, 7, 8, 9, 10, 11, 12, 13, 14,
571 15, 16, 17, 18, 19, 20, 21, 22, 23
575 /* YYPRHS[YYN] -- Index of the first RHS symbol of rule number YYN in
577 static const yytype_uint8 yyprhs
[] =
579 0, 0, 3, 5, 6, 8, 12, 16, 20, 24,
580 28, 32, 36, 40, 44, 48, 52, 55, 58, 62,
584 /* YYRHS -- A `-1'-separated list of the rules' RHS. */
585 static const yytype_int8 yyrhs
[] =
587 25, 0, -1, 26, -1, -1, 23, -1, 21, 26,
588 22, -1, 26, 5, 26, -1, 26, 6, 26, -1,
589 26, 12, 26, -1, 26, 11, 26, -1, 26, 10,
590 26, -1, 26, 9, 26, -1, 26, 8, 26, -1,
591 26, 7, 26, -1, 26, 14, 26, -1, 26, 13,
592 26, -1, 13, 26, -1, 18, 26, -1, 26, 17,
593 26, -1, 26, 16, 26, -1, 26, 15, 26, -1,
594 26, 20, 26, -1, 26, 19, 26, -1, 26, 4,
598 /* YYRLINE[YYN] -- source line where rule number YYN was defined. */
599 static const yytype_uint16 yyrline
[] =
601 0, 168, 168, 176, 183, 184, 188, 192, 196, 200,
602 204, 208, 212, 216, 220, 224, 228, 232, 236, 240,
607 #if YYDEBUG || YYERROR_VERBOSE || YYTOKEN_TABLE
608 /* YYTNAME[SYMBOL-NUM] -- String name of the symbol SYMBOL-NUM.
609 First, the terminals, then, starting at YYNTOKENS, nonterminals. */
610 static const char *const yytname
[] =
612 "$end", "error", "$undefined", "TOK_COLONCOLON", "TOK_COND", "TOK_OR",
613 "TOK_AND", "TOK_NE", "TOK_LE", "TOK_GE", "TOK_LT", "TOK_GT", "TOK_EQ",
614 "TOK_MINUS", "TOK_PLUS", "TOK_MOD", "TOK_DIV", "TOK_MULT", "TOK_COMPL",
615 "TOK_EQTILDE", "TOK_COLON", "TOK_LP", "TOK_RP", "TOKEN", "$accept",
621 /* YYTOKNUM[YYLEX-NUM] -- Internal token number corresponding to
623 static const yytype_uint16 yytoknum
[] =
625 0, 256, 257, 258, 259, 260, 261, 262, 263, 264,
626 265, 266, 267, 268, 269, 270, 271, 272, 273, 274,
631 /* YYR1[YYN] -- Symbol number of symbol that rule YYN derives. */
632 static const yytype_uint8 yyr1
[] =
634 0, 24, 25, 25, 26, 26, 26, 26, 26, 26,
635 26, 26, 26, 26, 26, 26, 26, 26, 26, 26,
639 /* YYR2[YYN] -- Number of symbols composing right hand side of rule YYN. */
640 static const yytype_uint8 yyr2
[] =
642 0, 2, 1, 0, 1, 3, 3, 3, 3, 3,
643 3, 3, 3, 3, 3, 3, 2, 2, 3, 3,
647 /* YYDEFACT[STATE-NAME] -- Default rule to reduce with in state
648 STATE-NUM when YYTABLE doesn't specify something else to do. Zero
649 means the default is an error. */
650 static const yytype_uint8 yydefact
[] =
652 3, 0, 0, 0, 4, 0, 2, 16, 17, 0,
653 1, 0, 0, 0, 0, 0, 0, 0, 0, 0,
654 0, 0, 0, 0, 0, 0, 0, 5, 0, 6,
655 7, 13, 12, 11, 10, 9, 8, 15, 14, 20,
656 19, 18, 22, 21, 0, 23
659 /* YYDEFGOTO[NTERM-NUM]. */
660 static const yytype_int8 yydefgoto
[] =
665 /* YYPACT[STATE-NUM] -- Index in YYTABLE of the portion describing
667 #define YYPACT_NINF -13
668 static const yytype_int8 yypact
[] =
670 109, 109, 109, 109, -13, 6, 59, 106, 106, 22,
671 -13, 109, 109, 109, 109, 109, 109, 109, 109, 109,
672 109, 109, 109, 109, 109, 109, 109, -13, 42, 90,
673 104, 120, 120, 120, 120, 120, 120, -12, -12, 106,
674 106, 106, -13, -13, 109, 75
677 /* YYPGOTO[NTERM-NUM]. */
678 static const yytype_int8 yypgoto
[] =
683 /* YYTABLE[YYPACT[STATE-NUM]]. What to do in state STATE-NUM. If
684 positive, shift that token. If negative, reduce the rule which
685 number is the opposite. If zero, do what YYDEFACT says.
686 If YYTABLE_NINF, syntax error. */
687 #define YYTABLE_NINF -1
688 static const yytype_uint8 yytable
[] =
690 7, 8, 9, 22, 23, 24, 10, 25, 26, 0,
691 28, 29, 30, 31, 32, 33, 34, 35, 36, 37,
692 38, 39, 40, 41, 42, 43, 11, 12, 13, 14,
693 15, 16, 17, 18, 19, 20, 21, 22, 23, 24,
694 0, 25, 26, 45, 27, 44, 11, 12, 13, 14,
695 15, 16, 17, 18, 19, 20, 21, 22, 23, 24,
696 0, 25, 26, 11, 12, 13, 14, 15, 16, 17,
697 18, 19, 20, 21, 22, 23, 24, 0, 25, 26,
698 12, 13, 14, 15, 16, 17, 18, 19, 20, 21,
699 22, 23, 24, 0, 25, 26, 13, 14, 15, 16,
700 17, 18, 19, 20, 21, 22, 23, 24, 0, 25,
701 26, 14, 15, 16, 17, 18, 19, 20, 21, 22,
702 23, 24, 1, 25, 26, 25, 26, 2, 0, 0,
703 3, 0, 4, 20, 21, 22, 23, 24, 0, 25,
707 static const yytype_int8 yycheck
[] =
709 1, 2, 3, 15, 16, 17, 0, 19, 20, -1,
710 11, 12, 13, 14, 15, 16, 17, 18, 19, 20,
711 21, 22, 23, 24, 25, 26, 4, 5, 6, 7,
712 8, 9, 10, 11, 12, 13, 14, 15, 16, 17,
713 -1, 19, 20, 44, 22, 3, 4, 5, 6, 7,
714 8, 9, 10, 11, 12, 13, 14, 15, 16, 17,
715 -1, 19, 20, 4, 5, 6, 7, 8, 9, 10,
716 11, 12, 13, 14, 15, 16, 17, -1, 19, 20,
717 5, 6, 7, 8, 9, 10, 11, 12, 13, 14,
718 15, 16, 17, -1, 19, 20, 6, 7, 8, 9,
719 10, 11, 12, 13, 14, 15, 16, 17, -1, 19,
720 20, 7, 8, 9, 10, 11, 12, 13, 14, 15,
721 16, 17, 13, 19, 20, 19, 20, 18, -1, -1,
722 21, -1, 23, 13, 14, 15, 16, 17, -1, 19,
726 /* YYSTOS[STATE-NUM] -- The (internal number of the) accessing
727 symbol of state STATE-NUM. */
728 static const yytype_uint8 yystos
[] =
730 0, 13, 18, 21, 23, 25, 26, 26, 26, 26,
731 0, 4, 5, 6, 7, 8, 9, 10, 11, 12,
732 13, 14, 15, 16, 17, 19, 20, 22, 26, 26,
733 26, 26, 26, 26, 26, 26, 26, 26, 26, 26,
734 26, 26, 26, 26, 3, 26
737 #define yyerrok (yyerrstatus = 0)
738 #define yyclearin (yychar = YYEMPTY)
742 #define YYACCEPT goto yyacceptlab
743 #define YYABORT goto yyabortlab
744 #define YYERROR goto yyerrorlab
747 /* Like YYERROR except do call yyerror. This remains here temporarily
748 to ease the transition to the new meaning of YYERROR, for GCC.
749 Once GCC version 2 has supplanted version 1, this can go. */
751 #define YYFAIL goto yyerrlab
753 #define YYRECOVERING() (!!yyerrstatus)
755 #define YYBACKUP(Token, Value) \
757 if (yychar == YYEMPTY && yylen == 1) \
761 yytoken = YYTRANSLATE (yychar); \
767 yyerror (YY_("syntax error: cannot back up")); \
774 #define YYERRCODE 256
777 /* YYLLOC_DEFAULT -- Set CURRENT to span from RHS[1] to RHS[N].
778 If N is 0, then set CURRENT to the empty location which ends
779 the previous symbol: RHS[0] (always defined). */
781 #define YYRHSLOC(Rhs, K) ((Rhs)[K])
782 #ifndef YYLLOC_DEFAULT
783 # define YYLLOC_DEFAULT(Current, Rhs, N) \
787 (Current).first_line = YYRHSLOC (Rhs, 1).first_line; \
788 (Current).first_column = YYRHSLOC (Rhs, 1).first_column; \
789 (Current).last_line = YYRHSLOC (Rhs, N).last_line; \
790 (Current).last_column = YYRHSLOC (Rhs, N).last_column; \
794 (Current).first_line = (Current).last_line = \
795 YYRHSLOC (Rhs, 0).last_line; \
796 (Current).first_column = (Current).last_column = \
797 YYRHSLOC (Rhs, 0).last_column; \
803 /* YY_LOCATION_PRINT -- Print the location on the stream.
804 This macro was not mandated originally: define only if we know
805 we won't break user code: when these are the locations we know. */
807 #ifndef YY_LOCATION_PRINT
808 # if YYLTYPE_IS_TRIVIAL
809 # define YY_LOCATION_PRINT(File, Loc) \
810 fprintf (File, "%d.%d-%d.%d", \
811 (Loc).first_line, (Loc).first_column, \
812 (Loc).last_line, (Loc).last_column)
814 # define YY_LOCATION_PRINT(File, Loc) ((void) 0)
819 /* YYLEX -- calling `yylex' with the right arguments. */
822 # define YYLEX yylex (&yylval, &yylloc, YYLEX_PARAM)
824 # define YYLEX yylex (&yylval, &yylloc)
827 /* Enable debugging if requested. */
831 # include <stdio.h> /* INFRINGES ON USER NAME SPACE */
832 # define YYFPRINTF fprintf
835 # define YYDPRINTF(Args) \
841 # define YY_SYMBOL_PRINT(Title, Type, Value, Location) \
845 YYFPRINTF (stderr, "%s ", Title); \
846 yy_symbol_print (stderr, \
847 Type, Value, Location); \
848 YYFPRINTF (stderr, "\n"); \
853 /*--------------------------------.
854 | Print this symbol on YYOUTPUT. |
855 `--------------------------------*/
858 #if (defined __STDC__ || defined __C99__FUNC__ \
859 || defined __cplusplus || defined _MSC_VER)
861 yy_symbol_value_print (FILE *yyoutput
, int yytype
, const YYSTYPE
* const yyvaluep
, const YYLTYPE
* const yylocationp
)
864 yy_symbol_value_print (yyoutput
, yytype
, yyvaluep
, yylocationp
)
867 const YYSTYPE
* const yyvaluep
;
868 const YYLTYPE
* const yylocationp
;
875 if (yytype
< YYNTOKENS
)
876 YYPRINT (yyoutput
, yytoknum
[yytype
], *yyvaluep
);
888 /*--------------------------------.
889 | Print this symbol on YYOUTPUT. |
890 `--------------------------------*/
892 #if (defined __STDC__ || defined __C99__FUNC__ \
893 || defined __cplusplus || defined _MSC_VER)
895 yy_symbol_print (FILE *yyoutput
, int yytype
, const YYSTYPE
* const yyvaluep
, const YYLTYPE
* const yylocationp
)
898 yy_symbol_print (yyoutput
, yytype
, yyvaluep
, yylocationp
)
901 const YYSTYPE
* const yyvaluep
;
902 const YYLTYPE
* const yylocationp
;
905 if (yytype
< YYNTOKENS
)
906 YYFPRINTF (yyoutput
, "token %s (", yytname
[yytype
]);
908 YYFPRINTF (yyoutput
, "nterm %s (", yytname
[yytype
]);
910 YY_LOCATION_PRINT (yyoutput
, *yylocationp
);
911 YYFPRINTF (yyoutput
, ": ");
912 yy_symbol_value_print (yyoutput
, yytype
, yyvaluep
, yylocationp
);
913 YYFPRINTF (yyoutput
, ")");
916 /*------------------------------------------------------------------.
917 | yy_stack_print -- Print the state stack from its BOTTOM up to its |
919 `------------------------------------------------------------------*/
921 #if (defined __STDC__ || defined __C99__FUNC__ \
922 || defined __cplusplus || defined _MSC_VER)
924 yy_stack_print (yytype_int16
*bottom
, yytype_int16
*top
)
927 yy_stack_print (bottom
, top
)
928 yytype_int16
*bottom
;
932 YYFPRINTF (stderr
, "Stack now");
933 for (; bottom
<= top
; ++bottom
)
934 YYFPRINTF (stderr
, " %d", *bottom
);
935 YYFPRINTF (stderr
, "\n");
938 # define YY_STACK_PRINT(Bottom, Top) \
941 yy_stack_print ((Bottom), (Top)); \
945 /*------------------------------------------------.
946 | Report that the YYRULE is going to be reduced. |
947 `------------------------------------------------*/
949 #if (defined __STDC__ || defined __C99__FUNC__ \
950 || defined __cplusplus || defined _MSC_VER)
952 yy_reduce_print (YYSTYPE
*yyvsp
, YYLTYPE
*yylsp
, int yyrule
)
955 yy_reduce_print (yyvsp
, yylsp
, yyrule
962 int yynrhs
= yyr2
[yyrule
];
964 unsigned long int yylno
= yyrline
[yyrule
];
965 YYFPRINTF (stderr
, "Reducing stack by rule %d (line %lu):\n",
967 /* The symbols being reduced. */
968 for (yyi
= 0; yyi
< yynrhs
; yyi
++)
970 fprintf (stderr
, " $%d = ", yyi
+ 1);
971 yy_symbol_print (stderr
, yyrhs
[yyprhs
[yyrule
] + yyi
],
972 &(yyvsp
[(yyi
+ 1) - (yynrhs
)])
973 , &(yylsp
[(yyi
+ 1) - (yynrhs
)]) );
974 fprintf (stderr
, "\n");
978 # define YY_REDUCE_PRINT(Rule) \
981 yy_reduce_print (yyvsp, yylsp, Rule); \
984 /* Nonzero means print parse trace. It is left uninitialized so that
985 multiple parsers can coexist. */
988 # define YYDPRINTF(Args)
989 # define YY_SYMBOL_PRINT(Title, Type, Value, Location)
990 # define YY_STACK_PRINT(Bottom, Top)
991 # define YY_REDUCE_PRINT(Rule)
992 #endif /* !YYDEBUG */
995 /* YYINITDEPTH -- initial size of the parser's stacks. */
997 # define YYINITDEPTH 200
1000 /* YYMAXDEPTH -- maximum size the stacks can grow to (effective only
1001 if the built-in stack extension method is used).
1003 Do not make this value too large; the results are undefined if
1004 YYSTACK_ALLOC_MAXIMUM < YYSTACK_BYTES (YYMAXDEPTH)
1005 evaluated with infinite-precision integer arithmetic. */
1008 # define YYMAXDEPTH 10000
1016 # if defined __GLIBC__ && defined _STRING_H
1017 # define yystrlen strlen
1019 /* Return the length of YYSTR. */
1020 #if (defined __STDC__ || defined __C99__FUNC__ \
1021 || defined __cplusplus || defined _MSC_VER)
1023 yystrlen (const char *yystr
)
1031 for (yylen
= 0; yystr
[yylen
]; yylen
++)
1039 # if defined __GLIBC__ && defined _STRING_H && defined _GNU_SOURCE
1040 # define yystpcpy stpcpy
1042 /* Copy YYSRC to YYDEST, returning the address of the terminating '\0' in
1044 #if (defined __STDC__ || defined __C99__FUNC__ \
1045 || defined __cplusplus || defined _MSC_VER)
1047 yystpcpy (char *yydest
, const char *yysrc
)
1050 yystpcpy (yydest
, yysrc
)
1056 const char *yys
= yysrc
;
1058 while ((*yyd
++ = *yys
++) != '\0')
1067 /* Copy to YYRES the contents of YYSTR after stripping away unnecessary
1068 quotes and backslashes, so that it's suitable for yyerror. The
1069 heuristic is that double-quoting is unnecessary unless the string
1070 contains an apostrophe, a comma, or backslash (other than
1071 backslash-backslash). YYSTR is taken from yytname. If YYRES is
1072 null, do not copy; instead, return the length of what the result
1075 yytnamerr (char *yyres
, const char *yystr
)
1080 char const *yyp
= yystr
;
1087 goto do_not_strip_quotes
;
1091 goto do_not_strip_quotes
;
1104 do_not_strip_quotes
: ;
1108 return yystrlen (yystr
);
1110 return yystpcpy (yyres
, yystr
) - yyres
;
1114 /* Copy into YYRESULT an error message about the unexpected token
1115 YYCHAR while in state YYSTATE. Return the number of bytes copied,
1116 including the terminating null byte. If YYRESULT is null, do not
1117 copy anything; just return the number of bytes that would be
1118 copied. As a special case, return 0 if an ordinary "syntax error"
1119 message will do. Return YYSIZE_MAXIMUM if overflow occurs during
1120 size calculation. */
1122 yysyntax_error (char *yyresult
, int yystate
, int yychar
)
1124 int yyn
= yypact
[yystate
];
1126 if (! (YYPACT_NINF
< yyn
&& yyn
< YYLAST
))
1130 int yytype
= YYTRANSLATE (yychar
);
1131 YYSIZE_T yysize0
= yytnamerr (0, yytname
[yytype
]);
1132 YYSIZE_T yysize
= yysize0
;
1134 int yysize_overflow
= 0;
1135 enum { YYERROR_VERBOSE_ARGS_MAXIMUM
= 5 };
1136 char const *yyarg
[YYERROR_VERBOSE_ARGS_MAXIMUM
];
1140 /* This is so xgettext sees the translatable formats that are
1141 constructed on the fly. */
1142 YY_("syntax error, unexpected %s");
1143 YY_("syntax error, unexpected %s, expecting %s");
1144 YY_("syntax error, unexpected %s, expecting %s or %s");
1145 YY_("syntax error, unexpected %s, expecting %s or %s or %s");
1146 YY_("syntax error, unexpected %s, expecting %s or %s or %s or %s");
1150 static char const yyunexpected
[] = "syntax error, unexpected %s";
1151 static char const yyexpecting
[] = ", expecting %s";
1152 static char const yyor
[] = " or %s";
1153 char yyformat
[sizeof yyunexpected
1154 + sizeof yyexpecting
- 1
1155 + ((YYERROR_VERBOSE_ARGS_MAXIMUM
- 2)
1156 * (sizeof yyor
- 1))];
1157 char const *yyprefix
= yyexpecting
;
1159 /* Start YYX at -YYN if negative to avoid negative indexes in
1161 int yyxbegin
= yyn
< 0 ? -yyn
: 0;
1163 /* Stay within bounds of both yycheck and yytname. */
1164 int yychecklim
= YYLAST
- yyn
;
1165 int yyxend
= yychecklim
< YYNTOKENS
? yychecklim
: YYNTOKENS
;
1168 yyarg
[0] = yytname
[yytype
];
1169 yyfmt
= yystpcpy (yyformat
, yyunexpected
);
1171 for (yyx
= yyxbegin
; yyx
< yyxend
; ++yyx
)
1172 if (yycheck
[yyx
+ yyn
] == yyx
&& yyx
!= YYTERROR
)
1174 if (yycount
== YYERROR_VERBOSE_ARGS_MAXIMUM
)
1178 yyformat
[sizeof yyunexpected
- 1] = '\0';
1181 yyarg
[yycount
++] = yytname
[yyx
];
1182 yysize1
= yysize
+ yytnamerr (0, yytname
[yyx
]);
1183 yysize_overflow
|= (yysize1
< yysize
);
1185 yyfmt
= yystpcpy (yyfmt
, yyprefix
);
1189 yyf
= YY_(yyformat
);
1190 yysize1
= yysize
+ yystrlen (yyf
);
1191 yysize_overflow
|= (yysize1
< yysize
);
1194 if (yysize_overflow
)
1195 return YYSIZE_MAXIMUM
;
1199 /* Avoid sprintf, as that infringes on the user's name space.
1200 Don't have undefined behavior even if the translation
1201 produced a string with the wrong number of "%s"s. */
1202 char *yyp
= yyresult
;
1204 while ((*yyp
= *yyf
) != '\0')
1206 if (*yyp
== '%' && yyf
[1] == 's' && yyi
< yycount
)
1208 yyp
+= yytnamerr (yyp
, yyarg
[yyi
++]);
1221 #endif /* YYERROR_VERBOSE */
1224 /*-----------------------------------------------.
1225 | Release the memory associated to this symbol. |
1226 `-----------------------------------------------*/
1229 #if (defined __STDC__ || defined __C99__FUNC__ \
1230 || defined __cplusplus || defined _MSC_VER)
1232 yydestruct (const char *yymsg
, int yytype
, YYSTYPE
*yyvaluep
, YYLTYPE
*yylocationp
)
1235 yydestruct (yymsg
, yytype
, yyvaluep
, yylocationp
)
1239 YYLTYPE
*yylocationp
;
1243 YYUSE (yylocationp
);
1247 YY_SYMBOL_PRINT (yymsg
, yytype
, yyvaluep
, yylocationp
);
1251 case 3: /* "TOK_COLONCOLON" */
1252 #line 162 "ast_expr2.y"
1253 { free_value((yyvaluep
->val
)); };
1254 #line 1250 "ast_expr2.c"
1256 case 4: /* "TOK_COND" */
1257 #line 162 "ast_expr2.y"
1258 { free_value((yyvaluep
->val
)); };
1259 #line 1255 "ast_expr2.c"
1261 case 5: /* "TOK_OR" */
1262 #line 162 "ast_expr2.y"
1263 { free_value((yyvaluep
->val
)); };
1264 #line 1260 "ast_expr2.c"
1266 case 6: /* "TOK_AND" */
1267 #line 162 "ast_expr2.y"
1268 { free_value((yyvaluep
->val
)); };
1269 #line 1265 "ast_expr2.c"
1271 case 7: /* "TOK_NE" */
1272 #line 162 "ast_expr2.y"
1273 { free_value((yyvaluep
->val
)); };
1274 #line 1270 "ast_expr2.c"
1276 case 8: /* "TOK_LE" */
1277 #line 162 "ast_expr2.y"
1278 { free_value((yyvaluep
->val
)); };
1279 #line 1275 "ast_expr2.c"
1281 case 9: /* "TOK_GE" */
1282 #line 162 "ast_expr2.y"
1283 { free_value((yyvaluep
->val
)); };
1284 #line 1280 "ast_expr2.c"
1286 case 10: /* "TOK_LT" */
1287 #line 162 "ast_expr2.y"
1288 { free_value((yyvaluep
->val
)); };
1289 #line 1285 "ast_expr2.c"
1291 case 11: /* "TOK_GT" */
1292 #line 162 "ast_expr2.y"
1293 { free_value((yyvaluep
->val
)); };
1294 #line 1290 "ast_expr2.c"
1296 case 12: /* "TOK_EQ" */
1297 #line 162 "ast_expr2.y"
1298 { free_value((yyvaluep
->val
)); };
1299 #line 1295 "ast_expr2.c"
1301 case 13: /* "TOK_MINUS" */
1302 #line 162 "ast_expr2.y"
1303 { free_value((yyvaluep
->val
)); };
1304 #line 1300 "ast_expr2.c"
1306 case 14: /* "TOK_PLUS" */
1307 #line 162 "ast_expr2.y"
1308 { free_value((yyvaluep
->val
)); };
1309 #line 1305 "ast_expr2.c"
1311 case 15: /* "TOK_MOD" */
1312 #line 162 "ast_expr2.y"
1313 { free_value((yyvaluep
->val
)); };
1314 #line 1310 "ast_expr2.c"
1316 case 16: /* "TOK_DIV" */
1317 #line 162 "ast_expr2.y"
1318 { free_value((yyvaluep
->val
)); };
1319 #line 1315 "ast_expr2.c"
1321 case 17: /* "TOK_MULT" */
1322 #line 162 "ast_expr2.y"
1323 { free_value((yyvaluep
->val
)); };
1324 #line 1320 "ast_expr2.c"
1326 case 18: /* "TOK_COMPL" */
1327 #line 162 "ast_expr2.y"
1328 { free_value((yyvaluep
->val
)); };
1329 #line 1325 "ast_expr2.c"
1331 case 19: /* "TOK_EQTILDE" */
1332 #line 162 "ast_expr2.y"
1333 { free_value((yyvaluep
->val
)); };
1334 #line 1330 "ast_expr2.c"
1336 case 20: /* "TOK_COLON" */
1337 #line 162 "ast_expr2.y"
1338 { free_value((yyvaluep
->val
)); };
1339 #line 1335 "ast_expr2.c"
1341 case 21: /* "TOK_LP" */
1342 #line 162 "ast_expr2.y"
1343 { free_value((yyvaluep
->val
)); };
1344 #line 1340 "ast_expr2.c"
1346 case 22: /* "TOK_RP" */
1347 #line 162 "ast_expr2.y"
1348 { free_value((yyvaluep
->val
)); };
1349 #line 1345 "ast_expr2.c"
1351 case 23: /* "TOKEN" */
1352 #line 162 "ast_expr2.y"
1353 { free_value((yyvaluep
->val
)); };
1354 #line 1350 "ast_expr2.c"
1356 case 26: /* "expr" */
1357 #line 162 "ast_expr2.y"
1358 { free_value((yyvaluep
->val
)); };
1359 #line 1355 "ast_expr2.c"
1368 /* Prevent warnings from -Wmissing-prototypes. */
1370 #ifdef YYPARSE_PARAM
1371 #if defined __STDC__ || defined __cplusplus
1372 int yyparse (void *YYPARSE_PARAM
);
1376 #else /* ! YYPARSE_PARAM */
1377 #if defined __STDC__ || defined __cplusplus
1382 #endif /* ! YYPARSE_PARAM */
1393 #ifdef YYPARSE_PARAM
1394 #if (defined __STDC__ || defined __C99__FUNC__ \
1395 || defined __cplusplus || defined _MSC_VER)
1397 yyparse (void *YYPARSE_PARAM
)
1400 yyparse (YYPARSE_PARAM
)
1401 void *YYPARSE_PARAM
;
1403 #else /* ! YYPARSE_PARAM */
1404 #if (defined __STDC__ || defined __C99__FUNC__ \
1405 || defined __cplusplus || defined _MSC_VER)
1415 /* The look-ahead symbol. */
1418 /* The semantic value of the look-ahead symbol. */
1421 /* Number of syntax errors so far. */
1423 /* Location data for the look-ahead symbol. */
1429 /* Number of tokens to shift before error messages enabled. */
1431 /* Look-ahead token as an internal (translated) token number. */
1434 /* Buffer for error messages, and its allocated size. */
1436 char *yymsg
= yymsgbuf
;
1437 YYSIZE_T yymsg_alloc
= sizeof yymsgbuf
;
1440 /* Three stacks and their tools:
1441 `yyss': related to states,
1442 `yyvs': related to semantic values,
1443 `yyls': related to locations.
1445 Refer to the stacks thru separate pointers, to allow yyoverflow
1446 to reallocate them elsewhere. */
1448 /* The state stack. */
1449 yytype_int16 yyssa
[YYINITDEPTH
];
1450 yytype_int16
*yyss
= yyssa
;
1451 yytype_int16
*yyssp
;
1453 /* The semantic value stack. */
1454 YYSTYPE yyvsa
[YYINITDEPTH
];
1455 YYSTYPE
*yyvs
= yyvsa
;
1458 /* The location stack. */
1459 YYLTYPE yylsa
[YYINITDEPTH
];
1460 YYLTYPE
*yyls
= yylsa
;
1462 /* The locations where the error started and ended. */
1463 YYLTYPE yyerror_range
[2];
1465 #define YYPOPSTACK(N) (yyvsp -= (N), yyssp -= (N), yylsp -= (N))
1467 YYSIZE_T yystacksize
= YYINITDEPTH
;
1469 /* The variables used to return semantic value and location from the
1474 /* The number of symbols on the RHS of the reduced rule.
1475 Keep to zero when no symbol should be popped. */
1478 YYDPRINTF ((stderr
, "Starting parse\n"));
1483 yychar
= YYEMPTY
; /* Cause a token to be read. */
1485 /* Initialize stack pointers.
1486 Waste one element of value and location stack
1487 so that they stay on the same level as the state stack.
1488 The wasted elements are never initialized. */
1493 #if YYLTYPE_IS_TRIVIAL
1494 /* Initialize the default location before parsing starts. */
1495 yylloc
.first_line
= yylloc
.last_line
= 1;
1496 yylloc
.first_column
= yylloc
.last_column
= 0;
1501 /*------------------------------------------------------------.
1502 | yynewstate -- Push a new state, which is found in yystate. |
1503 `------------------------------------------------------------*/
1505 /* In all cases, when you get here, the value and location stacks
1506 have just been pushed. So pushing a state here evens the stacks. */
1512 if (yyss
+ yystacksize
- 1 <= yyssp
)
1514 /* Get the current used size of the three stacks, in elements. */
1515 YYSIZE_T yysize
= yyssp
- yyss
+ 1;
1519 /* Give user a chance to reallocate the stack. Use copies of
1520 these so that the &'s don't force the real ones into
1522 YYSTYPE
*yyvs1
= yyvs
;
1523 yytype_int16
*yyss1
= yyss
;
1524 YYLTYPE
*yyls1
= yyls
;
1526 /* Each stack pointer address is followed by the size of the
1527 data in use in that stack, in bytes. This used to be a
1528 conditional around just the two extra args, but that might
1529 be undefined if yyoverflow is a macro. */
1530 yyoverflow (YY_("memory exhausted"),
1531 &yyss1
, yysize
* sizeof (*yyssp
),
1532 &yyvs1
, yysize
* sizeof (*yyvsp
),
1533 &yyls1
, yysize
* sizeof (*yylsp
),
1539 #else /* no yyoverflow */
1540 # ifndef YYSTACK_RELOCATE
1541 goto yyexhaustedlab
;
1543 /* Extend the stack our own way. */
1544 if (YYMAXDEPTH
<= yystacksize
)
1545 goto yyexhaustedlab
;
1547 if (YYMAXDEPTH
< yystacksize
)
1548 yystacksize
= YYMAXDEPTH
;
1551 yytype_int16
*yyss1
= yyss
;
1552 union yyalloc
*yyptr
=
1553 (union yyalloc
*) YYSTACK_ALLOC (YYSTACK_BYTES (yystacksize
));
1555 goto yyexhaustedlab
;
1556 YYSTACK_RELOCATE (yyss
);
1557 YYSTACK_RELOCATE (yyvs
);
1558 YYSTACK_RELOCATE (yyls
);
1559 # undef YYSTACK_RELOCATE
1561 YYSTACK_FREE (yyss1
);
1564 #endif /* no yyoverflow */
1566 yyssp
= yyss
+ yysize
- 1;
1567 yyvsp
= yyvs
+ yysize
- 1;
1568 yylsp
= yyls
+ yysize
- 1;
1570 YYDPRINTF ((stderr
, "Stack size increased to %lu\n",
1571 (unsigned long int) yystacksize
));
1573 if (yyss
+ yystacksize
- 1 <= yyssp
)
1577 YYDPRINTF ((stderr
, "Entering state %d\n", yystate
));
1586 /* Do appropriate processing given the current state. Read a
1587 look-ahead token if we need one and don't already have one. */
1589 /* First try to decide what to do without reference to look-ahead token. */
1590 yyn
= yypact
[yystate
];
1591 if (yyn
== YYPACT_NINF
)
1594 /* Not known => get a look-ahead token if don't already have one. */
1596 /* YYCHAR is either YYEMPTY or YYEOF or a valid look-ahead symbol. */
1597 if (yychar
== YYEMPTY
)
1599 YYDPRINTF ((stderr
, "Reading a token: "));
1603 if (yychar
<= YYEOF
)
1605 yychar
= yytoken
= YYEOF
;
1606 YYDPRINTF ((stderr
, "Now at end of input.\n"));
1610 yytoken
= YYTRANSLATE (yychar
);
1611 YY_SYMBOL_PRINT ("Next token is", yytoken
, &yylval
, &yylloc
);
1614 /* If the proper action on seeing token YYTOKEN is to reduce or to
1615 detect an error, take that action. */
1617 if (yyn
< 0 || YYLAST
< yyn
|| yycheck
[yyn
] != yytoken
)
1622 if (yyn
== 0 || yyn
== YYTABLE_NINF
)
1631 /* Count tokens shifted since error; after three, turn off error
1636 /* Shift the look-ahead token. */
1637 YY_SYMBOL_PRINT ("Shifting", yytoken
, &yylval
, &yylloc
);
1639 /* Discard the shifted token unless it is eof. */
1640 if (yychar
!= YYEOF
)
1649 /*-----------------------------------------------------------.
1650 | yydefault -- do the default action for the current state. |
1651 `-----------------------------------------------------------*/
1653 yyn
= yydefact
[yystate
];
1659 /*-----------------------------.
1660 | yyreduce -- Do a reduction. |
1661 `-----------------------------*/
1663 /* yyn is the number of a rule to reduce with. */
1666 /* If YYLEN is nonzero, implement the default value of the action:
1669 Otherwise, the following line sets YYVAL to garbage.
1670 This behavior is undocumented and Bison
1671 users should not rely upon it. Assigning to YYVAL
1672 unconditionally makes the parser a bit smaller, and it avoids a
1673 GCC warning that YYVAL may be used uninitialized. */
1674 yyval
= yyvsp
[1-yylen
];
1676 /* Default location. */
1677 YYLLOC_DEFAULT (yyloc
, (yylsp
- yylen
), yylen
);
1678 YY_REDUCE_PRINT (yyn
);
1682 #line 168 "ast_expr2.y"
1683 { ((struct parse_io
*)parseio
)->val
= (struct val
*)calloc(sizeof(struct val
),1);
1684 ((struct parse_io
*)parseio
)->val
->type
= (yyvsp
[(1) - (1)].val
)->type
;
1685 if( (yyvsp
[(1) - (1)].val
)->type
== AST_EXPR_integer
)
1686 ((struct parse_io
*)parseio
)->val
->u
.i
= (yyvsp
[(1) - (1)].val
)->u
.i
;
1688 ((struct parse_io
*)parseio
)->val
->u
.s
= (yyvsp
[(1) - (1)].val
)->u
.s
;
1689 free((yyvsp
[(1) - (1)].val
));
1694 #line 176 "ast_expr2.y"
1695 {/* nothing */ ((struct parse_io
*)parseio
)->val
= (struct val
*)calloc(sizeof(struct val
),1);
1696 ((struct parse_io
*)parseio
)->val
->type
= AST_EXPR_string
;
1697 ((struct parse_io
*)parseio
)->val
->u
.s
= strdup("");
1702 #line 183 "ast_expr2.y"
1703 { (yyval
.val
)= (yyvsp
[(1) - (1)].val
);;}
1707 #line 184 "ast_expr2.y"
1708 { (yyval
.val
) = (yyvsp
[(2) - (3)].val
);
1709 (yyloc
).first_column
= (yylsp
[(1) - (3)]).first_column
; (yyloc
).last_column
= (yylsp
[(3) - (3)]).last_column
;
1710 (yyloc
).first_line
=0; (yyloc
).last_line
=0;
1711 DESTROY((yyvsp
[(1) - (3)].val
)); DESTROY((yyvsp
[(3) - (3)].val
)); ;}
1715 #line 188 "ast_expr2.y"
1716 { (yyval
.val
) = op_or ((yyvsp
[(1) - (3)].val
), (yyvsp
[(3) - (3)].val
));
1717 DESTROY((yyvsp
[(2) - (3)].val
));
1718 (yyloc
).first_column
= (yylsp
[(1) - (3)]).first_column
; (yyloc
).last_column
= (yylsp
[(3) - (3)]).last_column
;
1719 (yyloc
).first_line
=0; (yyloc
).last_line
=0;;}
1723 #line 192 "ast_expr2.y"
1724 { (yyval
.val
) = op_and ((yyvsp
[(1) - (3)].val
), (yyvsp
[(3) - (3)].val
));
1725 DESTROY((yyvsp
[(2) - (3)].val
));
1726 (yyloc
).first_column
= (yylsp
[(1) - (3)]).first_column
; (yyloc
).last_column
= (yylsp
[(3) - (3)]).last_column
;
1727 (yyloc
).first_line
=0; (yyloc
).last_line
=0;;}
1731 #line 196 "ast_expr2.y"
1732 { (yyval
.val
) = op_eq ((yyvsp
[(1) - (3)].val
), (yyvsp
[(3) - (3)].val
));
1733 DESTROY((yyvsp
[(2) - (3)].val
));
1734 (yyloc
).first_column
= (yylsp
[(1) - (3)]).first_column
; (yyloc
).last_column
= (yylsp
[(3) - (3)]).last_column
;
1735 (yyloc
).first_line
=0; (yyloc
).last_line
=0;;}
1739 #line 200 "ast_expr2.y"
1740 { (yyval
.val
) = op_gt ((yyvsp
[(1) - (3)].val
), (yyvsp
[(3) - (3)].val
));
1741 DESTROY((yyvsp
[(2) - (3)].val
));
1742 (yyloc
).first_column
= (yylsp
[(1) - (3)]).first_column
; (yyloc
).last_column
= (yylsp
[(3) - (3)]).last_column
;
1743 (yyloc
).first_line
=0; (yyloc
).last_line
=0;;}
1747 #line 204 "ast_expr2.y"
1748 { (yyval
.val
) = op_lt ((yyvsp
[(1) - (3)].val
), (yyvsp
[(3) - (3)].val
));
1749 DESTROY((yyvsp
[(2) - (3)].val
));
1750 (yyloc
).first_column
= (yylsp
[(1) - (3)]).first_column
; (yyloc
).last_column
= (yylsp
[(3) - (3)]).last_column
;
1751 (yyloc
).first_line
=0; (yyloc
).last_line
=0;;}
1755 #line 208 "ast_expr2.y"
1756 { (yyval
.val
) = op_ge ((yyvsp
[(1) - (3)].val
), (yyvsp
[(3) - (3)].val
));
1757 DESTROY((yyvsp
[(2) - (3)].val
));
1758 (yyloc
).first_column
= (yylsp
[(1) - (3)]).first_column
; (yyloc
).last_column
= (yylsp
[(3) - (3)]).last_column
;
1759 (yyloc
).first_line
=0; (yyloc
).last_line
=0;;}
1763 #line 212 "ast_expr2.y"
1764 { (yyval
.val
) = op_le ((yyvsp
[(1) - (3)].val
), (yyvsp
[(3) - (3)].val
));
1765 DESTROY((yyvsp
[(2) - (3)].val
));
1766 (yyloc
).first_column
= (yylsp
[(1) - (3)]).first_column
; (yyloc
).last_column
= (yylsp
[(3) - (3)]).last_column
;
1767 (yyloc
).first_line
=0; (yyloc
).last_line
=0;;}
1771 #line 216 "ast_expr2.y"
1772 { (yyval
.val
) = op_ne ((yyvsp
[(1) - (3)].val
), (yyvsp
[(3) - (3)].val
));
1773 DESTROY((yyvsp
[(2) - (3)].val
));
1774 (yyloc
).first_column
= (yylsp
[(1) - (3)]).first_column
; (yyloc
).last_column
= (yylsp
[(3) - (3)]).last_column
;
1775 (yyloc
).first_line
=0; (yyloc
).last_line
=0;;}
1779 #line 220 "ast_expr2.y"
1780 { (yyval
.val
) = op_plus ((yyvsp
[(1) - (3)].val
), (yyvsp
[(3) - (3)].val
));
1781 DESTROY((yyvsp
[(2) - (3)].val
));
1782 (yyloc
).first_column
= (yylsp
[(1) - (3)]).first_column
; (yyloc
).last_column
= (yylsp
[(3) - (3)]).last_column
;
1783 (yyloc
).first_line
=0; (yyloc
).last_line
=0;;}
1787 #line 224 "ast_expr2.y"
1788 { (yyval
.val
) = op_minus ((yyvsp
[(1) - (3)].val
), (yyvsp
[(3) - (3)].val
));
1789 DESTROY((yyvsp
[(2) - (3)].val
));
1790 (yyloc
).first_column
= (yylsp
[(1) - (3)]).first_column
; (yyloc
).last_column
= (yylsp
[(3) - (3)]).last_column
;
1791 (yyloc
).first_line
=0; (yyloc
).last_line
=0;;}
1795 #line 228 "ast_expr2.y"
1796 { (yyval
.val
) = op_negate ((yyvsp
[(2) - (2)].val
));
1797 DESTROY((yyvsp
[(1) - (2)].val
));
1798 (yyloc
).first_column
= (yylsp
[(1) - (2)]).first_column
; (yyloc
).last_column
= (yylsp
[(2) - (2)]).last_column
;
1799 (yyloc
).first_line
=0; (yyloc
).last_line
=0;;}
1803 #line 232 "ast_expr2.y"
1804 { (yyval
.val
) = op_compl ((yyvsp
[(2) - (2)].val
));
1805 DESTROY((yyvsp
[(1) - (2)].val
));
1806 (yyloc
).first_column
= (yylsp
[(1) - (2)]).first_column
; (yyloc
).last_column
= (yylsp
[(2) - (2)]).last_column
;
1807 (yyloc
).first_line
=0; (yyloc
).last_line
=0;;}
1811 #line 236 "ast_expr2.y"
1812 { (yyval
.val
) = op_times ((yyvsp
[(1) - (3)].val
), (yyvsp
[(3) - (3)].val
));
1813 DESTROY((yyvsp
[(2) - (3)].val
));
1814 (yyloc
).first_column
= (yylsp
[(1) - (3)]).first_column
; (yyloc
).last_column
= (yylsp
[(3) - (3)]).last_column
;
1815 (yyloc
).first_line
=0; (yyloc
).last_line
=0;;}
1819 #line 240 "ast_expr2.y"
1820 { (yyval
.val
) = op_div ((yyvsp
[(1) - (3)].val
), (yyvsp
[(3) - (3)].val
));
1821 DESTROY((yyvsp
[(2) - (3)].val
));
1822 (yyloc
).first_column
= (yylsp
[(1) - (3)]).first_column
; (yyloc
).last_column
= (yylsp
[(3) - (3)]).last_column
;
1823 (yyloc
).first_line
=0; (yyloc
).last_line
=0;;}
1827 #line 244 "ast_expr2.y"
1828 { (yyval
.val
) = op_rem ((yyvsp
[(1) - (3)].val
), (yyvsp
[(3) - (3)].val
));
1829 DESTROY((yyvsp
[(2) - (3)].val
));
1830 (yyloc
).first_column
= (yylsp
[(1) - (3)]).first_column
; (yyloc
).last_column
= (yylsp
[(3) - (3)]).last_column
;
1831 (yyloc
).first_line
=0; (yyloc
).last_line
=0;;}
1835 #line 248 "ast_expr2.y"
1836 { (yyval
.val
) = op_colon ((yyvsp
[(1) - (3)].val
), (yyvsp
[(3) - (3)].val
));
1837 DESTROY((yyvsp
[(2) - (3)].val
));
1838 (yyloc
).first_column
= (yylsp
[(1) - (3)]).first_column
; (yyloc
).last_column
= (yylsp
[(3) - (3)]).last_column
;
1839 (yyloc
).first_line
=0; (yyloc
).last_line
=0;;}
1843 #line 252 "ast_expr2.y"
1844 { (yyval
.val
) = op_eqtilde ((yyvsp
[(1) - (3)].val
), (yyvsp
[(3) - (3)].val
));
1845 DESTROY((yyvsp
[(2) - (3)].val
));
1846 (yyloc
).first_column
= (yylsp
[(1) - (3)]).first_column
; (yyloc
).last_column
= (yylsp
[(3) - (3)]).last_column
;
1847 (yyloc
).first_line
=0; (yyloc
).last_line
=0;;}
1851 #line 256 "ast_expr2.y"
1852 { (yyval
.val
) = op_cond ((yyvsp
[(1) - (5)].val
), (yyvsp
[(3) - (5)].val
), (yyvsp
[(5) - (5)].val
));
1853 DESTROY((yyvsp
[(2) - (5)].val
));
1854 DESTROY((yyvsp
[(4) - (5)].val
));
1855 (yyloc
).first_column
= (yylsp
[(1) - (5)]).first_column
; (yyloc
).last_column
= (yylsp
[(3) - (5)]).last_column
;
1856 (yyloc
).first_line
=0; (yyloc
).last_line
=0;;}
1860 /* Line 1270 of yacc.c. */
1861 #line 1857 "ast_expr2.c"
1864 YY_SYMBOL_PRINT ("-> $$ =", yyr1
[yyn
], &yyval
, &yyloc
);
1868 YY_STACK_PRINT (yyss
, yyssp
);
1873 /* Now `shift' the result of the reduction. Determine what state
1874 that goes to, based on the state we popped back to and the rule
1875 number reduced by. */
1879 yystate
= yypgoto
[yyn
- YYNTOKENS
] + *yyssp
;
1880 if (0 <= yystate
&& yystate
<= YYLAST
&& yycheck
[yystate
] == *yyssp
)
1881 yystate
= yytable
[yystate
];
1883 yystate
= yydefgoto
[yyn
- YYNTOKENS
];
1888 /*------------------------------------.
1889 | yyerrlab -- here on detecting error |
1890 `------------------------------------*/
1892 /* If not already recovering from an error, report this error. */
1896 #if ! YYERROR_VERBOSE
1897 yyerror (YY_("syntax error"));
1900 YYSIZE_T yysize
= yysyntax_error (0, yystate
, yychar
);
1901 if (yymsg_alloc
< yysize
&& yymsg_alloc
< YYSTACK_ALLOC_MAXIMUM
)
1903 YYSIZE_T yyalloc
= 2 * yysize
;
1904 if (! (yysize
<= yyalloc
&& yyalloc
<= YYSTACK_ALLOC_MAXIMUM
))
1905 yyalloc
= YYSTACK_ALLOC_MAXIMUM
;
1906 if (yymsg
!= yymsgbuf
)
1907 YYSTACK_FREE (yymsg
);
1908 yymsg
= (char *) YYSTACK_ALLOC (yyalloc
);
1910 yymsg_alloc
= yyalloc
;
1914 yymsg_alloc
= sizeof yymsgbuf
;
1918 if (0 < yysize
&& yysize
<= yymsg_alloc
)
1920 (void) yysyntax_error (yymsg
, yystate
, yychar
);
1925 yyerror (YY_("syntax error"));
1927 goto yyexhaustedlab
;
1933 yyerror_range
[0] = yylloc
;
1935 if (yyerrstatus
== 3)
1937 /* If just tried and failed to reuse look-ahead token after an
1938 error, discard it. */
1940 if (yychar
<= YYEOF
)
1942 /* Return failure if at end of input. */
1943 if (yychar
== YYEOF
)
1948 yydestruct ("Error: discarding",
1949 yytoken
, &yylval
, &yylloc
);
1954 /* Else will try to reuse look-ahead token after shifting the error
1959 /*---------------------------------------------------.
1960 | yyerrorlab -- error raised explicitly by YYERROR. |
1961 `---------------------------------------------------*/
1964 /* Pacify compilers like GCC when the user code never invokes
1965 YYERROR and the label yyerrorlab therefore never appears in user
1967 if (/*CONSTCOND*/ 0)
1970 yyerror_range
[0] = yylsp
[1-yylen
];
1971 /* Do not reclaim the symbols of the rule which action triggered
1975 YY_STACK_PRINT (yyss
, yyssp
);
1980 /*-------------------------------------------------------------.
1981 | yyerrlab1 -- common code for both syntax error and YYERROR. |
1982 `-------------------------------------------------------------*/
1984 yyerrstatus
= 3; /* Each real token shifted decrements this. */
1988 yyn
= yypact
[yystate
];
1989 if (yyn
!= YYPACT_NINF
)
1992 if (0 <= yyn
&& yyn
<= YYLAST
&& yycheck
[yyn
] == YYTERROR
)
2000 /* Pop the current state because it cannot handle the error token. */
2004 yyerror_range
[0] = *yylsp
;
2005 yydestruct ("Error: popping",
2006 yystos
[yystate
], yyvsp
, yylsp
);
2009 YY_STACK_PRINT (yyss
, yyssp
);
2017 yyerror_range
[1] = yylloc
;
2018 /* Using YYLLOC is tempting, but would change the location of
2019 the look-ahead. YYLOC is available though. */
2020 YYLLOC_DEFAULT (yyloc
, (yyerror_range
- 1), 2);
2023 /* Shift the error token. */
2024 YY_SYMBOL_PRINT ("Shifting", yystos
[yyn
], yyvsp
, yylsp
);
2030 /*-------------------------------------.
2031 | yyacceptlab -- YYACCEPT comes here. |
2032 `-------------------------------------*/
2037 /*-----------------------------------.
2038 | yyabortlab -- YYABORT comes here. |
2039 `-----------------------------------*/
2045 /*-------------------------------------------------.
2046 | yyexhaustedlab -- memory exhaustion comes here. |
2047 `-------------------------------------------------*/
2049 yyerror (YY_("memory exhausted"));
2055 if (yychar
!= YYEOF
&& yychar
!= YYEMPTY
)
2056 yydestruct ("Cleanup: discarding lookahead",
2057 yytoken
, &yylval
, &yylloc
);
2058 /* Do not reclaim the symbols of the rule which action triggered
2059 this YYABORT or YYACCEPT. */
2061 YY_STACK_PRINT (yyss
, yyssp
);
2062 while (yyssp
!= yyss
)
2064 yydestruct ("Cleanup: popping",
2065 yystos
[*yyssp
], yyvsp
, yylsp
);
2070 YYSTACK_FREE (yyss
);
2073 if (yymsg
!= yymsgbuf
)
2074 YYSTACK_FREE (yymsg
);
2080 #line 263 "ast_expr2.y"
2084 make_integer (quad_t i
)
2088 vp
= (struct val
*) malloc (sizeof (*vp
));
2090 ast_log(LOG_WARNING
, "malloc() failed\n");
2094 vp
->type
= AST_EXPR_integer
;
2100 make_str (const char *s
)
2106 vp
= (struct val
*) malloc (sizeof (*vp
));
2107 if (vp
== NULL
|| ((vp
->u
.s
= strdup (s
)) == NULL
)) {
2108 ast_log(LOG_WARNING
,"malloc() failed\n");
2112 for(i
= 1, isint
= isdigit(s
[0]) || s
[0] == '-';
2113 isint
&& i
< strlen(s
);
2121 vp
->type
= AST_EXPR_numeric_string
;
2123 vp
->type
= AST_EXPR_string
;
2130 free_value (struct val
*vp
)
2135 if (vp
->type
== AST_EXPR_string
|| vp
->type
== AST_EXPR_numeric_string
)
2142 to_integer (struct val
*vp
)
2147 ast_log(LOG_WARNING
,"vp==NULL in to_integer()\n");
2151 if (vp
->type
== AST_EXPR_integer
)
2154 if (vp
->type
== AST_EXPR_string
)
2157 /* vp->type == AST_EXPR_numeric_string, make it numeric */
2159 i
= strtoll(vp
->u
.s
, (char**)NULL
, 10);
2161 ast_log(LOG_WARNING
,"Conversion of %s to integer under/overflowed!\n", vp
->u
.s
);
2168 vp
->type
= AST_EXPR_integer
;
2173 strip_quotes(struct val
*vp
)
2175 if (vp
->type
!= AST_EXPR_string
&& vp
->type
!= AST_EXPR_numeric_string
)
2178 if( vp
->u
.s
[0] == '"' && vp
->u
.s
[strlen(vp
->u
.s
)-1] == '"' )
2186 if( *f
&& *f
!= '"' )
2196 to_string (struct val
*vp
)
2200 if (vp
->type
== AST_EXPR_string
|| vp
->type
== AST_EXPR_numeric_string
)
2203 tmp
= malloc ((size_t)25);
2205 ast_log(LOG_WARNING
,"malloc() failed\n");
2209 sprintf(tmp
, "%ld", (long int) vp
->u
.i
);
2210 vp
->type
= AST_EXPR_string
;
2216 isstring (struct val
*vp
)
2218 /* only TRUE if this string is not a valid integer */
2219 return (vp
->type
== AST_EXPR_string
);
2224 is_zero_or_null (struct val
*vp
)
2226 if (vp
->type
== AST_EXPR_integer
) {
2227 return (vp
->u
.i
== 0);
2229 return (*vp
->u
.s
== 0 || (to_integer (vp
) && vp
->u
.i
== 0));
2236 void ast_log(int level
, const char *file
, int line
, const char *function
, const char *fmt
, ...)
2241 printf("LOG: lev:%d file:%s line:%d func: %s ",
2242 level
, file
, line
, function
);
2249 int main(int argc
,char **argv
) {
2257 if( access(argv
[1],F_OK
)== 0 )
2261 infile
= fopen(argv
[1],"r");
2264 printf("Sorry, couldn't open %s for reading!\n", argv
[1]);
2267 while( fgets(s
,sizeof(s
),infile
) )
2269 if( s
[strlen(s
)-1] == '\n' )
2272 ret
= ast_expr(s
, out
, sizeof(out
));
2273 printf("Expression: %s Result: [%d] '%s'\n",
2280 if (ast_expr(argv
[1], s
, sizeof(s
)))
2281 printf("=====%s======\n",s
);
2283 printf("No result\n");
2290 #define ast_yyerror(x) ast_yyerror(x, YYLTYPE *yylloc, struct parse_io *parseio)
2292 /* I put the ast_yyerror func in the flex input file,
2293 because it refers to the buffer state. Best to
2294 let it access the BUFFER stuff there and not trying
2295 define all the structs, macros etc. in this file! */
2299 op_or (struct val
*a
, struct val
*b
)
2301 if (is_zero_or_null (a
)) {
2311 op_and (struct val
*a
, struct val
*b
)
2313 if (is_zero_or_null (a
) || is_zero_or_null (b
)) {
2316 return (make_integer ((quad_t
)0));
2324 op_eq (struct val
*a
, struct val
*b
)
2328 if (isstring (a
) || isstring (b
)) {
2331 r
= make_integer ((quad_t
)(strcoll (a
->u
.s
, b
->u
.s
) == 0));
2333 #ifdef DEBUG_FOR_CONVERSIONS
2335 sprintf(buffer
,"Converting '%s' and '%s' ", a
->u
.s
, b
->u
.s
);
2337 (void)to_integer(a
);
2338 (void)to_integer(b
);
2339 #ifdef DEBUG_FOR_CONVERSIONS
2340 ast_log(LOG_WARNING
,"%s to '%lld' and '%lld'\n", buffer
, a
->u
.i
, b
->u
.i
);
2342 r
= make_integer ((quad_t
)(a
->u
.i
== b
->u
.i
));
2351 op_gt (struct val
*a
, struct val
*b
)
2355 if (isstring (a
) || isstring (b
)) {
2358 r
= make_integer ((quad_t
)(strcoll (a
->u
.s
, b
->u
.s
) > 0));
2360 (void)to_integer(a
);
2361 (void)to_integer(b
);
2362 r
= make_integer ((quad_t
)(a
->u
.i
> b
->u
.i
));
2371 op_lt (struct val
*a
, struct val
*b
)
2375 if (isstring (a
) || isstring (b
)) {
2378 r
= make_integer ((quad_t
)(strcoll (a
->u
.s
, b
->u
.s
) < 0));
2380 (void)to_integer(a
);
2381 (void)to_integer(b
);
2382 r
= make_integer ((quad_t
)(a
->u
.i
< b
->u
.i
));
2391 op_ge (struct val
*a
, struct val
*b
)
2395 if (isstring (a
) || isstring (b
)) {
2398 r
= make_integer ((quad_t
)(strcoll (a
->u
.s
, b
->u
.s
) >= 0));
2400 (void)to_integer(a
);
2401 (void)to_integer(b
);
2402 r
= make_integer ((quad_t
)(a
->u
.i
>= b
->u
.i
));
2411 op_le (struct val
*a
, struct val
*b
)
2415 if (isstring (a
) || isstring (b
)) {
2418 r
= make_integer ((quad_t
)(strcoll (a
->u
.s
, b
->u
.s
) <= 0));
2420 (void)to_integer(a
);
2421 (void)to_integer(b
);
2422 r
= make_integer ((quad_t
)(a
->u
.i
<= b
->u
.i
));
2431 op_cond (struct val
*a
, struct val
*b
, struct val
*c
)
2437 if( strlen(a
->u
.s
) && strcmp(a
->u
.s
, "\"\"") != 0 && strcmp(a
->u
.s
,"0") != 0 )
2452 (void)to_integer(a
);
2470 op_ne (struct val
*a
, struct val
*b
)
2474 if (isstring (a
) || isstring (b
)) {
2477 r
= make_integer ((quad_t
)(strcoll (a
->u
.s
, b
->u
.s
) != 0));
2479 (void)to_integer(a
);
2480 (void)to_integer(b
);
2481 r
= make_integer ((quad_t
)(a
->u
.i
!= b
->u
.i
));
2490 chk_plus (quad_t a
, quad_t b
, quad_t r
)
2492 /* sum of two positive numbers must be positive */
2493 if (a
> 0 && b
> 0 && r
<= 0)
2495 /* sum of two negative numbers must be negative */
2496 if (a
< 0 && b
< 0 && r
>= 0)
2498 /* all other cases are OK */
2503 op_plus (struct val
*a
, struct val
*b
)
2507 if (!to_integer (a
)) {
2508 if( !extra_error_message_supplied
)
2509 ast_log(LOG_WARNING
,"non-numeric argument\n");
2510 if (!to_integer (b
)) {
2513 return make_integer(0);
2518 } else if (!to_integer(b
)) {
2523 r
= make_integer (/*(quad_t)*/(a
->u
.i
+ b
->u
.i
));
2524 if (chk_plus (a
->u
.i
, b
->u
.i
, r
->u
.i
)) {
2525 ast_log(LOG_WARNING
,"overflow\n");
2533 chk_minus (quad_t a
, quad_t b
, quad_t r
)
2535 /* special case subtraction of QUAD_MIN */
2536 if (b
== QUAD_MIN
) {
2542 /* this is allowed for b != QUAD_MIN */
2543 return chk_plus (a
, -b
, r
);
2547 op_minus (struct val
*a
, struct val
*b
)
2551 if (!to_integer (a
)) {
2552 if( !extra_error_message_supplied
)
2553 ast_log(LOG_WARNING
, "non-numeric argument\n");
2554 if (!to_integer (b
)) {
2557 return make_integer(0);
2559 r
= make_integer(0 - b
->u
.i
);
2564 } else if (!to_integer(b
)) {
2565 if( !extra_error_message_supplied
)
2566 ast_log(LOG_WARNING
, "non-numeric argument\n");
2571 r
= make_integer (/*(quad_t)*/(a
->u
.i
- b
->u
.i
));
2572 if (chk_minus (a
->u
.i
, b
->u
.i
, r
->u
.i
)) {
2573 ast_log(LOG_WARNING
, "overflow\n");
2581 op_negate (struct val
*a
)
2585 if (!to_integer (a
) ) {
2587 if( !extra_error_message_supplied
)
2588 ast_log(LOG_WARNING
, "non-numeric argument\n");
2589 return make_integer(0);
2592 r
= make_integer (/*(quad_t)*/(- a
->u
.i
));
2593 if (chk_minus (0, a
->u
.i
, r
->u
.i
)) {
2594 ast_log(LOG_WARNING
, "overflow\n");
2601 op_compl (struct val
*a
)
2614 case AST_EXPR_integer
:
2619 case AST_EXPR_string
:
2624 if( a
->u
.s
[0] == 0 )
2626 else if (strlen(a
->u
.s
) == 1 && a
->u
.s
[0] == '0' )
2631 case AST_EXPR_numeric_string
:
2636 if( a
->u
.s
[0] == 0 )
2638 else if (strlen(a
->u
.s
) == 1 && a
->u
.s
[0] == '0' )
2645 r
= make_integer (!v1
);
2651 chk_times (quad_t a
, quad_t b
, quad_t r
)
2653 /* special case: first operand is 0, no overflow possible */
2656 /* cerify that result of division matches second operand */
2663 op_times (struct val
*a
, struct val
*b
)
2667 if (!to_integer (a
) || !to_integer (b
)) {
2670 if( !extra_error_message_supplied
)
2671 ast_log(LOG_WARNING
, "non-numeric argument\n");
2672 return(make_integer(0));
2675 r
= make_integer (/*(quad_t)*/(a
->u
.i
* b
->u
.i
));
2676 if (chk_times (a
->u
.i
, b
->u
.i
, r
->u
.i
)) {
2677 ast_log(LOG_WARNING
, "overflow\n");
2685 chk_div (quad_t a
, quad_t b
)
2687 /* div by zero has been taken care of before */
2688 /* only QUAD_MIN / -1 causes overflow */
2689 if (a
== QUAD_MIN
&& b
== -1)
2691 /* everything else is OK */
2696 op_div (struct val
*a
, struct val
*b
)
2700 if (!to_integer (a
)) {
2703 if( !extra_error_message_supplied
)
2704 ast_log(LOG_WARNING
, "non-numeric argument\n");
2705 return make_integer(0);
2706 } else if (!to_integer (b
)) {
2709 if( !extra_error_message_supplied
)
2710 ast_log(LOG_WARNING
, "non-numeric argument\n");
2711 return make_integer(INT_MAX
);
2715 ast_log(LOG_WARNING
, "division by zero\n");
2718 return make_integer(INT_MAX
);
2721 r
= make_integer (/*(quad_t)*/(a
->u
.i
/ b
->u
.i
));
2722 if (chk_div (a
->u
.i
, b
->u
.i
)) {
2723 ast_log(LOG_WARNING
, "overflow\n");
2731 op_rem (struct val
*a
, struct val
*b
)
2735 if (!to_integer (a
) || !to_integer (b
)) {
2736 if( !extra_error_message_supplied
)
2737 ast_log(LOG_WARNING
, "non-numeric argument\n");
2740 return make_integer(0);
2744 ast_log(LOG_WARNING
, "div by zero\n");
2749 r
= make_integer (/*(quad_t)*/(a
->u
.i
% b
->u
.i
));
2750 /* chk_rem necessary ??? */
2758 op_colon (struct val
*a
, struct val
*b
)
2766 /* coerce to both arguments to strings */
2769 /* strip double quotes from both -- they'll screw up the pattern, and the search string starting at ^ */
2772 /* compile regular expression */
2773 if ((eval
= regcomp (&rp
, b
->u
.s
, REG_EXTENDED
)) != 0) {
2774 regerror (eval
, &rp
, errbuf
, sizeof(errbuf
));
2775 ast_log(LOG_WARNING
,"regcomp() error : %s",errbuf
);
2778 return make_str("");
2781 /* compare string against pattern */
2782 /* remember that patterns are anchored to the beginning of the line */
2783 if (regexec(&rp
, a
->u
.s
, (size_t)2, rm
, 0) == 0 && rm
[0].rm_so
== 0) {
2784 if (rm
[1].rm_so
>= 0) {
2785 *(a
->u
.s
+ rm
[1].rm_eo
) = '\0';
2786 v
= make_str (a
->u
.s
+ rm
[1].rm_so
);
2789 v
= make_integer ((quad_t
)(rm
[0].rm_eo
- rm
[0].rm_so
));
2792 if (rp
.re_nsub
== 0) {
2793 v
= make_integer ((quad_t
)0);
2799 /* free arguments and pattern buffer */
2809 op_eqtilde (struct val
*a
, struct val
*b
)
2817 /* coerce to both arguments to strings */
2820 /* strip double quotes from both -- they'll screw up the pattern, and the search string starting at ^ */
2823 /* compile regular expression */
2824 if ((eval
= regcomp (&rp
, b
->u
.s
, REG_EXTENDED
)) != 0) {
2825 regerror (eval
, &rp
, errbuf
, sizeof(errbuf
));
2826 ast_log(LOG_WARNING
,"regcomp() error : %s",errbuf
);
2829 return make_str("");
2832 /* compare string against pattern */
2833 /* remember that patterns are anchored to the beginning of the line */
2834 if (regexec(&rp
, a
->u
.s
, (size_t)2, rm
, 0) == 0 ) {
2835 if (rm
[1].rm_so
>= 0) {
2836 *(a
->u
.s
+ rm
[1].rm_eo
) = '\0';
2837 v
= make_str (a
->u
.s
+ rm
[1].rm_so
);
2840 v
= make_integer ((quad_t
)(rm
[0].rm_eo
- rm
[0].rm_so
));
2843 if (rp
.re_nsub
== 0) {
2844 v
= make_integer ((quad_t
)0);
2850 /* free arguments and pattern buffer */