![]() |
Home page |
Mailing list |
Docs
Asterisk developer's documentation :: Codename Pineapple
ast_expr2.c
Go to the documentation of this file.
00001 /* A Bison parser, made by GNU Bison 2.3. */ 00002 00003 /* Skeleton implementation for Bison's Yacc-like parsers in C 00004 00005 Copyright (C) 1984, 1989, 1990, 2000, 2001, 2002, 2003, 2004, 2005, 2006 00006 Free Software Foundation, Inc. 00007 00008 This program is free software; you can redistribute it and/or modify 00009 it under the terms of the GNU General Public License as published by 00010 the Free Software Foundation; either version 2, or (at your option) 00011 any later version. 00012 00013 This program is distributed in the hope that it will be useful, 00014 but WITHOUT ANY WARRANTY; without even the implied warranty of 00015 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00016 GNU General Public License for more details. 00017 00018 You should have received a copy of the GNU General Public License 00019 along with this program; if not, write to the Free Software 00020 Foundation, Inc., 51 Franklin Street, Fifth Floor, 00021 Boston, MA 02110-1301, USA. */ 00022 00023 /* As a special exception, you may create a larger work that contains 00024 part or all of the Bison parser skeleton and distribute that work 00025 under terms of your choice, so long as that work isn't itself a 00026 parser generator using the skeleton or a modified version thereof 00027 as a parser skeleton. Alternatively, if you modify or redistribute 00028 the parser skeleton itself, you may (at your option) remove this 00029 special exception, which will cause the skeleton and the resulting 00030 Bison output files to be licensed under the GNU General Public 00031 License without this special exception. 00032 00033 This special exception was added by the Free Software Foundation in 00034 version 2.2 of Bison. */ 00035 00036 /* C LALR(1) parser skeleton written by Richard Stallman, by 00037 simplifying the original so-called "semantic" parser. */ 00038 00039 /* All symbols defined below should begin with yy or YY, to avoid 00040 infringing on user name space. This should be done even for local 00041 variables, as they might otherwise be expanded by user macros. 00042 There are some unavoidable exceptions within include files to 00043 define necessary library symbols; they are noted "INFRINGES ON 00044 USER NAME SPACE" below. */ 00045 00046 /* Identify Bison output. */ 00047 #define YYBISON 1 00048 00049 /* Bison version. */ 00050 #define YYBISON_VERSION "2.3" 00051 00052 /* Skeleton name. */ 00053 #define YYSKELETON_NAME "yacc.c" 00054 00055 /* Pure parsers. */ 00056 #define YYPURE 1 00057 00058 /* Using locations. */ 00059 #define YYLSP_NEEDED 1 00060 00061 /* Substitute the variable and function names. */ 00062 #define yyparse ast_yyparse 00063 #define yylex ast_yylex 00064 #define yyerror ast_yyerror 00065 #define yylval ast_yylval 00066 #define yychar ast_yychar 00067 #define yydebug ast_yydebug 00068 #define yynerrs ast_yynerrs 00069 #define yylloc ast_yylloc 00070 00071 /* Tokens. */ 00072 #ifndef YYTOKENTYPE 00073 # define YYTOKENTYPE 00074 /* Put the tokens into the symbol table, so that GDB and other debuggers 00075 know about them. */ 00076 enum yytokentype { 00077 TOK_COLONCOLON = 258, 00078 TOK_COND = 259, 00079 TOK_OR = 260, 00080 TOK_AND = 261, 00081 TOK_NE = 262, 00082 TOK_LE = 263, 00083 TOK_GE = 264, 00084 TOK_LT = 265, 00085 TOK_GT = 266, 00086 TOK_EQ = 267, 00087 TOK_MINUS = 268, 00088 TOK_PLUS = 269, 00089 TOK_MOD = 270, 00090 TOK_DIV = 271, 00091 TOK_MULT = 272, 00092 TOK_COMPL = 273, 00093 TOK_EQTILDE = 274, 00094 TOK_COLON = 275, 00095 TOK_LP = 276, 00096 TOK_RP = 277, 00097 TOKEN = 278 00098 }; 00099 #endif 00100 /* Tokens. */ 00101 #define TOK_COLONCOLON 258 00102 #define TOK_COND 259 00103 #define TOK_OR 260 00104 #define TOK_AND 261 00105 #define TOK_NE 262 00106 #define TOK_LE 263 00107 #define TOK_GE 264 00108 #define TOK_LT 265 00109 #define TOK_GT 266 00110 #define TOK_EQ 267 00111 #define TOK_MINUS 268 00112 #define TOK_PLUS 269 00113 #define TOK_MOD 270 00114 #define TOK_DIV 271 00115 #define TOK_MULT 272 00116 #define TOK_COMPL 273 00117 #define TOK_EQTILDE 274 00118 #define TOK_COLON 275 00119 #define TOK_LP 276 00120 #define TOK_RP 277 00121 #define TOKEN 278 00122 00123 00124 00125 00126 /* Copy the first part of user declarations. */ 00127 #line 1 "ast_expr2.y" 00128 00129 /* Written by Pace Willisson (pace@blitz.com) 00130 * and placed in the public domain. 00131 * 00132 * Largely rewritten by J.T. Conklin (jtc@wimsey.com) 00133 * 00134 * And then overhauled twice by Steve Murphy (murf@e-tools.com) 00135 * to add double-quoted strings, allow mult. spaces, improve 00136 * error messages, and then to fold in a flex scanner for the 00137 * yylex operation. 00138 * 00139 * $FreeBSD: src/bin/expr/expr.y,v 1.16 2000/07/22 10:59:36 se Exp $ 00140 */ 00141 00142 #include "asterisk.h" 00143 00144 #ifndef STANDALONE 00145 ASTERISK_FILE_VERSION(__FILE__, "$Revision: 49116 $") 00146 #endif 00147 00148 #include <sys/types.h> 00149 #include <stdio.h> 00150 #include <stdlib.h> 00151 #include <string.h> 00152 #include <locale.h> 00153 #include <unistd.h> 00154 #include <ctype.h> 00155 #if !defined(SOLARIS) && !defined(__CYGWIN__) 00156 /* #include <err.h> */ 00157 #else 00158 #define quad_t int64_t 00159 #endif 00160 #include <errno.h> 00161 #include <regex.h> 00162 #include <limits.h> 00163 00164 #include "asterisk/ast_expr.h" 00165 #include "asterisk/logger.h" 00166 00167 #if defined(LONG_LONG_MIN) && !defined(QUAD_MIN) 00168 #define QUAD_MIN LONG_LONG_MIN 00169 #endif 00170 #if defined(LONG_LONG_MAX) && !defined(QUAD_MAX) 00171 #define QUAD_MAX LONG_LONG_MAX 00172 #endif 00173 00174 # if ! defined(QUAD_MIN) 00175 # define QUAD_MIN (-0x7fffffffffffffffLL-1) 00176 # endif 00177 # if ! defined(QUAD_MAX) 00178 # define QUAD_MAX (0x7fffffffffffffffLL) 00179 # endif 00180 00181 #define YYPARSE_PARAM parseio 00182 #define YYLEX_PARAM ((struct parse_io *)parseio)->scanner 00183 #define YYERROR_VERBOSE 1 00184 extern char extra_error_message[4095]; 00185 extern int extra_error_message_supplied; 00186 00187 enum valtype { 00188 AST_EXPR_integer, AST_EXPR_numeric_string, AST_EXPR_string 00189 } ; 00190 00191 #ifdef STANDALONE 00192 void ast_log(int level, const char *file, int line, const char *function, const char *fmt, ...) __attribute__ ((format (printf,5,6))); 00193 #endif 00194 00195 struct val { 00196 enum valtype type; 00197 union { 00198 char *s; 00199 quad_t i; 00200 } u; 00201 } ; 00202 00203 typedef void *yyscan_t; 00204 00205 struct parse_io 00206 { 00207 char *string; 00208 struct val *val; 00209 yyscan_t scanner; 00210 }; 00211 00212 static int chk_div __P((quad_t, quad_t)); 00213 static int chk_minus __P((quad_t, quad_t, quad_t)); 00214 static int chk_plus __P((quad_t, quad_t, quad_t)); 00215 static int chk_times __P((quad_t, quad_t, quad_t)); 00216 static void free_value __P((struct val *)); 00217 static int is_zero_or_null __P((struct val *)); 00218 static int isstring __P((struct val *)); 00219 static struct val *make_integer __P((quad_t)); 00220 static struct val *make_str __P((const char *)); 00221 static struct val *op_and __P((struct val *, struct val *)); 00222 static struct val *op_colon __P((struct val *, struct val *)); 00223 static struct val *op_eqtilde __P((struct val *, struct val *)); 00224 static struct val *op_div __P((struct val *, struct val *)); 00225 static struct val *op_eq __P((struct val *, struct val *)); 00226 static struct val *op_ge __P((struct val *, struct val *)); 00227 static struct val *op_gt __P((struct val *, struct val *)); 00228 static struct val *op_le __P((struct val *, struct val *)); 00229 static struct val *op_lt __P((struct val *, struct val *)); 00230 static struct val *op_cond __P((struct val *, struct val *, struct val *)); 00231 static struct val *op_minus __P((struct val *, struct val *)); 00232 static struct val *op_negate __P((struct val *)); 00233 static struct val *op_compl __P((struct val *)); 00234 static struct val *op_ne __P((struct val *, struct val *)); 00235 static struct val *op_or __P((struct val *, struct val *)); 00236 static struct val *op_plus __P((struct val *, struct val *)); 00237 static struct val *op_rem __P((struct val *, struct val *)); 00238 static struct val *op_times __P((struct val *, struct val *)); 00239 static quad_t to_integer __P((struct val *)); 00240 static void to_string __P((struct val *)); 00241 00242 /* uh, if I want to predeclare yylex with a YYLTYPE, I have to predeclare the yyltype... sigh */ 00243 typedef struct yyltype 00244 { 00245 int first_line; 00246 int first_column; 00247 00248 int last_line; 00249 int last_column; 00250 } yyltype; 00251 00252 # define YYLTYPE yyltype 00253 # define YYLTYPE_IS_TRIVIAL 1 00254 00255 /* we will get warning about no prototype for yylex! But we can't 00256 define it here, we have no definition yet for YYSTYPE. */ 00257 00258 int ast_yyerror(const char *,YYLTYPE *, struct parse_io *); 00259 00260 /* I wanted to add args to the yyerror routine, so I could print out 00261 some useful info about the error. Not as easy as it looks, but it 00262 is possible. */ 00263 #define ast_yyerror(x) ast_yyerror(x,&yyloc,parseio) 00264 #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);} 00265 00266 00267 /* Enabling traces. */ 00268 #ifndef YYDEBUG 00269 # define YYDEBUG 0 00270 #endif 00271 00272 /* Enabling verbose error messages. */ 00273 #ifdef YYERROR_VERBOSE 00274 # undef YYERROR_VERBOSE 00275 # define YYERROR_VERBOSE 1 00276 #else 00277 # define YYERROR_VERBOSE 0 00278 #endif 00279 00280 /* Enabling the token table. */ 00281 #ifndef YYTOKEN_TABLE 00282 # define YYTOKEN_TABLE 0 00283 #endif 00284 00285 #if ! defined YYSTYPE && ! defined YYSTYPE_IS_DECLARED 00286 typedef union YYSTYPE 00287 #line 147 "ast_expr2.y" 00288 { 00289 struct val *val; 00290 } 00291 /* Line 193 of yacc.c. */ 00292 #line 293 "ast_expr2.c" 00293 YYSTYPE; 00294 # define yystype YYSTYPE /* obsolescent; will be withdrawn */ 00295 # define YYSTYPE_IS_DECLARED 1 00296 # define YYSTYPE_IS_TRIVIAL 1 00297 #endif 00298 00299 #if ! defined YYLTYPE && ! defined YYLTYPE_IS_DECLARED 00300 typedef struct YYLTYPE 00301 { 00302 int first_line; 00303 int first_column; 00304 int last_line; 00305 int last_column; 00306 } YYLTYPE; 00307 # define yyltype YYLTYPE /* obsolescent; will be withdrawn */ 00308 # define YYLTYPE_IS_DECLARED 1 00309 # define YYLTYPE_IS_TRIVIAL 1 00310 #endif 00311 00312 00313 /* Copy the second part of user declarations. */ 00314 #line 151 "ast_expr2.y" 00315 00316 extern int ast_yylex __P((YYSTYPE *, YYLTYPE *, yyscan_t)); 00317 00318 00319 /* Line 216 of yacc.c. */ 00320 #line 321 "ast_expr2.c" 00321 00322 #ifdef short 00323 # undef short 00324 #endif 00325 00326 #ifdef YYTYPE_UINT8 00327 typedef YYTYPE_UINT8 yytype_uint8; 00328 #else 00329 typedef unsigned char yytype_uint8; 00330 #endif 00331 00332 #ifdef YYTYPE_INT8 00333 typedef YYTYPE_INT8 yytype_int8; 00334 #elif (defined __STDC__ || defined __C99__FUNC__ \ 00335 || defined __cplusplus || defined _MSC_VER) 00336 typedef signed char yytype_int8; 00337 #else 00338 typedef short int yytype_int8; 00339 #endif 00340 00341 #ifdef YYTYPE_UINT16 00342 typedef YYTYPE_UINT16 yytype_uint16; 00343 #else 00344 typedef unsigned short int yytype_uint16; 00345 #endif 00346 00347 #ifdef YYTYPE_INT16 00348 typedef YYTYPE_INT16 yytype_int16; 00349 #else 00350 typedef short int yytype_int16; 00351 #endif 00352 00353 #ifndef YYSIZE_T 00354 # ifdef __SIZE_TYPE__ 00355 # define YYSIZE_T __SIZE_TYPE__ 00356 # elif defined size_t 00357 # define YYSIZE_T size_t 00358 # elif ! defined YYSIZE_T && (defined __STDC__ || defined __C99__FUNC__ \ 00359 || defined __cplusplus || defined _MSC_VER) 00360 # include <stddef.h> /* INFRINGES ON USER NAME SPACE */ 00361 # define YYSIZE_T size_t 00362 # else 00363 # define YYSIZE_T unsigned int 00364 # endif 00365 #endif 00366 00367 #define YYSIZE_MAXIMUM ((YYSIZE_T) -1) 00368 00369 #ifndef YY_ 00370 # if YYENABLE_NLS 00371 # if ENABLE_NLS 00372 # include <libintl.h> /* INFRINGES ON USER NAME SPACE */ 00373 # define YY_(msgid) dgettext ("bison-runtime", msgid) 00374 # endif 00375 # endif 00376 # ifndef YY_ 00377 # define YY_(msgid) msgid 00378 # endif 00379 #endif 00380 00381 /* Suppress unused-variable warnings by "using" E. */ 00382 #if ! defined lint || defined __GNUC__ 00383 # define YYUSE(e) ((void) (e)) 00384 #else 00385 # define YYUSE(e) /* empty */ 00386 #endif 00387 00388 /* Identity function, used to suppress warnings about constant conditions. */ 00389 #ifndef lint 00390 # define YYID(n) (n) 00391 #else 00392 #if (defined __STDC__ || defined __C99__FUNC__ \ 00393 || defined __cplusplus || defined _MSC_VER) 00394 static int 00395 YYID (int i) 00396 #else 00397 static int 00398 YYID (i) 00399 int i; 00400 #endif 00401 { 00402 return i; 00403 } 00404 #endif 00405 00406 #if ! defined yyoverflow || YYERROR_VERBOSE 00407 00408 /* The parser invokes alloca or malloc; define the necessary symbols. */ 00409 00410 # ifdef YYSTACK_USE_ALLOCA 00411 # if YYSTACK_USE_ALLOCA 00412 # ifdef __GNUC__ 00413 # define YYSTACK_ALLOC __builtin_alloca 00414 # elif defined __BUILTIN_VA_ARG_INCR 00415 # include <alloca.h> /* INFRINGES ON USER NAME SPACE */ 00416 # elif defined _AIX 00417 # define YYSTACK_ALLOC __alloca 00418 # elif defined _MSC_VER 00419 # include <malloc.h> /* INFRINGES ON USER NAME SPACE */ 00420 # define alloca _alloca 00421 # else 00422 # define YYSTACK_ALLOC alloca 00423 # if ! defined _ALLOCA_H && ! defined _STDLIB_H && (defined __STDC__ || defined __C99__FUNC__ \ 00424 || defined __cplusplus || defined _MSC_VER) 00425 # include <stdlib.h> /* INFRINGES ON USER NAME SPACE */ 00426 # ifndef _STDLIB_H 00427 # define _STDLIB_H 1 00428 # endif 00429 # endif 00430 # endif 00431 # endif 00432 # endif 00433 00434 # ifdef YYSTACK_ALLOC 00435 /* Pacify GCC's `empty if-body' warning. */ 00436 # define YYSTACK_FREE(Ptr) do { /* empty */; } while (YYID (0)) 00437 # ifndef YYSTACK_ALLOC_MAXIMUM 00438 /* The OS might guarantee only one guard page at the bottom of the stack, 00439 and a page size can be as small as 4096 bytes. So we cannot safely 00440 invoke alloca (N) if N exceeds 4096. Use a slightly smaller number 00441 to allow for a few compiler-allocated temporary stack slots. */ 00442 # define YYSTACK_ALLOC_MAXIMUM 4032 /* reasonable circa 2006 */ 00443 # endif 00444 # else 00445 # define YYSTACK_ALLOC YYMALLOC 00446 # define YYSTACK_FREE YYFREE 00447 # ifndef YYSTACK_ALLOC_MAXIMUM 00448 # define YYSTACK_ALLOC_MAXIMUM YYSIZE_MAXIMUM 00449 # endif 00450 # if (defined __cplusplus && ! defined _STDLIB_H \ 00451 && ! ((defined YYMALLOC || defined malloc) \ 00452 && (defined YYFREE || defined free))) 00453 # include <stdlib.h> /* INFRINGES ON USER NAME SPACE */ 00454 # ifndef _STDLIB_H 00455 # define _STDLIB_H 1 00456 # endif 00457 # endif 00458 # ifndef YYMALLOC 00459 # define YYMALLOC malloc 00460 # if ! defined malloc && ! defined _STDLIB_H && (defined __STDC__ || defined __C99__FUNC__ \ 00461 || defined __cplusplus || defined _MSC_VER) 00462 void *malloc (YYSIZE_T); /* INFRINGES ON USER NAME SPACE */ 00463 # endif 00464 # endif 00465 # ifndef YYFREE 00466 # define YYFREE free 00467 # if ! defined free && ! defined _STDLIB_H && (defined __STDC__ || defined __C99__FUNC__ \ 00468 || defined __cplusplus || defined _MSC_VER) 00469 void free (void *); /* INFRINGES ON USER NAME SPACE */ 00470 # endif 00471 # endif 00472 # endif 00473 #endif /* ! defined yyoverflow || YYERROR_VERBOSE */ 00474 00475 00476 #if (! defined yyoverflow \ 00477 && (! defined __cplusplus \ 00478 || (defined YYLTYPE_IS_TRIVIAL && YYLTYPE_IS_TRIVIAL \ 00479 && defined YYSTYPE_IS_TRIVIAL && YYSTYPE_IS_TRIVIAL))) 00480 00481 /* A type that is properly aligned for any stack member. */ 00482 union yyalloc 00483 { 00484 yytype_int16 yyss; 00485 YYSTYPE yyvs; 00486 YYLTYPE yyls; 00487 }; 00488 00489 /* The size of the maximum gap between one aligned stack and the next. */ 00490 # define YYSTACK_GAP_MAXIMUM (sizeof (union yyalloc) - 1) 00491 00492 /* The size of an array large to enough to hold all stacks, each with 00493 N elements. */ 00494 # define YYSTACK_BYTES(N) \ 00495 ((N) * (sizeof (yytype_int16) + sizeof (YYSTYPE) + sizeof (YYLTYPE)) \ 00496 + 2 * YYSTACK_GAP_MAXIMUM) 00497 00498 /* Copy COUNT objects from FROM to TO. The source and destination do 00499 not overlap. */ 00500 # ifndef YYCOPY 00501 # if defined __GNUC__ && 1 < __GNUC__ 00502 # define YYCOPY(To, From, Count) \ 00503 __builtin_memcpy (To, From, (Count) * sizeof (*(From))) 00504 # else 00505 # define YYCOPY(To, From, Count) \ 00506 do \ 00507 { \ 00508 YYSIZE_T yyi; \ 00509 for (yyi = 0; yyi < (Count); yyi++) \ 00510 (To)[yyi] = (From)[yyi]; \ 00511 } \ 00512 while (YYID (0)) 00513 # endif 00514 # endif 00515 00516 /* Relocate STACK from its old location to the new one. The 00517 local variables YYSIZE and YYSTACKSIZE give the old and new number of 00518 elements in the stack, and YYPTR gives the new location of the 00519 stack. Advance YYPTR to a properly aligned location for the next 00520 stack. */ 00521 # define YYSTACK_RELOCATE(Stack) \ 00522 do \ 00523 { \ 00524 YYSIZE_T yynewbytes; \ 00525 YYCOPY (&yyptr->Stack, Stack, yysize); \ 00526 Stack = &yyptr->Stack; \ 00527 yynewbytes = yystacksize * sizeof (*Stack) + YYSTACK_GAP_MAXIMUM; \ 00528 yyptr += yynewbytes / sizeof (*yyptr); \ 00529 } \ 00530 while (YYID (0)) 00531 00532 #endif 00533 00534 /* YYFINAL -- State number of the termination state. */ 00535 #define YYFINAL 10 00536 /* YYLAST -- Last index in YYTABLE. */ 00537 #define YYLAST 140 00538 00539 /* YYNTOKENS -- Number of terminals. */ 00540 #define YYNTOKENS 24 00541 /* YYNNTS -- Number of nonterminals. */ 00542 #define YYNNTS 3 00543 /* YYNRULES -- Number of rules. */ 00544 #define YYNRULES 23 00545 /* YYNRULES -- Number of states. */ 00546 #define YYNSTATES 46 00547 00548 /* YYTRANSLATE(YYLEX) -- Bison symbol number corresponding to YYLEX. */ 00549 #define YYUNDEFTOK 2 00550 #define YYMAXUTOK 278 00551 00552 #define YYTRANSLATE(YYX) \ 00553 ((unsigned int) (YYX) <= YYMAXUTOK ? yytranslate[YYX] : YYUNDEFTOK) 00554 00555 /* YYTRANSLATE[YYLEX] -- Bison symbol number corresponding to YYLEX. */ 00556 static const yytype_uint8 yytranslate[] = 00557 { 00558 0, 2, 2, 2, 2, 2, 2, 2, 2, 2, 00559 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 00560 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 00561 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 00562 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 00563 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 00564 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 00565 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 00566 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 00567 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 00568 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 00569 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 00570 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 00571 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 00572 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 00573 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 00574 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 00575 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 00576 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 00577 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 00578 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 00579 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 00580 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 00581 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 00582 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 00583 2, 2, 2, 2, 2, 2, 1, 2, 3, 4, 00584 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 00585 15, 16, 17, 18, 19, 20, 21, 22, 23 00586 }; 00587 00588 #if YYDEBUG 00589 /* YYPRHS[YYN] -- Index of the first RHS symbol of rule number YYN in 00590 YYRHS. */ 00591 static const yytype_uint8 yyprhs[] = 00592 { 00593 0, 0, 3, 5, 6, 8, 12, 16, 20, 24, 00594 28, 32, 36, 40, 44, 48, 52, 55, 58, 62, 00595 66, 70, 74, 78 00596 }; 00597 00598 /* YYRHS -- A `-1'-separated list of the rules' RHS. */ 00599 static const yytype_int8 yyrhs[] = 00600 { 00601 25, 0, -1, 26, -1, -1, 23, -1, 21, 26, 00602 22, -1, 26, 5, 26, -1, 26, 6, 26, -1, 00603 26, 12, 26, -1, 26, 11, 26, -1, 26, 10, 00604 26, -1, 26, 9, 26, -1, 26, 8, 26, -1, 00605 26, 7, 26, -1, 26, 14, 26, -1, 26, 13, 00606 26, -1, 13, 26, -1, 18, 26, -1, 26, 17, 00607 26, -1, 26, 16, 26, -1, 26, 15, 26, -1, 00608 26, 20, 26, -1, 26, 19, 26, -1, 26, 4, 00609 26, 3, 26, -1 00610 }; 00611 00612 /* YYRLINE[YYN] -- source line where rule number YYN was defined. */ 00613 static const yytype_uint16 yyrline[] = 00614 { 00615 0, 175, 175, 183, 190, 191, 195, 199, 203, 207, 00616 211, 215, 219, 223, 227, 231, 235, 239, 243, 247, 00617 251, 255, 259, 263 00618 }; 00619 #endif 00620 00621 #if YYDEBUG || YYERROR_VERBOSE || YYTOKEN_TABLE 00622 /* YYTNAME[SYMBOL-NUM] -- String name of the symbol SYMBOL-NUM. 00623 First, the terminals, then, starting at YYNTOKENS, nonterminals. */ 00624 static const char *const yytname[] = 00625 { 00626 "$end", "error", "$undefined", "TOK_COLONCOLON", "TOK_COND", "TOK_OR", 00627 "TOK_AND", "TOK_NE", "TOK_LE", "TOK_GE", "TOK_LT", "TOK_GT", "TOK_EQ", 00628 "TOK_MINUS", "TOK_PLUS", "TOK_MOD", "TOK_DIV", "TOK_MULT", "TOK_COMPL", 00629 "TOK_EQTILDE", "TOK_COLON", "TOK_LP", "TOK_RP", "TOKEN", "$accept", 00630 "start", "expr", 0 00631 }; 00632 #endif 00633 00634 # ifdef YYPRINT 00635 /* YYTOKNUM[YYLEX-NUM] -- Internal token number corresponding to 00636 token YYLEX-NUM. */ 00637 static const yytype_uint16 yytoknum[] = 00638 { 00639 0, 256, 257, 258, 259, 260, 261, 262, 263, 264, 00640 265, 266, 267, 268, 269, 270, 271, 272, 273, 274, 00641 275, 276, 277, 278 00642 }; 00643 # endif 00644 00645 /* YYR1[YYN] -- Symbol number of symbol that rule YYN derives. */ 00646 static const yytype_uint8 yyr1[] = 00647 { 00648 0, 24, 25, 25, 26, 26, 26, 26, 26, 26, 00649 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 00650 26, 26, 26, 26 00651 }; 00652 00653 /* YYR2[YYN] -- Number of symbols composing right hand side of rule YYN. */ 00654 static const yytype_uint8 yyr2[] = 00655 { 00656 0, 2, 1, 0, 1, 3, 3, 3, 3, 3, 00657 3, 3, 3, 3, 3, 3, 2, 2, 3, 3, 00658 3, 3, 3, 5 00659 }; 00660 00661 /* YYDEFACT[STATE-NAME] -- Default rule to reduce with in state 00662 STATE-NUM when YYTABLE doesn't specify something else to do. Zero 00663 means the default is an error. */ 00664 static const yytype_uint8 yydefact[] = 00665 { 00666 3, 0, 0, 0, 4, 0, 2, 16, 17, 0, 00667 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 00668 0, 0, 0, 0, 0, 0, 0, 5, 0, 6, 00669 7, 13, 12, 11, 10, 9, 8, 15, 14, 20, 00670 19, 18, 22, 21, 0, 23 00671 }; 00672 00673 /* YYDEFGOTO[NTERM-NUM]. */ 00674 static const yytype_int8 yydefgoto[] = 00675 { 00676 -1, 5, 6 00677 }; 00678 00679 /* YYPACT[STATE-NUM] -- Index in YYTABLE of the portion describing 00680 STATE-NUM. */ 00681 #define YYPACT_NINF -13 00682 static const yytype_int8 yypact[] = 00683 { 00684 109, 109, 109, 109, -13, 6, 59, 106, 106, 22, 00685 -13, 109, 109, 109, 109, 109, 109, 109, 109, 109, 00686 109, 109, 109, 109, 109, 109, 109, -13, 42, 90, 00687 104, 120, 120, 120, 120, 120, 120, -12, -12, 106, 00688 106, 106, -13, -13, 109, 75 00689 }; 00690 00691 /* YYPGOTO[NTERM-NUM]. */ 00692 static const yytype_int8 yypgoto[] = 00693 { 00694 -13, -13, -1 00695 }; 00696 00697 /* YYTABLE[YYPACT[STATE-NUM]]. What to do in state STATE-NUM. If 00698 positive, shift that token. If negative, reduce the rule which 00699 number is the opposite. If zero, do what YYDEFACT says. 00700 If YYTABLE_NINF, syntax error. */ 00701 #define YYTABLE_NINF -1 00702 static const yytype_uint8 yytable[] = 00703 { 00704 7, 8, 9, 22, 23, 24, 10, 25, 26, 0, 00705 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 00706 38, 39, 40, 41, 42, 43, 11, 12, 13, 14, 00707 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 00708 0, 25, 26, 45, 27, 44, 11, 12, 13, 14, 00709 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 00710 0, 25, 26, 11, 12, 13, 14, 15, 16, 17, 00711 18, 19, 20, 21, 22, 23, 24, 0, 25, 26, 00712 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 00713 22, 23, 24, 0, 25, 26, 13, 14, 15, 16, 00714 17, 18, 19, 20, 21, 22, 23, 24, 0, 25, 00715 26, 14, 15, 16, 17, 18, 19, 20, 21, 22, 00716 23, 24, 1, 25, 26, 25, 26, 2, 0, 0, 00717 3, 0, 4, 20, 21, 22, 23, 24, 0, 25, 00718 26 00719 }; 00720 00721 static const yytype_int8 yycheck[] = 00722 { 00723 1, 2, 3, 15, 16, 17, 0, 19, 20, -1, 00724 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 00725 21, 22, 23, 24, 25, 26, 4, 5, 6, 7, 00726 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 00727 -1, 19, 20, 44, 22, 3, 4, 5, 6, 7, 00728 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 00729 -1, 19, 20, 4, 5, 6, 7, 8, 9, 10, 00730 11, 12, 13, 14, 15, 16, 17, -1, 19, 20, 00731 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 00732 15, 16, 17, -1, 19, 20, 6, 7, 8, 9, 00733 10, 11, 12, 13, 14, 15, 16, 17, -1, 19, 00734 20, 7, 8, 9, 10, 11, 12, 13, 14, 15, 00735 16, 17, 13, 19, 20, 19, 20, 18, -1, -1, 00736 21, -1, 23, 13, 14, 15, 16, 17, -1, 19, 00737 20 00738 }; 00739 00740 /* YYSTOS[STATE-NUM] -- The (internal number of the) accessing 00741 symbol of state STATE-NUM. */ 00742 static const yytype_uint8 yystos[] = 00743 { 00744 0, 13, 18, 21, 23, 25, 26, 26, 26, 26, 00745 0, 4, 5, 6, 7, 8, 9, 10, 11, 12, 00746 13, 14, 15, 16, 17, 19, 20, 22, 26, 26, 00747 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 00748 26, 26, 26, 26, 3, 26 00749 }; 00750 00751 #define yyerrok (yyerrstatus = 0) 00752 #define yyclearin (yychar = YYEMPTY) 00753 #define YYEMPTY (-2) 00754 #define YYEOF 0 00755 00756 #define YYACCEPT goto yyacceptlab 00757 #define YYABORT goto yyabortlab 00758 #define YYERROR goto yyerrorlab 00759 00760 00761 /* Like YYERROR except do call yyerror. This remains here temporarily 00762 to ease the transition to the new meaning of YYERROR, for GCC. 00763 Once GCC version 2 has supplanted version 1, this can go. */ 00764 00765 #define YYFAIL goto yyerrlab 00766 00767 #define YYRECOVERING() (!!yyerrstatus) 00768 00769 #define YYBACKUP(Token, Value) \ 00770 do \ 00771 if (yychar == YYEMPTY && yylen == 1) \ 00772 { \ 00773 yychar = (Token); \ 00774 yylval = (Value); \ 00775 yytoken = YYTRANSLATE (yychar); \ 00776 YYPOPSTACK (1); \ 00777 goto yybackup; \ 00778 } \ 00779 else \ 00780 { \ 00781 yyerror (YY_("syntax error: cannot back up")); \ 00782 YYERROR; \ 00783 } \ 00784 while (YYID (0)) 00785 00786 00787 #define YYTERROR 1 00788 #define YYERRCODE 256 00789 00790 00791 /* YYLLOC_DEFAULT -- Set CURRENT to span from RHS[1] to RHS[N]. 00792 If N is 0, then set CURRENT to the empty location which ends 00793 the previous symbol: RHS[0] (always defined). */ 00794 00795 #define YYRHSLOC(Rhs, K) ((Rhs)[K]) 00796 #ifndef YYLLOC_DEFAULT 00797 # define YYLLOC_DEFAULT(Current, Rhs, N) \ 00798 do \ 00799 if (YYID (N)) \ 00800 { \ 00801 (Current).first_line = YYRHSLOC (Rhs, 1).first_line; \ 00802 (Current).first_column = YYRHSLOC (Rhs, 1).first_column; \ 00803 (Current).last_line = YYRHSLOC (Rhs, N).last_line; \ 00804 (Current).last_column = YYRHSLOC (Rhs, N).last_column; \ 00805 } \ 00806 else \ 00807 { \ 00808 (Current).first_line = (Current).last_line = \ 00809 YYRHSLOC (Rhs, 0).last_line; \ 00810 (Current).first_column = (Current).last_column = \ 00811 YYRHSLOC (Rhs, 0).last_column; \ 00812 } \ 00813 while (YYID (0)) 00814 #endif 00815 00816 00817 /* YY_LOCATION_PRINT -- Print the location on the stream. 00818 This macro was not mandated originally: define only if we know 00819 we won't break user code: when these are the locations we know. */ 00820 00821 #ifndef YY_LOCATION_PRINT 00822 # if YYLTYPE_IS_TRIVIAL 00823 # define YY_LOCATION_PRINT(File, Loc) \ 00824 fprintf (File, "%d.%d-%d.%d", \ 00825 (Loc).first_line, (Loc).first_column, \ 00826 (Loc).last_line, (Loc).last_column) 00827 # else 00828 # define YY_LOCATION_PRINT(File, Loc) ((void) 0) 00829 # endif 00830 #endif 00831 00832 00833 /* YYLEX -- calling `yylex' with the right arguments. */ 00834 00835 #ifdef YYLEX_PARAM 00836 # define YYLEX yylex (&yylval, &yylloc, YYLEX_PARAM) 00837 #else 00838 # define YYLEX yylex (&yylval, &yylloc) 00839 #endif 00840 00841 /* Enable debugging if requested. */ 00842 #if YYDEBUG 00843 00844 # ifndef YYFPRINTF 00845 # include <stdio.h> /* INFRINGES ON USER NAME SPACE */ 00846 # define YYFPRINTF fprintf 00847 # endif 00848 00849 # define YYDPRINTF(Args) \ 00850 do { \ 00851 if (yydebug) \ 00852 YYFPRINTF Args; \ 00853 } while (YYID (0)) 00854 00855 # define YY_SYMBOL_PRINT(Title, Type, Value, Location) \ 00856 do { \ 00857 if (yydebug) \ 00858 { \ 00859 YYFPRINTF (stderr, "%s ", Title); \ 00860 yy_symbol_print (stderr, \ 00861 Type, Value, Location); \ 00862 YYFPRINTF (stderr, "\n"); \ 00863 } \ 00864 } while (YYID (0)) 00865 00866 00867 /*--------------------------------. 00868 | Print this symbol on YYOUTPUT. | 00869 `--------------------------------*/ 00870 00871 /*ARGSUSED*/ 00872 #if (defined __STDC__ || defined __C99__FUNC__ \ 00873 || defined __cplusplus || defined _MSC_VER) 00874 static void 00875 yy_symbol_value_print (FILE *yyoutput, int yytype, YYSTYPE const * const yyvaluep, YYLTYPE const * const yylocationp) 00876 #else 00877 static void 00878 yy_symbol_value_print (yyoutput, yytype, yyvaluep, yylocationp) 00879 FILE *yyoutput; 00880 int yytype; 00881 YYSTYPE const * const yyvaluep; 00882 YYLTYPE const * const yylocationp; 00883 #endif 00884 { 00885 if (!yyvaluep) 00886 return; 00887 YYUSE (yylocationp); 00888 # ifdef YYPRINT 00889 if (yytype < YYNTOKENS) 00890 YYPRINT (yyoutput, yytoknum[yytype], *yyvaluep); 00891 # else 00892 YYUSE (yyoutput); 00893 # endif 00894 switch (yytype) 00895 { 00896 default: 00897 break; 00898 } 00899 } 00900 00901 00902 /*--------------------------------. 00903 | Print this symbol on YYOUTPUT. | 00904 `--------------------------------*/ 00905 00906 #if (defined __STDC__ || defined __C99__FUNC__ \ 00907 || defined __cplusplus || defined _MSC_VER) 00908 static void 00909 yy_symbol_print (FILE *yyoutput, int yytype, YYSTYPE const * const yyvaluep, YYLTYPE const * const yylocationp) 00910 #else 00911 static void 00912 yy_symbol_print (yyoutput, yytype, yyvaluep, yylocationp) 00913 FILE *yyoutput; 00914 int yytype; 00915 YYSTYPE const * const yyvaluep; 00916 YYLTYPE const * const yylocationp; 00917 #endif 00918 { 00919 if (yytype < YYNTOKENS) 00920 YYFPRINTF (yyoutput, "token %s (", yytname[yytype]); 00921 else 00922 YYFPRINTF (yyoutput, "nterm %s (", yytname[yytype]); 00923 00924 YY_LOCATION_PRINT (yyoutput, *yylocationp); 00925 YYFPRINTF (yyoutput, ": "); 00926 yy_symbol_value_print (yyoutput, yytype, yyvaluep, yylocationp); 00927 YYFPRINTF (yyoutput, ")"); 00928 } 00929 00930 /*------------------------------------------------------------------. 00931 | yy_stack_print -- Print the state stack from its BOTTOM up to its | 00932 | TOP (included). | 00933 `------------------------------------------------------------------*/ 00934 00935 #if (defined __STDC__ || defined __C99__FUNC__ \ 00936 || defined __cplusplus || defined _MSC_VER) 00937 static void 00938 yy_stack_print (yytype_int16 *bottom, yytype_int16 *top) 00939 #else 00940 static void 00941 yy_stack_print (bottom, top) 00942 yytype_int16 *bottom; 00943 yytype_int16 *top; 00944 #endif 00945 { 00946 YYFPRINTF (stderr, "Stack now"); 00947 for (; bottom <= top; ++bottom) 00948 YYFPRINTF (stderr, " %d", *bottom); 00949 YYFPRINTF (stderr, "\n"); 00950 } 00951 00952 # define YY_STACK_PRINT(Bottom, Top) \ 00953 do { \ 00954 if (yydebug) \ 00955 yy_stack_print ((Bottom), (Top)); \ 00956 } while (YYID (0)) 00957 00958 00959 /*------------------------------------------------. 00960 | Report that the YYRULE is going to be reduced. | 00961 `------------------------------------------------*/ 00962 00963 #if (defined __STDC__ || defined __C99__FUNC__ \ 00964 || defined __cplusplus || defined _MSC_VER) 00965 static void 00966 yy_reduce_print (YYSTYPE *yyvsp, YYLTYPE *yylsp, int yyrule) 00967 #else 00968 static void 00969 yy_reduce_print (yyvsp, yylsp, yyrule) 00970 YYSTYPE *yyvsp; 00971 YYLTYPE *yylsp; 00972 int yyrule; 00973 #endif 00974 { 00975 int yynrhs = yyr2[yyrule]; 00976 int yyi; 00977 unsigned long int yylno = yyrline[yyrule]; 00978 YYFPRINTF (stderr, "Reducing stack by rule %d (line %lu):\n", 00979 yyrule - 1, yylno); 00980 /* The symbols being reduced. */ 00981 for (yyi = 0; yyi < yynrhs; yyi++) 00982 { 00983 fprintf (stderr, " $%d = ", yyi + 1); 00984 yy_symbol_print (stderr, yyrhs[yyprhs[yyrule] + yyi], 00985 &(yyvsp[(yyi + 1) - (yynrhs)]) 00986 , &(yylsp[(yyi + 1) - (yynrhs)]) ); 00987 fprintf (stderr, "\n"); 00988 } 00989 } 00990 00991 # define YY_REDUCE_PRINT(Rule) \ 00992 do { \ 00993 if (yydebug) \ 00994 yy_reduce_print (yyvsp, yylsp, Rule); \ 00995 } while (YYID (0)) 00996 00997 /* Nonzero means print parse trace. It is left uninitialized so that 00998 multiple parsers can coexist. */ 00999 int yydebug; 01000 #else /* !YYDEBUG */ 01001 # define YYDPRINTF(Args) 01002 # define YY_SYMBOL_PRINT(Title, Type, Value, Location) 01003 # define YY_STACK_PRINT(Bottom, Top) 01004 # define YY_REDUCE_PRINT(Rule) 01005 #endif /* !YYDEBUG */ 01006 01007 01008 /* YYINITDEPTH -- initial size of the parser's stacks. */ 01009 #ifndef YYINITDEPTH 01010 # define YYINITDEPTH 200 01011 #endif 01012 01013 /* YYMAXDEPTH -- maximum size the stacks can grow to (effective only 01014 if the built-in stack extension method is used). 01015 01016 Do not make this value too large; the results are undefined if 01017 YYSTACK_ALLOC_MAXIMUM < YYSTACK_BYTES (YYMAXDEPTH) 01018 evaluated with infinite-precision integer arithmetic. */ 01019 01020 #ifndef YYMAXDEPTH 01021 # define YYMAXDEPTH 10000 01022 #endif 01023 01024 01025 01026 #if YYERROR_VERBOSE 01027 01028 # ifndef yystrlen 01029 # if defined __GLIBC__ && defined _STRING_H 01030 # define yystrlen strlen 01031 # else 01032 /* Return the length of YYSTR. */ 01033 #if (defined __STDC__ || defined __C99__FUNC__ \ 01034 || defined __cplusplus || defined _MSC_VER) 01035 static YYSIZE_T 01036 yystrlen (const char *yystr) 01037 #else 01038 static YYSIZE_T 01039 yystrlen (yystr) 01040 const char *yystr; 01041 #endif 01042 { 01043 YYSIZE_T yylen; 01044 for (yylen = 0; yystr[yylen]; yylen++) 01045 continue; 01046 return yylen; 01047 } 01048 # endif 01049 # endif 01050 01051 # ifndef yystpcpy 01052 # if defined __GLIBC__ && defined _STRING_H && defined _GNU_SOURCE 01053 # define yystpcpy stpcpy 01054 # else 01055 /* Copy YYSRC to YYDEST, returning the address of the terminating '\0' in 01056 YYDEST. */ 01057 #if (defined __STDC__ || defined __C99__FUNC__ \ 01058 || defined __cplusplus || defined _MSC_VER) 01059 static char * 01060 yystpcpy (char *yydest, const char *yysrc) 01061 #else 01062 static char * 01063 yystpcpy (yydest, yysrc) 01064 char *yydest; 01065 const char *yysrc; 01066 #endif 01067 { 01068 char *yyd = yydest; 01069 const char *yys = yysrc; 01070 01071 while ((*yyd++ = *yys++) != '\0') 01072 continue; 01073 01074 return yyd - 1; 01075 } 01076 # endif 01077 # endif 01078 01079 # ifndef yytnamerr 01080 /* Copy to YYRES the contents of YYSTR after stripping away unnecessary 01081 quotes and backslashes, so that it's suitable for yyerror. The 01082 heuristic is that double-quoting is unnecessary unless the string 01083 contains an apostrophe, a comma, or backslash (other than 01084 backslash-backslash). YYSTR is taken from yytname. If YYRES is 01085 null, do not copy; instead, return the length of what the result 01086 would have been. */ 01087 static YYSIZE_T 01088 yytnamerr (char *yyres, const char *yystr) 01089 { 01090 if (*yystr == '"') 01091 { 01092 YYSIZE_T yyn = 0; 01093 char const *yyp = yystr; 01094 01095 for (;;) 01096 switch (*++yyp) 01097 { 01098 case '\'': 01099 case ',': 01100 goto do_not_strip_quotes; 01101 01102 case '\\': 01103 if (*++yyp != '\\') 01104 goto do_not_strip_quotes; 01105 /* Fall through. */ 01106 default: 01107 if (yyres) 01108 yyres[yyn] = *yyp; 01109 yyn++; 01110 break; 01111 01112 case '"': 01113 if (yyres) 01114 yyres[yyn] = '\0'; 01115 return yyn; 01116 } 01117 do_not_strip_quotes: ; 01118 } 01119 01120 if (! yyres) 01121 return yystrlen (yystr); 01122 01123 return yystpcpy (yyres, yystr) - yyres; 01124 } 01125 # endif 01126 01127 /* Copy into YYRESULT an error message about the unexpected token 01128 YYCHAR while in state YYSTATE. Return the number of bytes copied, 01129 including the terminating null byte. If YYRESULT is null, do not 01130 copy anything; just return the number of bytes that would be 01131 copied. As a special case, return 0 if an ordinary "syntax error" 01132 message will do. Return YYSIZE_MAXIMUM if overflow occurs during 01133 size calculation. */ 01134 static YYSIZE_T 01135 yysyntax_error (char *yyresult, int yystate, int yychar) 01136 { 01137 int yyn = yypact[yystate]; 01138 01139 if (! (YYPACT_NINF < yyn && yyn <= YYLAST)) 01140 return 0; 01141 else 01142 { 01143 int yytype = YYTRANSLATE (yychar); 01144 YYSIZE_T yysize0 = yytnamerr (0, yytname[yytype]); 01145 YYSIZE_T yysize = yysize0; 01146 YYSIZE_T yysize1; 01147 int yysize_overflow = 0; 01148 enum { YYERROR_VERBOSE_ARGS_MAXIMUM = 5 }; 01149 char const *yyarg[YYERROR_VERBOSE_ARGS_MAXIMUM]; 01150 int yyx; 01151 01152 # if 0 01153 /* This is so xgettext sees the translatable formats that are 01154 constructed on the fly. */ 01155 YY_("syntax error, unexpected %s"); 01156 YY_("syntax error, unexpected %s, expecting %s"); 01157 YY_("syntax error, unexpected %s, expecting %s or %s"); 01158 YY_("syntax error, unexpected %s, expecting %s or %s or %s"); 01159 YY_("syntax error, unexpected %s, expecting %s or %s or %s or %s"); 01160 # endif 01161 char *yyfmt; 01162 char const *yyf; 01163 static char const yyunexpected[] = "syntax error, unexpected %s"; 01164 static char const yyexpecting[] = ", expecting %s"; 01165 static char const yyor[] = " or %s"; 01166 char yyformat[sizeof yyunexpected 01167 + sizeof yyexpecting - 1 01168 + ((YYERROR_VERBOSE_ARGS_MAXIMUM - 2) 01169 * (sizeof yyor - 1))]; 01170 char const *yyprefix = yyexpecting; 01171 01172 /* Start YYX at -YYN if negative to avoid negative indexes in 01173 YYCHECK. */ 01174 int yyxbegin = yyn < 0 ? -yyn : 0; 01175 01176 /* Stay within bounds of both yycheck and yytname. */ 01177 int yychecklim = YYLAST - yyn + 1; 01178 int yyxend = yychecklim < YYNTOKENS ? yychecklim : YYNTOKENS; 01179 int yycount = 1; 01180 01181 yyarg[0] = yytname[yytype]; 01182 yyfmt = yystpcpy (yyformat, yyunexpected); 01183 01184 for (yyx = yyxbegin; yyx < yyxend; ++yyx) 01185 if (yycheck[yyx + yyn] == yyx && yyx != YYTERROR) 01186 { 01187 if (yycount == YYERROR_VERBOSE_ARGS_MAXIMUM) 01188 { 01189 yycount = 1; 01190 yysize = yysize0; 01191 yyformat[sizeof yyunexpected - 1] = '\0'; 01192 break; 01193 } 01194 yyarg[yycount++] = yytname[yyx]; 01195 yysize1 = yysize + yytnamerr (0, yytname[yyx]); 01196 yysize_overflow |= (yysize1 < yysize); 01197 yysize = yysize1; 01198 yyfmt = yystpcpy (yyfmt, yyprefix); 01199 yyprefix = yyor; 01200 } 01201 01202 yyf = YY_(yyformat); 01203 yysize1 = yysize + yystrlen (yyf); 01204 yysize_overflow |= (yysize1 < yysize); 01205 yysize = yysize1; 01206 01207 if (yysize_overflow) 01208 return YYSIZE_MAXIMUM; 01209 01210 if (yyresult) 01211 { 01212 /* Avoid sprintf, as that infringes on the user's name space. 01213 Don't have undefined behavior even if the translation 01214 produced a string with the wrong number of "%s"s. */ 01215 char *yyp = yyresult; 01216 int yyi = 0; 01217 while ((*yyp = *yyf) != '\0') 01218 { 01219 if (*yyp == '%' && yyf[1] == 's' && yyi < yycount) 01220 { 01221 yyp += yytnamerr (yyp, yyarg[yyi++]); 01222 yyf += 2; 01223 } 01224 else 01225 { 01226 yyp++; 01227 yyf++; 01228 } 01229 } 01230 } 01231 return yysize; 01232 } 01233 } 01234 #endif /* YYERROR_VERBOSE */ 01235 01236 01237 /*-----------------------------------------------. 01238 | Release the memory associated to this symbol. | 01239 `-----------------------------------------------*/ 01240 01241 /*ARGSUSED*/ 01242 #if (defined __STDC__ || defined __C99__FUNC__ \ 01243 || defined __cplusplus || defined _MSC_VER) 01244 static void 01245 yydestruct (const char *yymsg, int yytype, YYSTYPE *yyvaluep, YYLTYPE *yylocationp) 01246 #else 01247 static void 01248 yydestruct (yymsg, yytype, yyvaluep, yylocationp) 01249 const char *yymsg; 01250 int yytype; 01251 YYSTYPE *yyvaluep; 01252 YYLTYPE *yylocationp; 01253 #endif 01254 { 01255 YYUSE (yyvaluep); 01256 YYUSE (yylocationp); 01257 01258 if (!yymsg) 01259 yymsg = "Deleting"; 01260 YY_SYMBOL_PRINT (yymsg, yytype, yyvaluep, yylocationp); 01261 01262 switch (yytype) 01263 { 01264 case 3: /* "TOK_COLONCOLON" */ 01265 #line 169 "ast_expr2.y" 01266 { free_value((yyvaluep->val)); }; 01267 #line 1268 "ast_expr2.c" 01268 break; 01269 case 4: /* "TOK_COND" */ 01270 #line 169 "ast_expr2.y" 01271 { free_value((yyvaluep->val)); }; 01272 #line 1273 "ast_expr2.c" 01273 break; 01274 case 5: /* "TOK_OR" */ 01275 #line 169 "ast_expr2.y" 01276 { free_value((yyvaluep->val)); }; 01277 #line 1278 "ast_expr2.c" 01278 break; 01279 case 6: /* "TOK_AND" */ 01280 #line 169 "ast_expr2.y" 01281 { free_value((yyvaluep->val)); }; 01282 #line 1283 "ast_expr2.c" 01283 break; 01284 case 7: /* "TOK_NE" */ 01285 #line 169 "ast_expr2.y" 01286 { free_value((yyvaluep->val)); }; 01287 #line 1288 "ast_expr2.c" 01288 break; 01289 case 8: /* "TOK_LE" */ 01290 #line 169 "ast_expr2.y" 01291 { free_value((yyvaluep->val)); }; 01292 #line 1293 "ast_expr2.c" 01293 break; 01294 case 9: /* "TOK_GE" */ 01295 #line 169 "ast_expr2.y" 01296 { free_value((yyvaluep->val)); }; 01297 #line 1298 "ast_expr2.c" 01298 break; 01299 case 10: /* "TOK_LT" */ 01300 #line 169 "ast_expr2.y" 01301 { free_value((yyvaluep->val)); }; 01302 #line 1303 "ast_expr2.c" 01303 break; 01304 case 11: /* "TOK_GT" */ 01305 #line 169 "ast_expr2.y" 01306 { free_value((yyvaluep->val)); }; 01307 #line 1308 "ast_expr2.c" 01308 break; 01309 case 12: /* "TOK_EQ" */ 01310 #line 169 "ast_expr2.y" 01311 { free_value((yyvaluep->val)); }; 01312 #line 1313 "ast_expr2.c" 01313 break; 01314 case 13: /* "TOK_MINUS" */ 01315 #line 169 "ast_expr2.y" 01316 { free_value((yyvaluep->val)); }; 01317 #line 1318 "ast_expr2.c" 01318 break; 01319 case 14: /* "TOK_PLUS" */ 01320 #line 169 "ast_expr2.y" 01321 { free_value((yyvaluep->val)); }; 01322 #line 1323 "ast_expr2.c" 01323 break; 01324 case 15: /* "TOK_MOD" */ 01325 #line 169 "ast_expr2.y" 01326 { free_value((yyvaluep->val)); }; 01327 #line 1328 "ast_expr2.c" 01328 break; 01329 case 16: /* "TOK_DIV" */ 01330 #line 169 "ast_expr2.y" 01331 { free_value((yyvaluep->val)); }; 01332 #line 1333 "ast_expr2.c" 01333 break; 01334 case 17: /* "TOK_MULT" */ 01335 #line 169 "ast_expr2.y" 01336 { free_value((yyvaluep->val)); }; 01337 #line 1338 "ast_expr2.c" 01338 break; 01339 case 18: /* "TOK_COMPL" */ 01340 #line 169 "ast_expr2.y" 01341 { free_value((yyvaluep->val)); }; 01342 #line 1343 "ast_expr2.c" 01343 break; 01344 case 19: /* "TOK_EQTILDE" */ 01345 #line 169 "ast_expr2.y" 01346 { free_value((yyvaluep->val)); }; 01347 #line 1348 "ast_expr2.c" 01348 break; 01349 case 20: /* "TOK_COLON" */ 01350 #line 169 "ast_expr2.y" 01351 { free_value((yyvaluep->val)); }; 01352 #line 1353 "ast_expr2.c" 01353 break; 01354 case 21: /* "TOK_LP" */ 01355 #line 169 "ast_expr2.y" 01356 { free_value((yyvaluep->val)); }; 01357 #line 1358 "ast_expr2.c" 01358 break; 01359 case 22: /* "TOK_RP" */ 01360 #line 169 "ast_expr2.y" 01361 { free_value((yyvaluep->val)); }; 01362 #line 1363 "ast_expr2.c" 01363 break; 01364 case 23: /* "TOKEN" */ 01365 #line 169 "ast_expr2.y" 01366 { free_value((yyvaluep->val)); }; 01367 #line 1368 "ast_expr2.c" 01368 break; 01369 case 26: /* "expr" */ 01370 #line 169 "ast_expr2.y" 01371 { free_value((yyvaluep->val)); }; 01372 #line 1373 "ast_expr2.c" 01373 break; 01374 01375 default: 01376 break; 01377 } 01378 } 01379 01380 01381 /* Prevent warnings from -Wmissing-prototypes. */ 01382 01383 #ifdef YYPARSE_PARAM 01384 #if defined __STDC__ || defined __cplusplus 01385 int yyparse (void *YYPARSE_PARAM); 01386 #else 01387 int yyparse (); 01388 #endif 01389 #else /* ! YYPARSE_PARAM */ 01390 #if defined __STDC__ || defined __cplusplus 01391 int yyparse (void); 01392 #else 01393 int yyparse (); 01394 #endif 01395 #endif /* ! YYPARSE_PARAM */ 01396 01397 01398 01399 01400 01401 01402 /*----------. 01403 | yyparse. | 01404 `----------*/ 01405 01406 #ifdef YYPARSE_PARAM 01407 #if (defined __STDC__ || defined __C99__FUNC__ \ 01408 || defined __cplusplus || defined _MSC_VER) 01409 int 01410 yyparse (void *YYPARSE_PARAM) 01411 #else 01412 int 01413 yyparse (YYPARSE_PARAM) 01414 void *YYPARSE_PARAM; 01415 #endif 01416 #else /* ! YYPARSE_PARAM */ 01417 #if (defined __STDC__ || defined __C99__FUNC__ \ 01418 || defined __cplusplus || defined _MSC_VER) 01419 int 01420 yyparse (void) 01421 #else 01422 int 01423 yyparse () 01424 01425 #endif 01426 #endif 01427 { 01428 /* The look-ahead symbol. */ 01429 int yychar; 01430 01431 /* The semantic value of the look-ahead symbol. */ 01432 YYSTYPE yylval; 01433 01434 /* Number of syntax errors so far. */ 01435 int yynerrs; 01436 /* Location data for the look-ahead symbol. */ 01437 YYLTYPE yylloc; 01438 01439 int yystate; 01440 int yyn; 01441 int yyresult; 01442 /* Number of tokens to shift before error messages enabled. */ 01443 int yyerrstatus; 01444 /* Look-ahead token as an internal (translated) token number. */ 01445 int yytoken = 0; 01446 #if YYERROR_VERBOSE 01447 /* Buffer for error messages, and its allocated size. */ 01448 char yymsgbuf[128]; 01449 char *yymsg = yymsgbuf; 01450 YYSIZE_T yymsg_alloc = sizeof yymsgbuf; 01451 #endif 01452 01453 /* Three stacks and their tools: 01454 `yyss': related to states, 01455 `yyvs': related to semantic values, 01456 `yyls': related to locations. 01457 01458 Refer to the stacks thru separate pointers, to allow yyoverflow 01459 to reallocate them elsewhere. */ 01460 01461 /* The state stack. */ 01462 yytype_int16 yyssa[YYINITDEPTH]; 01463 yytype_int16 *yyss = yyssa; 01464 yytype_int16 *yyssp; 01465 01466 /* The semantic value stack. */ 01467 YYSTYPE yyvsa[YYINITDEPTH]; 01468 YYSTYPE *yyvs = yyvsa; 01469 YYSTYPE *yyvsp; 01470 01471 /* The location stack. */ 01472 YYLTYPE yylsa[YYINITDEPTH]; 01473 YYLTYPE *yyls = yylsa; 01474 YYLTYPE *yylsp; 01475 /* The locations where the error started and ended. */ 01476 YYLTYPE yyerror_range[2]; 01477 01478 #define YYPOPSTACK(N) (yyvsp -= (N), yyssp -= (N), yylsp -= (N)) 01479 01480 YYSIZE_T yystacksize = YYINITDEPTH; 01481 01482 /* The variables used to return semantic value and location from the 01483 action routines. */ 01484 YYSTYPE yyval; 01485 YYLTYPE yyloc; 01486 01487 /* The number of symbols on the RHS of the reduced rule. 01488 Keep to zero when no symbol should be popped. */ 01489 int yylen = 0; 01490 01491 YYDPRINTF ((stderr, "Starting parse\n")); 01492 01493 yystate = 0; 01494 yyerrstatus = 0; 01495 yynerrs = 0; 01496 yychar = YYEMPTY; /* Cause a token to be read. */ 01497 01498 /* Initialize stack pointers. 01499 Waste one element of value and location stack 01500 so that they stay on the same level as the state stack. 01501 The wasted elements are never initialized. */ 01502 01503 yyssp = yyss; 01504 yyvsp = yyvs; 01505 yylsp = yyls; 01506 #if YYLTYPE_IS_TRIVIAL 01507 /* Initialize the default location before parsing starts. */ 01508 yylloc.first_line = yylloc.last_line = 1; 01509 yylloc.first_column = yylloc.last_column = 0; 01510 #endif 01511 01512 goto yysetstate; 01513 01514 /*------------------------------------------------------------. 01515 | yynewstate -- Push a new state, which is found in yystate. | 01516 `------------------------------------------------------------*/ 01517 yynewstate: 01518 /* In all cases, when you get here, the value and location stacks 01519 have just been pushed. So pushing a state here evens the stacks. */ 01520 yyssp++; 01521 01522 yysetstate: 01523 *yyssp = yystate; 01524 01525 if (yyss + yystacksize - 1 <= yyssp) 01526 { 01527 /* Get the current used size of the three stacks, in elements. */ 01528 YYSIZE_T yysize = yyssp - yyss + 1; 01529 01530 #ifdef yyoverflow 01531 { 01532 /* Give user a chance to reallocate the stack. Use copies of 01533 these so that the &'s don't force the real ones into 01534 memory. */ 01535 YYSTYPE *yyvs1 = yyvs; 01536 yytype_int16 *yyss1 = yyss; 01537 YYLTYPE *yyls1 = yyls; 01538 01539 /* Each stack pointer address is followed by the size of the 01540 data in use in that stack, in bytes. This used to be a 01541 conditional around just the two extra args, but that might 01542 be undefined if yyoverflow is a macro. */ 01543 yyoverflow (YY_("memory exhausted"), 01544 &yyss1, yysize * sizeof (*yyssp), 01545 &yyvs1, yysize * sizeof (*yyvsp), 01546 &yyls1, yysize * sizeof (*yylsp), 01547 &yystacksize); 01548 yyls = yyls1; 01549 yyss = yyss1; 01550 yyvs = yyvs1; 01551 } 01552 #else /* no yyoverflow */ 01553 # ifndef YYSTACK_RELOCATE 01554 goto yyexhaustedlab; 01555 # else 01556 /* Extend the stack our own way. */ 01557 if (YYMAXDEPTH <= yystacksize) 01558 goto yyexhaustedlab; 01559 yystacksize *= 2; 01560 if (YYMAXDEPTH < yystacksize) 01561 yystacksize = YYMAXDEPTH; 01562 01563 { 01564 yytype_int16 *yyss1 = yyss; 01565 union yyalloc *yyptr = 01566 (union yyalloc *) YYSTACK_ALLOC (YYSTACK_BYTES (yystacksize)); 01567 if (! yyptr) 01568 goto yyexhaustedlab; 01569 YYSTACK_RELOCATE (yyss); 01570 YYSTACK_RELOCATE (yyvs); 01571 YYSTACK_RELOCATE (yyls); 01572 # undef YYSTACK_RELOCATE 01573 if (yyss1 != yyssa) 01574 YYSTACK_FREE (yyss1); 01575 } 01576 # endif 01577 #endif /* no yyoverflow */ 01578 01579 yyssp = yyss + yysize - 1; 01580 yyvsp = yyvs + yysize - 1; 01581 yylsp = yyls + yysize - 1; 01582 01583 YYDPRINTF ((stderr, "Stack size increased to %lu\n", 01584 (unsigned long int) yystacksize)); 01585 01586 if (yyss + yystacksize - 1 <= yyssp) 01587 YYABORT; 01588 } 01589 01590 YYDPRINTF ((stderr, "Entering state %d\n", yystate)); 01591 01592 goto yybackup; 01593 01594 /*-----------. 01595 | yybackup. | 01596 `-----------*/ 01597 yybackup: 01598 01599 /* Do appropriate processing given the current state. Read a 01600 look-ahead token if we need one and don't already have one. */ 01601 01602 /* First try to decide what to do without reference to look-ahead token. */ 01603 yyn = yypact[yystate]; 01604 if (yyn == YYPACT_NINF) 01605 goto yydefault; 01606 01607 /* Not known => get a look-ahead token if don't already have one. */ 01608 01609 /* YYCHAR is either YYEMPTY or YYEOF or a valid look-ahead symbol. */ 01610 if (yychar == YYEMPTY) 01611 { 01612 YYDPRINTF ((stderr, "Reading a token: ")); 01613 yychar = YYLEX; 01614 } 01615 01616 if (yychar <= YYEOF) 01617 { 01618 yychar = yytoken = YYEOF; 01619 YYDPRINTF ((stderr, "Now at end of input.\n")); 01620 } 01621 else 01622 { 01623 yytoken = YYTRANSLATE (yychar); 01624 YY_SYMBOL_PRINT ("Next token is", yytoken, &yylval, &yylloc); 01625 } 01626 01627 /* If the proper action on seeing token YYTOKEN is to reduce or to 01628 detect an error, take that action. */ 01629 yyn += yytoken; 01630 if (yyn < 0 || YYLAST < yyn || yycheck[yyn] != yytoken) 01631 goto yydefault; 01632 yyn = yytable[yyn]; 01633 if (yyn <= 0) 01634 { 01635 if (yyn == 0 || yyn == YYTABLE_NINF) 01636 goto yyerrlab; 01637 yyn = -yyn; 01638 goto yyreduce; 01639 } 01640 01641 if (yyn == YYFINAL) 01642 YYACCEPT; 01643 01644 /* Count tokens shifted since error; after three, turn off error 01645 status. */ 01646 if (yyerrstatus) 01647 yyerrstatus--; 01648 01649 /* Shift the look-ahead token. */ 01650 YY_SYMBOL_PRINT ("Shifting", yytoken, &yylval, &yylloc); 01651 01652 /* Discard the shifted token unless it is eof. */ 01653 if (yychar != YYEOF) 01654 yychar = YYEMPTY; 01655 01656 yystate = yyn; 01657 *++yyvsp = yylval; 01658 *++yylsp = yylloc; 01659 goto yynewstate; 01660 01661 01662 /*-----------------------------------------------------------. 01663 | yydefault -- do the default action for the current state. | 01664 `-----------------------------------------------------------*/ 01665 yydefault: 01666 yyn = yydefact[yystate]; 01667 if (yyn == 0) 01668 goto yyerrlab; 01669 goto yyreduce; 01670 01671 01672 /*-----------------------------. 01673 | yyreduce -- Do a reduction. | 01674 `-----------------------------*/ 01675 yyreduce: 01676 /* yyn is the number of a rule to reduce with. */ 01677 yylen = yyr2[yyn]; 01678 01679 /* If YYLEN is nonzero, implement the default value of the action: 01680 `$$ = $1'. 01681 01682 Otherwise, the following line sets YYVAL to garbage. 01683 This behavior is undocumented and Bison 01684 users should not rely upon it. Assigning to YYVAL 01685 unconditionally makes the parser a bit smaller, and it avoids a 01686 GCC warning that YYVAL may be used uninitialized. */ 01687 yyval = yyvsp[1-yylen]; 01688 01689 /* Default location. */ 01690 YYLLOC_DEFAULT (yyloc, (yylsp - yylen), yylen); 01691 YY_REDUCE_PRINT (yyn); 01692 switch (yyn) 01693 { 01694 case 2: 01695 #line 175 "ast_expr2.y" 01696 { ((struct parse_io *)parseio)->val = (struct val *)calloc(sizeof(struct val),1); 01697 ((struct parse_io *)parseio)->val->type = (yyvsp[(1) - (1)].val)->type; 01698 if( (yyvsp[(1) - (1)].val)->type == AST_EXPR_integer ) 01699 ((struct parse_io *)parseio)->val->u.i = (yyvsp[(1) - (1)].val)->u.i; 01700 else 01701 ((struct parse_io *)parseio)->val->u.s = (yyvsp[(1) - (1)].val)->u.s; 01702 free((yyvsp[(1) - (1)].val)); 01703 ;} 01704 break; 01705 01706 case 3: 01707 #line 183 "ast_expr2.y" 01708 {/* nothing */ ((struct parse_io *)parseio)->val = (struct val *)calloc(sizeof(struct val),1); 01709 ((struct parse_io *)parseio)->val->type = AST_EXPR_string; 01710 ((struct parse_io *)parseio)->val->u.s = strdup(""); 01711 ;} 01712 break; 01713 01714 case 4: 01715 #line 190 "ast_expr2.y" 01716 { (yyval.val)= (yyvsp[(1) - (1)].val);;} 01717 break; 01718 01719 case 5: 01720 #line 191 "ast_expr2.y" 01721 { (yyval.val) = (yyvsp[(2) - (3)].val); 01722 (yyloc).first_column = (yylsp[(1) - (3)]).first_column; (yyloc).last_column = (yylsp[(3) - (3)]).last_column; 01723 (yyloc).first_line=0; (yyloc).last_line=0; 01724 DESTROY((yyvsp[(1) - (3)].val)); DESTROY((yyvsp[(3) - (3)].val)); ;} 01725 break; 01726 01727 case 6: 01728 #line 195 "ast_expr2.y" 01729 { (yyval.val) = op_or ((yyvsp[(1) - (3)].val), (yyvsp[(3) - (3)].val)); 01730 DESTROY((yyvsp[(2) - (3)].val)); 01731 (yyloc).first_column = (yylsp[(1) - (3)]).first_column; (yyloc).last_column = (yylsp[(3) - (3)]).last_column; 01732 (yyloc).first_line=0; (yyloc).last_line=0;;} 01733 break; 01734 01735 case 7: 01736 #line 199 "ast_expr2.y" 01737 { (yyval.val) = op_and ((yyvsp[(1) - (3)].val), (yyvsp[(3) - (3)].val)); 01738 DESTROY((yyvsp[(2) - (3)].val)); 01739 (yyloc).first_column = (yylsp[(1) - (3)]).first_column; (yyloc).last_column = (yylsp[(3) - (3)]).last_column; 01740 (yyloc).first_line=0; (yyloc).last_line=0;;} 01741 break; 01742 01743 case 8: 01744 #line 203 "ast_expr2.y" 01745 { (yyval.val) = op_eq ((yyvsp[(1) - (3)].val), (yyvsp[(3) - (3)].val)); 01746 DESTROY((yyvsp[(2) - (3)].val)); 01747 (yyloc).first_column = (yylsp[(1) - (3)]).first_column; (yyloc).last_column = (yylsp[(3) - (3)]).last_column; 01748 (yyloc).first_line=0; (yyloc).last_line=0;;} 01749 break; 01750 01751 case 9: 01752 #line 207 "ast_expr2.y" 01753 { (yyval.val) = op_gt ((yyvsp[(1) - (3)].val), (yyvsp[(3) - (3)].val)); 01754 DESTROY((yyvsp[(2) - (3)].val)); 01755 (yyloc).first_column = (yylsp[(1) - (3)]).first_column; (yyloc).last_column = (yylsp[(3) - (3)]).last_column; 01756 (yyloc).first_line=0; (yyloc).last_line=0;;} 01757 break; 01758 01759 case 10: 01760 #line 211 "ast_expr2.y" 01761 { (yyval.val) = op_lt ((yyvsp[(1) - (3)].val), (yyvsp[(3) - (3)].val)); 01762 DESTROY((yyvsp[(2) - (3)].val)); 01763 (yyloc).first_column = (yylsp[(1) - (3)]).first_column; (yyloc).last_column = (yylsp[(3) - (3)]).last_column; 01764 (yyloc).first_line=0; (yyloc).last_line=0;;} 01765 break; 01766 01767 case 11: 01768 #line 215 "ast_expr2.y" 01769 { (yyval.val) = op_ge ((yyvsp[(1) - (3)].val), (yyvsp[(3) - (3)].val)); 01770 DESTROY((yyvsp[(2) - (3)].val)); 01771 (yyloc).first_column = (yylsp[(1) - (3)]).first_column; (yyloc).last_column = (yylsp[(3) - (3)]).last_column; 01772 (yyloc).first_line=0; (yyloc).last_line=0;;} 01773 break; 01774 01775 case 12: 01776 #line 219 "ast_expr2.y" 01777 { (yyval.val) = op_le ((yyvsp[(1) - (3)].val), (yyvsp[(3) - (3)].val)); 01778 DESTROY((yyvsp[(2) - (3)].val)); 01779 (yyloc).first_column = (yylsp[(1) - (3)]).first_column; (yyloc).last_column = (yylsp[(3) - (3)]).last_column; 01780 (yyloc).first_line=0; (yyloc).last_line=0;;} 01781 break; 01782 01783 case 13: 01784 #line 223 "ast_expr2.y" 01785 { (yyval.val) = op_ne ((yyvsp[(1) - (3)].val), (yyvsp[(3) - (3)].val)); 01786 DESTROY((yyvsp[(2) - (3)].val)); 01787 (yyloc).first_column = (yylsp[(1) - (3)]).first_column; (yyloc).last_column = (yylsp[(3) - (3)]).last_column; 01788 (yyloc).first_line=0; (yyloc).last_line=0;;} 01789 break; 01790 01791 case 14: 01792 #line 227 "ast_expr2.y" 01793 { (yyval.val) = op_plus ((yyvsp[(1) - (3)].val), (yyvsp[(3) - (3)].val)); 01794 DESTROY((yyvsp[(2) - (3)].val)); 01795 (yyloc).first_column = (yylsp[(1) - (3)]).first_column; (yyloc).last_column = (yylsp[(3) - (3)]).last_column; 01796 (yyloc).first_line=0; (yyloc).last_line=0;;} 01797 break; 01798 01799 case 15: 01800 #line 231 "ast_expr2.y" 01801 { (yyval.val) = op_minus ((yyvsp[(1) - (3)].val), (yyvsp[(3) - (3)].val)); 01802 DESTROY((yyvsp[(2) - (3)].val)); 01803 (yyloc).first_column = (yylsp[(1) - (3)]).first_column; (yyloc).last_column = (yylsp[(3) - (3)]).last_column; 01804 (yyloc).first_line=0; (yyloc).last_line=0;;} 01805 break; 01806 01807 case 16: 01808 #line 235 "ast_expr2.y" 01809 { (yyval.val) = op_negate ((yyvsp[(2) - (2)].val)); 01810 DESTROY((yyvsp[(1) - (2)].val)); 01811 (yyloc).first_column = (yylsp[(1) - (2)]).first_column; (yyloc).last_column = (yylsp[(2) - (2)]).last_column; 01812 (yyloc).first_line=0; (yyloc).last_line=0;;} 01813 break; 01814 01815 case 17: 01816 #line 239 "ast_expr2.y" 01817 { (yyval.val) = op_compl ((yyvsp[(2) - (2)].val)); 01818 DESTROY((yyvsp[(1) - (2)].val)); 01819 (yyloc).first_column = (yylsp[(1) - (2)]).first_column; (yyloc).last_column = (yylsp[(2) - (2)]).last_column; 01820 (yyloc).first_line=0; (yyloc).last_line=0;;} 01821 break; 01822 01823 case 18: 01824 #line 243 "ast_expr2.y" 01825 { (yyval.val) = op_times ((yyvsp[(1) - (3)].val), (yyvsp[(3) - (3)].val)); 01826 DESTROY((yyvsp[(2) - (3)].val)); 01827 (yyloc).first_column = (yylsp[(1) - (3)]).first_column; (yyloc).last_column = (yylsp[(3) - (3)]).last_column; 01828 (yyloc).first_line=0; (yyloc).last_line=0;;} 01829 break; 01830 01831 case 19: 01832 #line 247 "ast_expr2.y" 01833 { (yyval.val) = op_div ((yyvsp[(1) - (3)].val), (yyvsp[(3) - (3)].val)); 01834 DESTROY((yyvsp[(2) - (3)].val)); 01835 (yyloc).first_column = (yylsp[(1) - (3)]).first_column; (yyloc).last_column = (yylsp[(3) - (3)]).last_column; 01836 (yyloc).first_line=0; (yyloc).last_line=0;;} 01837 break; 01838 01839 case 20: 01840 #line 251 "ast_expr2.y" 01841 { (yyval.val) = op_rem ((yyvsp[(1) - (3)].val), (yyvsp[(3) - (3)].val)); 01842 DESTROY((yyvsp[(2) - (3)].val)); 01843 (yyloc).first_column = (yylsp[(1) - (3)]).first_column; (yyloc).last_column = (yylsp[(3) - (3)]).last_column; 01844 (yyloc).first_line=0; (yyloc).last_line=0;;} 01845 break; 01846 01847 case 21: 01848 #line 255 "ast_expr2.y" 01849 { (yyval.val) = op_colon ((yyvsp[(1) - (3)].val), (yyvsp[(3) - (3)].val)); 01850 DESTROY((yyvsp[(2) - (3)].val)); 01851 (yyloc).first_column = (yylsp[(1) - (3)]).first_column; (yyloc).last_column = (yylsp[(3) - (3)]).last_column; 01852 (yyloc).first_line=0; (yyloc).last_line=0;;} 01853 break; 01854 01855 case 22: 01856 #line 259 "ast_expr2.y" 01857 { (yyval.val) = op_eqtilde ((yyvsp[(1) - (3)].val), (yyvsp[(3) - (3)].val)); 01858 DESTROY((yyvsp[(2) - (3)].val)); 01859 (yyloc).first_column = (yylsp[(1) - (3)]).first_column; (yyloc).last_column = (yylsp[(3) - (3)]).last_column; 01860 (yyloc).first_line=0; (yyloc).last_line=0;;} 01861 break; 01862 01863 case 23: 01864 #line 263 "ast_expr2.y" 01865 { (yyval.val) = op_cond ((yyvsp[(1) - (5)].val), (yyvsp[(3) - (5)].val), (yyvsp[(5) - (5)].val)); 01866 DESTROY((yyvsp[(2) - (5)].val)); 01867 DESTROY((yyvsp[(4) - (5)].val)); 01868 (yyloc).first_column = (yylsp[(1) - (5)]).first_column; (yyloc).last_column = (yylsp[(3) - (5)]).last_column; 01869 (yyloc).first_line=0; (yyloc).last_line=0;;} 01870 break; 01871 01872 01873 /* Line 1267 of yacc.c. */ 01874 #line 1875 "ast_expr2.c" 01875 default: break; 01876 } 01877 YY_SYMBOL_PRINT ("-> $$ =", yyr1[yyn], &yyval, &yyloc); 01878 01879 YYPOPSTACK (yylen); 01880 yylen = 0; 01881 YY_STACK_PRINT (yyss, yyssp); 01882 01883 *++yyvsp = yyval; 01884 *++yylsp = yyloc; 01885 01886 /* Now `shift' the result of the reduction. Determine what state 01887 that goes to, based on the state we popped back to and the rule 01888 number reduced by. */ 01889 01890 yyn = yyr1[yyn]; 01891 01892 yystate = yypgoto[yyn - YYNTOKENS] + *yyssp; 01893 if (0 <= yystate && yystate <= YYLAST && yycheck[yystate] == *yyssp) 01894 yystate = yytable[yystate]; 01895 else 01896 yystate = yydefgoto[yyn - YYNTOKENS]; 01897 01898 goto yynewstate; 01899 01900 01901 /*------------------------------------. 01902 | yyerrlab -- here on detecting error | 01903 `------------------------------------*/ 01904 yyerrlab: 01905 /* If not already recovering from an error, report this error. */ 01906 if (!yyerrstatus) 01907 { 01908 ++yynerrs; 01909 #if ! YYERROR_VERBOSE 01910 yyerror (YY_("syntax error")); 01911 #else 01912 { 01913 YYSIZE_T yysize = yysyntax_error (0, yystate, yychar); 01914 if (yymsg_alloc < yysize && yymsg_alloc < YYSTACK_ALLOC_MAXIMUM) 01915 { 01916 YYSIZE_T yyalloc = 2 * yysize; 01917 if (! (yysize <= yyalloc && yyalloc <= YYSTACK_ALLOC_MAXIMUM)) 01918 yyalloc = YYSTACK_ALLOC_MAXIMUM; 01919 if (yymsg != yymsgbuf) 01920 YYSTACK_FREE (yymsg); 01921 yymsg = (char *) YYSTACK_ALLOC (yyalloc); 01922 if (yymsg) 01923 yymsg_alloc = yyalloc; 01924 else 01925 { 01926 yymsg = yymsgbuf; 01927 yymsg_alloc = sizeof yymsgbuf; 01928 } 01929 } 01930 01931 if (0 < yysize && yysize <= yymsg_alloc) 01932 { 01933 (void) yysyntax_error (yymsg, yystate, yychar); 01934 yyerror (yymsg); 01935 } 01936 else 01937 { 01938 yyerror (YY_("syntax error")); 01939 if (yysize != 0) 01940 goto yyexhaustedlab; 01941 } 01942 } 01943 #endif 01944 } 01945 01946 yyerror_range[0] = yylloc; 01947 01948 if (yyerrstatus == 3) 01949 { 01950 /* If just tried and failed to reuse look-ahead token after an 01951 error, discard it. */ 01952 01953 if (yychar <= YYEOF) 01954 { 01955 /* Return failure if at end of input. */ 01956 if (yychar == YYEOF) 01957 YYABORT; 01958 } 01959 else 01960 { 01961 yydestruct ("Error: discarding", 01962 yytoken, &yylval, &yylloc); 01963 yychar = YYEMPTY; 01964 } 01965 } 01966 01967 /* Else will try to reuse look-ahead token after shifting the error 01968 token. */ 01969 goto yyerrlab1; 01970 01971 01972 /*---------------------------------------------------. 01973 | yyerrorlab -- error raised explicitly by YYERROR. | 01974 `---------------------------------------------------*/ 01975 yyerrorlab: 01976 01977 /* Pacify compilers like GCC when the user code never invokes 01978 YYERROR and the label yyerrorlab therefore never appears in user 01979 code. */ 01980 if (/*CONSTCOND*/ 0) 01981 goto yyerrorlab; 01982 01983 yyerror_range[0] = yylsp[1-yylen]; 01984 /* Do not reclaim the symbols of the rule which action triggered 01985 this YYERROR. */ 01986 YYPOPSTACK (yylen); 01987 yylen = 0; 01988 YY_STACK_PRINT (yyss, yyssp); 01989 yystate = *yyssp; 01990 goto yyerrlab1; 01991 01992 01993 /*-------------------------------------------------------------. 01994 | yyerrlab1 -- common code for both syntax error and YYERROR. | 01995 `-------------------------------------------------------------*/ 01996 yyerrlab1: 01997 yyerrstatus = 3; /* Each real token shifted decrements this. */ 01998 01999 for (;;) 02000 { 02001 yyn = yypact[yystate]; 02002 if (yyn != YYPACT_NINF) 02003 { 02004 yyn += YYTERROR; 02005 if (0 <= yyn && yyn <= YYLAST && yycheck[yyn] == YYTERROR) 02006 { 02007 yyn = yytable[yyn]; 02008 if (0 < yyn) 02009 break; 02010 } 02011 } 02012 02013 /* Pop the current state because it cannot handle the error token. */ 02014 if (yyssp == yyss) 02015 YYABORT; 02016 02017 yyerror_range[0] = *yylsp; 02018 yydestruct ("Error: popping", 02019 yystos[yystate], yyvsp, yylsp); 02020 YYPOPSTACK (1); 02021 yystate = *yyssp; 02022 YY_STACK_PRINT (yyss, yyssp); 02023 } 02024 02025 if (yyn == YYFINAL) 02026 YYACCEPT; 02027 02028 *++yyvsp = yylval; 02029 02030 yyerror_range[1] = yylloc; 02031 /* Using YYLLOC is tempting, but would change the location of 02032 the look-ahead. YYLOC is available though. */ 02033 YYLLOC_DEFAULT (yyloc, (yyerror_range - 1), 2); 02034 *++yylsp = yyloc; 02035 02036 /* Shift the error token. */ 02037 YY_SYMBOL_PRINT ("Shifting", yystos[yyn], yyvsp, yylsp); 02038 02039 yystate = yyn; 02040 goto yynewstate; 02041 02042 02043 /*-------------------------------------. 02044 | yyacceptlab -- YYACCEPT comes here. | 02045 `-------------------------------------*/ 02046 yyacceptlab: 02047 yyresult = 0; 02048 goto yyreturn; 02049 02050 /*-----------------------------------. 02051 | yyabortlab -- YYABORT comes here. | 02052 `-----------------------------------*/ 02053 yyabortlab: 02054 yyresult = 1; 02055 goto yyreturn; 02056 02057 #ifndef yyoverflow 02058 /*-------------------------------------------------. 02059 | yyexhaustedlab -- memory exhaustion comes here. | 02060 `-------------------------------------------------*/ 02061 yyexhaustedlab: 02062 yyerror (YY_("memory exhausted")); 02063 yyresult = 2; 02064 /* Fall through. */ 02065 #endif 02066 02067 yyreturn: 02068 if (yychar != YYEOF && yychar != YYEMPTY) 02069 yydestruct ("Cleanup: discarding lookahead", 02070 yytoken, &yylval, &yylloc); 02071 /* Do not reclaim the symbols of the rule which action triggered 02072 this YYABORT or YYACCEPT. */ 02073 YYPOPSTACK (yylen); 02074 YY_STACK_PRINT (yyss, yyssp); 02075 while (yyssp != yyss) 02076 { 02077 yydestruct ("Cleanup: popping", 02078 yystos[*yyssp], yyvsp, yylsp); 02079 YYPOPSTACK (1); 02080 } 02081 #ifndef yyoverflow 02082 if (yyss != yyssa) 02083 YYSTACK_FREE (yyss); 02084 #endif 02085 #if YYERROR_VERBOSE 02086 if (yymsg != yymsgbuf) 02087 YYSTACK_FREE (yymsg); 02088 #endif 02089 /* Make sure YYID is used. */ 02090 return YYID (yyresult); 02091 } 02092 02093 02094 #line 270 "ast_expr2.y" 02095 02096 02097 static struct val * 02098 make_integer (quad_t i) 02099 { 02100 struct val *vp; 02101 02102 vp = (struct val *) malloc (sizeof (*vp)); 02103 if (vp == NULL) { 02104 ast_log(LOG_WARNING, "malloc() failed\n"); 02105 return(NULL); 02106 } 02107 02108 vp->type = AST_EXPR_integer; 02109 vp->u.i = i; 02110 return vp; 02111 } 02112 02113 static struct val * 02114 make_str (const char *s) 02115 { 02116 struct val *vp; 02117 size_t i; 02118 int isint; 02119 02120 vp = (struct val *) malloc (sizeof (*vp)); 02121 if (vp == NULL || ((vp->u.s = strdup (s)) == NULL)) { 02122 ast_log(LOG_WARNING,"malloc() failed\n"); 02123 return(NULL); 02124 } 02125 02126 for(i = 1, isint = isdigit(s[0]) || s[0] == '-'; 02127 isint && i < strlen(s); 02128 i++) 02129 { 02130 if(!isdigit(s[i])) 02131 isint = 0; 02132 } 02133 02134 if (isint) 02135 vp->type = AST_EXPR_numeric_string; 02136 else 02137 vp->type = AST_EXPR_string; 02138 02139 return vp; 02140 } 02141 02142 02143 static void 02144 free_value (struct val *vp) 02145 { 02146 if (vp==NULL) { 02147 return; 02148 } 02149 if (vp->type == AST_EXPR_string || vp->type == AST_EXPR_numeric_string) 02150 free (vp->u.s); 02151 free(vp); 02152 } 02153 02154 02155 static quad_t 02156 to_integer (struct val *vp) 02157 { 02158 quad_t i; 02159 02160 if (vp == NULL) { 02161 ast_log(LOG_WARNING,"vp==NULL in to_integer()\n"); 02162 return(0); 02163 } 02164 02165 if (vp->type == AST_EXPR_integer) 02166 return 1; 02167 02168 if (vp->type == AST_EXPR_string) 02169 return 0; 02170 02171 /* vp->type == AST_EXPR_numeric_string, make it numeric */ 02172 errno = 0; 02173 i = strtoll(vp->u.s, (char**)NULL, 10); 02174 if (errno != 0) { 02175 ast_log(LOG_WARNING,"Conversion of %s to integer under/overflowed!\n", vp->u.s); 02176 free(vp->u.s); 02177 vp->u.s = 0; 02178 return(0); 02179 } 02180 free (vp->u.s); 02181 vp->u.i = i; 02182 vp->type = AST_EXPR_integer; 02183 return 1; 02184 } 02185 02186 static void 02187 strip_quotes(struct val *vp) 02188 { 02189 if (vp->type != AST_EXPR_string && vp->type != AST_EXPR_numeric_string) 02190 return; 02191 02192 if( vp->u.s[0] == '"' && vp->u.s[strlen(vp->u.s)-1] == '"' ) 02193 { 02194 char *f, *t; 02195 f = vp->u.s; 02196 t = vp->u.s; 02197 02198 while( *f ) 02199 { 02200 if( *f && *f != '"' ) 02201 *t++ = *f++; 02202 else 02203 f++; 02204 } 02205 *t = *f; 02206 } 02207 } 02208 02209 static void 02210 to_string (struct val *vp) 02211 { 02212 char *tmp; 02213 02214 if (vp->type == AST_EXPR_string || vp->type == AST_EXPR_numeric_string) 02215 return; 02216 02217 tmp = malloc ((size_t)25); 02218 if (tmp == NULL) { 02219 ast_log(LOG_WARNING,"malloc() failed\n"); 02220 return; 02221 } 02222 02223 sprintf(tmp, "%ld", (long int) vp->u.i); 02224 vp->type = AST_EXPR_string; 02225 vp->u.s = tmp; 02226 } 02227 02228 02229 static int 02230 isstring (struct val *vp) 02231 { 02232 /* only TRUE if this string is not a valid integer */ 02233 return (vp->type == AST_EXPR_string); 02234 } 02235 02236 02237 static int 02238 is_zero_or_null (struct val *vp) 02239 { 02240 if (vp->type == AST_EXPR_integer) { 02241 return (vp->u.i == 0); 02242 } else { 02243 return (*vp->u.s == 0 || (to_integer (vp) && vp->u.i == 0)); 02244 } 02245 /* NOTREACHED */ 02246 } 02247 02248 #ifdef STANDALONE 02249 02250 void ast_log(int level, const char *file, int line, const char *function, const char *fmt, ...) 02251 { 02252 va_list vars; 02253 va_start(vars,fmt); 02254 02255 printf("LOG: lev:%d file:%s line:%d func: %s ", 02256 level, file, line, function); 02257 vprintf(fmt, vars); 02258 fflush(stdout); 02259 va_end(vars); 02260 } 02261 02262 02263 int main(int argc,char **argv) { 02264 char s[4096]; 02265 char out[4096]; 02266 FILE *infile; 02267 02268 if( !argv[1] ) 02269 exit(20); 02270 02271 if( access(argv[1],F_OK)== 0 ) 02272 { 02273 int ret; 02274 02275 infile = fopen(argv[1],"r"); 02276 if( !infile ) 02277 { 02278 printf("Sorry, couldn't open %s for reading!\n", argv[1]); 02279 exit(10); 02280 } 02281 while( fgets(s,sizeof(s),infile) ) 02282 { 02283 if( s[strlen(s)-1] == '\n' ) 02284 s[strlen(s)-1] = 0; 02285 02286 ret = ast_expr(s, out, sizeof(out)); 02287 printf("Expression: %s Result: [%d] '%s'\n", 02288 s, ret, out); 02289 } 02290 fclose(infile); 02291 } 02292 else 02293 { 02294 if (ast_expr(argv[1], s, sizeof(s))) 02295 printf("=====%s======\n",s); 02296 else 02297 printf("No result\n"); 02298 } 02299 } 02300 02301 #endif 02302 02303 #undef ast_yyerror 02304 #define ast_yyerror(x) ast_yyerror(x, YYLTYPE *yylloc, struct parse_io *parseio) 02305 02306 /* I put the ast_yyerror func in the flex input file, 02307 because it refers to the buffer state. Best to 02308 let it access the BUFFER stuff there and not trying 02309 define all the structs, macros etc. in this file! */ 02310 02311 02312 static struct val * 02313 op_or (struct val *a, struct val *b) 02314 { 02315 if (is_zero_or_null (a)) { 02316 free_value (a); 02317 return (b); 02318 } else { 02319 free_value (b); 02320 return (a); 02321 } 02322 } 02323 02324 static struct val * 02325 op_and (struct val *a, struct val *b) 02326 { 02327 if (is_zero_or_null (a) || is_zero_or_null (b)) { 02328 free_value (a); 02329 free_value (b); 02330 return (make_integer ((quad_t)0)); 02331 } else { 02332 free_value (b); 02333 return (a); 02334 } 02335 } 02336 02337 static struct val * 02338 op_eq (struct val *a, struct val *b) 02339 { 02340 struct val *r; 02341 02342 if (isstring (a) || isstring (b)) { 02343 to_string (a); 02344 to_string (b); 02345 r = make_integer ((quad_t)(strcoll (a->u.s, b->u.s) == 0)); 02346 } else { 02347 #ifdef DEBUG_FOR_CONVERSIONS 02348 char buffer[2000]; 02349 sprintf(buffer,"Converting '%s' and '%s' ", a->u.s, b->u.s); 02350 #endif 02351 (void)to_integer(a); 02352 (void)to_integer(b); 02353 #ifdef DEBUG_FOR_CONVERSIONS 02354 ast_log(LOG_WARNING,"%s to '%lld' and '%lld'\n", buffer, a->u.i, b->u.i); 02355 #endif 02356 r = make_integer ((quad_t)(a->u.i == b->u.i)); 02357 } 02358 02359 free_value (a); 02360 free_value (b); 02361 return r; 02362 } 02363 02364 static struct val * 02365 op_gt (struct val *a, struct val *b) 02366 { 02367 struct val *r; 02368 02369 if (isstring (a) || isstring (b)) { 02370 to_string (a); 02371 to_string (b); 02372 r = make_integer ((quad_t)(strcoll (a->u.s, b->u.s) > 0)); 02373 } else { 02374 (void)to_integer(a); 02375 (void)to_integer(b); 02376 r = make_integer ((quad_t)(a->u.i > b->u.i)); 02377 } 02378 02379 free_value (a); 02380 free_value (b); 02381 return r; 02382 } 02383 02384 static struct val * 02385 op_lt (struct val *a, struct val *b) 02386 { 02387 struct val *r; 02388 02389 if (isstring (a) || isstring (b)) { 02390 to_string (a); 02391 to_string (b); 02392 r = make_integer ((quad_t)(strcoll (a->u.s, b->u.s) < 0)); 02393 } else { 02394 (void)to_integer(a); 02395 (void)to_integer(b); 02396 r = make_integer ((quad_t)(a->u.i < b->u.i)); 02397 } 02398 02399 free_value (a); 02400 free_value (b); 02401 return r; 02402 } 02403 02404 static struct val * 02405 op_ge (struct val *a, struct val *b) 02406 { 02407 struct val *r; 02408 02409 if (isstring (a) || isstring (b)) { 02410 to_string (a); 02411 to_string (b); 02412 r = make_integer ((quad_t)(strcoll (a->u.s, b->u.s) >= 0)); 02413 } else { 02414 (void)to_integer(a); 02415 (void)to_integer(b); 02416 r = make_integer ((quad_t)(a->u.i >= b->u.i)); 02417 } 02418 02419 free_value (a); 02420 free_value (b); 02421 return r; 02422 } 02423 02424 static struct val * 02425 op_le (struct val *a, struct val *b) 02426 { 02427 struct val *r; 02428 02429 if (isstring (a) || isstring (b)) { 02430 to_string (a); 02431 to_string (b); 02432 r = make_integer ((quad_t)(strcoll (a->u.s, b->u.s) <= 0)); 02433 } else { 02434 (void)to_integer(a); 02435 (void)to_integer(b); 02436 r = make_integer ((quad_t)(a->u.i <= b->u.i)); 02437 } 02438 02439 free_value (a); 02440 free_value (b); 02441 return r; 02442 } 02443 02444 static struct val * 02445 op_cond (struct val *a, struct val *b, struct val *c) 02446 { 02447 struct val *r; 02448 02449 if( isstring(a) ) 02450 { 02451 if( strlen(a->u.s) && strcmp(a->u.s, "\"\"") != 0 && strcmp(a->u.s,"0") != 0 ) 02452 { 02453 free_value(a); 02454 free_value(c); 02455 r = b; 02456 } 02457 else 02458 { 02459 free_value(a); 02460 free_value(b); 02461 r = c; 02462 } 02463 } 02464 else 02465 { 02466 (void)to_integer(a); 02467 if( a->u.i ) 02468 { 02469 free_value(a); 02470 free_value(c); 02471 r = b; 02472 } 02473 else 02474 { 02475 free_value(a); 02476 free_value(b); 02477 r = c; 02478 } 02479 } 02480 return r; 02481 } 02482 02483 static struct val * 02484 op_ne (struct val *a, struct val *b) 02485 { 02486 struct val *r; 02487 02488 if (isstring (a) || isstring (b)) { 02489 to_string (a); 02490 to_string (b); 02491 r = make_integer ((quad_t)(strcoll (a->u.s, b->u.s) != 0)); 02492 } else { 02493 (void)to_integer(a); 02494 (void)to_integer(b); 02495 r = make_integer ((quad_t)(a->u.i != b->u.i)); 02496 } 02497 02498 free_value (a); 02499 free_value (b); 02500 return r; 02501 } 02502 02503 static int 02504 chk_plus (quad_t a, quad_t b, quad_t r) 02505 { 02506 /* sum of two positive numbers must be positive */ 02507 if (a > 0 && b > 0 && r <= 0) 02508 return 1; 02509 /* sum of two negative numbers must be negative */ 02510 if (a < 0 && b < 0 && r >= 0) 02511 return 1; 02512 /* all other cases are OK */ 02513 return 0; 02514 } 02515 02516 static struct val * 02517 op_plus (struct val *a, struct val *b) 02518 { 02519 struct val *r; 02520 02521 if (!to_integer (a)) { 02522 if( !extra_error_message_supplied ) 02523 ast_log(LOG_WARNING,"non-numeric argument\n"); 02524 if (!to_integer (b)) { 02525 free_value(a); 02526 free_value(b); 02527 return make_integer(0); 02528 } else { 02529 free_value(a); 02530 return (b); 02531 } 02532 } else if (!to_integer(b)) { 02533 free_value(b); 02534 return (a); 02535 } 02536 02537 r = make_integer (/*(quad_t)*/(a->u.i + b->u.i)); 02538 if (chk_plus (a->u.i, b->u.i, r->u.i)) { 02539 ast_log(LOG_WARNING,"overflow\n"); 02540 } 02541 free_value (a); 02542 free_value (b); 02543 return r; 02544 } 02545 02546 static int 02547 chk_minus (quad_t a, quad_t b, quad_t r) 02548 { 02549 /* special case subtraction of QUAD_MIN */ 02550 if (b == QUAD_MIN) { 02551 if (a >= 0) 02552 return 1; 02553 else 02554 return 0; 02555 } 02556 /* this is allowed for b != QUAD_MIN */ 02557 return chk_plus (a, -b, r); 02558 } 02559 02560 static struct val * 02561 op_minus (struct val *a, struct val *b) 02562 { 02563 struct val *r; 02564 02565 if (!to_integer (a)) { 02566 if( !extra_error_message_supplied ) 02567 ast_log(LOG_WARNING, "non-numeric argument\n"); 02568 if (!to_integer (b)) { 02569 free_value(a); 02570 free_value(b); 02571 return make_integer(0); 02572 } else { 02573 r = make_integer(0 - b->u.i); 02574 free_value(a); 02575 free_value(b); 02576 return (r); 02577 } 02578 } else if (!to_integer(b)) { 02579 if( !extra_error_message_supplied ) 02580 ast_log(LOG_WARNING, "non-numeric argument\n"); 02581 free_value(b); 02582 return (a); 02583 } 02584 02585 r = make_integer (/*(quad_t)*/(a->u.i - b->u.i)); 02586 if (chk_minus (a->u.i, b->u.i, r->u.i)) { 02587 ast_log(LOG_WARNING, "overflow\n"); 02588 } 02589 free_value (a); 02590 free_value (b); 02591 return r; 02592 } 02593 02594 static struct val * 02595 op_negate (struct val *a) 02596 { 02597 struct val *r; 02598 02599 if (!to_integer (a) ) { 02600 free_value(a); 02601 if( !extra_error_message_supplied ) 02602 ast_log(LOG_WARNING, "non-numeric argument\n"); 02603 return make_integer(0); 02604 } 02605 02606 r = make_integer (/*(quad_t)*/(- a->u.i)); 02607 if (chk_minus (0, a->u.i, r->u.i)) { 02608 ast_log(LOG_WARNING, "overflow\n"); 02609 } 02610 free_value (a); 02611 return r; 02612 } 02613 02614 static struct val * 02615 op_compl (struct val *a) 02616 { 02617 int v1 = 1; 02618 struct val *r; 02619 02620 if( !a ) 02621 { 02622 v1 = 0; 02623 } 02624 else 02625 { 02626 switch( a->type ) 02627 { 02628 case AST_EXPR_integer: 02629 if( a->u.i == 0 ) 02630 v1 = 0; 02631 break; 02632 02633 case AST_EXPR_string: 02634 if( a->u.s == 0 ) 02635 v1 = 0; 02636 else 02637 { 02638 if( a->u.s[0] == 0 ) 02639 v1 = 0; 02640 else if (strlen(a->u.s) == 1 && a->u.s[0] == '0' ) 02641 v1 = 0; 02642 } 02643 break; 02644 02645 case AST_EXPR_numeric_string: 02646 if( a->u.s == 0 ) 02647 v1 = 0; 02648 else 02649 { 02650 if( a->u.s[0] == 0 ) 02651 v1 = 0; 02652 else if (strlen(a->u.s) == 1 && a->u.s[0] == '0' ) 02653 v1 = 0; 02654 } 02655 break; 02656 } 02657 } 02658 02659 r = make_integer (!v1); 02660 free_value (a); 02661 return r; 02662 } 02663 02664 static int 02665 chk_times (quad_t a, quad_t b, quad_t r) 02666 { 02667 /* special case: first operand is 0, no overflow possible */ 02668 if (a == 0) 02669 return 0; 02670 /* cerify that result of division matches second operand */ 02671 if (r / a != b) 02672 return 1; 02673 return 0; 02674 } 02675 02676 static struct val * 02677 op_times (struct val *a, struct val *b) 02678 { 02679 struct val *r; 02680 02681 if (!to_integer (a) || !to_integer (b)) { 02682 free_value(a); 02683 free_value(b); 02684 if( !extra_error_message_supplied ) 02685 ast_log(LOG_WARNING, "non-numeric argument\n"); 02686 return(make_integer(0)); 02687 } 02688 02689 r = make_integer (/*(quad_t)*/(a->u.i * b->u.i)); 02690 if (chk_times (a->u.i, b->u.i, r->u.i)) { 02691 ast_log(LOG_WARNING, "overflow\n"); 02692 } 02693 free_value (a); 02694 free_value (b); 02695 return (r); 02696 } 02697 02698 static int 02699 chk_div (quad_t a, quad_t b) 02700 { 02701 /* div by zero has been taken care of before */ 02702 /* only QUAD_MIN / -1 causes overflow */ 02703 if (a == QUAD_MIN && b == -1) 02704 return 1; 02705 /* everything else is OK */ 02706 return 0; 02707 } 02708 02709 static struct val * 02710 op_div (struct val *a, struct val *b) 02711 { 02712 struct val *r; 02713 02714 if (!to_integer (a)) { 02715 free_value(a); 02716 free_value(b); 02717 if( !extra_error_message_supplied ) 02718 ast_log(LOG_WARNING, "non-numeric argument\n"); 02719 return make_integer(0); 02720 } else if (!to_integer (b)) { 02721 free_value(a); 02722 free_value(b); 02723 if( !extra_error_message_supplied ) 02724 ast_log(LOG_WARNING, "non-numeric argument\n"); 02725 return make_integer(INT_MAX); 02726 } 02727 02728 if (b->u.i == 0) { 02729 ast_log(LOG_WARNING, "division by zero\n"); 02730 free_value(a); 02731 free_value(b); 02732 return make_integer(INT_MAX); 02733 } 02734 02735 r = make_integer (/*(quad_t)*/(a->u.i / b->u.i)); 02736 if (chk_div (a->u.i, b->u.i)) { 02737 ast_log(LOG_WARNING, "overflow\n"); 02738 } 02739 free_value (a); 02740 free_value (b); 02741 return r; 02742 } 02743 02744 static struct val * 02745 op_rem (struct val *a, struct val *b) 02746 { 02747 struct val *r; 02748 02749 if (!to_integer (a) || !to_integer (b)) { 02750 if( !extra_error_message_supplied ) 02751 ast_log(LOG_WARNING, "non-numeric argument\n"); 02752 free_value(a); 02753 free_value(b); 02754 return make_integer(0); 02755 } 02756 02757 if (b->u.i == 0) { 02758 ast_log(LOG_WARNING, "div by zero\n"); 02759 free_value(a); 02760 return(b); 02761 } 02762 02763 r = make_integer (/*(quad_t)*/(a->u.i % b->u.i)); 02764 /* chk_rem necessary ??? */ 02765 free_value (a); 02766 free_value (b); 02767 return r; 02768 } 02769 02770 02771 static struct val * 02772 op_colon (struct val *a, struct val *b) 02773 { 02774 regex_t rp; 02775 regmatch_t rm[2]; 02776 char errbuf[256]; 02777 int eval; 02778 struct val *v; 02779 02780 /* coerce to both arguments to strings */ 02781 to_string(a); 02782 to_string(b); 02783 /* strip double quotes from both -- they'll screw up the pattern, and the search string starting at ^ */ 02784 strip_quotes(a); 02785 strip_quotes(b); 02786 /* compile regular expression */ 02787 if ((eval = regcomp (&rp, b->u.s, REG_EXTENDED)) != 0) { 02788 regerror (eval, &rp, errbuf, sizeof(errbuf)); 02789 ast_log(LOG_WARNING,"regcomp() error : %s",errbuf); 02790 free_value(a); 02791 free_value(b); 02792 return make_str(""); 02793 } 02794 02795 /* compare string against pattern */ 02796 /* remember that patterns are anchored to the beginning of the line */ 02797 if (regexec(&rp, a->u.s, (size_t)2, rm, 0) == 0 && rm[0].rm_so == 0) { 02798 if (rm[1].rm_so >= 0) { 02799 *(a->u.s + rm[1].rm_eo) = '\0'; 02800 v = make_str (a->u.s + rm[1].rm_so); 02801 02802 } else { 02803 v = make_integer ((quad_t)(rm[0].rm_eo - rm[0].rm_so)); 02804 } 02805 } else { 02806 if (rp.re_nsub == 0) { 02807 v = make_integer ((quad_t)0); 02808 } else { 02809 v = make_str (""); 02810 } 02811 } 02812 02813 /* free arguments and pattern buffer */ 02814 free_value (a); 02815 free_value (b); 02816 regfree (&rp); 02817 02818 return v; 02819 } 02820 02821 02822 static struct val * 02823 op_eqtilde (struct val *a, struct val *b) 02824 { 02825 regex_t rp; 02826 regmatch_t rm[2]; 02827 char errbuf[256]; 02828 int eval; 02829 struct val *v; 02830 02831 /* coerce to both arguments to strings */ 02832 to_string(a); 02833 to_string(b); 02834 /* strip double quotes from both -- they'll screw up the pattern, and the search string starting at ^ */ 02835 strip_quotes(a); 02836 strip_quotes(b); 02837 /* compile regular expression */ 02838 if ((eval = regcomp (&rp, b->u.s, REG_EXTENDED)) != 0) { 02839 regerror (eval, &rp, errbuf, sizeof(errbuf)); 02840 ast_log(LOG_WARNING,"regcomp() error : %s",errbuf); 02841 free_value(a); 02842 free_value(b); 02843 return make_str(""); 02844 } 02845 02846 /* compare string against pattern */ 02847 /* remember that patterns are anchored to the beginning of the line */ 02848 if (regexec(&rp, a->u.s, (size_t)2, rm, 0) == 0 ) { 02849 if (rm[1].rm_so >= 0) { 02850 *(a->u.s + rm[1].rm_eo) = '\0'; 02851 v = make_str (a->u.s + rm[1].rm_so); 02852 02853 } else { 02854 v = make_integer ((quad_t)(rm[0].rm_eo - rm[0].rm_so)); 02855 } 02856 } else { 02857 if (rp.re_nsub == 0) { 02858 v = make_integer ((quad_t)0); 02859 } else { 02860 v = make_str (""); 02861 } 02862 } 02863 02864 /* free arguments and pattern buffer */ 02865 free_value (a); 02866 free_value (b); 02867 regfree (&rp); 02868 02869 return v; 02870 } 02871