49 #define YYBISON_VERSION "2.4.1"
52 #define YYSKELETON_NAME "yacc.c"
64 #define YYLSP_NEEDED 1
67 #define yyparse ast_yyparse
68 #define yylex ast_yylex
69 #define yyerror ast_yyerror
70 #define yylval ast_yylval
71 #define yychar ast_yychar
72 #define yydebug ast_yydebug
73 #define yynerrs ast_yynerrs
74 #define yylloc ast_yylloc
94 #define ASTMM_LIBC ASTMM_REDIRECT
97 #include <sys/types.h>
100 #if defined(STANDALONE) || defined(STANDALONE2)
102 #define __USE_ISOC99 1
107 #define FP___PRINTF "%.18Lg"
108 #define FP___TYPE long double
110 #define FP___PRINTF "%.16g"
111 #define FP___TYPE double
115 #define FUNC_COS cosl
116 #elif defined(HAVE_COS)
117 #define FUNC_COS (long double)cos
121 #define FUNC_SIN sinl
122 #elif defined(HAVE_SIN)
123 #define FUNC_SIN (long double)sin
127 #define FUNC_TAN tanl
128 #elif defined(HAVE_TAN)
129 #define FUNC_TAN (long double)tan
133 #define FUNC_ACOS acosl
134 #elif defined(HAVE_ACOS)
135 #define FUNC_ACOS (long double)acos
139 #define FUNC_ASIN asinl
140 #elif defined(HAVE_ASIN)
141 #define FUNC_ASIN (long double)asin
145 #define FUNC_ATAN atanl
146 #elif defined(HAVE_ATAN)
147 #define FUNC_ATAN (long double)atan
151 #define FUNC_ATAN2 atan2l
152 #elif defined(HAVE_ATAN2)
153 #define FUNC_ATAN2 (long double)atan2
157 #define FUNC_POW powl
158 #elif defined(HAVE_POW)
159 #define FUNC_POW (long double)pow
163 #define FUNC_SQRT sqrtl
164 #elif defined(HAVE_SQRT)
165 #define FUNC_SQRT (long double)sqrt
169 #define FUNC_RINT rintl
170 #elif defined(HAVE_RINT)
171 #define FUNC_RINT (long double)rint
175 #define FUNC_EXP expl
176 #elif defined(HAVE_EXP)
177 #define FUNC_EXP (long double)exp
181 #define FUNC_LOG logl
182 #elif defined(HAVE_LOG)
183 #define FUNC_LOG (long double)log
186 #ifdef HAVE_REMAINDERL
187 #define FUNC_REMAINDER remainderl
188 #elif defined(HAVE_REMAINDER)
189 #define FUNC_REMAINDER (long double)remainder
193 #define FUNC_FMOD fmodl
194 #elif defined(HAVE_FMOD)
195 #define FUNC_FMOD (long double)fmod
199 #define FUNC_STRTOD strtold
200 #elif defined(HAVE_STRTOD)
201 #define FUNC_STRTOD (long double)strtod
205 #define FUNC_FLOOR floorl
206 #elif defined(HAVE_FLOOR)
207 #define FUNC_FLOOR (long double)floor
211 #define FUNC_CEIL ceill
212 #elif defined(HAVE_CEIL)
213 #define FUNC_CEIL (long double)ceil
217 #define FUNC_ROUND roundl
218 #elif defined(HAVE_ROUND)
219 #define FUNC_ROUND (long double)round
223 #define FUNC_TRUNC truncl
224 #elif defined(HAVE_TRUNC)
225 #define FUNC_TRUNC (long double)trunc
233 #define FUNC_EXP2 exp2l
234 #elif (defined(HAVE_EXPL) && defined(HAVE_LOGL))
235 #define FUNC_EXP2(x) expl((x) * logl(2.0))
236 #elif (defined(HAVE_EXP) && defined(HAVE_LOG))
237 #define FUNC_EXP2(x) (long double)exp((x) * log(2.0))
241 #define FUNC_EXP10 exp10l
242 #elif (defined(HAVE_EXPL) && defined(HAVE_LOGL))
243 #define FUNC_EXP10(x) expl((x) * logl(10.0))
244 #elif (defined(HAVE_EXP) && defined(HAVE_LOG))
245 #define FUNC_EXP10(x) (long double)exp((x) * log(10.0))
249 #define FUNC_LOG2 log2l
250 #elif defined(HAVE_LOGL)
251 #define FUNC_LOG2(x) (logl(x) / logl(2.0))
252 #elif defined(HAVE_LOG10L)
253 #define FUNC_LOG2(x) (log10l(x) / log10l(2.0))
254 #elif defined(HAVE_LOG2)
255 #define FUNC_LOG2 (long double)log2
256 #elif defined(HAVE_LOG)
257 #define FUNC_LOG2(x) ((long double)log(x) / log(2.0))
261 #define FUNC_LOG10 log10l
262 #elif defined(HAVE_LOGL)
263 #define FUNC_LOG10(x) (logl(x) / logl(10.0))
264 #elif defined(HAVE_LOG2L)
265 #define FUNC_LOG10(x) (log2l(x) / log2l(10.0))
266 #elif defined(HAVE_LOG10)
267 #define FUNC_LOG10(x) (long double)log10(x)
268 #elif defined(HAVE_LOG)
269 #define FUNC_LOG10(x) ((long double)log(x) / log(10.0))
282 #if !defined(SOLARIS) && !defined(__CYGWIN__)
285 #define quad_t int64_t
293 #if !defined(STANDALONE) && !defined(STANDALONE2)
297 #if defined(LONG_LONG_MIN) && !defined(QUAD_MIN)
298 #define QUAD_MIN LONG_LONG_MIN
300 #if defined(LONG_LONG_MAX) && !defined(QUAD_MAX)
301 #define QUAD_MAX LONG_LONG_MAX
304 # if ! defined(QUAD_MIN)
305 # define QUAD_MIN (-0x7fffffffffffffffLL-1)
307 # if ! defined(QUAD_MAX)
308 # define QUAD_MAX (0x7fffffffffffffffLL)
310 #define YYENABLE_NLS 0
311 #define YYPARSE_PARAM parseio
312 #define YYLEX_PARAM ((struct parse_io *)parseio)->scanner
313 #define YYERROR_VERBOSE 1
314 extern char extra_error_message[4095];
315 extern int extra_error_message_supplied;
318 AST_EXPR_number, AST_EXPR_numeric_string, AST_EXPR_string
321 #if defined(STANDALONE) || defined(STANDALONE2)
322 void ast_log(
int level,
const char *file,
int line,
const char *
function,
const char *fmt, ...) __attribute__ ((format (printf,5,6)));
334 AST_EXPR_NODE_COMMA, AST_EXPR_NODE_STRING, AST_EXPR_NODE_VAL
346 typedef void *yyscan_t;
356 static int chk_div __P((FP___TYPE, FP___TYPE));
357 static int chk_minus __P((FP___TYPE, FP___TYPE, FP___TYPE));
358 static int chk_plus __P((FP___TYPE, FP___TYPE, FP___TYPE));
359 static int chk_times __P((FP___TYPE, FP___TYPE, FP___TYPE));
360 static void free_value __P((
struct val *));
361 static int is_zero_or_null __P((
struct val *));
362 static int isstring __P((
struct val *));
363 static struct val *make_number __P((FP___TYPE));
364 static struct val *make_str __P((
const char *));
365 static struct val *op_and __P((
struct val *,
struct val *));
366 static struct val *op_colon __P((
struct val *,
struct val *));
367 static struct val *op_eqtilde __P((
struct val *,
struct val *));
368 static struct val *op_tildetilde __P((
struct val *,
struct val *));
369 static struct val *op_div __P((
struct val *,
struct val *));
370 static struct val *op_eq __P((
struct val *,
struct val *));
371 static struct val *op_ge __P((
struct val *,
struct val *));
372 static struct val *op_gt __P((
struct val *,
struct val *));
373 static struct val *op_le __P((
struct val *,
struct val *));
374 static struct val *op_lt __P((
struct val *,
struct val *));
375 static struct val *op_cond __P((
struct val *,
struct val *,
struct val *));
376 static struct val *op_minus __P((
struct val *,
struct val *));
377 static struct val *op_negate __P((
struct val *));
378 static struct val *op_compl __P((
struct val *));
379 static struct val *op_ne __P((
struct val *,
struct val *));
380 static struct val *op_or __P((
struct val *,
struct val *));
381 static struct val *op_plus __P((
struct val *,
struct val *));
382 static struct val *op_rem __P((
struct val *,
struct val *));
383 static struct val *op_times __P((
struct val *,
struct val *));
385 static int to_number __P((
struct val *));
386 static void to_string __P((
struct val *));
387 static struct expr_node *alloc_expr_node(
enum node_type);
388 static void destroy_arglist(
struct expr_node *arglist);
400 # define YYLTYPE yyltype
401 # define YYLTYPE_IS_TRIVIAL 1
411 #define ast_yyerror(x) ast_yyerror(x,&yyloc,parseio)
412 #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);}
416 #line 417 "ast_expr2.c"
424 #ifdef YYERROR_VERBOSE
425 # undef YYERROR_VERBOSE
426 # define YYERROR_VERBOSE 1
428 # define YYERROR_VERBOSE 0
432 #ifndef YYTOKEN_TABLE
433 # define YYTOKEN_TABLE 0
444 TOK_COLONCOLON = 259,
460 TOK_TILDETILDE = 275,
471 #if ! defined YYSTYPE && ! defined YYSTYPE_IS_DECLARED
476 #line 343 "ast_expr2.y"
484 #line 485 "ast_expr2.c"
486 # define YYSTYPE_IS_TRIVIAL 1
487 # define yystype YYSTYPE
488 # define YYSTYPE_IS_DECLARED 1
491 #if ! defined YYLTYPE && ! defined YYLTYPE_IS_DECLARED
499 # define yyltype YYLTYPE
500 # define YYLTYPE_IS_DECLARED 1
501 # define YYLTYPE_IS_TRIVIAL 1
508 #line 348 "ast_expr2.y"
514 #line 515 "ast_expr2.c"
521 typedef YYTYPE_UINT8 yytype_uint8;
523 typedef unsigned char yytype_uint8;
527 typedef YYTYPE_INT8 yytype_int8;
528 #elif (defined __STDC__ || defined __C99__FUNC__ \
529 || defined __cplusplus || defined _MSC_VER)
530 typedef signed char yytype_int8;
532 typedef short int yytype_int8;
536 typedef YYTYPE_UINT16 yytype_uint16;
538 typedef unsigned short int yytype_uint16;
542 typedef YYTYPE_INT16 yytype_int16;
544 typedef short int yytype_int16;
548 # ifdef __SIZE_TYPE__
549 # define YYSIZE_T __SIZE_TYPE__
550 # elif defined size_t
551 # define YYSIZE_T size_t
552 # elif ! defined YYSIZE_T && (defined __STDC__ || defined __C99__FUNC__ \
553 || defined __cplusplus || defined _MSC_VER)
555 # define YYSIZE_T size_t
557 # define YYSIZE_T unsigned int
561 #define YYSIZE_MAXIMUM ((YYSIZE_T) -1)
566 # include <libintl.h>
567 # define YY_(msgid) dgettext ("bison-runtime", msgid)
571 # define YY_(msgid) msgid
576 #if ! defined lint || defined __GNUC__
577 # define YYUSE(e) ((void) (e))
586 #if (defined __STDC__ || defined __C99__FUNC__ \
587 || defined __cplusplus || defined _MSC_VER)
600 #if ! defined yyoverflow || YYERROR_VERBOSE
604 # ifdef YYSTACK_USE_ALLOCA
605 # if YYSTACK_USE_ALLOCA
607 # define YYSTACK_ALLOC __builtin_alloca
608 # elif defined __BUILTIN_VA_ARG_INCR
611 # define YYSTACK_ALLOC __alloca
612 # elif defined _MSC_VER
614 # define alloca _alloca
616 # define YYSTACK_ALLOC alloca
617 # if ! defined _ALLOCA_H && ! defined _STDLIB_H && (defined __STDC__ || defined __C99__FUNC__ \
618 || defined __cplusplus || defined _MSC_VER)
628 # ifdef YYSTACK_ALLOC
630 # define YYSTACK_FREE(Ptr) do { ; } while (YYID (0))
631 # ifndef YYSTACK_ALLOC_MAXIMUM
636 # define YYSTACK_ALLOC_MAXIMUM 4032
639 # define YYSTACK_ALLOC YYMALLOC
640 # define YYSTACK_FREE YYFREE
641 # ifndef YYSTACK_ALLOC_MAXIMUM
642 # define YYSTACK_ALLOC_MAXIMUM YYSIZE_MAXIMUM
644 # if (defined __cplusplus && ! defined _STDLIB_H \
645 && ! ((defined YYMALLOC || defined malloc) \
646 && (defined YYFREE || defined free)))
653 # define YYMALLOC malloc
654 # if ! defined malloc && ! defined _STDLIB_H && (defined __STDC__ || defined __C99__FUNC__ \
655 || defined __cplusplus || defined _MSC_VER)
656 void *malloc (YYSIZE_T);
661 # if ! defined free && ! defined _STDLIB_H && (defined __STDC__ || defined __C99__FUNC__ \
662 || defined __cplusplus || defined _MSC_VER)
670 #if (! defined yyoverflow \
671 && (! defined __cplusplus \
672 || (defined YYLTYPE_IS_TRIVIAL && YYLTYPE_IS_TRIVIAL \
673 && defined YYSTYPE_IS_TRIVIAL && YYSTYPE_IS_TRIVIAL)))
678 yytype_int16 yyss_alloc;
684 # define YYSTACK_GAP_MAXIMUM (sizeof (union yyalloc) - 1)
688 # define YYSTACK_BYTES(N) \
689 ((N) * (sizeof (yytype_int16) + sizeof (YYSTYPE) + sizeof (YYLTYPE)) \
690 + 2 * YYSTACK_GAP_MAXIMUM)
695 # if defined __GNUC__ && 1 < __GNUC__
696 # define YYCOPY(To, From, Count) \
697 __builtin_memcpy (To, From, (Count) * sizeof (*(From)))
699 # define YYCOPY(To, From, Count) \
703 for (yyi = 0; yyi < (Count); yyi++) \
704 (To)[yyi] = (From)[yyi]; \
715 # define YYSTACK_RELOCATE(Stack_alloc, Stack) \
718 YYSIZE_T yynewbytes; \
719 YYCOPY (&yyptr->Stack_alloc, Stack, yysize); \
720 Stack = &yyptr->Stack_alloc; \
721 yynewbytes = yystacksize * sizeof (*Stack) + YYSTACK_GAP_MAXIMUM; \
722 yyptr += yynewbytes / sizeof (*yyptr); \
744 #define YYMAXUTOK 280
746 #define YYTRANSLATE(YYX) \
747 ((unsigned int) (YYX) <= YYMAXUTOK ? yytranslate[YYX] : YYUNDEFTOK)
750 static const yytype_uint8 yytranslate[] =
752 0, 2, 2, 2, 2, 2, 2, 2, 2, 2,
753 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
754 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
755 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
756 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
757 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
758 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
759 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
760 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
761 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
762 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
763 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
764 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
765 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
766 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
767 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
768 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
769 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
770 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
771 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
772 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
773 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
774 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
775 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
776 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
777 2, 2, 2, 2, 2, 2, 1, 2, 3, 4,
778 5, 6, 7, 8, 9, 10, 11, 12, 13, 14,
779 15, 16, 17, 18, 19, 20, 21, 22, 23, 24,
786 static const yytype_uint8 yyprhs[] =
788 0, 0, 3, 5, 6, 8, 12, 15, 20, 22,
789 26, 30, 34, 38, 42, 46, 50, 54, 58, 62,
790 66, 69, 72, 76, 80, 84, 88, 92, 98
794 static const yytype_int8 yyrhs[] =
796 27, 0, -1, 29, -1, -1, 29, -1, 28, 3,
797 29, -1, 28, 3, -1, 25, 23, 28, 24, -1,
798 25, -1, 23, 29, 24, -1, 29, 6, 29, -1,
799 29, 7, 29, -1, 29, 13, 29, -1, 29, 12,
800 29, -1, 29, 11, 29, -1, 29, 10, 29, -1,
801 29, 9, 29, -1, 29, 8, 29, -1, 29, 15,
802 29, -1, 29, 14, 29, -1, 14, 29, -1, 19,
803 29, -1, 29, 18, 29, -1, 29, 17, 29, -1,
804 29, 16, 29, -1, 29, 22, 29, -1, 29, 21,
805 29, -1, 29, 5, 29, 4, 29, -1, 29, 20,
810 static const yytype_uint16 yyrline[] =
812 0, 372, 372, 380, 387, 388, 394, 403, 409, 410,
813 414, 418, 422, 426, 430, 434, 438, 442, 446, 450,
814 454, 458, 462, 466, 470, 474, 478, 482, 487
818 #if YYDEBUG || YYERROR_VERBOSE || YYTOKEN_TABLE
821 static const char *
const yytname[] =
823 "$end",
"error",
"$undefined",
"TOK_COMMA",
"TOK_COLONCOLON",
824 "TOK_COND",
"TOK_OR",
"TOK_AND",
"TOK_NE",
"TOK_LE",
"TOK_GE",
"TOK_LT",
825 "TOK_GT",
"TOK_EQ",
"TOK_MINUS",
"TOK_PLUS",
"TOK_MOD",
"TOK_DIV",
826 "TOK_MULT",
"TOK_COMPL",
"TOK_TILDETILDE",
"TOK_EQTILDE",
"TOK_COLON",
827 "TOK_LP",
"TOK_RP",
"TOKEN",
"$accept",
"start",
"arglist",
"expr", 0
834 static const yytype_uint16 yytoknum[] =
836 0, 256, 257, 258, 259, 260, 261, 262, 263, 264,
837 265, 266, 267, 268, 269, 270, 271, 272, 273, 274,
838 275, 276, 277, 278, 279, 280
843 static const yytype_uint8 yyr1[] =
845 0, 26, 27, 27, 28, 28, 28, 29, 29, 29,
846 29, 29, 29, 29, 29, 29, 29, 29, 29, 29,
847 29, 29, 29, 29, 29, 29, 29, 29, 29
851 static const yytype_uint8 yyr2[] =
853 0, 2, 1, 0, 1, 3, 2, 4, 1, 3,
854 3, 3, 3, 3, 3, 3, 3, 3, 3, 3,
855 2, 2, 3, 3, 3, 3, 3, 5, 3
861 static const yytype_uint8 yydefact[] =
863 3, 0, 0, 0, 8, 0, 2, 20, 21, 0,
864 0, 1, 0, 0, 0, 0, 0, 0, 0, 0,
865 0, 0, 0, 0, 0, 0, 0, 0, 0, 9,
866 0, 4, 0, 10, 11, 17, 16, 15, 14, 13,
867 12, 19, 18, 24, 23, 22, 28, 26, 25, 6,
872 static const yytype_int8 yydefgoto[] =
879 #define YYPACT_NINF -18
880 static const yytype_int16 yypact[] =
882 118, 118, 118, 118, -15, 6, 65, -17, -17, 25,
883 118, -18, 118, 118, 118, 118, 118, 118, 118, 118,
884 118, 118, 118, 118, 118, 118, 118, 118, 118, -18,
885 4, 65, 47, 98, 113, 130, 130, 130, 130, 130,
886 130, 137, 137, -17, -17, -17, -18, -18, -18, 118,
891 static const yytype_int8 yypgoto[] =
900 #define YYTABLE_NINF -1
901 static const yytype_uint8 yytable[] =
903 7, 8, 9, 26, 27, 28, 11, 49, 10, 31,
904 0, 32, 33, 34, 35, 36, 37, 38, 39, 40,
905 41, 42, 43, 44, 45, 46, 47, 48, 50, 0,
906 12, 13, 14, 15, 16, 17, 18, 19, 20, 21,
907 22, 23, 24, 25, 0, 26, 27, 28, 52, 29,
908 53, 51, 12, 13, 14, 15, 16, 17, 18, 19,
909 20, 21, 22, 23, 24, 25, 0, 26, 27, 28,
910 12, 13, 14, 15, 16, 17, 18, 19, 20, 21,
911 22, 23, 24, 25, 0, 26, 27, 28, 13, 14,
912 15, 16, 17, 18, 19, 20, 21, 22, 23, 24,
913 25, 0, 26, 27, 28, 14, 15, 16, 17, 18,
914 19, 20, 21, 22, 23, 24, 25, 0, 26, 27,
915 28, 15, 16, 17, 18, 19, 20, 21, 22, 23,
916 24, 25, 1, 26, 27, 28, 0, 2, 0, 0,
917 0, 3, 0, 4, 21, 22, 23, 24, 25, 0,
918 26, 27, 28, 23, 24, 25, 0, 26, 27, 28
921 static const yytype_int8 yycheck[] =
923 1, 2, 3, 20, 21, 22, 0, 3, 23, 10,
924 -1, 12, 13, 14, 15, 16, 17, 18, 19, 20,
925 21, 22, 23, 24, 25, 26, 27, 28, 24, -1,
926 5, 6, 7, 8, 9, 10, 11, 12, 13, 14,
927 15, 16, 17, 18, -1, 20, 21, 22, 49, 24,
928 51, 4, 5, 6, 7, 8, 9, 10, 11, 12,
929 13, 14, 15, 16, 17, 18, -1, 20, 21, 22,
930 5, 6, 7, 8, 9, 10, 11, 12, 13, 14,
931 15, 16, 17, 18, -1, 20, 21, 22, 6, 7,
932 8, 9, 10, 11, 12, 13, 14, 15, 16, 17,
933 18, -1, 20, 21, 22, 7, 8, 9, 10, 11,
934 12, 13, 14, 15, 16, 17, 18, -1, 20, 21,
935 22, 8, 9, 10, 11, 12, 13, 14, 15, 16,
936 17, 18, 14, 20, 21, 22, -1, 19, -1, -1,
937 -1, 23, -1, 25, 14, 15, 16, 17, 18, -1,
938 20, 21, 22, 16, 17, 18, -1, 20, 21, 22
943 static const yytype_uint8 yystos[] =
945 0, 14, 19, 23, 25, 27, 29, 29, 29, 29,
946 23, 0, 5, 6, 7, 8, 9, 10, 11, 12,
947 13, 14, 15, 16, 17, 18, 20, 21, 22, 24,
948 28, 29, 29, 29, 29, 29, 29, 29, 29, 29,
949 29, 29, 29, 29, 29, 29, 29, 29, 29, 3,
953 #define yyerrok (yyerrstatus = 0)
954 #define yyclearin (yychar = YYEMPTY)
958 #define YYACCEPT goto yyacceptlab
959 #define YYABORT goto yyabortlab
960 #define YYERROR goto yyerrorlab
967 #define YYFAIL goto yyerrlab
969 #define YYRECOVERING() (!!yyerrstatus)
971 #define YYBACKUP(Token, Value) \
973 if (yychar == YYEMPTY && yylen == 1) \
977 yytoken = YYTRANSLATE (yychar); \
983 yyerror (YY_("syntax error: cannot back up")); \
990 #define YYERRCODE 256
997 #define YYRHSLOC(Rhs, K) ((Rhs)[K])
998 #ifndef YYLLOC_DEFAULT
999 # define YYLLOC_DEFAULT(Current, Rhs, N) \
1003 (Current).first_line = YYRHSLOC (Rhs, 1).first_line; \
1004 (Current).first_column = YYRHSLOC (Rhs, 1).first_column; \
1005 (Current).last_line = YYRHSLOC (Rhs, N).last_line; \
1006 (Current).last_column = YYRHSLOC (Rhs, N).last_column; \
1010 (Current).first_line = (Current).last_line = \
1011 YYRHSLOC (Rhs, 0).last_line; \
1012 (Current).first_column = (Current).last_column = \
1013 YYRHSLOC (Rhs, 0).last_column; \
1023 #ifndef YY_LOCATION_PRINT
1024 # if YYLTYPE_IS_TRIVIAL
1025 # define YY_LOCATION_PRINT(File, Loc) \
1026 fprintf (File, "%d.%d-%d.%d", \
1027 (Loc).first_line, (Loc).first_column, \
1028 (Loc).last_line, (Loc).last_column)
1030 # define YY_LOCATION_PRINT(File, Loc) ((void) 0)
1038 # define YYLEX yylex (&yylval, &yylloc, YYLEX_PARAM)
1040 # define YYLEX yylex (&yylval, &yylloc)
1048 # define YYFPRINTF fprintf
1051 # define YYDPRINTF(Args) \
1057 # define YY_SYMBOL_PRINT(Title, Type, Value, Location) \
1061 YYFPRINTF (stderr, "%s ", Title); \
1062 yy_symbol_print (stderr, \
1063 Type, Value, Location); \
1064 YYFPRINTF (stderr, "\n"); \
1074 #if (defined __STDC__ || defined __C99__FUNC__ \
1075 || defined __cplusplus || defined _MSC_VER)
1077 yy_symbol_value_print (FILE *yyoutput,
int yytype,
YYSTYPE const *
const yyvaluep,
YYLTYPE const *
const yylocationp)
1080 yy_symbol_value_print (yyoutput, yytype, yyvaluep, yylocationp)
1083 YYSTYPE const * const yyvaluep;
1084 YYLTYPE const * const yylocationp;
1089 YYUSE (yylocationp);
1091 if (yytype < YYNTOKENS)
1092 YYPRINT (yyoutput, yytoknum[yytype], *yyvaluep);
1108 #if (defined __STDC__ || defined __C99__FUNC__ \
1109 || defined __cplusplus || defined _MSC_VER)
1111 yy_symbol_print (FILE *yyoutput,
int yytype,
YYSTYPE const *
const yyvaluep,
YYLTYPE const *
const yylocationp)
1114 yy_symbol_print (yyoutput, yytype, yyvaluep, yylocationp)
1117 YYSTYPE const * const yyvaluep;
1118 YYLTYPE const * const yylocationp;
1121 if (yytype < YYNTOKENS)
1122 YYFPRINTF (yyoutput,
"token %s (", yytname[yytype]);
1124 YYFPRINTF (yyoutput,
"nterm %s (", yytname[yytype]);
1126 YY_LOCATION_PRINT (yyoutput, *yylocationp);
1127 YYFPRINTF (yyoutput,
": ");
1128 yy_symbol_value_print (yyoutput, yytype, yyvaluep, yylocationp);
1129 YYFPRINTF (yyoutput,
")");
1137 #if (defined __STDC__ || defined __C99__FUNC__ \
1138 || defined __cplusplus || defined _MSC_VER)
1140 yy_stack_print (yytype_int16 *yybottom, yytype_int16 *yytop)
1143 yy_stack_print (yybottom, yytop)
1144 yytype_int16 *yybottom;
1145 yytype_int16 *yytop;
1148 YYFPRINTF (stderr,
"Stack now");
1149 for (; yybottom <= yytop; yybottom++)
1151 int yybot = *yybottom;
1152 YYFPRINTF (stderr,
" %d", yybot);
1154 YYFPRINTF (stderr,
"\n");
1157 # define YY_STACK_PRINT(Bottom, Top) \
1160 yy_stack_print ((Bottom), (Top)); \
1168 #if (defined __STDC__ || defined __C99__FUNC__ \
1169 || defined __cplusplus || defined _MSC_VER)
1174 yy_reduce_print (yyvsp, yylsp, yyrule)
1180 int yynrhs = yyr2[yyrule];
1182 unsigned long int yylno = yyrline[yyrule];
1183 YYFPRINTF (stderr,
"Reducing stack by rule %d (line %lu):\n",
1186 for (yyi = 0; yyi < yynrhs; yyi++)
1188 YYFPRINTF (stderr,
" $%d = ", yyi + 1);
1189 yy_symbol_print (stderr, yyrhs[yyprhs[yyrule] + yyi],
1190 &(yyvsp[(yyi + 1) - (yynrhs)])
1191 , &(yylsp[(yyi + 1) - (yynrhs)]) );
1192 YYFPRINTF (stderr,
"\n");
1196 # define YY_REDUCE_PRINT(Rule) \
1199 yy_reduce_print (yyvsp, yylsp, Rule); \
1206 # define YYDPRINTF(Args)
1207 # define YY_SYMBOL_PRINT(Title, Type, Value, Location)
1208 # define YY_STACK_PRINT(Bottom, Top)
1209 # define YY_REDUCE_PRINT(Rule)
1215 # define YYINITDEPTH 200
1226 # define YYMAXDEPTH 10000
1234 # if defined __GLIBC__ && defined _STRING_H
1235 # define yystrlen strlen
1238 #if (defined __STDC__ || defined __C99__FUNC__ \
1239 || defined __cplusplus || defined _MSC_VER)
1241 yystrlen (
const char *yystr)
1249 for (yylen = 0; yystr[yylen]; yylen++)
1257 # if defined __GLIBC__ && defined _STRING_H && defined _GNU_SOURCE
1258 # define yystpcpy stpcpy
1262 #if (defined __STDC__ || defined __C99__FUNC__ \
1263 || defined __cplusplus || defined _MSC_VER)
1265 yystpcpy (
char *yydest,
const char *yysrc)
1268 yystpcpy (yydest, yysrc)
1274 const char *yys = yysrc;
1276 while ((*yyd++ = *yys++) !=
'\0')
1293 yytnamerr (
char *yyres,
const char *yystr)
1298 char const *yyp = yystr;
1305 goto do_not_strip_quotes;
1309 goto do_not_strip_quotes;
1322 do_not_strip_quotes: ;
1326 return yystrlen (yystr);
1328 return yystpcpy (yyres, yystr) - yyres;
1340 yysyntax_error (
char *yyresult,
int yystate,
int yychar)
1342 int yyn = yypact[yystate];
1344 if (! (YYPACT_NINF < yyn && yyn <= YYLAST))
1348 int yytype = YYTRANSLATE (yychar);
1349 YYSIZE_T yysize0 = yytnamerr (0, yytname[yytype]);
1350 YYSIZE_T yysize = yysize0;
1352 int yysize_overflow = 0;
1353 enum { YYERROR_VERBOSE_ARGS_MAXIMUM = 5 };
1354 char const *yyarg[YYERROR_VERBOSE_ARGS_MAXIMUM];
1360 YY_(
"syntax error, unexpected %s");
1361 YY_(
"syntax error, unexpected %s, expecting %s");
1362 YY_(
"syntax error, unexpected %s, expecting %s or %s");
1363 YY_(
"syntax error, unexpected %s, expecting %s or %s or %s");
1364 YY_(
"syntax error, unexpected %s, expecting %s or %s or %s or %s");
1368 static char const yyunexpected[] =
"syntax error, unexpected %s";
1369 static char const yyexpecting[] =
", expecting %s";
1370 static char const yyor[] =
" or %s";
1371 char yyformat[
sizeof yyunexpected
1372 +
sizeof yyexpecting - 1
1373 + ((YYERROR_VERBOSE_ARGS_MAXIMUM - 2)
1374 * (
sizeof yyor - 1))];
1375 char const *yyprefix = yyexpecting;
1379 int yyxbegin = yyn < 0 ? -yyn : 0;
1382 int yychecklim = YYLAST - yyn + 1;
1383 int yyxend = yychecklim < YYNTOKENS ? yychecklim : YYNTOKENS;
1386 yyarg[0] = yytname[yytype];
1387 yyfmt = yystpcpy (yyformat, yyunexpected);
1389 for (yyx = yyxbegin; yyx < yyxend; ++yyx)
1390 if (yycheck[yyx + yyn] == yyx && yyx != YYTERROR)
1392 if (yycount == YYERROR_VERBOSE_ARGS_MAXIMUM)
1396 yyformat[
sizeof yyunexpected - 1] =
'\0';
1399 yyarg[yycount++] = yytname[yyx];
1400 yysize1 = yysize + yytnamerr (0, yytname[yyx]);
1401 yysize_overflow |= (yysize1 < yysize);
1403 yyfmt = yystpcpy (yyfmt, yyprefix);
1407 yyf = YY_(yyformat);
1408 yysize1 = yysize + yystrlen (yyf);
1409 yysize_overflow |= (yysize1 < yysize);
1412 if (yysize_overflow)
1413 return YYSIZE_MAXIMUM;
1420 char *yyp = yyresult;
1422 while ((*yyp = *yyf) !=
'\0')
1424 if (*yyp ==
'%' && yyf[1] ==
's' && yyi < yycount)
1426 yyp += yytnamerr (yyp, yyarg[yyi++]);
1447 #if (defined __STDC__ || defined __C99__FUNC__ \
1448 || defined __cplusplus || defined _MSC_VER)
1450 yydestruct (
const char *yymsg,
int yytype,
YYSTYPE *yyvaluep,
YYLTYPE *yylocationp)
1453 yydestruct (yymsg, yytype, yyvaluep, yylocationp)
1461 YYUSE (yylocationp);
1465 YY_SYMBOL_PRINT (yymsg, yytype, yyvaluep, yylocationp);
1472 #line 366 "ast_expr2.y"
1473 { free_value((yyvaluep->val)); };
1476 #line 1477 "ast_expr2.c"
1481 #line 366 "ast_expr2.y"
1482 { free_value((yyvaluep->val)); };
1485 #line 1486 "ast_expr2.c"
1490 #line 366 "ast_expr2.y"
1491 { free_value((yyvaluep->val)); };
1494 #line 1495 "ast_expr2.c"
1499 #line 366 "ast_expr2.y"
1500 { free_value((yyvaluep->val)); };
1503 #line 1504 "ast_expr2.c"
1508 #line 366 "ast_expr2.y"
1509 { free_value((yyvaluep->val)); };
1512 #line 1513 "ast_expr2.c"
1517 #line 366 "ast_expr2.y"
1518 { free_value((yyvaluep->val)); };
1521 #line 1522 "ast_expr2.c"
1526 #line 366 "ast_expr2.y"
1527 { free_value((yyvaluep->val)); };
1530 #line 1531 "ast_expr2.c"
1535 #line 366 "ast_expr2.y"
1536 { free_value((yyvaluep->val)); };
1539 #line 1540 "ast_expr2.c"
1544 #line 366 "ast_expr2.y"
1545 { free_value((yyvaluep->val)); };
1548 #line 1549 "ast_expr2.c"
1553 #line 366 "ast_expr2.y"
1554 { free_value((yyvaluep->val)); };
1557 #line 1558 "ast_expr2.c"
1562 #line 366 "ast_expr2.y"
1563 { free_value((yyvaluep->val)); };
1566 #line 1567 "ast_expr2.c"
1571 #line 366 "ast_expr2.y"
1572 { free_value((yyvaluep->val)); };
1575 #line 1576 "ast_expr2.c"
1580 #line 366 "ast_expr2.y"
1581 { free_value((yyvaluep->val)); };
1584 #line 1585 "ast_expr2.c"
1589 #line 366 "ast_expr2.y"
1590 { free_value((yyvaluep->val)); };
1593 #line 1594 "ast_expr2.c"
1598 #line 366 "ast_expr2.y"
1599 { free_value((yyvaluep->val)); };
1602 #line 1603 "ast_expr2.c"
1607 #line 366 "ast_expr2.y"
1608 { free_value((yyvaluep->val)); };
1611 #line 1612 "ast_expr2.c"
1616 #line 366 "ast_expr2.y"
1617 { free_value((yyvaluep->val)); };
1620 #line 1621 "ast_expr2.c"
1625 #line 366 "ast_expr2.y"
1626 { free_value((yyvaluep->val)); };
1629 #line 1630 "ast_expr2.c"
1634 #line 366 "ast_expr2.y"
1635 { free_value((yyvaluep->val)); };
1638 #line 1639 "ast_expr2.c"
1643 #line 366 "ast_expr2.y"
1644 { free_value((yyvaluep->val)); };
1647 #line 1648 "ast_expr2.c"
1652 #line 366 "ast_expr2.y"
1653 { free_value((yyvaluep->val)); };
1656 #line 1657 "ast_expr2.c"
1661 #line 366 "ast_expr2.y"
1662 { free_value((yyvaluep->val)); };
1665 #line 1666 "ast_expr2.c"
1670 #line 366 "ast_expr2.y"
1671 { free_value((yyvaluep->val)); };
1674 #line 1675 "ast_expr2.c"
1683 #ifdef YYPARSE_PARAM
1684 #if defined __STDC__ || defined __cplusplus
1685 int yyparse (
void *YYPARSE_PARAM);
1690 #if defined __STDC__ || defined __cplusplus
1705 #ifdef YYPARSE_PARAM
1706 #if (defined __STDC__ || defined __C99__FUNC__ \
1707 || defined __cplusplus || defined _MSC_VER)
1709 yyparse (
void *YYPARSE_PARAM)
1712 yyparse (YYPARSE_PARAM)
1713 void *YYPARSE_PARAM;
1716 #if (defined __STDC__ || defined __C99__FUNC__ \
1717 || defined __cplusplus || defined _MSC_VER)
1752 yytype_int16 yyssa[YYINITDEPTH];
1754 yytype_int16 *yyssp;
1769 YYSIZE_T yystacksize;
1783 char *yymsg = yymsgbuf;
1784 YYSIZE_T yymsg_alloc =
sizeof yymsgbuf;
1787 #define YYPOPSTACK(N) (yyvsp -= (N), yyssp -= (N), yylsp -= (N))
1797 yystacksize = YYINITDEPTH;
1799 YYDPRINTF ((stderr,
"Starting parse\n"));
1814 #if YYLTYPE_IS_TRIVIAL
1816 yylloc.first_line = yylloc.last_line = 1;
1817 yylloc.first_column = yylloc.last_column = 1;
1833 if (yyss + yystacksize - 1 <= yyssp)
1836 YYSIZE_T yysize = yyssp - yyss + 1;
1844 yytype_int16 *yyss1 = yyss;
1851 yyoverflow (YY_(
"memory exhausted"),
1852 &yyss1, yysize *
sizeof (*yyssp),
1853 &yyvs1, yysize *
sizeof (*yyvsp),
1854 &yyls1, yysize *
sizeof (*yylsp),
1862 # ifndef YYSTACK_RELOCATE
1863 goto yyexhaustedlab;
1866 if (YYMAXDEPTH <= yystacksize)
1867 goto yyexhaustedlab;
1869 if (YYMAXDEPTH < yystacksize)
1870 yystacksize = YYMAXDEPTH;
1873 yytype_int16 *yyss1 = yyss;
1875 (
union yyalloc *) YYSTACK_ALLOC (YYSTACK_BYTES (yystacksize));
1877 goto yyexhaustedlab;
1878 YYSTACK_RELOCATE (yyss_alloc, yyss);
1879 YYSTACK_RELOCATE (yyvs_alloc, yyvs);
1880 YYSTACK_RELOCATE (yyls_alloc, yyls);
1881 # undef YYSTACK_RELOCATE
1883 YYSTACK_FREE (yyss1);
1888 yyssp = yyss + yysize - 1;
1889 yyvsp = yyvs + yysize - 1;
1890 yylsp = yyls + yysize - 1;
1892 YYDPRINTF ((stderr,
"Stack size increased to %lu\n",
1893 (
unsigned long int) yystacksize));
1895 if (yyss + yystacksize - 1 <= yyssp)
1899 YYDPRINTF ((stderr,
"Entering state %d\n", yystate));
1901 if (yystate == YYFINAL)
1915 yyn = yypact[yystate];
1916 if (yyn == YYPACT_NINF)
1922 if (yychar == YYEMPTY)
1924 YYDPRINTF ((stderr,
"Reading a token: "));
1928 if (yychar <= YYEOF)
1930 yychar = yytoken = YYEOF;
1931 YYDPRINTF ((stderr,
"Now at end of input.\n"));
1935 yytoken = YYTRANSLATE (yychar);
1936 YY_SYMBOL_PRINT (
"Next token is", yytoken, &yylval, &yylloc);
1942 if (yyn < 0 || YYLAST < yyn || yycheck[yyn] != yytoken)
1947 if (yyn == 0 || yyn == YYTABLE_NINF)
1959 YY_SYMBOL_PRINT (
"Shifting", yytoken, &yylval, &yylloc);
1974 yyn = yydefact[yystate];
1995 yyval = yyvsp[1-yylen];
1998 YYLLOC_DEFAULT (yyloc, (yylsp - yylen), yylen);
1999 YY_REDUCE_PRINT (yyn);
2005 #line 372 "ast_expr2.y"
2006 { ((
struct parse_io *)parseio)->val = (
struct val *)calloc(
sizeof(
struct val),1);
2007 ((
struct parse_io *)parseio)->val->type = (yyvsp[(1) - (1)].val)->type;
2008 if( (yyvsp[(1) - (1)].
val)->type == AST_EXPR_number )
2009 ((
struct parse_io *)parseio)->
val->u.i = (yyvsp[(1) - (1)].
val)->u.i;
2011 ((
struct parse_io *)parseio)->
val->u.s = (yyvsp[(1) - (1)].
val)->u.s;
2012 free((yyvsp[(1) - (1)].
val));
2019 #line 380 "ast_expr2.y"
2020 { ((
struct parse_io *)parseio)->val = (
struct val *)calloc(
sizeof(
struct val),1);
2021 ((
struct parse_io *)parseio)->val->type = AST_EXPR_string;
2022 ((
struct parse_io *)parseio)->val->u.s = strdup(
"");
2029 #line 387 "ast_expr2.y"
2030 { (yyval.arglist) = alloc_expr_node(AST_EXPR_NODE_VAL); (yyval.arglist)->
val = (yyvsp[(1) - (1)].
val);;}
2036 #line 388 "ast_expr2.y"
2037 {
struct expr_node *x = alloc_expr_node(AST_EXPR_NODE_VAL);
2039 DESTROY((yyvsp[(2) - (3)].
val));
2040 for (t=(yyvsp[(1) - (3)].arglist);t->right;t=t->right)
2042 (yyval.arglist) = (yyvsp[(1) - (3)].arglist); t->right = x; x->val = (yyvsp[(3) - (3)].val);;}
2048 #line 394 "ast_expr2.y"
2049 {
struct expr_node *x = alloc_expr_node(AST_EXPR_NODE_VAL);
2051 DESTROY((yyvsp[(2) - (2)].
val));
2052 for (t=(yyvsp[(1) - (2)].arglist);t->right;t=t->right)
2054 (yyval.arglist) = (yyvsp[(1) - (2)].arglist); t->right = x; x->val = make_str(
"");;}
2060 #line 403 "ast_expr2.y"
2061 { (yyval.val) = op_func((yyvsp[(1) - (4)].
val),(yyvsp[(3) - (4)].arglist), ((
struct parse_io *)parseio)->chan);
2062 DESTROY((yyvsp[(2) - (4)].
val));
2063 DESTROY((yyvsp[(4) - (4)].
val));
2064 DESTROY((yyvsp[(1) - (4)].
val));
2065 destroy_arglist((yyvsp[(3) - (4)].arglist));
2072 #line 409 "ast_expr2.y"
2073 {(yyval.val) = (yyvsp[(1) - (1)].
val);;}
2079 #line 410 "ast_expr2.y"
2080 { (yyval.val) = (yyvsp[(2) - (3)].
val);
2081 (yyloc).first_column = (yylsp[(1) - (3)]).first_column; (yyloc).last_column = (yylsp[(3) - (3)]).last_column;
2082 (yyloc).first_line=0; (yyloc).last_line=0;
2083 DESTROY((yyvsp[(1) - (3)].
val)); DESTROY((yyvsp[(3) - (3)].
val)); ;}
2089 #line 414 "ast_expr2.y"
2090 { (yyval.val) = op_or ((yyvsp[(1) - (3)].
val), (yyvsp[(3) - (3)].val));
2091 DESTROY((yyvsp[(2) - (3)].
val));
2092 (yyloc).first_column = (yylsp[(1) - (3)]).first_column; (yyloc).last_column = (yylsp[(3) - (3)]).last_column;
2093 (yyloc).first_line=0; (yyloc).last_line=0;;}
2099 #line 418 "ast_expr2.y"
2100 { (yyval.val) = op_and ((yyvsp[(1) - (3)].
val), (yyvsp[(3) - (3)].val));
2101 DESTROY((yyvsp[(2) - (3)].
val));
2102 (yyloc).first_column = (yylsp[(1) - (3)]).first_column; (yyloc).last_column = (yylsp[(3) - (3)]).last_column;
2103 (yyloc).first_line=0; (yyloc).last_line=0;;}
2109 #line 422 "ast_expr2.y"
2110 { (yyval.val) = op_eq ((yyvsp[(1) - (3)].
val), (yyvsp[(3) - (3)].val));
2111 DESTROY((yyvsp[(2) - (3)].
val));
2112 (yyloc).first_column = (yylsp[(1) - (3)]).first_column; (yyloc).last_column = (yylsp[(3) - (3)]).last_column;
2113 (yyloc).first_line=0; (yyloc).last_line=0;;}
2119 #line 426 "ast_expr2.y"
2120 { (yyval.val) = op_gt ((yyvsp[(1) - (3)].
val), (yyvsp[(3) - (3)].val));
2121 DESTROY((yyvsp[(2) - (3)].
val));
2122 (yyloc).first_column = (yylsp[(1) - (3)]).first_column; (yyloc).last_column = (yylsp[(3) - (3)]).last_column;
2123 (yyloc).first_line=0; (yyloc).last_line=0;;}
2129 #line 430 "ast_expr2.y"
2130 { (yyval.val) = op_lt ((yyvsp[(1) - (3)].
val), (yyvsp[(3) - (3)].val));
2131 DESTROY((yyvsp[(2) - (3)].
val));
2132 (yyloc).first_column = (yylsp[(1) - (3)]).first_column; (yyloc).last_column = (yylsp[(3) - (3)]).last_column;
2133 (yyloc).first_line=0; (yyloc).last_line=0;;}
2139 #line 434 "ast_expr2.y"
2140 { (yyval.val) = op_ge ((yyvsp[(1) - (3)].
val), (yyvsp[(3) - (3)].val));
2141 DESTROY((yyvsp[(2) - (3)].
val));
2142 (yyloc).first_column = (yylsp[(1) - (3)]).first_column; (yyloc).last_column = (yylsp[(3) - (3)]).last_column;
2143 (yyloc).first_line=0; (yyloc).last_line=0;;}
2149 #line 438 "ast_expr2.y"
2150 { (yyval.val) = op_le ((yyvsp[(1) - (3)].
val), (yyvsp[(3) - (3)].val));
2151 DESTROY((yyvsp[(2) - (3)].
val));
2152 (yyloc).first_column = (yylsp[(1) - (3)]).first_column; (yyloc).last_column = (yylsp[(3) - (3)]).last_column;
2153 (yyloc).first_line=0; (yyloc).last_line=0;;}
2159 #line 442 "ast_expr2.y"
2160 { (yyval.val) = op_ne ((yyvsp[(1) - (3)].
val), (yyvsp[(3) - (3)].val));
2161 DESTROY((yyvsp[(2) - (3)].
val));
2162 (yyloc).first_column = (yylsp[(1) - (3)]).first_column; (yyloc).last_column = (yylsp[(3) - (3)]).last_column;
2163 (yyloc).first_line=0; (yyloc).last_line=0;;}
2169 #line 446 "ast_expr2.y"
2170 { (yyval.val) = op_plus ((yyvsp[(1) - (3)].
val), (yyvsp[(3) - (3)].val));
2171 DESTROY((yyvsp[(2) - (3)].
val));
2172 (yyloc).first_column = (yylsp[(1) - (3)]).first_column; (yyloc).last_column = (yylsp[(3) - (3)]).last_column;
2173 (yyloc).first_line=0; (yyloc).last_line=0;;}
2179 #line 450 "ast_expr2.y"
2180 { (yyval.val) = op_minus ((yyvsp[(1) - (3)].
val), (yyvsp[(3) - (3)].val));
2181 DESTROY((yyvsp[(2) - (3)].
val));
2182 (yyloc).first_column = (yylsp[(1) - (3)]).first_column; (yyloc).last_column = (yylsp[(3) - (3)]).last_column;
2183 (yyloc).first_line=0; (yyloc).last_line=0;;}
2189 #line 454 "ast_expr2.y"
2190 { (yyval.val) = op_negate ((yyvsp[(2) - (2)].
val));
2191 DESTROY((yyvsp[(1) - (2)].
val));
2192 (yyloc).first_column = (yylsp[(1) - (2)]).first_column; (yyloc).last_column = (yylsp[(2) - (2)]).last_column;
2193 (yyloc).first_line=0; (yyloc).last_line=0;;}
2199 #line 458 "ast_expr2.y"
2200 { (yyval.val) = op_compl ((yyvsp[(2) - (2)].
val));
2201 DESTROY((yyvsp[(1) - (2)].
val));
2202 (yyloc).first_column = (yylsp[(1) - (2)]).first_column; (yyloc).last_column = (yylsp[(2) - (2)]).last_column;
2203 (yyloc).first_line=0; (yyloc).last_line=0;;}
2209 #line 462 "ast_expr2.y"
2210 { (yyval.val) = op_times ((yyvsp[(1) - (3)].
val), (yyvsp[(3) - (3)].val));
2211 DESTROY((yyvsp[(2) - (3)].
val));
2212 (yyloc).first_column = (yylsp[(1) - (3)]).first_column; (yyloc).last_column = (yylsp[(3) - (3)]).last_column;
2213 (yyloc).first_line=0; (yyloc).last_line=0;;}
2219 #line 466 "ast_expr2.y"
2220 { (yyval.val) = op_div ((yyvsp[(1) - (3)].
val), (yyvsp[(3) - (3)].val));
2221 DESTROY((yyvsp[(2) - (3)].
val));
2222 (yyloc).first_column = (yylsp[(1) - (3)]).first_column; (yyloc).last_column = (yylsp[(3) - (3)]).last_column;
2223 (yyloc).first_line=0; (yyloc).last_line=0;;}
2229 #line 470 "ast_expr2.y"
2230 { (yyval.val) = op_rem ((yyvsp[(1) - (3)].
val), (yyvsp[(3) - (3)].val));
2231 DESTROY((yyvsp[(2) - (3)].
val));
2232 (yyloc).first_column = (yylsp[(1) - (3)]).first_column; (yyloc).last_column = (yylsp[(3) - (3)]).last_column;
2233 (yyloc).first_line=0; (yyloc).last_line=0;;}
2239 #line 474 "ast_expr2.y"
2240 { (yyval.val) = op_colon ((yyvsp[(1) - (3)].
val), (yyvsp[(3) - (3)].val));
2241 DESTROY((yyvsp[(2) - (3)].
val));
2242 (yyloc).first_column = (yylsp[(1) - (3)]).first_column; (yyloc).last_column = (yylsp[(3) - (3)]).last_column;
2243 (yyloc).first_line=0; (yyloc).last_line=0;;}
2249 #line 478 "ast_expr2.y"
2250 { (yyval.val) = op_eqtilde ((yyvsp[(1) - (3)].
val), (yyvsp[(3) - (3)].val));
2251 DESTROY((yyvsp[(2) - (3)].
val));
2252 (yyloc).first_column = (yylsp[(1) - (3)]).first_column; (yyloc).last_column = (yylsp[(3) - (3)]).last_column;
2253 (yyloc).first_line=0; (yyloc).last_line=0;;}
2259 #line 482 "ast_expr2.y"
2260 { (yyval.val) = op_cond ((yyvsp[(1) - (5)].
val), (yyvsp[(3) - (5)].val), (yyvsp[(5) - (5)].
val));
2261 DESTROY((yyvsp[(2) - (5)].
val));
2262 DESTROY((yyvsp[(4) - (5)].
val));
2263 (yyloc).first_column = (yylsp[(1) - (5)]).first_column; (yyloc).last_column = (yylsp[(3) - (5)]).last_column;
2264 (yyloc).first_line=0; (yyloc).last_line=0;;}
2270 #line 487 "ast_expr2.y"
2271 { (yyval.val) = op_tildetilde ((yyvsp[(1) - (3)].
val), (yyvsp[(3) - (3)].val));
2272 DESTROY((yyvsp[(2) - (3)].
val));
2273 (yyloc).first_column = (yylsp[(1) - (3)]).first_column; (yyloc).last_column = (yylsp[(3) - (3)]).last_column;
2274 (yyloc).first_line=0; (yyloc).last_line=0;;}
2280 #line 2281 "ast_expr2.c"
2283 YY_SYMBOL_PRINT (
"-> $$ =", yyr1[yyn], &yyval, &yyloc);
2287 YY_STACK_PRINT (yyss, yyssp);
2298 yystate = yypgoto[yyn - YYNTOKENS] + *yyssp;
2299 if (0 <= yystate && yystate <= YYLAST && yycheck[yystate] == *yyssp)
2300 yystate = yytable[yystate];
2302 yystate = yydefgoto[yyn - YYNTOKENS];
2315 #if ! YYERROR_VERBOSE
2316 yyerror (YY_(
"syntax error"));
2319 YYSIZE_T yysize = yysyntax_error (0, yystate, yychar);
2320 if (yymsg_alloc < yysize && yymsg_alloc < YYSTACK_ALLOC_MAXIMUM)
2322 YYSIZE_T
yyalloc = 2 * yysize;
2323 if (! (yysize <= yyalloc && yyalloc <= YYSTACK_ALLOC_MAXIMUM))
2324 yyalloc = YYSTACK_ALLOC_MAXIMUM;
2325 if (yymsg != yymsgbuf)
2326 YYSTACK_FREE (yymsg);
2327 yymsg = (
char *) YYSTACK_ALLOC (yyalloc);
2329 yymsg_alloc = yyalloc;
2333 yymsg_alloc =
sizeof yymsgbuf;
2337 if (0 < yysize && yysize <= yymsg_alloc)
2339 (void) yysyntax_error (yymsg, yystate, yychar);
2344 yyerror (YY_(
"syntax error"));
2346 goto yyexhaustedlab;
2352 yyerror_range[0] = yylloc;
2354 if (yyerrstatus == 3)
2359 if (yychar <= YYEOF)
2362 if (yychar == YYEOF)
2367 yydestruct (
"Error: discarding",
2368 yytoken, &yylval, &yylloc);
2389 yyerror_range[0] = yylsp[1-yylen];
2394 YY_STACK_PRINT (yyss, yyssp);
2407 yyn = yypact[yystate];
2408 if (yyn != YYPACT_NINF)
2411 if (0 <= yyn && yyn <= YYLAST && yycheck[yyn] == YYTERROR)
2423 yyerror_range[0] = *yylsp;
2424 yydestruct (
"Error: popping",
2425 yystos[yystate], yyvsp, yylsp);
2428 YY_STACK_PRINT (yyss, yyssp);
2433 yyerror_range[1] = yylloc;
2436 YYLLOC_DEFAULT (yyloc, (yyerror_range - 1), 2);
2440 YY_SYMBOL_PRINT (
"Shifting", yystos[yyn], yyvsp, yylsp);
2460 #if !defined(yyoverflow) || YYERROR_VERBOSE
2465 yyerror (YY_(
"memory exhausted"));
2471 if (yychar != YYEMPTY)
2472 yydestruct (
"Cleanup: discarding lookahead",
2473 yytoken, &yylval, &yylloc);
2477 YY_STACK_PRINT (yyss, yyssp);
2478 while (yyssp != yyss)
2480 yydestruct (
"Cleanup: popping",
2481 yystos[*yyssp], yyvsp, yylsp);
2486 YYSTACK_FREE (yyss);
2489 if (yymsg != yymsgbuf)
2490 YYSTACK_FREE (yymsg);
2493 return YYID (yyresult);
2499 #line 493 "ast_expr2.y"
2502 static struct expr_node *alloc_expr_node(
enum node_type nt)
2506 ast_log(LOG_ERROR,
"Allocation for expr_node FAILED!!\n");
2516 make_number (FP___TYPE i)
2520 vp = (
struct val *) malloc (
sizeof (*vp));
2522 ast_log(LOG_WARNING,
"malloc() failed\n");
2526 vp->type = AST_EXPR_number;
2532 make_str (
const char *s)
2538 vp = (
struct val *) malloc (
sizeof (*vp));
2539 if (vp == NULL || ((vp->u.s = strdup (s)) == NULL)) {
2543 ast_log(LOG_WARNING,
"malloc() failed\n");
2547 for (i = 0, isint = (isdigit(s[0]) || s[0] ==
'-' || s[0]==
'.'); isint && i < strlen(s); i++)
2549 if (!isdigit(s[i]) && s[i] !=
'.') {
2555 vp->type = AST_EXPR_numeric_string;
2557 vp->type = AST_EXPR_string;
2564 free_value (
struct val *vp)
2569 if (vp->type == AST_EXPR_string || vp->type == AST_EXPR_numeric_string)
2576 to_number (
struct val *vp)
2581 ast_log(LOG_WARNING,
"vp==NULL in to_number()\n");
2585 if (vp->type == AST_EXPR_number)
2588 if (vp->type == AST_EXPR_string)
2593 i = FUNC_STRTOD(vp->u.s, (
char**)0);
2595 ast_log(LOG_WARNING,
"Conversion of %s to number under/overflowed!\n", vp->u.s);
2602 vp->type = AST_EXPR_number;
2607 strip_quotes(
struct val *vp)
2609 if (vp->type != AST_EXPR_string && vp->type != AST_EXPR_numeric_string)
2612 if( vp->u.s[0] ==
'"' && vp->u.s[strlen(vp->u.s)-1] ==
'"' )
2620 if( *f && *f !=
'"' )
2630 to_string (
struct val *vp)
2634 if (vp->type == AST_EXPR_string || vp->type == AST_EXPR_numeric_string)
2637 if (asprintf(&tmp, FP___PRINTF, vp->u.i) == -1) {
2638 ast_log(LOG_WARNING,
"asprintf() failed\n");
2642 vp->type = AST_EXPR_string;
2648 isstring (
struct val *vp)
2651 return (vp->type == AST_EXPR_string);
2656 is_zero_or_null (
struct val *vp)
2658 if (vp->type == AST_EXPR_number) {
2659 return (vp->u.i == 0);
2661 return (*vp->u.s == 0 || (to_number(vp) && vp->u.i == 0));
2668 void ast_log(
int level,
const char *file,
int line,
const char *
function,
const char *fmt, ...)
2673 printf(
"LOG: lev:%d file:%s line:%d func: %s ",
2674 level, file, line,
function);
2681 int main(
int argc,
char **argv) {
2689 if( access(argv[1],F_OK)== 0 )
2693 infile = fopen(argv[1],
"r");
2696 printf(
"Sorry, couldn't open %s for reading!\n", argv[1]);
2699 while( fgets(s,
sizeof(s),infile) )
2701 if( s[strlen(s)-1] ==
'\n' )
2704 ret =
ast_expr(s, out,
sizeof(out), NULL);
2705 printf(
"Expression: %s Result: [%d] '%s'\n",
2712 if (
ast_expr(argv[1], s,
sizeof(s), NULL))
2713 printf(
"=====%s======\n",s);
2715 printf(
"No result\n");
2723 #define ast_yyerror(x) ast_yyerror(x, YYLTYPE *yylloc, struct parse_io *parseio)
2730 static void destroy_arglist(
struct expr_node *arglist)
2736 arglist_next = arglist->right;
2738 free_value(arglist->val);
2742 arglist = arglist_next;
2746 #if !defined(STANDALONE) && !defined(STANDALONE2)
2747 static char *compose_func_args(
struct expr_node *arglist)
2757 if (t->val->type == AST_EXPR_number)
2760 total_len += strlen(t->val->u.s);
2766 ast_log(LOG_NOTICE,
"argbuf allocated %d bytes;\n", total_len);
2767 argbuf = malloc(total_len);
2777 if (t->val->type == AST_EXPR_number) {
2778 sprintf(numbuf,FP___PRINTF,t->val->u.i);
2779 strcat(argbuf,numbuf);
2781 strcat(argbuf,t->val->u.s);
2785 ast_log(LOG_NOTICE,
"argbuf uses %d bytes;\n", (
int) strlen(argbuf));
2789 static int is_really_num(
char *str)
2791 if ( strspn(str,
"-0123456789. ") == strlen(str))
2800 if (strspn(funcname->u.s,
"ABCDEFGHIJKLMNOPQRSTUVWXYZ_0123456789") == strlen(funcname->u.s))
2805 }
else if (strcmp(funcname->u.s,
"COS") == 0) {
2806 if (arglist && !arglist->right && arglist->val){
2807 to_number(arglist->val);
2808 result = make_number(FUNC_COS(arglist->val->u.i));
2811 ast_log(LOG_WARNING,
"Wrong args to %s() function\n",funcname->u.s);
2812 return make_number(0.0);
2816 }
else if (strcmp(funcname->u.s,
"SIN") == 0) {
2817 if (arglist && !arglist->right && arglist->val){
2818 to_number(arglist->val);
2819 result = make_number(FUNC_SIN(arglist->val->u.i));
2822 ast_log(LOG_WARNING,
"Wrong args to %s() function\n",funcname->u.s);
2823 return make_number(0.0);
2827 }
else if (strcmp(funcname->u.s,
"TAN") == 0) {
2828 if (arglist && !arglist->right && arglist->val){
2829 to_number(arglist->val);
2830 result = make_number(FUNC_TAN(arglist->val->u.i));
2833 ast_log(LOG_WARNING,
"Wrong args to %s() function\n",funcname->u.s);
2834 return make_number(0.0);
2838 }
else if (strcmp(funcname->u.s,
"ACOS") == 0) {
2839 if (arglist && !arglist->right && arglist->val){
2840 to_number(arglist->val);
2841 result = make_number(FUNC_ACOS(arglist->val->u.i));
2844 ast_log(LOG_WARNING,
"Wrong args to %s() function\n",funcname->u.s);
2845 return make_number(0.0);
2849 }
else if (strcmp(funcname->u.s,
"ASIN") == 0) {
2850 if (arglist && !arglist->right && arglist->val){
2851 to_number(arglist->val);
2852 result = make_number(FUNC_ASIN(arglist->val->u.i));
2855 ast_log(LOG_WARNING,
"Wrong args to %s() function\n",funcname->u.s);
2856 return make_number(0.0);
2860 }
else if (strcmp(funcname->u.s,
"ATAN") == 0) {
2861 if (arglist && !arglist->right && arglist->val){
2862 to_number(arglist->val);
2863 result = make_number(FUNC_ATAN(arglist->val->u.i));
2866 ast_log(LOG_WARNING,
"Wrong args to %s() function\n",funcname->u.s);
2867 return make_number(0.0);
2871 }
else if (strcmp(funcname->u.s,
"ATAN2") == 0) {
2872 if (arglist && arglist->right && !arglist->right->right && arglist->val && arglist->right->val){
2873 to_number(arglist->val);
2874 to_number(arglist->right->val);
2875 result = make_number(FUNC_ATAN2(arglist->val->u.i, arglist->right->val->u.i));
2878 ast_log(LOG_WARNING,
"Wrong args to %s() function\n",funcname->u.s);
2879 return make_number(0.0);
2883 }
else if (strcmp(funcname->u.s,
"POW") == 0) {
2884 if (arglist && arglist->right && !arglist->right->right && arglist->val && arglist->right->val){
2885 to_number(arglist->val);
2886 to_number(arglist->right->val);
2887 result = make_number(FUNC_POW(arglist->val->u.i, arglist->right->val->u.i));
2890 ast_log(LOG_WARNING,
"Wrong args to %s() function\n",funcname->u.s);
2891 return make_number(0.0);
2895 }
else if (strcmp(funcname->u.s,
"SQRT") == 0) {
2896 if (arglist && !arglist->right && arglist->val){
2897 to_number(arglist->val);
2898 result = make_number(FUNC_SQRT(arglist->val->u.i));
2901 ast_log(LOG_WARNING,
"Wrong args to %s() function\n",funcname->u.s);
2902 return make_number(0.0);
2906 }
else if (strcmp(funcname->u.s,
"FLOOR") == 0) {
2907 if (arglist && !arglist->right && arglist->val){
2908 to_number(arglist->val);
2909 result = make_number(FUNC_FLOOR(arglist->val->u.i));
2912 ast_log(LOG_WARNING,
"Wrong args to %s() function\n",funcname->u.s);
2913 return make_number(0.0);
2917 }
else if (strcmp(funcname->u.s,
"CEIL") == 0) {
2918 if (arglist && !arglist->right && arglist->val){
2919 to_number(arglist->val);
2920 result = make_number(FUNC_CEIL(arglist->val->u.i));
2923 ast_log(LOG_WARNING,
"Wrong args to %s() function\n",funcname->u.s);
2924 return make_number(0.0);
2928 }
else if (strcmp(funcname->u.s,
"ROUND") == 0) {
2929 if (arglist && !arglist->right && arglist->val){
2930 to_number(arglist->val);
2931 result = make_number(FUNC_ROUND(arglist->val->u.i));
2934 ast_log(LOG_WARNING,
"Wrong args to %s() function\n",funcname->u.s);
2935 return make_number(0.0);
2939 }
else if (strcmp(funcname->u.s,
"RINT") == 0) {
2940 if (arglist && !arglist->right && arglist->val){
2941 to_number(arglist->val);
2942 result = make_number(FUNC_RINT(arglist->val->u.i));
2945 ast_log(LOG_WARNING,
"Wrong args to %s() function\n",funcname->u.s);
2946 return make_number(0.0);
2950 }
else if (strcmp(funcname->u.s,
"TRUNC") == 0) {
2951 if (arglist && !arglist->right && arglist->val){
2952 to_number(arglist->val);
2953 result = make_number(FUNC_TRUNC(arglist->val->u.i));
2956 ast_log(LOG_WARNING,
"Wrong args to %s() function\n",funcname->u.s);
2957 return make_number(0.0);
2961 }
else if (strcmp(funcname->u.s,
"EXP") == 0) {
2962 if (arglist && !arglist->right && arglist->val){
2963 to_number(arglist->val);
2964 result = make_number(FUNC_EXP(arglist->val->u.i));
2967 ast_log(LOG_WARNING,
"Wrong args to %s() function\n",funcname->u.s);
2968 return make_number(0.0);
2972 }
else if (strcmp(funcname->u.s,
"EXP2") == 0) {
2973 if (arglist && !arglist->right && arglist->val){
2974 to_number(arglist->val);
2975 result = make_number(FUNC_EXP2(arglist->val->u.i));
2978 ast_log(LOG_WARNING,
"Wrong args to %s() function\n",funcname->u.s);
2979 return make_number(0.0);
2983 }
else if (strcmp(funcname->u.s,
"EXP10") == 0) {
2984 if (arglist && !arglist->right && arglist->val){
2985 to_number(arglist->val);
2986 result = make_number(FUNC_EXP10(arglist->val->u.i));
2989 ast_log(LOG_WARNING,
"Wrong args to %s() function\n",funcname->u.s);
2990 return make_number(0.0);
2994 }
else if (strcmp(funcname->u.s,
"LOG") == 0) {
2995 if (arglist && !arglist->right && arglist->val){
2996 to_number(arglist->val);
2997 result = make_number(FUNC_LOG(arglist->val->u.i));
3000 ast_log(LOG_WARNING,
"Wrong args to %s() function\n",funcname->u.s);
3001 return make_number(0.0);
3005 }
else if (strcmp(funcname->u.s,
"LOG2") == 0) {
3006 if (arglist && !arglist->right && arglist->val){
3007 to_number(arglist->val);
3008 result = make_number(FUNC_LOG2(arglist->val->u.i));
3011 ast_log(LOG_WARNING,
"Wrong args to %s() function\n",funcname->u.s);
3012 return make_number(0.0);
3016 }
else if (strcmp(funcname->u.s,
"LOG10") == 0) {
3017 if (arglist && !arglist->right && arglist->val){
3018 to_number(arglist->val);
3019 result = make_number(FUNC_LOG10(arglist->val->u.i));
3022 ast_log(LOG_WARNING,
"Wrong args to %s() function\n",funcname->u.s);
3023 return make_number(0.0);
3026 #ifdef FUNC_REMAINDER
3027 }
else if (strcmp(funcname->u.s,
"REMAINDER") == 0) {
3028 if (arglist && arglist->right && !arglist->right->right && arglist->val && arglist->right->val){
3029 to_number(arglist->val);
3030 to_number(arglist->right->val);
3031 result = make_number(FUNC_REMAINDER(arglist->val->u.i, arglist->right->val->u.i));
3034 ast_log(LOG_WARNING,
"Wrong args to %s() function\n",funcname->u.s);
3035 return make_number(0.0);
3038 }
else if (strcmp(funcname->u.s,
"ABS") == 0) {
3039 if (arglist && !arglist->right && arglist->val) {
3040 to_number(arglist->val);
3041 result = make_number(arglist->val->u.i < 0 ? arglist->val->u.i * -1 : arglist->val->u.i);
3044 ast_log(LOG_WARNING,
"Wrong args to %s() function\n", funcname->u.s);
3045 return make_number(0.0);
3049 #if !defined(STANDALONE) && !defined(STANDALONE2)
3052 ast_log(LOG_WARNING,
"Hey! chan is NULL.\n");
3054 ast_log(LOG_WARNING,
"Hey! could not find func %s.\n", funcname->u.s);
3058 char workspace[512];
3059 char *argbuf = compose_func_args(arglist);
3060 f->
read(chan, funcname->u.s, argbuf, workspace,
sizeof(workspace));
3062 if (is_really_num(workspace))
3063 return make_number(FUNC_STRTOD(workspace,(
char **)NULL));
3065 return make_str(workspace);
3067 ast_log(LOG_ERROR,
"Error! Function '%s' cannot be read!\n", funcname->u.s);
3068 return (make_number ((FP___TYPE)0.0));
3072 ast_log(LOG_ERROR,
"Error! '%s' doesn't appear to be an available function!\n", funcname->u.s);
3073 return (make_number ((FP___TYPE)0.0));
3076 ast_log(LOG_ERROR,
"Error! '%s' is not available in the standalone version!\n", funcname->u.s);
3077 return (make_number ((FP___TYPE)0.0));
3083 ast_log(LOG_ERROR,
"Error! '%s' is not possibly a function name!\n", funcname->u.s);
3084 return (make_number ((FP___TYPE)0.0));
3086 return (make_number ((FP___TYPE)0.0));
3091 op_or (
struct val *a,
struct val *b)
3093 if (is_zero_or_null (a)) {
3103 op_and (
struct val *a,
struct val *b)
3105 if (is_zero_or_null (a) || is_zero_or_null (b)) {
3108 return (make_number ((FP___TYPE)0.0));
3116 op_eq (
struct val *a,
struct val *b)
3120 if (isstring (a) || isstring (b)) {
3123 r = make_number ((FP___TYPE)(strcoll (a->u.s, b->u.s) == 0));
3125 #ifdef DEBUG_FOR_CONVERSIONS
3127 sprintf(buffer,
"Converting '%s' and '%s' ", a->u.s, b->u.s);
3131 #ifdef DEBUG_FOR_CONVERSIONS
3132 ast_log(LOG_WARNING,
"%s to '%lld' and '%lld'\n", buffer, a->u.i, b->u.i);
3134 r = make_number ((FP___TYPE)(a->u.i == b->u.i));
3143 op_gt (
struct val *a,
struct val *b)
3147 if (isstring (a) || isstring (b)) {
3150 r = make_number ((FP___TYPE)(strcoll (a->u.s, b->u.s) > 0));
3154 r = make_number ((FP___TYPE)(a->u.i > b->u.i));
3163 op_lt (
struct val *a,
struct val *b)
3167 if (isstring (a) || isstring (b)) {
3170 r = make_number ((FP___TYPE)(strcoll (a->u.s, b->u.s) < 0));
3174 r = make_number ((FP___TYPE)(a->u.i < b->u.i));
3183 op_ge (
struct val *a,
struct val *b)
3187 if (isstring (a) || isstring (b)) {
3190 r = make_number ((FP___TYPE)(strcoll (a->u.s, b->u.s) >= 0));
3194 r = make_number ((FP___TYPE)(a->u.i >= b->u.i));
3203 op_le (
struct val *a,
struct val *b)
3207 if (isstring (a) || isstring (b)) {
3210 r = make_number ((FP___TYPE)(strcoll (a->u.s, b->u.s) <= 0));
3214 r = make_number ((FP___TYPE)(a->u.i <= b->u.i));
3223 op_cond (
struct val *a,
struct val *b,
struct val *c)
3229 if( strlen(a->u.s) && strcmp(a->u.s,
"\"\"") != 0 && strcmp(a->u.s,
"0") != 0 )
3262 op_ne (
struct val *a,
struct val *b)
3266 if (isstring (a) || isstring (b)) {
3269 r = make_number ((FP___TYPE)(strcoll (a->u.s, b->u.s) != 0));
3273 r = make_number ((FP___TYPE)(a->u.i != b->u.i));
3282 chk_plus (FP___TYPE a, FP___TYPE b, FP___TYPE r)
3285 if (a > 0 && b > 0 && r <= 0)
3288 if (a < 0 && b < 0 && r >= 0)
3295 op_plus (
struct val *a,
struct val *b)
3299 if (!to_number (a)) {
3300 if( !extra_error_message_supplied )
3301 ast_log(LOG_WARNING,
"non-numeric argument\n");
3302 if (!to_number (b)) {
3305 return make_number(0);
3310 }
else if (!to_number(b)) {
3315 r = make_number (a->u.i + b->u.i);
3316 if (chk_plus (a->u.i, b->u.i, r->u.i)) {
3317 ast_log(LOG_WARNING,
"overflow\n");
3325 chk_minus (FP___TYPE a, FP___TYPE b, FP___TYPE r)
3328 if (b == QUAD_MIN) {
3335 return chk_plus (a, -b, r);
3339 op_minus (
struct val *a,
struct val *b)
3343 if (!to_number (a)) {
3344 if( !extra_error_message_supplied )
3345 ast_log(LOG_WARNING,
"non-numeric argument\n");
3346 if (!to_number (b)) {
3349 return make_number(0);
3351 r = make_number(0 - b->u.i);
3356 }
else if (!to_number(b)) {
3357 if( !extra_error_message_supplied )
3358 ast_log(LOG_WARNING,
"non-numeric argument\n");
3363 r = make_number (a->u.i - b->u.i);
3364 if (chk_minus (a->u.i, b->u.i, r->u.i)) {
3365 ast_log(LOG_WARNING,
"overflow\n");
3373 op_negate (
struct val *a)
3377 if (!to_number (a) ) {
3379 if( !extra_error_message_supplied )
3380 ast_log(LOG_WARNING,
"non-numeric argument\n");
3381 return make_number(0);
3384 r = make_number (- a->u.i);
3385 if (chk_minus (0, a->u.i, r->u.i)) {
3386 ast_log(LOG_WARNING,
"overflow\n");
3393 op_compl (
struct val *a)
3406 case AST_EXPR_number:
3411 case AST_EXPR_string:
3416 if( a->u.s[0] == 0 )
3418 else if (strlen(a->u.s) == 1 && a->u.s[0] ==
'0' )
3425 case AST_EXPR_numeric_string:
3430 if( a->u.s[0] == 0 )
3432 else if (strlen(a->u.s) == 1 && a->u.s[0] ==
'0' )
3441 r = make_number (!v1);
3447 chk_times (FP___TYPE a, FP___TYPE b, FP___TYPE r)
3459 op_times (
struct val *a,
struct val *b)
3463 if (!to_number (a) || !to_number (b)) {
3466 if( !extra_error_message_supplied )
3467 ast_log(LOG_WARNING,
"non-numeric argument\n");
3468 return(make_number(0));
3471 r = make_number (a->u.i * b->u.i);
3472 if (chk_times (a->u.i, b->u.i, r->u.i)) {
3473 ast_log(LOG_WARNING,
"overflow\n");
3481 chk_div (FP___TYPE a, FP___TYPE b)
3485 if (a == QUAD_MIN && b == -1)
3492 op_div (
struct val *a,
struct val *b)
3496 if (!to_number (a)) {
3499 if( !extra_error_message_supplied )
3500 ast_log(LOG_WARNING,
"non-numeric argument\n");
3501 return make_number(0);
3502 }
else if (!to_number (b)) {
3505 if( !extra_error_message_supplied )
3506 ast_log(LOG_WARNING,
"non-numeric argument\n");
3507 return make_number(INT_MAX);
3511 ast_log(LOG_WARNING,
"division by zero\n");
3514 return make_number(INT_MAX);
3517 r = make_number (a->u.i / b->u.i);
3518 if (chk_div (a->u.i, b->u.i)) {
3519 ast_log(LOG_WARNING,
"overflow\n");
3527 op_rem (
struct val *a,
struct val *b)
3531 if (!to_number (a) || !to_number (b)) {
3532 if( !extra_error_message_supplied )
3533 ast_log(LOG_WARNING,
"non-numeric argument\n");
3536 return make_number(0);
3540 ast_log(LOG_WARNING,
"div by zero\n");
3545 r = make_number (FUNC_FMOD(a->u.i, b->u.i));
3554 op_colon (
struct val *a,
struct val *b)
3569 if ((eval = regcomp (&rp, b->u.s, REG_EXTENDED)) != 0) {
3570 regerror (eval, &rp, errbuf,
sizeof(errbuf));
3571 ast_log(LOG_WARNING,
"regcomp() error : %s\n", errbuf);
3574 return make_str(
"");
3579 if (regexec(&rp, a->u.s, (
size_t)2, rm, 0) == 0 && rm[0].rm_so == 0) {
3580 if (rm[1].rm_so >= 0) {
3581 *(a->u.s + rm[1].rm_eo) =
'\0';
3582 v = make_str (a->u.s + rm[1].rm_so);
3585 v = make_number ((FP___TYPE)(rm[0].rm_eo - rm[0].rm_so));
3588 if (rp.re_nsub == 0) {
3589 v = make_number ((FP___TYPE)0);
3605 op_eqtilde (
struct val *a,
struct val *b)
3620 if ((eval = regcomp (&rp, b->u.s, REG_EXTENDED)) != 0) {
3621 regerror (eval, &rp, errbuf,
sizeof(errbuf));
3622 ast_log(LOG_WARNING,
"regcomp() error : %s\n", errbuf);
3625 return make_str(
"");
3630 if (regexec(&rp, a->u.s, (
size_t)2, rm, 0) == 0 ) {
3631 if (rm[1].rm_so >= 0) {
3632 *(a->u.s + rm[1].rm_eo) =
'\0';
3633 v = make_str (a->u.s + rm[1].rm_so);
3636 v = make_number ((FP___TYPE)(rm[0].rm_eo - rm[0].rm_so));
3639 if (rp.re_nsub == 0) {
3640 v = make_number ((FP___TYPE)0.0);
3655 op_tildetilde (
struct val *a,
struct val *b)
3667 vs = malloc(strlen(a->u.s)+strlen(b->u.s)+1);
3669 ast_log(LOG_WARNING,
"malloc() failed\n");
Main Channel structure associated with a channel.
Asterisk main include file. File version handling, generic pbx functions.
Data structure associated with a custom dialplan function.
Core PBX routines and definitions.
Support for logging to various files, console and syslog Configuration in file logger.conf.
int main(int argc, char *argv[])
int ast_expr(char *expr, char *buf, int length, struct ast_channel *chan)
Evaluate the given expression.