00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042
00043
00044
00045
00046
00047 #define YYBISON 1
00048
00049
00050 #define YYBISON_VERSION "2.3"
00051
00052
00053 #define YYSKELETON_NAME "yacc.c"
00054
00055
00056 #define YYPURE 1
00057
00058
00059 #define YYLSP_NEEDED 1
00060
00061
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
00072 #ifndef YYTOKENTYPE
00073 # define YYTOKENTYPE
00074
00075
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
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
00127 #line 1 "ast_expr2.y"
00128
00129
00130
00131
00132
00133
00134
00135
00136
00137
00138
00139
00140
00141
00142 #include "asterisk.h"
00143
00144 #if !defined(STANDALONE_AEL)
00145 ASTERISK_FILE_VERSION(__FILE__, "$Revision: 179807 $")
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
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
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
00256
00257
00258 int ast_yyerror(const char *,YYLTYPE *, struct parse_io *);
00259
00260
00261
00262
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
00268 #ifndef YYDEBUG
00269 # define YYDEBUG 0
00270 #endif
00271
00272
00273 #ifdef YYERROR_VERBOSE
00274 # undef YYERROR_VERBOSE
00275 # define YYERROR_VERBOSE 1
00276 #else
00277 # define YYERROR_VERBOSE 0
00278 #endif
00279
00280
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
00292 #line 293 "ast_expr2.c"
00293 YYSTYPE;
00294 # define yystype YYSTYPE
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
00308 # define YYLTYPE_IS_DECLARED 1
00309 # define YYLTYPE_IS_TRIVIAL 1
00310 #endif
00311
00312
00313
00314 #line 151 "ast_expr2.y"
00315
00316 extern int ast_yylex __P((YYSTYPE *, YYLTYPE *, yyscan_t));
00317
00318
00319
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>
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>
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
00382 #if ! defined lint || defined __GNUC__
00383 # define YYUSE(e) ((void) (e))
00384 #else
00385 # define YYUSE(e)
00386 #endif
00387
00388
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
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>
00416 # elif defined _AIX
00417 # define YYSTACK_ALLOC __alloca
00418 # elif defined _MSC_VER
00419 # include <malloc.h>
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>
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
00436 # define YYSTACK_FREE(Ptr) do { ; } while (YYID (0))
00437 # ifndef YYSTACK_ALLOC_MAXIMUM
00438
00439
00440
00441
00442 # define YYSTACK_ALLOC_MAXIMUM 4032
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>
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);
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 *);
00470 # endif
00471 # endif
00472 # endif
00473 #endif
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
00482 union yyalloc
00483 {
00484 yytype_int16 yyss;
00485 YYSTYPE yyvs;
00486 YYLTYPE yyls;
00487 };
00488
00489
00490 # define YYSTACK_GAP_MAXIMUM (sizeof (union yyalloc) - 1)
00491
00492
00493
00494 # define YYSTACK_BYTES(N) \
00495 ((N) * (sizeof (yytype_int16) + sizeof (YYSTYPE) + sizeof (YYLTYPE)) \
00496 + 2 * YYSTACK_GAP_MAXIMUM)
00497
00498
00499
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
00517
00518
00519
00520
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
00535 #define YYFINAL 10
00536
00537 #define YYLAST 140
00538
00539
00540 #define YYNTOKENS 24
00541
00542 #define YYNNTS 3
00543
00544 #define YYNRULES 23
00545
00546 #define YYNSTATES 46
00547
00548
00549 #define YYUNDEFTOK 2
00550 #define YYMAXUTOK 278
00551
00552 #define YYTRANSLATE(YYX) \
00553 ((unsigned int) (YYX) <= YYMAXUTOK ? yytranslate[YYX] : YYUNDEFTOK)
00554
00555
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
00590
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
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
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
00623
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
00636
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
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
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
00662
00663
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
00674 static const yytype_int8 yydefgoto[] =
00675 {
00676 -1, 5, 6
00677 };
00678
00679
00680
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
00692 static const yytype_int8 yypgoto[] =
00693 {
00694 -13, -13, -1
00695 };
00696
00697
00698
00699
00700
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
00741
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
00762
00763
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
00792
00793
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
00818
00819
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
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
00842 #if YYDEBUG
00843
00844 # ifndef YYFPRINTF
00845 # include <stdio.h>
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
00869
00870
00871
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
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
00932
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
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
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
00998
00999 int yydebug;
01000 #else
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
01006
01007
01008
01009 #ifndef YYINITDEPTH
01010 # define YYINITDEPTH 200
01011 #endif
01012
01013
01014
01015
01016
01017
01018
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
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
01056
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
01081
01082
01083
01084
01085
01086
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
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
01128
01129
01130
01131
01132
01133
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
01154
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
01173
01174 int yyxbegin = yyn < 0 ? -yyn : 0;
01175
01176
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
01213
01214
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
01235
01236
01237
01238
01239
01240
01241
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:
01265 #line 169 "ast_expr2.y"
01266 { free_value((yyvaluep->val)); };
01267 #line 1268 "ast_expr2.c"
01268 break;
01269 case 4:
01270 #line 169 "ast_expr2.y"
01271 { free_value((yyvaluep->val)); };
01272 #line 1273 "ast_expr2.c"
01273 break;
01274 case 5:
01275 #line 169 "ast_expr2.y"
01276 { free_value((yyvaluep->val)); };
01277 #line 1278 "ast_expr2.c"
01278 break;
01279 case 6:
01280 #line 169 "ast_expr2.y"
01281 { free_value((yyvaluep->val)); };
01282 #line 1283 "ast_expr2.c"
01283 break;
01284 case 7:
01285 #line 169 "ast_expr2.y"
01286 { free_value((yyvaluep->val)); };
01287 #line 1288 "ast_expr2.c"
01288 break;
01289 case 8:
01290 #line 169 "ast_expr2.y"
01291 { free_value((yyvaluep->val)); };
01292 #line 1293 "ast_expr2.c"
01293 break;
01294 case 9:
01295 #line 169 "ast_expr2.y"
01296 { free_value((yyvaluep->val)); };
01297 #line 1298 "ast_expr2.c"
01298 break;
01299 case 10:
01300 #line 169 "ast_expr2.y"
01301 { free_value((yyvaluep->val)); };
01302 #line 1303 "ast_expr2.c"
01303 break;
01304 case 11:
01305 #line 169 "ast_expr2.y"
01306 { free_value((yyvaluep->val)); };
01307 #line 1308 "ast_expr2.c"
01308 break;
01309 case 12:
01310 #line 169 "ast_expr2.y"
01311 { free_value((yyvaluep->val)); };
01312 #line 1313 "ast_expr2.c"
01313 break;
01314 case 13:
01315 #line 169 "ast_expr2.y"
01316 { free_value((yyvaluep->val)); };
01317 #line 1318 "ast_expr2.c"
01318 break;
01319 case 14:
01320 #line 169 "ast_expr2.y"
01321 { free_value((yyvaluep->val)); };
01322 #line 1323 "ast_expr2.c"
01323 break;
01324 case 15:
01325 #line 169 "ast_expr2.y"
01326 { free_value((yyvaluep->val)); };
01327 #line 1328 "ast_expr2.c"
01328 break;
01329 case 16:
01330 #line 169 "ast_expr2.y"
01331 { free_value((yyvaluep->val)); };
01332 #line 1333 "ast_expr2.c"
01333 break;
01334 case 17:
01335 #line 169 "ast_expr2.y"
01336 { free_value((yyvaluep->val)); };
01337 #line 1338 "ast_expr2.c"
01338 break;
01339 case 18:
01340 #line 169 "ast_expr2.y"
01341 { free_value((yyvaluep->val)); };
01342 #line 1343 "ast_expr2.c"
01343 break;
01344 case 19:
01345 #line 169 "ast_expr2.y"
01346 { free_value((yyvaluep->val)); };
01347 #line 1348 "ast_expr2.c"
01348 break;
01349 case 20:
01350 #line 169 "ast_expr2.y"
01351 { free_value((yyvaluep->val)); };
01352 #line 1353 "ast_expr2.c"
01353 break;
01354 case 21:
01355 #line 169 "ast_expr2.y"
01356 { free_value((yyvaluep->val)); };
01357 #line 1358 "ast_expr2.c"
01358 break;
01359 case 22:
01360 #line 169 "ast_expr2.y"
01361 { free_value((yyvaluep->val)); };
01362 #line 1363 "ast_expr2.c"
01363 break;
01364 case 23:
01365 #line 169 "ast_expr2.y"
01366 { free_value((yyvaluep->val)); };
01367 #line 1368 "ast_expr2.c"
01368 break;
01369 case 26:
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
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
01390 #if defined __STDC__ || defined __cplusplus
01391 int yyparse (void);
01392 #else
01393 int yyparse ();
01394 #endif
01395 #endif
01396
01397
01398
01399
01400
01401
01402
01403
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
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
01429 int yychar;
01430
01431
01432 YYSTYPE yylval;
01433
01434
01435 int yynerrs;
01436
01437 YYLTYPE yylloc;
01438
01439 int yystate;
01440 int yyn;
01441 int yyresult;
01442
01443 int yyerrstatus;
01444
01445 int yytoken = 0;
01446 #if YYERROR_VERBOSE
01447
01448 char yymsgbuf[128];
01449 char *yymsg = yymsgbuf;
01450 YYSIZE_T yymsg_alloc = sizeof yymsgbuf;
01451 #endif
01452
01453
01454
01455
01456
01457
01458
01459
01460
01461
01462 yytype_int16 yyssa[YYINITDEPTH];
01463 yytype_int16 *yyss = yyssa;
01464 yytype_int16 *yyssp;
01465
01466
01467 YYSTYPE yyvsa[YYINITDEPTH];
01468 YYSTYPE *yyvs = yyvsa;
01469 YYSTYPE *yyvsp;
01470
01471
01472 YYLTYPE yylsa[YYINITDEPTH];
01473 YYLTYPE *yyls = yylsa;
01474 YYLTYPE *yylsp;
01475
01476 YYLTYPE yyerror_range[2];
01477
01478 #define YYPOPSTACK(N) (yyvsp -= (N), yyssp -= (N), yylsp -= (N))
01479
01480 YYSIZE_T yystacksize = YYINITDEPTH;
01481
01482
01483
01484 YYSTYPE yyval;
01485 YYLTYPE yyloc;
01486
01487
01488
01489 int yylen = 0;
01490
01491 YYDPRINTF ((stderr, "Starting parse\n"));
01492
01493 yystate = 0;
01494 yyerrstatus = 0;
01495 yynerrs = 0;
01496 yychar = YYEMPTY;
01497
01498
01499
01500
01501
01502
01503 yyssp = yyss;
01504 yyvsp = yyvs;
01505 yylsp = yyls;
01506 #if YYLTYPE_IS_TRIVIAL
01507
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
01516
01517 yynewstate:
01518
01519
01520 yyssp++;
01521
01522 yysetstate:
01523 *yyssp = yystate;
01524
01525 if (yyss + yystacksize - 1 <= yyssp)
01526 {
01527
01528 YYSIZE_T yysize = yyssp - yyss + 1;
01529
01530 #ifdef yyoverflow
01531 {
01532
01533
01534
01535 YYSTYPE *yyvs1 = yyvs;
01536 yytype_int16 *yyss1 = yyss;
01537 YYLTYPE *yyls1 = yyls;
01538
01539
01540
01541
01542
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
01553 # ifndef YYSTACK_RELOCATE
01554 goto yyexhaustedlab;
01555 # else
01556
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
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
01596
01597 yybackup:
01598
01599
01600
01601
01602
01603 yyn = yypact[yystate];
01604 if (yyn == YYPACT_NINF)
01605 goto yydefault;
01606
01607
01608
01609
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
01628
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
01645
01646 if (yyerrstatus)
01647 yyerrstatus--;
01648
01649
01650 YY_SYMBOL_PRINT ("Shifting", yytoken, &yylval, &yylloc);
01651
01652
01653 if (yychar != YYEOF)
01654 yychar = YYEMPTY;
01655
01656 yystate = yyn;
01657 *++yyvsp = yylval;
01658 *++yylsp = yylloc;
01659 goto yynewstate;
01660
01661
01662
01663
01664
01665 yydefault:
01666 yyn = yydefact[yystate];
01667 if (yyn == 0)
01668 goto yyerrlab;
01669 goto yyreduce;
01670
01671
01672
01673
01674
01675 yyreduce:
01676
01677 yylen = yyr2[yyn];
01678
01679
01680
01681
01682
01683
01684
01685
01686
01687 yyval = yyvsp[1-yylen];
01688
01689
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 { ((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
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
01887
01888
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
01903
01904 yyerrlab:
01905
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
01951
01952
01953 if (yychar <= YYEOF)
01954 {
01955
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
01968
01969 goto yyerrlab1;
01970
01971
01972
01973
01974
01975 yyerrorlab:
01976
01977
01978
01979
01980 if ( 0)
01981 goto yyerrorlab;
01982
01983 yyerror_range[0] = yylsp[1-yylen];
01984
01985
01986 YYPOPSTACK (yylen);
01987 yylen = 0;
01988 YY_STACK_PRINT (yyss, yyssp);
01989 yystate = *yyssp;
01990 goto yyerrlab1;
01991
01992
01993
01994
01995
01996 yyerrlab1:
01997 yyerrstatus = 3;
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
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
02032
02033 YYLLOC_DEFAULT (yyloc, (yyerror_range - 1), 2);
02034 *++yylsp = yyloc;
02035
02036
02037 YY_SYMBOL_PRINT ("Shifting", yystos[yyn], yyvsp, yylsp);
02038
02039 yystate = yyn;
02040 goto yynewstate;
02041
02042
02043
02044
02045
02046 yyacceptlab:
02047 yyresult = 0;
02048 goto yyreturn;
02049
02050
02051
02052
02053 yyabortlab:
02054 yyresult = 1;
02055 goto yyreturn;
02056
02057 #ifndef yyoverflow
02058
02059
02060
02061 yyexhaustedlab:
02062 yyerror (YY_("memory exhausted"));
02063 yyresult = 2;
02064
02065 #endif
02066
02067 yyreturn:
02068 if (yychar != YYEOF && yychar != YYEMPTY)
02069 yydestruct ("Cleanup: discarding lookahead",
02070 yytoken, &yylval, &yylloc);
02071
02072
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
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
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
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
02246 }
02247
02248 #ifdef STANDALONE
02249
02250 void ast_register_file_version(const char *file, const char *version)
02251 {
02252 }
02253
02254 void ast_unregister_file_version(const char *file)
02255 {
02256 }
02257
02258 void ast_log(int level, const char *file, int line, const char *function, const char *fmt, ...)
02259 {
02260 va_list vars;
02261 va_start(vars,fmt);
02262
02263 printf("LOG: lev:%d file:%s line:%d func: %s ",
02264 level, file, line, function);
02265 vprintf(fmt, vars);
02266 fflush(stdout);
02267 va_end(vars);
02268 }
02269
02270
02271 int main(int argc,char **argv) {
02272 char s[4096];
02273 char out[4096];
02274 FILE *infile;
02275
02276 if( !argv[1] )
02277 exit(20);
02278
02279 if( access(argv[1],F_OK)== 0 )
02280 {
02281 int ret;
02282
02283 infile = fopen(argv[1],"r");
02284 if( !infile )
02285 {
02286 printf("Sorry, couldn't open %s for reading!\n", argv[1]);
02287 exit(10);
02288 }
02289 while( fgets(s,sizeof(s),infile) )
02290 {
02291 if( s[strlen(s)-1] == '\n' )
02292 s[strlen(s)-1] = 0;
02293
02294 ret = ast_expr(s, out, sizeof(out));
02295 printf("Expression: %s Result: [%d] '%s'\n",
02296 s, ret, out);
02297 }
02298 fclose(infile);
02299 }
02300 else
02301 {
02302 if (ast_expr(argv[1], s, sizeof(s)))
02303 printf("=====%s======\n",s);
02304 else
02305 printf("No result\n");
02306 }
02307 }
02308
02309 #endif
02310
02311 #undef ast_yyerror
02312 #define ast_yyerror(x) ast_yyerror(x, YYLTYPE *yylloc, struct parse_io *parseio)
02313
02314
02315
02316
02317
02318
02319
02320 static struct val *
02321 op_or (struct val *a, struct val *b)
02322 {
02323 if (is_zero_or_null (a)) {
02324 free_value (a);
02325 return (b);
02326 } else {
02327 free_value (b);
02328 return (a);
02329 }
02330 }
02331
02332 static struct val *
02333 op_and (struct val *a, struct val *b)
02334 {
02335 if (is_zero_or_null (a) || is_zero_or_null (b)) {
02336 free_value (a);
02337 free_value (b);
02338 return (make_integer ((quad_t)0));
02339 } else {
02340 free_value (b);
02341 return (a);
02342 }
02343 }
02344
02345 static struct val *
02346 op_eq (struct val *a, struct val *b)
02347 {
02348 struct val *r;
02349
02350 if (isstring (a) || isstring (b)) {
02351 to_string (a);
02352 to_string (b);
02353 r = make_integer ((quad_t)(strcoll (a->u.s, b->u.s) == 0));
02354 } else {
02355 #ifdef DEBUG_FOR_CONVERSIONS
02356 char buffer[2000];
02357 sprintf(buffer,"Converting '%s' and '%s' ", a->u.s, b->u.s);
02358 #endif
02359 (void)to_integer(a);
02360 (void)to_integer(b);
02361 #ifdef DEBUG_FOR_CONVERSIONS
02362 ast_log(LOG_WARNING,"%s to '%lld' and '%lld'\n", buffer, a->u.i, b->u.i);
02363 #endif
02364 r = make_integer ((quad_t)(a->u.i == b->u.i));
02365 }
02366
02367 free_value (a);
02368 free_value (b);
02369 return r;
02370 }
02371
02372 static struct val *
02373 op_gt (struct val *a, struct val *b)
02374 {
02375 struct val *r;
02376
02377 if (isstring (a) || isstring (b)) {
02378 to_string (a);
02379 to_string (b);
02380 r = make_integer ((quad_t)(strcoll (a->u.s, b->u.s) > 0));
02381 } else {
02382 (void)to_integer(a);
02383 (void)to_integer(b);
02384 r = make_integer ((quad_t)(a->u.i > b->u.i));
02385 }
02386
02387 free_value (a);
02388 free_value (b);
02389 return r;
02390 }
02391
02392 static struct val *
02393 op_lt (struct val *a, struct val *b)
02394 {
02395 struct val *r;
02396
02397 if (isstring (a) || isstring (b)) {
02398 to_string (a);
02399 to_string (b);
02400 r = make_integer ((quad_t)(strcoll (a->u.s, b->u.s) < 0));
02401 } else {
02402 (void)to_integer(a);
02403 (void)to_integer(b);
02404 r = make_integer ((quad_t)(a->u.i < b->u.i));
02405 }
02406
02407 free_value (a);
02408 free_value (b);
02409 return r;
02410 }
02411
02412 static struct val *
02413 op_ge (struct val *a, struct val *b)
02414 {
02415 struct val *r;
02416
02417 if (isstring (a) || isstring (b)) {
02418 to_string (a);
02419 to_string (b);
02420 r = make_integer ((quad_t)(strcoll (a->u.s, b->u.s) >= 0));
02421 } else {
02422 (void)to_integer(a);
02423 (void)to_integer(b);
02424 r = make_integer ((quad_t)(a->u.i >= b->u.i));
02425 }
02426
02427 free_value (a);
02428 free_value (b);
02429 return r;
02430 }
02431
02432 static struct val *
02433 op_le (struct val *a, struct val *b)
02434 {
02435 struct val *r;
02436
02437 if (isstring (a) || isstring (b)) {
02438 to_string (a);
02439 to_string (b);
02440 r = make_integer ((quad_t)(strcoll (a->u.s, b->u.s) <= 0));
02441 } else {
02442 (void)to_integer(a);
02443 (void)to_integer(b);
02444 r = make_integer ((quad_t)(a->u.i <= b->u.i));
02445 }
02446
02447 free_value (a);
02448 free_value (b);
02449 return r;
02450 }
02451
02452 static struct val *
02453 op_cond (struct val *a, struct val *b, struct val *c)
02454 {
02455 struct val *r;
02456
02457 if( isstring(a) )
02458 {
02459 if( strlen(a->u.s) && strcmp(a->u.s, "\"\"") != 0 && strcmp(a->u.s,"0") != 0 )
02460 {
02461 free_value(a);
02462 free_value(c);
02463 r = b;
02464 }
02465 else
02466 {
02467 free_value(a);
02468 free_value(b);
02469 r = c;
02470 }
02471 }
02472 else
02473 {
02474 (void)to_integer(a);
02475 if( a->u.i )
02476 {
02477 free_value(a);
02478 free_value(c);
02479 r = b;
02480 }
02481 else
02482 {
02483 free_value(a);
02484 free_value(b);
02485 r = c;
02486 }
02487 }
02488 return r;
02489 }
02490
02491 static struct val *
02492 op_ne (struct val *a, struct val *b)
02493 {
02494 struct val *r;
02495
02496 if (isstring (a) || isstring (b)) {
02497 to_string (a);
02498 to_string (b);
02499 r = make_integer ((quad_t)(strcoll (a->u.s, b->u.s) != 0));
02500 } else {
02501 (void)to_integer(a);
02502 (void)to_integer(b);
02503 r = make_integer ((quad_t)(a->u.i != b->u.i));
02504 }
02505
02506 free_value (a);
02507 free_value (b);
02508 return r;
02509 }
02510
02511 static int
02512 chk_plus (quad_t a, quad_t b, quad_t r)
02513 {
02514
02515 if (a > 0 && b > 0 && r <= 0)
02516 return 1;
02517
02518 if (a < 0 && b < 0 && r >= 0)
02519 return 1;
02520
02521 return 0;
02522 }
02523
02524 static struct val *
02525 op_plus (struct val *a, struct val *b)
02526 {
02527 struct val *r;
02528
02529 if (!to_integer (a)) {
02530 if( !extra_error_message_supplied )
02531 ast_log(LOG_WARNING,"non-numeric argument\n");
02532 if (!to_integer (b)) {
02533 free_value(a);
02534 free_value(b);
02535 return make_integer(0);
02536 } else {
02537 free_value(a);
02538 return (b);
02539 }
02540 } else if (!to_integer(b)) {
02541 free_value(b);
02542 return (a);
02543 }
02544
02545 r = make_integer ((a->u.i + b->u.i));
02546 if (chk_plus (a->u.i, b->u.i, r->u.i)) {
02547 ast_log(LOG_WARNING,"overflow\n");
02548 }
02549 free_value (a);
02550 free_value (b);
02551 return r;
02552 }
02553
02554 static int
02555 chk_minus (quad_t a, quad_t b, quad_t r)
02556 {
02557
02558 if (b == QUAD_MIN) {
02559 if (a >= 0)
02560 return 1;
02561 else
02562 return 0;
02563 }
02564
02565 return chk_plus (a, -b, r);
02566 }
02567
02568 static struct val *
02569 op_minus (struct val *a, struct val *b)
02570 {
02571 struct val *r;
02572
02573 if (!to_integer (a)) {
02574 if( !extra_error_message_supplied )
02575 ast_log(LOG_WARNING, "non-numeric argument\n");
02576 if (!to_integer (b)) {
02577 free_value(a);
02578 free_value(b);
02579 return make_integer(0);
02580 } else {
02581 r = make_integer(0 - b->u.i);
02582 free_value(a);
02583 free_value(b);
02584 return (r);
02585 }
02586 } else if (!to_integer(b)) {
02587 if( !extra_error_message_supplied )
02588 ast_log(LOG_WARNING, "non-numeric argument\n");
02589 free_value(b);
02590 return (a);
02591 }
02592
02593 r = make_integer ((a->u.i - b->u.i));
02594 if (chk_minus (a->u.i, b->u.i, r->u.i)) {
02595 ast_log(LOG_WARNING, "overflow\n");
02596 }
02597 free_value (a);
02598 free_value (b);
02599 return r;
02600 }
02601
02602 static struct val *
02603 op_negate (struct val *a)
02604 {
02605 struct val *r;
02606
02607 if (!to_integer (a) ) {
02608 free_value(a);
02609 if( !extra_error_message_supplied )
02610 ast_log(LOG_WARNING, "non-numeric argument\n");
02611 return make_integer(0);
02612 }
02613
02614 r = make_integer ((- a->u.i));
02615 if (chk_minus (0, a->u.i, r->u.i)) {
02616 ast_log(LOG_WARNING, "overflow\n");
02617 }
02618 free_value (a);
02619 return r;
02620 }
02621
02622 static struct val *
02623 op_compl (struct val *a)
02624 {
02625 int v1 = 1;
02626 struct val *r;
02627
02628 if( !a )
02629 {
02630 v1 = 0;
02631 }
02632 else
02633 {
02634 switch( a->type )
02635 {
02636 case AST_EXPR_integer:
02637 if( a->u.i == 0 )
02638 v1 = 0;
02639 break;
02640
02641 case AST_EXPR_string:
02642 if( a->u.s == 0 )
02643 v1 = 0;
02644 else
02645 {
02646 if( a->u.s[0] == 0 )
02647 v1 = 0;
02648 else if (strlen(a->u.s) == 1 && a->u.s[0] == '0' )
02649 v1 = 0;
02650 }
02651 break;
02652
02653 case AST_EXPR_numeric_string:
02654 if( a->u.s == 0 )
02655 v1 = 0;
02656 else
02657 {
02658 if( a->u.s[0] == 0 )
02659 v1 = 0;
02660 else if (strlen(a->u.s) == 1 && a->u.s[0] == '0' )
02661 v1 = 0;
02662 }
02663 break;
02664 }
02665 }
02666
02667 r = make_integer (!v1);
02668 free_value (a);
02669 return r;
02670 }
02671
02672 static int
02673 chk_times (quad_t a, quad_t b, quad_t r)
02674 {
02675
02676 if (a == 0)
02677 return 0;
02678
02679 if (r / a != b)
02680 return 1;
02681 return 0;
02682 }
02683
02684 static struct val *
02685 op_times (struct val *a, struct val *b)
02686 {
02687 struct val *r;
02688
02689 if (!to_integer (a) || !to_integer (b)) {
02690 free_value(a);
02691 free_value(b);
02692 if( !extra_error_message_supplied )
02693 ast_log(LOG_WARNING, "non-numeric argument\n");
02694 return(make_integer(0));
02695 }
02696
02697 r = make_integer ((a->u.i * b->u.i));
02698 if (chk_times (a->u.i, b->u.i, r->u.i)) {
02699 ast_log(LOG_WARNING, "overflow\n");
02700 }
02701 free_value (a);
02702 free_value (b);
02703 return (r);
02704 }
02705
02706 static int
02707 chk_div (quad_t a, quad_t b)
02708 {
02709
02710
02711 if (a == QUAD_MIN && b == -1)
02712 return 1;
02713
02714 return 0;
02715 }
02716
02717 static struct val *
02718 op_div (struct val *a, struct val *b)
02719 {
02720 struct val *r;
02721
02722 if (!to_integer (a)) {
02723 free_value(a);
02724 free_value(b);
02725 if( !extra_error_message_supplied )
02726 ast_log(LOG_WARNING, "non-numeric argument\n");
02727 return make_integer(0);
02728 } else if (!to_integer (b)) {
02729 free_value(a);
02730 free_value(b);
02731 if( !extra_error_message_supplied )
02732 ast_log(LOG_WARNING, "non-numeric argument\n");
02733 return make_integer(INT_MAX);
02734 }
02735
02736 if (b->u.i == 0) {
02737 ast_log(LOG_WARNING, "division by zero\n");
02738 free_value(a);
02739 free_value(b);
02740 return make_integer(INT_MAX);
02741 }
02742
02743 r = make_integer ((a->u.i / b->u.i));
02744 if (chk_div (a->u.i, b->u.i)) {
02745 ast_log(LOG_WARNING, "overflow\n");
02746 }
02747 free_value (a);
02748 free_value (b);
02749 return r;
02750 }
02751
02752 static struct val *
02753 op_rem (struct val *a, struct val *b)
02754 {
02755 struct val *r;
02756
02757 if (!to_integer (a) || !to_integer (b)) {
02758 if( !extra_error_message_supplied )
02759 ast_log(LOG_WARNING, "non-numeric argument\n");
02760 free_value(a);
02761 free_value(b);
02762 return make_integer(0);
02763 }
02764
02765 if (b->u.i == 0) {
02766 ast_log(LOG_WARNING, "div by zero\n");
02767 free_value(a);
02768 return(b);
02769 }
02770
02771 r = make_integer ((a->u.i % b->u.i));
02772
02773 free_value (a);
02774 free_value (b);
02775 return r;
02776 }
02777
02778
02779 static struct val *
02780 op_colon (struct val *a, struct val *b)
02781 {
02782 regex_t rp;
02783 regmatch_t rm[2];
02784 char errbuf[256];
02785 int eval;
02786 struct val *v;
02787
02788
02789 to_string(a);
02790 to_string(b);
02791
02792 strip_quotes(a);
02793 strip_quotes(b);
02794
02795 if ((eval = regcomp (&rp, b->u.s, REG_EXTENDED)) != 0) {
02796 regerror (eval, &rp, errbuf, sizeof(errbuf));
02797 ast_log(LOG_WARNING,"regcomp() error : %s",errbuf);
02798 free_value(a);
02799 free_value(b);
02800 return make_str("");
02801 }
02802
02803
02804
02805 if (regexec(&rp, a->u.s, (size_t)2, rm, 0) == 0 && rm[0].rm_so == 0) {
02806 if (rm[1].rm_so >= 0) {
02807 *(a->u.s + rm[1].rm_eo) = '\0';
02808 v = make_str (a->u.s + rm[1].rm_so);
02809
02810 } else {
02811 v = make_integer ((quad_t)(rm[0].rm_eo - rm[0].rm_so));
02812 }
02813 } else {
02814 if (rp.re_nsub == 0) {
02815 v = make_integer ((quad_t)0);
02816 } else {
02817 v = make_str ("");
02818 }
02819 }
02820
02821
02822 free_value (a);
02823 free_value (b);
02824 regfree (&rp);
02825
02826 return v;
02827 }
02828
02829
02830 static struct val *
02831 op_eqtilde (struct val *a, struct val *b)
02832 {
02833 regex_t rp;
02834 regmatch_t rm[2];
02835 char errbuf[256];
02836 int eval;
02837 struct val *v;
02838
02839
02840 to_string(a);
02841 to_string(b);
02842
02843 strip_quotes(a);
02844 strip_quotes(b);
02845
02846 if ((eval = regcomp (&rp, b->u.s, REG_EXTENDED)) != 0) {
02847 regerror (eval, &rp, errbuf, sizeof(errbuf));
02848 ast_log(LOG_WARNING,"regcomp() error : %s",errbuf);
02849 free_value(a);
02850 free_value(b);
02851 return make_str("");
02852 }
02853
02854
02855
02856 if (regexec(&rp, a->u.s, (size_t)2, rm, 0) == 0 ) {
02857 if (rm[1].rm_so >= 0) {
02858 *(a->u.s + rm[1].rm_eo) = '\0';
02859 v = make_str (a->u.s + rm[1].rm_so);
02860
02861 } else {
02862 v = make_integer ((quad_t)(rm[0].rm_eo - rm[0].rm_so));
02863 }
02864 } else {
02865 if (rp.re_nsub == 0) {
02866 v = make_integer ((quad_t)0);
02867 } else {
02868 v = make_str ("");
02869 }
02870 }
02871
02872
02873 free_value (a);
02874 free_value (b);
02875 regfree (&rp);
02876
02877 return v;
02878 }
02879