Let's also include aclocal.m4
[asterisk-bristuff.git] / main / ast_expr2.c
blob9133e76ea2185f7b1365d1c254276044940a3709
1 /* A Bison parser, made by GNU Bison 2.1a. */
3 /* Skeleton parser for Yacc-like parsing with Bison,
4 Copyright (C) 1984, 1989, 1990, 2000, 2001, 2002, 2003, 2004, 2005, 2006 Free Software Foundation, Inc.
6 This program is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2, or (at your option)
9 any later version.
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with this program; if not, write to the Free Software
18 Foundation, Inc., 51 Franklin Street, Fifth Floor,
19 Boston, MA 02110-1301, USA. */
21 /* As a special exception, when this file is copied by Bison into a
22 Bison output file, you may use that output file without restriction.
23 This special exception was added by the Free Software Foundation
24 in version 1.24 of Bison. */
26 /* C LALR(1) parser skeleton written by Richard Stallman, by
27 simplifying the original so-called "semantic" parser. */
29 /* All symbols defined below should begin with yy or YY, to avoid
30 infringing on user name space. This should be done even for local
31 variables, as they might otherwise be expanded by user macros.
32 There are some unavoidable exceptions within include files to
33 define necessary library symbols; they are noted "INFRINGES ON
34 USER NAME SPACE" below. */
36 /* Identify Bison output. */
37 #define YYBISON 1
39 /* Bison version. */
40 #define YYBISON_VERSION "2.1a"
42 /* Skeleton name. */
43 #define YYSKELETON_NAME "yacc.c"
45 /* Pure parsers. */
46 #define YYPURE 1
48 /* Using locations. */
49 #define YYLSP_NEEDED 1
51 /* Substitute the variable and function names. */
52 #define yyparse ast_yyparse
53 #define yylex ast_yylex
54 #define yyerror ast_yyerror
55 #define yylval ast_yylval
56 #define yychar ast_yychar
57 #define yydebug ast_yydebug
58 #define yynerrs ast_yynerrs
59 #define yylloc ast_yylloc
61 /* Tokens. */
62 #ifndef YYTOKENTYPE
63 # define YYTOKENTYPE
64 /* Put the tokens into the symbol table, so that GDB and other debuggers
65 know about them. */
66 enum yytokentype {
67 TOK_COLONCOLON = 258,
68 TOK_COND = 259,
69 TOK_OR = 260,
70 TOK_AND = 261,
71 TOK_NE = 262,
72 TOK_LE = 263,
73 TOK_GE = 264,
74 TOK_LT = 265,
75 TOK_GT = 266,
76 TOK_EQ = 267,
77 TOK_MINUS = 268,
78 TOK_PLUS = 269,
79 TOK_MOD = 270,
80 TOK_DIV = 271,
81 TOK_MULT = 272,
82 TOK_COMPL = 273,
83 TOK_EQTILDE = 274,
84 TOK_COLON = 275,
85 TOK_LP = 276,
86 TOK_RP = 277,
87 TOKEN = 278
89 #endif
90 /* Tokens. */
91 #define TOK_COLONCOLON 258
92 #define TOK_COND 259
93 #define TOK_OR 260
94 #define TOK_AND 261
95 #define TOK_NE 262
96 #define TOK_LE 263
97 #define TOK_GE 264
98 #define TOK_LT 265
99 #define TOK_GT 266
100 #define TOK_EQ 267
101 #define TOK_MINUS 268
102 #define TOK_PLUS 269
103 #define TOK_MOD 270
104 #define TOK_DIV 271
105 #define TOK_MULT 272
106 #define TOK_COMPL 273
107 #define TOK_EQTILDE 274
108 #define TOK_COLON 275
109 #define TOK_LP 276
110 #define TOK_RP 277
111 #define TOKEN 278
116 /* Copy the first part of user declarations. */
117 #line 1 "ast_expr2.y"
119 /* Written by Pace Willisson (pace@blitz.com)
120 * and placed in the public domain.
122 * Largely rewritten by J.T. Conklin (jtc@wimsey.com)
124 * And then overhauled twice by Steve Murphy (murf@digium.com)
125 * to add double-quoted strings, allow mult. spaces, improve
126 * error messages, and then to fold in a flex scanner for the
127 * yylex operation.
129 * $FreeBSD: src/bin/expr/expr.y,v 1.16 2000/07/22 10:59:36 se Exp $
132 #include "asterisk.h"
134 #if !defined(STANDALONE_AEL)
135 ASTERISK_FILE_VERSION(__FILE__, "$Revision$")
136 #endif
138 #include <sys/types.h>
139 #include <stdio.h>
140 #include <stdlib.h>
141 #include <string.h>
142 #include <locale.h>
143 #include <unistd.h>
144 #include <ctype.h>
145 #if !defined(SOLARIS) && !defined(__CYGWIN__)
146 /* #include <err.h> */
147 #else
148 #define quad_t int64_t
149 #endif
150 #include <errno.h>
151 #include <regex.h>
152 #include <limits.h>
154 #include "asterisk/ast_expr.h"
155 #include "asterisk/logger.h"
157 #if defined(LONG_LONG_MIN) && !defined(QUAD_MIN)
158 #define QUAD_MIN LONG_LONG_MIN
159 #endif
160 #if defined(LONG_LONG_MAX) && !defined(QUAD_MAX)
161 #define QUAD_MAX LONG_LONG_MAX
162 #endif
164 # if ! defined(QUAD_MIN)
165 # define QUAD_MIN (-0x7fffffffffffffffLL-1)
166 # endif
167 # if ! defined(QUAD_MAX)
168 # define QUAD_MAX (0x7fffffffffffffffLL)
169 # endif
171 #define YYPARSE_PARAM parseio
172 #define YYLEX_PARAM ((struct parse_io *)parseio)->scanner
173 #define YYERROR_VERBOSE 1
174 extern char extra_error_message[4095];
175 extern int extra_error_message_supplied;
177 enum valtype {
178 AST_EXPR_integer, AST_EXPR_numeric_string, AST_EXPR_string
181 #ifdef STANDALONE
182 void ast_log(int level, const char *file, int line, const char *function, const char *fmt, ...) __attribute__ ((format (printf,5,6)));
183 #endif
185 struct val {
186 enum valtype type;
187 union {
188 char *s;
189 quad_t i;
190 } u;
193 typedef void *yyscan_t;
195 struct parse_io
197 char *string;
198 struct val *val;
199 yyscan_t scanner;
202 static int chk_div __P((quad_t, quad_t));
203 static int chk_minus __P((quad_t, quad_t, quad_t));
204 static int chk_plus __P((quad_t, quad_t, quad_t));
205 static int chk_times __P((quad_t, quad_t, quad_t));
206 static void free_value __P((struct val *));
207 static int is_zero_or_null __P((struct val *));
208 static int isstring __P((struct val *));
209 static struct val *make_integer __P((quad_t));
210 static struct val *make_str __P((const char *));
211 static struct val *op_and __P((struct val *, struct val *));
212 static struct val *op_colon __P((struct val *, struct val *));
213 static struct val *op_eqtilde __P((struct val *, struct val *));
214 static struct val *op_div __P((struct val *, struct val *));
215 static struct val *op_eq __P((struct val *, struct val *));
216 static struct val *op_ge __P((struct val *, struct val *));
217 static struct val *op_gt __P((struct val *, struct val *));
218 static struct val *op_le __P((struct val *, struct val *));
219 static struct val *op_lt __P((struct val *, struct val *));
220 static struct val *op_cond __P((struct val *, struct val *, struct val *));
221 static struct val *op_minus __P((struct val *, struct val *));
222 static struct val *op_negate __P((struct val *));
223 static struct val *op_compl __P((struct val *));
224 static struct val *op_ne __P((struct val *, struct val *));
225 static struct val *op_or __P((struct val *, struct val *));
226 static struct val *op_plus __P((struct val *, struct val *));
227 static struct val *op_rem __P((struct val *, struct val *));
228 static struct val *op_times __P((struct val *, struct val *));
229 static quad_t to_integer __P((struct val *));
230 static void to_string __P((struct val *));
232 /* uh, if I want to predeclare yylex with a YYLTYPE, I have to predeclare the yyltype... sigh */
233 typedef struct yyltype
235 int first_line;
236 int first_column;
238 int last_line;
239 int last_column;
240 } yyltype;
242 # define YYLTYPE yyltype
243 # define YYLTYPE_IS_TRIVIAL 1
245 /* we will get warning about no prototype for yylex! But we can't
246 define it here, we have no definition yet for YYSTYPE. */
248 int ast_yyerror(const char *,YYLTYPE *, struct parse_io *);
250 /* I wanted to add args to the yyerror routine, so I could print out
251 some useful info about the error. Not as easy as it looks, but it
252 is possible. */
253 #define ast_yyerror(x) ast_yyerror(x,&yyloc,parseio)
254 #define DESTROY(x) {if((x)->type == AST_EXPR_numeric_string || (x)->type == AST_EXPR_string) free((x)->u.s); (x)->u.s = 0; free(x);}
257 /* Enabling traces. */
258 #ifndef YYDEBUG
259 # define YYDEBUG 0
260 #endif
262 /* Enabling verbose error messages. */
263 #ifdef YYERROR_VERBOSE
264 # undef YYERROR_VERBOSE
265 # define YYERROR_VERBOSE 1
266 #else
267 # define YYERROR_VERBOSE 0
268 #endif
270 /* Enabling the token table. */
271 #ifndef YYTOKEN_TABLE
272 # define YYTOKEN_TABLE 0
273 #endif
275 #if ! defined YYSTYPE && ! defined YYSTYPE_IS_DECLARED
276 typedef union YYSTYPE
277 #line 147 "ast_expr2.y"
279 struct val *val;
281 /* Line 198 of yacc.c. */
282 #line 283 "ast_expr2.c"
283 YYSTYPE;
284 # define yystype YYSTYPE /* obsolescent; will be withdrawn */
285 # define YYSTYPE_IS_DECLARED 1
286 # define YYSTYPE_IS_TRIVIAL 1
287 #endif
289 #if ! defined YYLTYPE && ! defined YYLTYPE_IS_DECLARED
290 typedef struct YYLTYPE
292 int first_line;
293 int first_column;
294 int last_line;
295 int last_column;
296 } YYLTYPE;
297 # define yyltype YYLTYPE /* obsolescent; will be withdrawn */
298 # define YYLTYPE_IS_DECLARED 1
299 # define YYLTYPE_IS_TRIVIAL 1
300 #endif
303 /* Copy the second part of user declarations. */
304 #line 151 "ast_expr2.y"
306 extern int ast_yylex __P((YYSTYPE *, YYLTYPE *, yyscan_t));
309 /* Line 221 of yacc.c. */
310 #line 311 "ast_expr2.c"
312 #ifdef short
313 # undef short
314 #endif
316 #ifdef YYTYPE_UINT8
317 typedef YYTYPE_UINT8 yytype_uint8;
318 #else
319 typedef unsigned char yytype_uint8;
320 #endif
322 #ifdef YYTYPE_INT8
323 typedef YYTYPE_INT8 yytype_int8;
324 #elif (defined __STDC__ || defined __C99__FUNC__ \
325 || defined __cplusplus || defined _MSC_VER)
326 typedef signed char yytype_int8;
327 #else
328 typedef short int yytype_int8;
329 #endif
331 #ifdef YYTYPE_UINT16
332 typedef YYTYPE_UINT16 yytype_uint16;
333 #else
334 typedef unsigned short int yytype_uint16;
335 #endif
337 #ifdef YYTYPE_INT16
338 typedef YYTYPE_INT16 yytype_int16;
339 #else
340 typedef short int yytype_int16;
341 #endif
343 #ifndef YYSIZE_T
344 # ifdef __SIZE_TYPE__
345 # define YYSIZE_T __SIZE_TYPE__
346 # elif defined size_t
347 # define YYSIZE_T size_t
348 # elif ! defined YYSIZE_T && (defined __STDC__ || defined __C99__FUNC__ \
349 || defined __cplusplus || defined _MSC_VER)
350 # include <stddef.h> /* INFRINGES ON USER NAME SPACE */
351 # define YYSIZE_T size_t
352 # else
353 # define YYSIZE_T unsigned int
354 # endif
355 #endif
357 #define YYSIZE_MAXIMUM ((YYSIZE_T) -1)
359 #ifndef YY_
360 # if YYENABLE_NLS
361 # if ENABLE_NLS
362 # include <libintl.h> /* INFRINGES ON USER NAME SPACE */
363 # define YY_(msgid) dgettext ("bison-runtime", msgid)
364 # endif
365 # endif
366 # ifndef YY_
367 # define YY_(msgid) msgid
368 # endif
369 #endif
371 /* Suppress unused-variable warnings by "using" E. */
372 #if ! defined lint || defined __GNUC__
373 # define YYUSE(e) ((void) (e))
374 #else
375 # define YYUSE(e) /* empty */
376 #endif
378 /* Identity function, used to suppress warnings about constant conditions. */
379 #ifndef lint
380 # define YYID(n) (n)
381 #else
382 #if (defined __STDC__ || defined __C99__FUNC__ \
383 || defined __cplusplus || defined _MSC_VER)
384 static int
385 YYID (int i)
386 #else
387 static int
388 YYID (i)
389 int i;
390 #endif
392 return i;
394 #endif
396 #if ! defined yyoverflow || YYERROR_VERBOSE
398 /* The parser invokes alloca or malloc; define the necessary symbols. */
400 # ifdef YYSTACK_USE_ALLOCA
401 # if YYSTACK_USE_ALLOCA
402 # ifdef __GNUC__
403 # define YYSTACK_ALLOC __builtin_alloca
404 # elif defined __BUILTIN_VA_ARG_INCR
405 # include <alloca.h> /* INFRINGES ON USER NAME SPACE */
406 # elif defined _AIX
407 # define YYSTACK_ALLOC __alloca
408 # elif defined _MSC_VER
409 # include <malloc.h> /* INFRINGES ON USER NAME SPACE */
410 # define alloca _alloca
411 # else
412 # define YYSTACK_ALLOC alloca
413 # if ! defined _ALLOCA_H && ! defined _STDLIB_H && (defined __STDC__ || defined __C99__FUNC__ \
414 || defined __cplusplus || defined _MSC_VER)
415 # include <stdlib.h> /* INFRINGES ON USER NAME SPACE */
416 # ifndef _STDLIB_H
417 # define _STDLIB_H 1
418 # endif
419 # endif
420 # endif
421 # endif
422 # endif
424 # ifdef YYSTACK_ALLOC
425 /* Pacify GCC's `empty if-body' warning. */
426 # define YYSTACK_FREE(Ptr) do { /* empty */; } while (YYID (0))
427 # ifndef YYSTACK_ALLOC_MAXIMUM
428 /* The OS might guarantee only one guard page at the bottom of the stack,
429 and a page size can be as small as 4096 bytes. So we cannot safely
430 invoke alloca (N) if N exceeds 4096. Use a slightly smaller number
431 to allow for a few compiler-allocated temporary stack slots. */
432 # define YYSTACK_ALLOC_MAXIMUM 4032 /* reasonable circa 2006 */
433 # endif
434 # else
435 # define YYSTACK_ALLOC YYMALLOC
436 # define YYSTACK_FREE YYFREE
437 # ifndef YYSTACK_ALLOC_MAXIMUM
438 # define YYSTACK_ALLOC_MAXIMUM YYSIZE_MAXIMUM
439 # endif
440 # ifdef __cplusplus
441 extern "C" {
442 # endif
443 # ifndef YYMALLOC
444 # define YYMALLOC malloc
445 # if ! defined malloc && ! defined _STDLIB_H && (defined __STDC__ || defined __C99__FUNC__ \
446 || defined __cplusplus || defined _MSC_VER)
447 void *malloc (YYSIZE_T); /* INFRINGES ON USER NAME SPACE */
448 # endif
449 # endif
450 # ifndef YYFREE
451 # define YYFREE free
452 # if ! defined free && ! defined _STDLIB_H && (defined __STDC__ || defined __C99__FUNC__ \
453 || defined __cplusplus || defined _MSC_VER)
454 void free (void *); /* INFRINGES ON USER NAME SPACE */
455 # endif
456 # endif
457 # ifdef __cplusplus
459 # endif
460 # endif
461 #endif /* ! defined yyoverflow || YYERROR_VERBOSE */
464 #if (! defined yyoverflow \
465 && (! defined __cplusplus \
466 || (defined YYLTYPE_IS_TRIVIAL && YYLTYPE_IS_TRIVIAL \
467 && defined YYSTYPE_IS_TRIVIAL && YYSTYPE_IS_TRIVIAL)))
469 /* A type that is properly aligned for any stack member. */
470 union yyalloc
472 yytype_int16 yyss;
473 YYSTYPE yyvs;
474 YYLTYPE yyls;
477 /* The size of the maximum gap between one aligned stack and the next. */
478 # define YYSTACK_GAP_MAXIMUM (sizeof (union yyalloc) - 1)
480 /* The size of an array large to enough to hold all stacks, each with
481 N elements. */
482 # define YYSTACK_BYTES(N) \
483 ((N) * (sizeof (yytype_int16) + sizeof (YYSTYPE) + sizeof (YYLTYPE)) \
484 + 2 * YYSTACK_GAP_MAXIMUM)
486 /* Copy COUNT objects from FROM to TO. The source and destination do
487 not overlap. */
488 # ifndef YYCOPY
489 # if defined __GNUC__ && 1 < __GNUC__
490 # define YYCOPY(To, From, Count) \
491 __builtin_memcpy (To, From, (Count) * sizeof (*(From)))
492 # else
493 # define YYCOPY(To, From, Count) \
494 do \
496 YYSIZE_T yyi; \
497 for (yyi = 0; yyi < (Count); yyi++) \
498 (To)[yyi] = (From)[yyi]; \
500 while (YYID (0))
501 # endif
502 # endif
504 /* Relocate STACK from its old location to the new one. The
505 local variables YYSIZE and YYSTACKSIZE give the old and new number of
506 elements in the stack, and YYPTR gives the new location of the
507 stack. Advance YYPTR to a properly aligned location for the next
508 stack. */
509 # define YYSTACK_RELOCATE(Stack) \
510 do \
512 YYSIZE_T yynewbytes; \
513 YYCOPY (&yyptr->Stack, Stack, yysize); \
514 Stack = &yyptr->Stack; \
515 yynewbytes = yystacksize * sizeof (*Stack) + YYSTACK_GAP_MAXIMUM; \
516 yyptr += yynewbytes / sizeof (*yyptr); \
518 while (YYID (0))
520 #endif
522 /* YYFINAL -- State number of the termination state. */
523 #define YYFINAL 10
524 /* YYLAST -- Last index in YYTABLE. */
525 #define YYLAST 140
527 /* YYNTOKENS -- Number of terminals. */
528 #define YYNTOKENS 24
529 /* YYNNTS -- Number of nonterminals. */
530 #define YYNNTS 3
531 /* YYNRULES -- Number of rules. */
532 #define YYNRULES 23
533 /* YYNRULES -- Number of states. */
534 #define YYNSTATES 46
536 /* YYTRANSLATE(YYLEX) -- Bison symbol number corresponding to YYLEX. */
537 #define YYUNDEFTOK 2
538 #define YYMAXUTOK 278
540 #define YYTRANSLATE(YYX) \
541 ((unsigned int) (YYX) <= YYMAXUTOK ? yytranslate[YYX] : YYUNDEFTOK)
543 /* YYTRANSLATE[YYLEX] -- Bison symbol number corresponding to YYLEX. */
544 static const yytype_uint8 yytranslate[] =
546 0, 2, 2, 2, 2, 2, 2, 2, 2, 2,
547 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
548 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
549 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
550 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
551 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
552 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
553 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
554 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
555 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
556 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
557 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
558 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
559 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
560 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
561 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
562 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
563 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
564 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
565 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
566 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
567 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
568 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
569 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
570 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
571 2, 2, 2, 2, 2, 2, 1, 2, 3, 4,
572 5, 6, 7, 8, 9, 10, 11, 12, 13, 14,
573 15, 16, 17, 18, 19, 20, 21, 22, 23
576 #if YYDEBUG
577 /* YYPRHS[YYN] -- Index of the first RHS symbol of rule number YYN in
578 YYRHS. */
579 static const yytype_uint8 yyprhs[] =
581 0, 0, 3, 5, 6, 8, 12, 16, 20, 24,
582 28, 32, 36, 40, 44, 48, 52, 55, 58, 62,
583 66, 70, 74, 78
586 /* YYRHS -- A `-1'-separated list of the rules' RHS. */
587 static const yytype_int8 yyrhs[] =
589 25, 0, -1, 26, -1, -1, 23, -1, 21, 26,
590 22, -1, 26, 5, 26, -1, 26, 6, 26, -1,
591 26, 12, 26, -1, 26, 11, 26, -1, 26, 10,
592 26, -1, 26, 9, 26, -1, 26, 8, 26, -1,
593 26, 7, 26, -1, 26, 14, 26, -1, 26, 13,
594 26, -1, 13, 26, -1, 18, 26, -1, 26, 17,
595 26, -1, 26, 16, 26, -1, 26, 15, 26, -1,
596 26, 20, 26, -1, 26, 19, 26, -1, 26, 4,
597 26, 3, 26, -1
600 /* YYRLINE[YYN] -- source line where rule number YYN was defined. */
601 static const yytype_uint16 yyrline[] =
603 0, 175, 175, 183, 190, 191, 195, 199, 203, 207,
604 211, 215, 219, 223, 227, 231, 235, 239, 243, 247,
605 251, 255, 259, 263
607 #endif
609 #if YYDEBUG || YYERROR_VERBOSE || YYTOKEN_TABLE
610 /* YYTNAME[SYMBOL-NUM] -- String name of the symbol SYMBOL-NUM.
611 First, the terminals, then, starting at YYNTOKENS, nonterminals. */
612 static const char *const yytname[] =
614 "$end", "error", "$undefined", "TOK_COLONCOLON", "TOK_COND", "TOK_OR",
615 "TOK_AND", "TOK_NE", "TOK_LE", "TOK_GE", "TOK_LT", "TOK_GT", "TOK_EQ",
616 "TOK_MINUS", "TOK_PLUS", "TOK_MOD", "TOK_DIV", "TOK_MULT", "TOK_COMPL",
617 "TOK_EQTILDE", "TOK_COLON", "TOK_LP", "TOK_RP", "TOKEN", "$accept",
618 "start", "expr", 0
620 #endif
622 # ifdef YYPRINT
623 /* YYTOKNUM[YYLEX-NUM] -- Internal token number corresponding to
624 token YYLEX-NUM. */
625 static const yytype_uint16 yytoknum[] =
627 0, 256, 257, 258, 259, 260, 261, 262, 263, 264,
628 265, 266, 267, 268, 269, 270, 271, 272, 273, 274,
629 275, 276, 277, 278
631 # endif
633 /* YYR1[YYN] -- Symbol number of symbol that rule YYN derives. */
634 static const yytype_uint8 yyr1[] =
636 0, 24, 25, 25, 26, 26, 26, 26, 26, 26,
637 26, 26, 26, 26, 26, 26, 26, 26, 26, 26,
638 26, 26, 26, 26
641 /* YYR2[YYN] -- Number of symbols composing right hand side of rule YYN. */
642 static const yytype_uint8 yyr2[] =
644 0, 2, 1, 0, 1, 3, 3, 3, 3, 3,
645 3, 3, 3, 3, 3, 3, 2, 2, 3, 3,
646 3, 3, 3, 5
649 /* YYDEFACT[STATE-NAME] -- Default rule to reduce with in state
650 STATE-NUM when YYTABLE doesn't specify something else to do. Zero
651 means the default is an error. */
652 static const yytype_uint8 yydefact[] =
654 3, 0, 0, 0, 4, 0, 2, 16, 17, 0,
655 1, 0, 0, 0, 0, 0, 0, 0, 0, 0,
656 0, 0, 0, 0, 0, 0, 0, 5, 0, 6,
657 7, 13, 12, 11, 10, 9, 8, 15, 14, 20,
658 19, 18, 22, 21, 0, 23
661 /* YYDEFGOTO[NTERM-NUM]. */
662 static const yytype_int8 yydefgoto[] =
664 -1, 5, 6
667 /* YYPACT[STATE-NUM] -- Index in YYTABLE of the portion describing
668 STATE-NUM. */
669 #define YYPACT_NINF -13
670 static const yytype_int8 yypact[] =
672 109, 109, 109, 109, -13, 6, 59, 106, 106, 22,
673 -13, 109, 109, 109, 109, 109, 109, 109, 109, 109,
674 109, 109, 109, 109, 109, 109, 109, -13, 42, 90,
675 104, 120, 120, 120, 120, 120, 120, -12, -12, 106,
676 106, 106, -13, -13, 109, 75
679 /* YYPGOTO[NTERM-NUM]. */
680 static const yytype_int8 yypgoto[] =
682 -13, -13, -1
685 /* YYTABLE[YYPACT[STATE-NUM]]. What to do in state STATE-NUM. If
686 positive, shift that token. If negative, reduce the rule which
687 number is the opposite. If zero, do what YYDEFACT says.
688 If YYTABLE_NINF, syntax error. */
689 #define YYTABLE_NINF -1
690 static const yytype_uint8 yytable[] =
692 7, 8, 9, 22, 23, 24, 10, 25, 26, 0,
693 28, 29, 30, 31, 32, 33, 34, 35, 36, 37,
694 38, 39, 40, 41, 42, 43, 11, 12, 13, 14,
695 15, 16, 17, 18, 19, 20, 21, 22, 23, 24,
696 0, 25, 26, 45, 27, 44, 11, 12, 13, 14,
697 15, 16, 17, 18, 19, 20, 21, 22, 23, 24,
698 0, 25, 26, 11, 12, 13, 14, 15, 16, 17,
699 18, 19, 20, 21, 22, 23, 24, 0, 25, 26,
700 12, 13, 14, 15, 16, 17, 18, 19, 20, 21,
701 22, 23, 24, 0, 25, 26, 13, 14, 15, 16,
702 17, 18, 19, 20, 21, 22, 23, 24, 0, 25,
703 26, 14, 15, 16, 17, 18, 19, 20, 21, 22,
704 23, 24, 1, 25, 26, 25, 26, 2, 0, 0,
705 3, 0, 4, 20, 21, 22, 23, 24, 0, 25,
709 static const yytype_int8 yycheck[] =
711 1, 2, 3, 15, 16, 17, 0, 19, 20, -1,
712 11, 12, 13, 14, 15, 16, 17, 18, 19, 20,
713 21, 22, 23, 24, 25, 26, 4, 5, 6, 7,
714 8, 9, 10, 11, 12, 13, 14, 15, 16, 17,
715 -1, 19, 20, 44, 22, 3, 4, 5, 6, 7,
716 8, 9, 10, 11, 12, 13, 14, 15, 16, 17,
717 -1, 19, 20, 4, 5, 6, 7, 8, 9, 10,
718 11, 12, 13, 14, 15, 16, 17, -1, 19, 20,
719 5, 6, 7, 8, 9, 10, 11, 12, 13, 14,
720 15, 16, 17, -1, 19, 20, 6, 7, 8, 9,
721 10, 11, 12, 13, 14, 15, 16, 17, -1, 19,
722 20, 7, 8, 9, 10, 11, 12, 13, 14, 15,
723 16, 17, 13, 19, 20, 19, 20, 18, -1, -1,
724 21, -1, 23, 13, 14, 15, 16, 17, -1, 19,
728 /* YYSTOS[STATE-NUM] -- The (internal number of the) accessing
729 symbol of state STATE-NUM. */
730 static const yytype_uint8 yystos[] =
732 0, 13, 18, 21, 23, 25, 26, 26, 26, 26,
733 0, 4, 5, 6, 7, 8, 9, 10, 11, 12,
734 13, 14, 15, 16, 17, 19, 20, 22, 26, 26,
735 26, 26, 26, 26, 26, 26, 26, 26, 26, 26,
736 26, 26, 26, 26, 3, 26
739 #define yyerrok (yyerrstatus = 0)
740 #define yyclearin (yychar = YYEMPTY)
741 #define YYEMPTY (-2)
742 #define YYEOF 0
744 #define YYACCEPT goto yyacceptlab
745 #define YYABORT goto yyabortlab
746 #define YYERROR goto yyerrorlab
749 /* Like YYERROR except do call yyerror. This remains here temporarily
750 to ease the transition to the new meaning of YYERROR, for GCC.
751 Once GCC version 2 has supplanted version 1, this can go. */
753 #define YYFAIL goto yyerrlab
755 #define YYRECOVERING() (!!yyerrstatus)
757 #define YYBACKUP(Token, Value) \
758 do \
759 if (yychar == YYEMPTY && yylen == 1) \
761 yychar = (Token); \
762 yylval = (Value); \
763 yytoken = YYTRANSLATE (yychar); \
764 YYPOPSTACK (1); \
765 goto yybackup; \
767 else \
769 yyerror (YY_("syntax error: cannot back up")); \
770 YYERROR; \
772 while (YYID (0))
775 #define YYTERROR 1
776 #define YYERRCODE 256
779 /* YYLLOC_DEFAULT -- Set CURRENT to span from RHS[1] to RHS[N].
780 If N is 0, then set CURRENT to the empty location which ends
781 the previous symbol: RHS[0] (always defined). */
783 #define YYRHSLOC(Rhs, K) ((Rhs)[K])
784 #ifndef YYLLOC_DEFAULT
785 # define YYLLOC_DEFAULT(Current, Rhs, N) \
786 do \
787 if (YYID (N)) \
789 (Current).first_line = YYRHSLOC (Rhs, 1).first_line; \
790 (Current).first_column = YYRHSLOC (Rhs, 1).first_column; \
791 (Current).last_line = YYRHSLOC (Rhs, N).last_line; \
792 (Current).last_column = YYRHSLOC (Rhs, N).last_column; \
794 else \
796 (Current).first_line = (Current).last_line = \
797 YYRHSLOC (Rhs, 0).last_line; \
798 (Current).first_column = (Current).last_column = \
799 YYRHSLOC (Rhs, 0).last_column; \
801 while (YYID (0))
802 #endif
805 /* YY_LOCATION_PRINT -- Print the location on the stream.
806 This macro was not mandated originally: define only if we know
807 we won't break user code: when these are the locations we know. */
809 #ifndef YY_LOCATION_PRINT
810 # if YYLTYPE_IS_TRIVIAL
811 # define YY_LOCATION_PRINT(File, Loc) \
812 fprintf (File, "%d.%d-%d.%d", \
813 (Loc).first_line, (Loc).first_column, \
814 (Loc).last_line, (Loc).last_column)
815 # else
816 # define YY_LOCATION_PRINT(File, Loc) ((void) 0)
817 # endif
818 #endif
821 /* YYLEX -- calling `yylex' with the right arguments. */
823 #ifdef YYLEX_PARAM
824 # define YYLEX yylex (&yylval, &yylloc, YYLEX_PARAM)
825 #else
826 # define YYLEX yylex (&yylval, &yylloc)
827 #endif
829 /* Enable debugging if requested. */
830 #if YYDEBUG
832 # ifndef YYFPRINTF
833 # include <stdio.h> /* INFRINGES ON USER NAME SPACE */
834 # define YYFPRINTF fprintf
835 # endif
837 # define YYDPRINTF(Args) \
838 do { \
839 if (yydebug) \
840 YYFPRINTF Args; \
841 } while (YYID (0))
843 # define YY_SYMBOL_PRINT(Title, Type, Value, Location) \
844 do { \
845 if (yydebug) \
847 YYFPRINTF (stderr, "%s ", Title); \
848 yy_symbol_print (stderr, \
849 Type, Value, Location); \
850 YYFPRINTF (stderr, "\n"); \
852 } while (YYID (0))
855 /*--------------------------------.
856 | Print this symbol on YYOUTPUT. |
857 `--------------------------------*/
859 /*ARGSUSED*/
860 #if (defined __STDC__ || defined __C99__FUNC__ \
861 || defined __cplusplus || defined _MSC_VER)
862 static void
863 yy_symbol_value_print (FILE *yyoutput, int yytype, const YYSTYPE * const yyvaluep, const YYLTYPE * const yylocationp)
864 #else
865 static void
866 yy_symbol_value_print (yyoutput, yytype, yyvaluep, yylocationp)
867 FILE *yyoutput;
868 int yytype;
869 const YYSTYPE * const yyvaluep;
870 const YYLTYPE * const yylocationp;
871 #endif
873 if (!yyvaluep)
874 return;
875 YYUSE (yylocationp);
876 # ifdef YYPRINT
877 if (yytype < YYNTOKENS)
878 YYPRINT (yyoutput, yytoknum[yytype], *yyvaluep);
879 # else
880 YYUSE (yyoutput);
881 # endif
882 switch (yytype)
884 default:
885 break;
890 /*--------------------------------.
891 | Print this symbol on YYOUTPUT. |
892 `--------------------------------*/
894 #if (defined __STDC__ || defined __C99__FUNC__ \
895 || defined __cplusplus || defined _MSC_VER)
896 static void
897 yy_symbol_print (FILE *yyoutput, int yytype, const YYSTYPE * const yyvaluep, const YYLTYPE * const yylocationp)
898 #else
899 static void
900 yy_symbol_print (yyoutput, yytype, yyvaluep, yylocationp)
901 FILE *yyoutput;
902 int yytype;
903 const YYSTYPE * const yyvaluep;
904 const YYLTYPE * const yylocationp;
905 #endif
907 if (yytype < YYNTOKENS)
908 YYFPRINTF (yyoutput, "token %s (", yytname[yytype]);
909 else
910 YYFPRINTF (yyoutput, "nterm %s (", yytname[yytype]);
912 YY_LOCATION_PRINT (yyoutput, *yylocationp);
913 YYFPRINTF (yyoutput, ": ");
914 yy_symbol_value_print (yyoutput, yytype, yyvaluep, yylocationp);
915 YYFPRINTF (yyoutput, ")");
918 /*------------------------------------------------------------------.
919 | yy_stack_print -- Print the state stack from its BOTTOM up to its |
920 | TOP (included). |
921 `------------------------------------------------------------------*/
923 #if (defined __STDC__ || defined __C99__FUNC__ \
924 || defined __cplusplus || defined _MSC_VER)
925 static void
926 yy_stack_print (yytype_int16 *bottom, yytype_int16 *top)
927 #else
928 static void
929 yy_stack_print (bottom, top)
930 yytype_int16 *bottom;
931 yytype_int16 *top;
932 #endif
934 YYFPRINTF (stderr, "Stack now");
935 for (; bottom <= top; ++bottom)
936 YYFPRINTF (stderr, " %d", *bottom);
937 YYFPRINTF (stderr, "\n");
940 # define YY_STACK_PRINT(Bottom, Top) \
941 do { \
942 if (yydebug) \
943 yy_stack_print ((Bottom), (Top)); \
944 } while (YYID (0))
947 /*------------------------------------------------.
948 | Report that the YYRULE is going to be reduced. |
949 `------------------------------------------------*/
951 #if (defined __STDC__ || defined __C99__FUNC__ \
952 || defined __cplusplus || defined _MSC_VER)
953 static void
954 yy_reduce_print (YYSTYPE *yyvsp, YYLTYPE *yylsp, int yyrule)
955 #else
956 static void
957 yy_reduce_print (yyvsp, yylsp, yyrule
959 YYSTYPE *yyvsp;
960 YYLTYPE *yylsp;
961 int yyrule;
962 #endif
964 int yynrhs = yyr2[yyrule];
965 int yyi;
966 unsigned long int yylno = yyrline[yyrule];
967 YYFPRINTF (stderr, "Reducing stack by rule %d (line %lu):\n",
968 yyrule - 1, yylno);
969 /* The symbols being reduced. */
970 for (yyi = 0; yyi < yynrhs; yyi++)
972 fprintf (stderr, " $%d = ", yyi + 1);
973 yy_symbol_print (stderr, yyrhs[yyprhs[yyrule] + yyi],
974 &(yyvsp[(yyi + 1) - (yynrhs)])
975 , &(yylsp[(yyi + 1) - (yynrhs)]) );
976 fprintf (stderr, "\n");
980 # define YY_REDUCE_PRINT(Rule) \
981 do { \
982 if (yydebug) \
983 yy_reduce_print (yyvsp, yylsp, Rule); \
984 } while (YYID (0))
986 /* Nonzero means print parse trace. It is left uninitialized so that
987 multiple parsers can coexist. */
988 int yydebug;
989 #else /* !YYDEBUG */
990 # define YYDPRINTF(Args)
991 # define YY_SYMBOL_PRINT(Title, Type, Value, Location)
992 # define YY_STACK_PRINT(Bottom, Top)
993 # define YY_REDUCE_PRINT(Rule)
994 #endif /* !YYDEBUG */
997 /* YYINITDEPTH -- initial size of the parser's stacks. */
998 #ifndef YYINITDEPTH
999 # define YYINITDEPTH 200
1000 #endif
1002 /* YYMAXDEPTH -- maximum size the stacks can grow to (effective only
1003 if the built-in stack extension method is used).
1005 Do not make this value too large; the results are undefined if
1006 YYSTACK_ALLOC_MAXIMUM < YYSTACK_BYTES (YYMAXDEPTH)
1007 evaluated with infinite-precision integer arithmetic. */
1009 #ifndef YYMAXDEPTH
1010 # define YYMAXDEPTH 10000
1011 #endif
1015 #if YYERROR_VERBOSE
1017 # ifndef yystrlen
1018 # if defined __GLIBC__ && defined _STRING_H
1019 # define yystrlen strlen
1020 # else
1021 /* Return the length of YYSTR. */
1022 #if (defined __STDC__ || defined __C99__FUNC__ \
1023 || defined __cplusplus || defined _MSC_VER)
1024 static YYSIZE_T
1025 yystrlen (const char *yystr)
1026 #else
1027 static YYSIZE_T
1028 yystrlen (yystr)
1029 const char *yystr;
1030 #endif
1032 YYSIZE_T yylen;
1033 for (yylen = 0; yystr[yylen]; yylen++)
1034 continue;
1035 return yylen;
1037 # endif
1038 # endif
1040 # ifndef yystpcpy
1041 # if defined __GLIBC__ && defined _STRING_H && defined _GNU_SOURCE
1042 # define yystpcpy stpcpy
1043 # else
1044 /* Copy YYSRC to YYDEST, returning the address of the terminating '\0' in
1045 YYDEST. */
1046 #if (defined __STDC__ || defined __C99__FUNC__ \
1047 || defined __cplusplus || defined _MSC_VER)
1048 static char *
1049 yystpcpy (char *yydest, const char *yysrc)
1050 #else
1051 static char *
1052 yystpcpy (yydest, yysrc)
1053 char *yydest;
1054 const char *yysrc;
1055 #endif
1057 char *yyd = yydest;
1058 const char *yys = yysrc;
1060 while ((*yyd++ = *yys++) != '\0')
1061 continue;
1063 return yyd - 1;
1065 # endif
1066 # endif
1068 # ifndef yytnamerr
1069 /* Copy to YYRES the contents of YYSTR after stripping away unnecessary
1070 quotes and backslashes, so that it's suitable for yyerror. The
1071 heuristic is that double-quoting is unnecessary unless the string
1072 contains an apostrophe, a comma, or backslash (other than
1073 backslash-backslash). YYSTR is taken from yytname. If YYRES is
1074 null, do not copy; instead, return the length of what the result
1075 would have been. */
1076 static YYSIZE_T
1077 yytnamerr (char *yyres, const char *yystr)
1079 if (*yystr == '"')
1081 size_t yyn = 0;
1082 char const *yyp = yystr;
1084 for (;;)
1085 switch (*++yyp)
1087 case '\'':
1088 case ',':
1089 goto do_not_strip_quotes;
1091 case '\\':
1092 if (*++yyp != '\\')
1093 goto do_not_strip_quotes;
1094 /* Fall through. */
1095 default:
1096 if (yyres)
1097 yyres[yyn] = *yyp;
1098 yyn++;
1099 break;
1101 case '"':
1102 if (yyres)
1103 yyres[yyn] = '\0';
1104 return yyn;
1106 do_not_strip_quotes: ;
1109 if (! yyres)
1110 return yystrlen (yystr);
1112 return yystpcpy (yyres, yystr) - yyres;
1114 # endif
1116 /* Copy into YYRESULT an error message about the unexpected token
1117 YYCHAR while in state YYSTATE. Return the number of bytes copied,
1118 including the terminating null byte. If YYRESULT is null, do not
1119 copy anything; just return the number of bytes that would be
1120 copied. As a special case, return 0 if an ordinary "syntax error"
1121 message will do. Return YYSIZE_MAXIMUM if overflow occurs during
1122 size calculation. */
1123 static YYSIZE_T
1124 yysyntax_error (char *yyresult, int yystate, int yychar)
1126 int yyn = yypact[yystate];
1128 if (! (YYPACT_NINF < yyn && yyn < YYLAST))
1129 return 0;
1130 else
1132 int yytype = YYTRANSLATE (yychar);
1133 YYSIZE_T yysize0 = yytnamerr (0, yytname[yytype]);
1134 YYSIZE_T yysize = yysize0;
1135 YYSIZE_T yysize1;
1136 int yysize_overflow = 0;
1137 enum { YYERROR_VERBOSE_ARGS_MAXIMUM = 5 };
1138 char const *yyarg[YYERROR_VERBOSE_ARGS_MAXIMUM];
1139 int yyx;
1141 # if 0
1142 /* This is so xgettext sees the translatable formats that are
1143 constructed on the fly. */
1144 YY_("syntax error, unexpected %s");
1145 YY_("syntax error, unexpected %s, expecting %s");
1146 YY_("syntax error, unexpected %s, expecting %s or %s");
1147 YY_("syntax error, unexpected %s, expecting %s or %s or %s");
1148 YY_("syntax error, unexpected %s, expecting %s or %s or %s or %s");
1149 # endif
1150 char *yyfmt;
1151 char const *yyf;
1152 static char const yyunexpected[] = "syntax error, unexpected %s";
1153 static char const yyexpecting[] = ", expecting %s";
1154 static char const yyor[] = " or %s";
1155 char yyformat[sizeof yyunexpected
1156 + sizeof yyexpecting - 1
1157 + ((YYERROR_VERBOSE_ARGS_MAXIMUM - 2)
1158 * (sizeof yyor - 1))];
1159 char const *yyprefix = yyexpecting;
1161 /* Start YYX at -YYN if negative to avoid negative indexes in
1162 YYCHECK. */
1163 int yyxbegin = yyn < 0 ? -yyn : 0;
1165 /* Stay within bounds of both yycheck and yytname. */
1166 int yychecklim = YYLAST - yyn;
1167 int yyxend = yychecklim < YYNTOKENS ? yychecklim : YYNTOKENS;
1168 int yycount = 1;
1170 yyarg[0] = yytname[yytype];
1171 yyfmt = yystpcpy (yyformat, yyunexpected);
1173 for (yyx = yyxbegin; yyx < yyxend; ++yyx)
1174 if (yycheck[yyx + yyn] == yyx && yyx != YYTERROR)
1176 if (yycount == YYERROR_VERBOSE_ARGS_MAXIMUM)
1178 yycount = 1;
1179 yysize = yysize0;
1180 yyformat[sizeof yyunexpected - 1] = '\0';
1181 break;
1183 yyarg[yycount++] = yytname[yyx];
1184 yysize1 = yysize + yytnamerr (0, yytname[yyx]);
1185 yysize_overflow |= (yysize1 < yysize);
1186 yysize = yysize1;
1187 yyfmt = yystpcpy (yyfmt, yyprefix);
1188 yyprefix = yyor;
1191 yyf = YY_(yyformat);
1192 yysize1 = yysize + yystrlen (yyf);
1193 yysize_overflow |= (yysize1 < yysize);
1194 yysize = yysize1;
1196 if (yysize_overflow)
1197 return YYSIZE_MAXIMUM;
1199 if (yyresult)
1201 /* Avoid sprintf, as that infringes on the user's name space.
1202 Don't have undefined behavior even if the translation
1203 produced a string with the wrong number of "%s"s. */
1204 char *yyp = yyresult;
1205 int yyi = 0;
1206 while ((*yyp = *yyf) != '\0')
1208 if (*yyp == '%' && yyf[1] == 's' && yyi < yycount)
1210 yyp += yytnamerr (yyp, yyarg[yyi++]);
1211 yyf += 2;
1213 else
1215 yyp++;
1216 yyf++;
1220 return yysize;
1223 #endif /* YYERROR_VERBOSE */
1226 /*-----------------------------------------------.
1227 | Release the memory associated to this symbol. |
1228 `-----------------------------------------------*/
1230 /*ARGSUSED*/
1231 #if (defined __STDC__ || defined __C99__FUNC__ \
1232 || defined __cplusplus || defined _MSC_VER)
1233 static void
1234 yydestruct (const char *yymsg, int yytype, YYSTYPE *yyvaluep, YYLTYPE *yylocationp)
1235 #else
1236 static void
1237 yydestruct (yymsg, yytype, yyvaluep, yylocationp)
1238 const char *yymsg;
1239 int yytype;
1240 YYSTYPE *yyvaluep;
1241 YYLTYPE *yylocationp;
1242 #endif
1244 YYUSE (yyvaluep);
1245 YYUSE (yylocationp);
1247 if (!yymsg)
1248 yymsg = "Deleting";
1249 YY_SYMBOL_PRINT (yymsg, yytype, yyvaluep, yylocationp);
1251 switch (yytype)
1253 case 3: /* "TOK_COLONCOLON" */
1254 #line 169 "ast_expr2.y"
1255 { free_value((yyvaluep->val)); };
1256 #line 1257 "ast_expr2.c"
1257 break;
1258 case 4: /* "TOK_COND" */
1259 #line 169 "ast_expr2.y"
1260 { free_value((yyvaluep->val)); };
1261 #line 1262 "ast_expr2.c"
1262 break;
1263 case 5: /* "TOK_OR" */
1264 #line 169 "ast_expr2.y"
1265 { free_value((yyvaluep->val)); };
1266 #line 1267 "ast_expr2.c"
1267 break;
1268 case 6: /* "TOK_AND" */
1269 #line 169 "ast_expr2.y"
1270 { free_value((yyvaluep->val)); };
1271 #line 1272 "ast_expr2.c"
1272 break;
1273 case 7: /* "TOK_NE" */
1274 #line 169 "ast_expr2.y"
1275 { free_value((yyvaluep->val)); };
1276 #line 1277 "ast_expr2.c"
1277 break;
1278 case 8: /* "TOK_LE" */
1279 #line 169 "ast_expr2.y"
1280 { free_value((yyvaluep->val)); };
1281 #line 1282 "ast_expr2.c"
1282 break;
1283 case 9: /* "TOK_GE" */
1284 #line 169 "ast_expr2.y"
1285 { free_value((yyvaluep->val)); };
1286 #line 1287 "ast_expr2.c"
1287 break;
1288 case 10: /* "TOK_LT" */
1289 #line 169 "ast_expr2.y"
1290 { free_value((yyvaluep->val)); };
1291 #line 1292 "ast_expr2.c"
1292 break;
1293 case 11: /* "TOK_GT" */
1294 #line 169 "ast_expr2.y"
1295 { free_value((yyvaluep->val)); };
1296 #line 1297 "ast_expr2.c"
1297 break;
1298 case 12: /* "TOK_EQ" */
1299 #line 169 "ast_expr2.y"
1300 { free_value((yyvaluep->val)); };
1301 #line 1302 "ast_expr2.c"
1302 break;
1303 case 13: /* "TOK_MINUS" */
1304 #line 169 "ast_expr2.y"
1305 { free_value((yyvaluep->val)); };
1306 #line 1307 "ast_expr2.c"
1307 break;
1308 case 14: /* "TOK_PLUS" */
1309 #line 169 "ast_expr2.y"
1310 { free_value((yyvaluep->val)); };
1311 #line 1312 "ast_expr2.c"
1312 break;
1313 case 15: /* "TOK_MOD" */
1314 #line 169 "ast_expr2.y"
1315 { free_value((yyvaluep->val)); };
1316 #line 1317 "ast_expr2.c"
1317 break;
1318 case 16: /* "TOK_DIV" */
1319 #line 169 "ast_expr2.y"
1320 { free_value((yyvaluep->val)); };
1321 #line 1322 "ast_expr2.c"
1322 break;
1323 case 17: /* "TOK_MULT" */
1324 #line 169 "ast_expr2.y"
1325 { free_value((yyvaluep->val)); };
1326 #line 1327 "ast_expr2.c"
1327 break;
1328 case 18: /* "TOK_COMPL" */
1329 #line 169 "ast_expr2.y"
1330 { free_value((yyvaluep->val)); };
1331 #line 1332 "ast_expr2.c"
1332 break;
1333 case 19: /* "TOK_EQTILDE" */
1334 #line 169 "ast_expr2.y"
1335 { free_value((yyvaluep->val)); };
1336 #line 1337 "ast_expr2.c"
1337 break;
1338 case 20: /* "TOK_COLON" */
1339 #line 169 "ast_expr2.y"
1340 { free_value((yyvaluep->val)); };
1341 #line 1342 "ast_expr2.c"
1342 break;
1343 case 21: /* "TOK_LP" */
1344 #line 169 "ast_expr2.y"
1345 { free_value((yyvaluep->val)); };
1346 #line 1347 "ast_expr2.c"
1347 break;
1348 case 22: /* "TOK_RP" */
1349 #line 169 "ast_expr2.y"
1350 { free_value((yyvaluep->val)); };
1351 #line 1352 "ast_expr2.c"
1352 break;
1353 case 23: /* "TOKEN" */
1354 #line 169 "ast_expr2.y"
1355 { free_value((yyvaluep->val)); };
1356 #line 1357 "ast_expr2.c"
1357 break;
1358 case 26: /* "expr" */
1359 #line 169 "ast_expr2.y"
1360 { free_value((yyvaluep->val)); };
1361 #line 1362 "ast_expr2.c"
1362 break;
1364 default:
1365 break;
1370 /* Prevent warnings from -Wmissing-prototypes. */
1372 #ifdef YYPARSE_PARAM
1373 #if defined __STDC__ || defined __cplusplus
1374 int yyparse (void *YYPARSE_PARAM);
1375 #else
1376 int yyparse ();
1377 #endif
1378 #else /* ! YYPARSE_PARAM */
1379 #if defined __STDC__ || defined __cplusplus
1380 int yyparse (void);
1381 #else
1382 int yyparse ();
1383 #endif
1384 #endif /* ! YYPARSE_PARAM */
1391 /*----------.
1392 | yyparse. |
1393 `----------*/
1395 #ifdef YYPARSE_PARAM
1396 #if (defined __STDC__ || defined __C99__FUNC__ \
1397 || defined __cplusplus || defined _MSC_VER)
1399 yyparse (void *YYPARSE_PARAM)
1400 #else
1402 yyparse (YYPARSE_PARAM)
1403 void *YYPARSE_PARAM;
1404 #endif
1405 #else /* ! YYPARSE_PARAM */
1406 #if (defined __STDC__ || defined __C99__FUNC__ \
1407 || defined __cplusplus || defined _MSC_VER)
1409 yyparse (void)
1410 #else
1412 yyparse ()
1414 #endif
1415 #endif
1417 /* The look-ahead symbol. */
1418 int yychar;
1420 /* The semantic value of the look-ahead symbol. */
1421 YYSTYPE yylval;
1423 /* Number of syntax errors so far. */
1424 int yynerrs;
1425 /* Location data for the look-ahead symbol. */
1426 YYLTYPE yylloc;
1428 int yystate;
1429 int yyn;
1430 int yyresult;
1431 /* Number of tokens to shift before error messages enabled. */
1432 int yyerrstatus;
1433 /* Look-ahead token as an internal (translated) token number. */
1434 int yytoken = 0;
1435 #if YYERROR_VERBOSE
1436 /* Buffer for error messages, and its allocated size. */
1437 char yymsgbuf[128];
1438 char *yymsg = yymsgbuf;
1439 YYSIZE_T yymsg_alloc = sizeof yymsgbuf;
1440 #endif
1442 /* Three stacks and their tools:
1443 `yyss': related to states,
1444 `yyvs': related to semantic values,
1445 `yyls': related to locations.
1447 Refer to the stacks thru separate pointers, to allow yyoverflow
1448 to reallocate them elsewhere. */
1450 /* The state stack. */
1451 yytype_int16 yyssa[YYINITDEPTH];
1452 yytype_int16 *yyss = yyssa;
1453 yytype_int16 *yyssp;
1455 /* The semantic value stack. */
1456 YYSTYPE yyvsa[YYINITDEPTH];
1457 YYSTYPE *yyvs = yyvsa;
1458 YYSTYPE *yyvsp;
1460 /* The location stack. */
1461 YYLTYPE yylsa[YYINITDEPTH];
1462 YYLTYPE *yyls = yylsa;
1463 YYLTYPE *yylsp;
1464 /* The locations where the error started and ended. */
1465 YYLTYPE yyerror_range[2];
1467 #define YYPOPSTACK(N) (yyvsp -= (N), yyssp -= (N), yylsp -= (N))
1469 YYSIZE_T yystacksize = YYINITDEPTH;
1471 /* The variables used to return semantic value and location from the
1472 action routines. */
1473 YYSTYPE yyval;
1474 YYLTYPE yyloc;
1476 /* The number of symbols on the RHS of the reduced rule.
1477 Keep to zero when no symbol should be popped. */
1478 int yylen = 0;
1480 YYDPRINTF ((stderr, "Starting parse\n"));
1482 yystate = 0;
1483 yyerrstatus = 0;
1484 yynerrs = 0;
1485 yychar = YYEMPTY; /* Cause a token to be read. */
1487 /* Initialize stack pointers.
1488 Waste one element of value and location stack
1489 so that they stay on the same level as the state stack.
1490 The wasted elements are never initialized. */
1492 yyssp = yyss;
1493 yyvsp = yyvs;
1494 yylsp = yyls;
1495 #if YYLTYPE_IS_TRIVIAL
1496 /* Initialize the default location before parsing starts. */
1497 yylloc.first_line = yylloc.last_line = 1;
1498 yylloc.first_column = yylloc.last_column = 0;
1499 #endif
1501 goto yysetstate;
1503 /*------------------------------------------------------------.
1504 | yynewstate -- Push a new state, which is found in yystate. |
1505 `------------------------------------------------------------*/
1506 yynewstate:
1507 /* In all cases, when you get here, the value and location stacks
1508 have just been pushed. So pushing a state here evens the stacks. */
1509 yyssp++;
1511 yysetstate:
1512 *yyssp = yystate;
1514 if (yyss + yystacksize - 1 <= yyssp)
1516 /* Get the current used size of the three stacks, in elements. */
1517 YYSIZE_T yysize = yyssp - yyss + 1;
1519 #ifdef yyoverflow
1521 /* Give user a chance to reallocate the stack. Use copies of
1522 these so that the &'s don't force the real ones into
1523 memory. */
1524 YYSTYPE *yyvs1 = yyvs;
1525 yytype_int16 *yyss1 = yyss;
1526 YYLTYPE *yyls1 = yyls;
1528 /* Each stack pointer address is followed by the size of the
1529 data in use in that stack, in bytes. This used to be a
1530 conditional around just the two extra args, but that might
1531 be undefined if yyoverflow is a macro. */
1532 yyoverflow (YY_("memory exhausted"),
1533 &yyss1, yysize * sizeof (*yyssp),
1534 &yyvs1, yysize * sizeof (*yyvsp),
1535 &yyls1, yysize * sizeof (*yylsp),
1536 &yystacksize);
1537 yyls = yyls1;
1538 yyss = yyss1;
1539 yyvs = yyvs1;
1541 #else /* no yyoverflow */
1542 # ifndef YYSTACK_RELOCATE
1543 goto yyexhaustedlab;
1544 # else
1545 /* Extend the stack our own way. */
1546 if (YYMAXDEPTH <= yystacksize)
1547 goto yyexhaustedlab;
1548 yystacksize *= 2;
1549 if (YYMAXDEPTH < yystacksize)
1550 yystacksize = YYMAXDEPTH;
1553 yytype_int16 *yyss1 = yyss;
1554 union yyalloc *yyptr =
1555 (union yyalloc *) YYSTACK_ALLOC (YYSTACK_BYTES (yystacksize));
1556 if (! yyptr)
1557 goto yyexhaustedlab;
1558 YYSTACK_RELOCATE (yyss);
1559 YYSTACK_RELOCATE (yyvs);
1560 YYSTACK_RELOCATE (yyls);
1561 # undef YYSTACK_RELOCATE
1562 if (yyss1 != yyssa)
1563 YYSTACK_FREE (yyss1);
1565 # endif
1566 #endif /* no yyoverflow */
1568 yyssp = yyss + yysize - 1;
1569 yyvsp = yyvs + yysize - 1;
1570 yylsp = yyls + yysize - 1;
1572 YYDPRINTF ((stderr, "Stack size increased to %lu\n",
1573 (unsigned long int) yystacksize));
1575 if (yyss + yystacksize - 1 <= yyssp)
1576 YYABORT;
1579 YYDPRINTF ((stderr, "Entering state %d\n", yystate));
1581 goto yybackup;
1583 /*-----------.
1584 | yybackup. |
1585 `-----------*/
1586 yybackup:
1588 /* Do appropriate processing given the current state. Read a
1589 look-ahead token if we need one and don't already have one. */
1591 /* First try to decide what to do without reference to look-ahead token. */
1592 yyn = yypact[yystate];
1593 if (yyn == YYPACT_NINF)
1594 goto yydefault;
1596 /* Not known => get a look-ahead token if don't already have one. */
1598 /* YYCHAR is either YYEMPTY or YYEOF or a valid look-ahead symbol. */
1599 if (yychar == YYEMPTY)
1601 YYDPRINTF ((stderr, "Reading a token: "));
1602 yychar = YYLEX;
1605 if (yychar <= YYEOF)
1607 yychar = yytoken = YYEOF;
1608 YYDPRINTF ((stderr, "Now at end of input.\n"));
1610 else
1612 yytoken = YYTRANSLATE (yychar);
1613 YY_SYMBOL_PRINT ("Next token is", yytoken, &yylval, &yylloc);
1616 /* If the proper action on seeing token YYTOKEN is to reduce or to
1617 detect an error, take that action. */
1618 yyn += yytoken;
1619 if (yyn < 0 || YYLAST < yyn || yycheck[yyn] != yytoken)
1620 goto yydefault;
1621 yyn = yytable[yyn];
1622 if (yyn <= 0)
1624 if (yyn == 0 || yyn == YYTABLE_NINF)
1625 goto yyerrlab;
1626 yyn = -yyn;
1627 goto yyreduce;
1630 if (yyn == YYFINAL)
1631 YYACCEPT;
1633 /* Count tokens shifted since error; after three, turn off error
1634 status. */
1635 if (yyerrstatus)
1636 yyerrstatus--;
1638 /* Shift the look-ahead token. */
1639 YY_SYMBOL_PRINT ("Shifting", yytoken, &yylval, &yylloc);
1641 /* Discard the shifted token unless it is eof. */
1642 if (yychar != YYEOF)
1643 yychar = YYEMPTY;
1645 yystate = yyn;
1646 *++yyvsp = yylval;
1647 *++yylsp = yylloc;
1648 goto yynewstate;
1651 /*-----------------------------------------------------------.
1652 | yydefault -- do the default action for the current state. |
1653 `-----------------------------------------------------------*/
1654 yydefault:
1655 yyn = yydefact[yystate];
1656 if (yyn == 0)
1657 goto yyerrlab;
1658 goto yyreduce;
1661 /*-----------------------------.
1662 | yyreduce -- Do a reduction. |
1663 `-----------------------------*/
1664 yyreduce:
1665 /* yyn is the number of a rule to reduce with. */
1666 yylen = yyr2[yyn];
1668 /* If YYLEN is nonzero, implement the default value of the action:
1669 `$$ = $1'.
1671 Otherwise, the following line sets YYVAL to garbage.
1672 This behavior is undocumented and Bison
1673 users should not rely upon it. Assigning to YYVAL
1674 unconditionally makes the parser a bit smaller, and it avoids a
1675 GCC warning that YYVAL may be used uninitialized. */
1676 yyval = yyvsp[1-yylen];
1678 /* Default location. */
1679 YYLLOC_DEFAULT (yyloc, (yylsp - yylen), yylen);
1680 YY_REDUCE_PRINT (yyn);
1681 switch (yyn)
1683 case 2:
1684 #line 175 "ast_expr2.y"
1685 { ((struct parse_io *)parseio)->val = (struct val *)calloc(sizeof(struct val),1);
1686 ((struct parse_io *)parseio)->val->type = (yyvsp[(1) - (1)].val)->type;
1687 if( (yyvsp[(1) - (1)].val)->type == AST_EXPR_integer )
1688 ((struct parse_io *)parseio)->val->u.i = (yyvsp[(1) - (1)].val)->u.i;
1689 else
1690 ((struct parse_io *)parseio)->val->u.s = (yyvsp[(1) - (1)].val)->u.s;
1691 free((yyvsp[(1) - (1)].val));
1693 break;
1695 case 3:
1696 #line 183 "ast_expr2.y"
1697 {/* nothing */ ((struct parse_io *)parseio)->val = (struct val *)calloc(sizeof(struct val),1);
1698 ((struct parse_io *)parseio)->val->type = AST_EXPR_string;
1699 ((struct parse_io *)parseio)->val->u.s = strdup("");
1701 break;
1703 case 4:
1704 #line 190 "ast_expr2.y"
1705 { (yyval.val)= (yyvsp[(1) - (1)].val);;}
1706 break;
1708 case 5:
1709 #line 191 "ast_expr2.y"
1710 { (yyval.val) = (yyvsp[(2) - (3)].val);
1711 (yyloc).first_column = (yylsp[(1) - (3)]).first_column; (yyloc).last_column = (yylsp[(3) - (3)]).last_column;
1712 (yyloc).first_line=0; (yyloc).last_line=0;
1713 DESTROY((yyvsp[(1) - (3)].val)); DESTROY((yyvsp[(3) - (3)].val)); ;}
1714 break;
1716 case 6:
1717 #line 195 "ast_expr2.y"
1718 { (yyval.val) = op_or ((yyvsp[(1) - (3)].val), (yyvsp[(3) - (3)].val));
1719 DESTROY((yyvsp[(2) - (3)].val));
1720 (yyloc).first_column = (yylsp[(1) - (3)]).first_column; (yyloc).last_column = (yylsp[(3) - (3)]).last_column;
1721 (yyloc).first_line=0; (yyloc).last_line=0;;}
1722 break;
1724 case 7:
1725 #line 199 "ast_expr2.y"
1726 { (yyval.val) = op_and ((yyvsp[(1) - (3)].val), (yyvsp[(3) - (3)].val));
1727 DESTROY((yyvsp[(2) - (3)].val));
1728 (yyloc).first_column = (yylsp[(1) - (3)]).first_column; (yyloc).last_column = (yylsp[(3) - (3)]).last_column;
1729 (yyloc).first_line=0; (yyloc).last_line=0;;}
1730 break;
1732 case 8:
1733 #line 203 "ast_expr2.y"
1734 { (yyval.val) = op_eq ((yyvsp[(1) - (3)].val), (yyvsp[(3) - (3)].val));
1735 DESTROY((yyvsp[(2) - (3)].val));
1736 (yyloc).first_column = (yylsp[(1) - (3)]).first_column; (yyloc).last_column = (yylsp[(3) - (3)]).last_column;
1737 (yyloc).first_line=0; (yyloc).last_line=0;;}
1738 break;
1740 case 9:
1741 #line 207 "ast_expr2.y"
1742 { (yyval.val) = op_gt ((yyvsp[(1) - (3)].val), (yyvsp[(3) - (3)].val));
1743 DESTROY((yyvsp[(2) - (3)].val));
1744 (yyloc).first_column = (yylsp[(1) - (3)]).first_column; (yyloc).last_column = (yylsp[(3) - (3)]).last_column;
1745 (yyloc).first_line=0; (yyloc).last_line=0;;}
1746 break;
1748 case 10:
1749 #line 211 "ast_expr2.y"
1750 { (yyval.val) = op_lt ((yyvsp[(1) - (3)].val), (yyvsp[(3) - (3)].val));
1751 DESTROY((yyvsp[(2) - (3)].val));
1752 (yyloc).first_column = (yylsp[(1) - (3)]).first_column; (yyloc).last_column = (yylsp[(3) - (3)]).last_column;
1753 (yyloc).first_line=0; (yyloc).last_line=0;;}
1754 break;
1756 case 11:
1757 #line 215 "ast_expr2.y"
1758 { (yyval.val) = op_ge ((yyvsp[(1) - (3)].val), (yyvsp[(3) - (3)].val));
1759 DESTROY((yyvsp[(2) - (3)].val));
1760 (yyloc).first_column = (yylsp[(1) - (3)]).first_column; (yyloc).last_column = (yylsp[(3) - (3)]).last_column;
1761 (yyloc).first_line=0; (yyloc).last_line=0;;}
1762 break;
1764 case 12:
1765 #line 219 "ast_expr2.y"
1766 { (yyval.val) = op_le ((yyvsp[(1) - (3)].val), (yyvsp[(3) - (3)].val));
1767 DESTROY((yyvsp[(2) - (3)].val));
1768 (yyloc).first_column = (yylsp[(1) - (3)]).first_column; (yyloc).last_column = (yylsp[(3) - (3)]).last_column;
1769 (yyloc).first_line=0; (yyloc).last_line=0;;}
1770 break;
1772 case 13:
1773 #line 223 "ast_expr2.y"
1774 { (yyval.val) = op_ne ((yyvsp[(1) - (3)].val), (yyvsp[(3) - (3)].val));
1775 DESTROY((yyvsp[(2) - (3)].val));
1776 (yyloc).first_column = (yylsp[(1) - (3)]).first_column; (yyloc).last_column = (yylsp[(3) - (3)]).last_column;
1777 (yyloc).first_line=0; (yyloc).last_line=0;;}
1778 break;
1780 case 14:
1781 #line 227 "ast_expr2.y"
1782 { (yyval.val) = op_plus ((yyvsp[(1) - (3)].val), (yyvsp[(3) - (3)].val));
1783 DESTROY((yyvsp[(2) - (3)].val));
1784 (yyloc).first_column = (yylsp[(1) - (3)]).first_column; (yyloc).last_column = (yylsp[(3) - (3)]).last_column;
1785 (yyloc).first_line=0; (yyloc).last_line=0;;}
1786 break;
1788 case 15:
1789 #line 231 "ast_expr2.y"
1790 { (yyval.val) = op_minus ((yyvsp[(1) - (3)].val), (yyvsp[(3) - (3)].val));
1791 DESTROY((yyvsp[(2) - (3)].val));
1792 (yyloc).first_column = (yylsp[(1) - (3)]).first_column; (yyloc).last_column = (yylsp[(3) - (3)]).last_column;
1793 (yyloc).first_line=0; (yyloc).last_line=0;;}
1794 break;
1796 case 16:
1797 #line 235 "ast_expr2.y"
1798 { (yyval.val) = op_negate ((yyvsp[(2) - (2)].val));
1799 DESTROY((yyvsp[(1) - (2)].val));
1800 (yyloc).first_column = (yylsp[(1) - (2)]).first_column; (yyloc).last_column = (yylsp[(2) - (2)]).last_column;
1801 (yyloc).first_line=0; (yyloc).last_line=0;;}
1802 break;
1804 case 17:
1805 #line 239 "ast_expr2.y"
1806 { (yyval.val) = op_compl ((yyvsp[(2) - (2)].val));
1807 DESTROY((yyvsp[(1) - (2)].val));
1808 (yyloc).first_column = (yylsp[(1) - (2)]).first_column; (yyloc).last_column = (yylsp[(2) - (2)]).last_column;
1809 (yyloc).first_line=0; (yyloc).last_line=0;;}
1810 break;
1812 case 18:
1813 #line 243 "ast_expr2.y"
1814 { (yyval.val) = op_times ((yyvsp[(1) - (3)].val), (yyvsp[(3) - (3)].val));
1815 DESTROY((yyvsp[(2) - (3)].val));
1816 (yyloc).first_column = (yylsp[(1) - (3)]).first_column; (yyloc).last_column = (yylsp[(3) - (3)]).last_column;
1817 (yyloc).first_line=0; (yyloc).last_line=0;;}
1818 break;
1820 case 19:
1821 #line 247 "ast_expr2.y"
1822 { (yyval.val) = op_div ((yyvsp[(1) - (3)].val), (yyvsp[(3) - (3)].val));
1823 DESTROY((yyvsp[(2) - (3)].val));
1824 (yyloc).first_column = (yylsp[(1) - (3)]).first_column; (yyloc).last_column = (yylsp[(3) - (3)]).last_column;
1825 (yyloc).first_line=0; (yyloc).last_line=0;;}
1826 break;
1828 case 20:
1829 #line 251 "ast_expr2.y"
1830 { (yyval.val) = op_rem ((yyvsp[(1) - (3)].val), (yyvsp[(3) - (3)].val));
1831 DESTROY((yyvsp[(2) - (3)].val));
1832 (yyloc).first_column = (yylsp[(1) - (3)]).first_column; (yyloc).last_column = (yylsp[(3) - (3)]).last_column;
1833 (yyloc).first_line=0; (yyloc).last_line=0;;}
1834 break;
1836 case 21:
1837 #line 255 "ast_expr2.y"
1838 { (yyval.val) = op_colon ((yyvsp[(1) - (3)].val), (yyvsp[(3) - (3)].val));
1839 DESTROY((yyvsp[(2) - (3)].val));
1840 (yyloc).first_column = (yylsp[(1) - (3)]).first_column; (yyloc).last_column = (yylsp[(3) - (3)]).last_column;
1841 (yyloc).first_line=0; (yyloc).last_line=0;;}
1842 break;
1844 case 22:
1845 #line 259 "ast_expr2.y"
1846 { (yyval.val) = op_eqtilde ((yyvsp[(1) - (3)].val), (yyvsp[(3) - (3)].val));
1847 DESTROY((yyvsp[(2) - (3)].val));
1848 (yyloc).first_column = (yylsp[(1) - (3)]).first_column; (yyloc).last_column = (yylsp[(3) - (3)]).last_column;
1849 (yyloc).first_line=0; (yyloc).last_line=0;;}
1850 break;
1852 case 23:
1853 #line 263 "ast_expr2.y"
1854 { (yyval.val) = op_cond ((yyvsp[(1) - (5)].val), (yyvsp[(3) - (5)].val), (yyvsp[(5) - (5)].val));
1855 DESTROY((yyvsp[(2) - (5)].val));
1856 DESTROY((yyvsp[(4) - (5)].val));
1857 (yyloc).first_column = (yylsp[(1) - (5)]).first_column; (yyloc).last_column = (yylsp[(3) - (5)]).last_column;
1858 (yyloc).first_line=0; (yyloc).last_line=0;;}
1859 break;
1862 /* Line 1270 of yacc.c. */
1863 #line 1864 "ast_expr2.c"
1864 default: break;
1866 YY_SYMBOL_PRINT ("-> $$ =", yyr1[yyn], &yyval, &yyloc);
1868 YYPOPSTACK (yylen);
1869 yylen = 0;
1870 YY_STACK_PRINT (yyss, yyssp);
1872 *++yyvsp = yyval;
1873 *++yylsp = yyloc;
1875 /* Now `shift' the result of the reduction. Determine what state
1876 that goes to, based on the state we popped back to and the rule
1877 number reduced by. */
1879 yyn = yyr1[yyn];
1881 yystate = yypgoto[yyn - YYNTOKENS] + *yyssp;
1882 if (0 <= yystate && yystate <= YYLAST && yycheck[yystate] == *yyssp)
1883 yystate = yytable[yystate];
1884 else
1885 yystate = yydefgoto[yyn - YYNTOKENS];
1887 goto yynewstate;
1890 /*------------------------------------.
1891 | yyerrlab -- here on detecting error |
1892 `------------------------------------*/
1893 yyerrlab:
1894 /* If not already recovering from an error, report this error. */
1895 if (!yyerrstatus)
1897 ++yynerrs;
1898 #if ! YYERROR_VERBOSE
1899 yyerror (YY_("syntax error"));
1900 #else
1902 YYSIZE_T yysize = yysyntax_error (0, yystate, yychar);
1903 if (yymsg_alloc < yysize && yymsg_alloc < YYSTACK_ALLOC_MAXIMUM)
1905 YYSIZE_T yyalloc = 2 * yysize;
1906 if (! (yysize <= yyalloc && yyalloc <= YYSTACK_ALLOC_MAXIMUM))
1907 yyalloc = YYSTACK_ALLOC_MAXIMUM;
1908 if (yymsg != yymsgbuf)
1909 YYSTACK_FREE (yymsg);
1910 yymsg = (char *) YYSTACK_ALLOC (yyalloc);
1911 if (yymsg)
1912 yymsg_alloc = yyalloc;
1913 else
1915 yymsg = yymsgbuf;
1916 yymsg_alloc = sizeof yymsgbuf;
1920 if (0 < yysize && yysize <= yymsg_alloc)
1922 (void) yysyntax_error (yymsg, yystate, yychar);
1923 yyerror (yymsg);
1925 else
1927 yyerror (YY_("syntax error"));
1928 if (yysize != 0)
1929 goto yyexhaustedlab;
1932 #endif
1935 yyerror_range[0] = yylloc;
1937 if (yyerrstatus == 3)
1939 /* If just tried and failed to reuse look-ahead token after an
1940 error, discard it. */
1942 if (yychar <= YYEOF)
1944 /* Return failure if at end of input. */
1945 if (yychar == YYEOF)
1946 YYABORT;
1948 else
1950 yydestruct ("Error: discarding",
1951 yytoken, &yylval, &yylloc);
1952 yychar = YYEMPTY;
1956 /* Else will try to reuse look-ahead token after shifting the error
1957 token. */
1958 goto yyerrlab1;
1961 /*---------------------------------------------------.
1962 | yyerrorlab -- error raised explicitly by YYERROR. |
1963 `---------------------------------------------------*/
1964 yyerrorlab:
1966 /* Pacify compilers like GCC when the user code never invokes
1967 YYERROR and the label yyerrorlab therefore never appears in user
1968 code. */
1969 if (/*CONSTCOND*/ 0)
1970 goto yyerrorlab;
1972 yyerror_range[0] = yylsp[1-yylen];
1973 /* Do not reclaim the symbols of the rule which action triggered
1974 this YYERROR. */
1975 YYPOPSTACK (yylen);
1976 yylen = 0;
1977 YY_STACK_PRINT (yyss, yyssp);
1978 yystate = *yyssp;
1979 goto yyerrlab1;
1982 /*-------------------------------------------------------------.
1983 | yyerrlab1 -- common code for both syntax error and YYERROR. |
1984 `-------------------------------------------------------------*/
1985 yyerrlab1:
1986 yyerrstatus = 3; /* Each real token shifted decrements this. */
1988 for (;;)
1990 yyn = yypact[yystate];
1991 if (yyn != YYPACT_NINF)
1993 yyn += YYTERROR;
1994 if (0 <= yyn && yyn <= YYLAST && yycheck[yyn] == YYTERROR)
1996 yyn = yytable[yyn];
1997 if (0 < yyn)
1998 break;
2002 /* Pop the current state because it cannot handle the error token. */
2003 if (yyssp == yyss)
2004 YYABORT;
2006 yyerror_range[0] = *yylsp;
2007 yydestruct ("Error: popping",
2008 yystos[yystate], yyvsp, yylsp);
2009 YYPOPSTACK (1);
2010 yystate = *yyssp;
2011 YY_STACK_PRINT (yyss, yyssp);
2014 if (yyn == YYFINAL)
2015 YYACCEPT;
2017 *++yyvsp = yylval;
2019 yyerror_range[1] = yylloc;
2020 /* Using YYLLOC is tempting, but would change the location of
2021 the look-ahead. YYLOC is available though. */
2022 YYLLOC_DEFAULT (yyloc, (yyerror_range - 1), 2);
2023 *++yylsp = yyloc;
2025 /* Shift the error token. */
2026 YY_SYMBOL_PRINT ("Shifting", yystos[yyn], yyvsp, yylsp);
2028 yystate = yyn;
2029 goto yynewstate;
2032 /*-------------------------------------.
2033 | yyacceptlab -- YYACCEPT comes here. |
2034 `-------------------------------------*/
2035 yyacceptlab:
2036 yyresult = 0;
2037 goto yyreturn;
2039 /*-----------------------------------.
2040 | yyabortlab -- YYABORT comes here. |
2041 `-----------------------------------*/
2042 yyabortlab:
2043 yyresult = 1;
2044 goto yyreturn;
2046 #ifndef yyoverflow
2047 /*-------------------------------------------------.
2048 | yyexhaustedlab -- memory exhaustion comes here. |
2049 `-------------------------------------------------*/
2050 yyexhaustedlab:
2051 yyerror (YY_("memory exhausted"));
2052 yyresult = 2;
2053 /* Fall through. */
2054 #endif
2056 yyreturn:
2057 if (yychar != YYEOF && yychar != YYEMPTY)
2058 yydestruct ("Cleanup: discarding lookahead",
2059 yytoken, &yylval, &yylloc);
2060 /* Do not reclaim the symbols of the rule which action triggered
2061 this YYABORT or YYACCEPT. */
2062 YYPOPSTACK (yylen);
2063 YY_STACK_PRINT (yyss, yyssp);
2064 while (yyssp != yyss)
2066 yydestruct ("Cleanup: popping",
2067 yystos[*yyssp], yyvsp, yylsp);
2068 YYPOPSTACK (1);
2070 #ifndef yyoverflow
2071 if (yyss != yyssa)
2072 YYSTACK_FREE (yyss);
2073 #endif
2074 #if YYERROR_VERBOSE
2075 if (yymsg != yymsgbuf)
2076 YYSTACK_FREE (yymsg);
2077 #endif
2078 return yyresult;
2082 #line 270 "ast_expr2.y"
2085 static struct val *
2086 make_integer (quad_t i)
2088 struct val *vp;
2090 vp = (struct val *) malloc (sizeof (*vp));
2091 if (vp == NULL) {
2092 ast_log(LOG_WARNING, "malloc() failed\n");
2093 return(NULL);
2096 vp->type = AST_EXPR_integer;
2097 vp->u.i = i;
2098 return vp;
2101 static struct val *
2102 make_str (const char *s)
2104 struct val *vp;
2105 size_t i;
2106 int isint;
2108 vp = (struct val *) malloc (sizeof (*vp));
2109 if (vp == NULL || ((vp->u.s = strdup (s)) == NULL)) {
2110 ast_log(LOG_WARNING,"malloc() failed\n");
2111 return(NULL);
2114 for(i = 1, isint = isdigit(s[0]) || s[0] == '-';
2115 isint && i < strlen(s);
2116 i++)
2118 if(!isdigit(s[i]))
2119 isint = 0;
2122 if (isint)
2123 vp->type = AST_EXPR_numeric_string;
2124 else
2125 vp->type = AST_EXPR_string;
2127 return vp;
2131 static void
2132 free_value (struct val *vp)
2134 if (vp==NULL) {
2135 return;
2137 if (vp->type == AST_EXPR_string || vp->type == AST_EXPR_numeric_string)
2138 free (vp->u.s);
2139 free(vp);
2143 static quad_t
2144 to_integer (struct val *vp)
2146 quad_t i;
2148 if (vp == NULL) {
2149 ast_log(LOG_WARNING,"vp==NULL in to_integer()\n");
2150 return(0);
2153 if (vp->type == AST_EXPR_integer)
2154 return 1;
2156 if (vp->type == AST_EXPR_string)
2157 return 0;
2159 /* vp->type == AST_EXPR_numeric_string, make it numeric */
2160 errno = 0;
2161 i = strtoll(vp->u.s, (char**)NULL, 10);
2162 if (errno != 0) {
2163 ast_log(LOG_WARNING,"Conversion of %s to integer under/overflowed!\n", vp->u.s);
2164 free(vp->u.s);
2165 vp->u.s = 0;
2166 return(0);
2168 free (vp->u.s);
2169 vp->u.i = i;
2170 vp->type = AST_EXPR_integer;
2171 return 1;
2174 static void
2175 strip_quotes(struct val *vp)
2177 if (vp->type != AST_EXPR_string && vp->type != AST_EXPR_numeric_string)
2178 return;
2180 if( vp->u.s[0] == '"' && vp->u.s[strlen(vp->u.s)-1] == '"' )
2182 char *f, *t;
2183 f = vp->u.s;
2184 t = vp->u.s;
2186 while( *f )
2188 if( *f && *f != '"' )
2189 *t++ = *f++;
2190 else
2191 f++;
2193 *t = *f;
2197 static void
2198 to_string (struct val *vp)
2200 char *tmp;
2202 if (vp->type == AST_EXPR_string || vp->type == AST_EXPR_numeric_string)
2203 return;
2205 tmp = malloc ((size_t)25);
2206 if (tmp == NULL) {
2207 ast_log(LOG_WARNING,"malloc() failed\n");
2208 return;
2211 sprintf(tmp, "%ld", (long int) vp->u.i);
2212 vp->type = AST_EXPR_string;
2213 vp->u.s = tmp;
2217 static int
2218 isstring (struct val *vp)
2220 /* only TRUE if this string is not a valid integer */
2221 return (vp->type == AST_EXPR_string);
2225 static int
2226 is_zero_or_null (struct val *vp)
2228 if (vp->type == AST_EXPR_integer) {
2229 return (vp->u.i == 0);
2230 } else {
2231 return (*vp->u.s == 0 || (to_integer (vp) && vp->u.i == 0));
2233 /* NOTREACHED */
2236 #ifdef STANDALONE
2238 void ast_log(int level, const char *file, int line, const char *function, const char *fmt, ...)
2240 va_list vars;
2241 va_start(vars,fmt);
2243 printf("LOG: lev:%d file:%s line:%d func: %s ",
2244 level, file, line, function);
2245 vprintf(fmt, vars);
2246 fflush(stdout);
2247 va_end(vars);
2251 int main(int argc,char **argv) {
2252 char s[4096];
2253 char out[4096];
2254 FILE *infile;
2256 if( !argv[1] )
2257 exit(20);
2259 if( access(argv[1],F_OK)== 0 )
2261 int ret;
2263 infile = fopen(argv[1],"r");
2264 if( !infile )
2266 printf("Sorry, couldn't open %s for reading!\n", argv[1]);
2267 exit(10);
2269 while( fgets(s,sizeof(s),infile) )
2271 if( s[strlen(s)-1] == '\n' )
2272 s[strlen(s)-1] = 0;
2274 ret = ast_expr(s, out, sizeof(out));
2275 printf("Expression: %s Result: [%d] '%s'\n",
2276 s, ret, out);
2278 fclose(infile);
2280 else
2282 if (ast_expr(argv[1], s, sizeof(s)))
2283 printf("=====%s======\n",s);
2284 else
2285 printf("No result\n");
2289 #endif
2291 #undef ast_yyerror
2292 #define ast_yyerror(x) ast_yyerror(x, YYLTYPE *yylloc, struct parse_io *parseio)
2294 /* I put the ast_yyerror func in the flex input file,
2295 because it refers to the buffer state. Best to
2296 let it access the BUFFER stuff there and not trying
2297 define all the structs, macros etc. in this file! */
2300 static struct val *
2301 op_or (struct val *a, struct val *b)
2303 if (is_zero_or_null (a)) {
2304 free_value (a);
2305 return (b);
2306 } else {
2307 free_value (b);
2308 return (a);
2312 static struct val *
2313 op_and (struct val *a, struct val *b)
2315 if (is_zero_or_null (a) || is_zero_or_null (b)) {
2316 free_value (a);
2317 free_value (b);
2318 return (make_integer ((quad_t)0));
2319 } else {
2320 free_value (b);
2321 return (a);
2325 static struct val *
2326 op_eq (struct val *a, struct val *b)
2328 struct val *r;
2330 if (isstring (a) || isstring (b)) {
2331 to_string (a);
2332 to_string (b);
2333 r = make_integer ((quad_t)(strcoll (a->u.s, b->u.s) == 0));
2334 } else {
2335 #ifdef DEBUG_FOR_CONVERSIONS
2336 char buffer[2000];
2337 sprintf(buffer,"Converting '%s' and '%s' ", a->u.s, b->u.s);
2338 #endif
2339 (void)to_integer(a);
2340 (void)to_integer(b);
2341 #ifdef DEBUG_FOR_CONVERSIONS
2342 ast_log(LOG_WARNING,"%s to '%lld' and '%lld'\n", buffer, a->u.i, b->u.i);
2343 #endif
2344 r = make_integer ((quad_t)(a->u.i == b->u.i));
2347 free_value (a);
2348 free_value (b);
2349 return r;
2352 static struct val *
2353 op_gt (struct val *a, struct val *b)
2355 struct val *r;
2357 if (isstring (a) || isstring (b)) {
2358 to_string (a);
2359 to_string (b);
2360 r = make_integer ((quad_t)(strcoll (a->u.s, b->u.s) > 0));
2361 } else {
2362 (void)to_integer(a);
2363 (void)to_integer(b);
2364 r = make_integer ((quad_t)(a->u.i > b->u.i));
2367 free_value (a);
2368 free_value (b);
2369 return r;
2372 static struct val *
2373 op_lt (struct val *a, struct val *b)
2375 struct val *r;
2377 if (isstring (a) || isstring (b)) {
2378 to_string (a);
2379 to_string (b);
2380 r = make_integer ((quad_t)(strcoll (a->u.s, b->u.s) < 0));
2381 } else {
2382 (void)to_integer(a);
2383 (void)to_integer(b);
2384 r = make_integer ((quad_t)(a->u.i < b->u.i));
2387 free_value (a);
2388 free_value (b);
2389 return r;
2392 static struct val *
2393 op_ge (struct val *a, struct val *b)
2395 struct val *r;
2397 if (isstring (a) || isstring (b)) {
2398 to_string (a);
2399 to_string (b);
2400 r = make_integer ((quad_t)(strcoll (a->u.s, b->u.s) >= 0));
2401 } else {
2402 (void)to_integer(a);
2403 (void)to_integer(b);
2404 r = make_integer ((quad_t)(a->u.i >= b->u.i));
2407 free_value (a);
2408 free_value (b);
2409 return r;
2412 static struct val *
2413 op_le (struct val *a, struct val *b)
2415 struct val *r;
2417 if (isstring (a) || isstring (b)) {
2418 to_string (a);
2419 to_string (b);
2420 r = make_integer ((quad_t)(strcoll (a->u.s, b->u.s) <= 0));
2421 } else {
2422 (void)to_integer(a);
2423 (void)to_integer(b);
2424 r = make_integer ((quad_t)(a->u.i <= b->u.i));
2427 free_value (a);
2428 free_value (b);
2429 return r;
2432 static struct val *
2433 op_cond (struct val *a, struct val *b, struct val *c)
2435 struct val *r;
2437 if( isstring(a) )
2439 if( strlen(a->u.s) && strcmp(a->u.s, "\"\"") != 0 && strcmp(a->u.s,"0") != 0 )
2441 free_value(a);
2442 free_value(c);
2443 r = b;
2445 else
2447 free_value(a);
2448 free_value(b);
2449 r = c;
2452 else
2454 (void)to_integer(a);
2455 if( a->u.i )
2457 free_value(a);
2458 free_value(c);
2459 r = b;
2461 else
2463 free_value(a);
2464 free_value(b);
2465 r = c;
2468 return r;
2471 static struct val *
2472 op_ne (struct val *a, struct val *b)
2474 struct val *r;
2476 if (isstring (a) || isstring (b)) {
2477 to_string (a);
2478 to_string (b);
2479 r = make_integer ((quad_t)(strcoll (a->u.s, b->u.s) != 0));
2480 } else {
2481 (void)to_integer(a);
2482 (void)to_integer(b);
2483 r = make_integer ((quad_t)(a->u.i != b->u.i));
2486 free_value (a);
2487 free_value (b);
2488 return r;
2491 static int
2492 chk_plus (quad_t a, quad_t b, quad_t r)
2494 /* sum of two positive numbers must be positive */
2495 if (a > 0 && b > 0 && r <= 0)
2496 return 1;
2497 /* sum of two negative numbers must be negative */
2498 if (a < 0 && b < 0 && r >= 0)
2499 return 1;
2500 /* all other cases are OK */
2501 return 0;
2504 static struct val *
2505 op_plus (struct val *a, struct val *b)
2507 struct val *r;
2509 if (!to_integer (a)) {
2510 if( !extra_error_message_supplied )
2511 ast_log(LOG_WARNING,"non-numeric argument\n");
2512 if (!to_integer (b)) {
2513 free_value(a);
2514 free_value(b);
2515 return make_integer(0);
2516 } else {
2517 free_value(a);
2518 return (b);
2520 } else if (!to_integer(b)) {
2521 free_value(b);
2522 return (a);
2525 r = make_integer (/*(quad_t)*/(a->u.i + b->u.i));
2526 if (chk_plus (a->u.i, b->u.i, r->u.i)) {
2527 ast_log(LOG_WARNING,"overflow\n");
2529 free_value (a);
2530 free_value (b);
2531 return r;
2534 static int
2535 chk_minus (quad_t a, quad_t b, quad_t r)
2537 /* special case subtraction of QUAD_MIN */
2538 if (b == QUAD_MIN) {
2539 if (a >= 0)
2540 return 1;
2541 else
2542 return 0;
2544 /* this is allowed for b != QUAD_MIN */
2545 return chk_plus (a, -b, r);
2548 static struct val *
2549 op_minus (struct val *a, struct val *b)
2551 struct val *r;
2553 if (!to_integer (a)) {
2554 if( !extra_error_message_supplied )
2555 ast_log(LOG_WARNING, "non-numeric argument\n");
2556 if (!to_integer (b)) {
2557 free_value(a);
2558 free_value(b);
2559 return make_integer(0);
2560 } else {
2561 r = make_integer(0 - b->u.i);
2562 free_value(a);
2563 free_value(b);
2564 return (r);
2566 } else if (!to_integer(b)) {
2567 if( !extra_error_message_supplied )
2568 ast_log(LOG_WARNING, "non-numeric argument\n");
2569 free_value(b);
2570 return (a);
2573 r = make_integer (/*(quad_t)*/(a->u.i - b->u.i));
2574 if (chk_minus (a->u.i, b->u.i, r->u.i)) {
2575 ast_log(LOG_WARNING, "overflow\n");
2577 free_value (a);
2578 free_value (b);
2579 return r;
2582 static struct val *
2583 op_negate (struct val *a)
2585 struct val *r;
2587 if (!to_integer (a) ) {
2588 free_value(a);
2589 if( !extra_error_message_supplied )
2590 ast_log(LOG_WARNING, "non-numeric argument\n");
2591 return make_integer(0);
2594 r = make_integer (/*(quad_t)*/(- a->u.i));
2595 if (chk_minus (0, a->u.i, r->u.i)) {
2596 ast_log(LOG_WARNING, "overflow\n");
2598 free_value (a);
2599 return r;
2602 static struct val *
2603 op_compl (struct val *a)
2605 int v1 = 1;
2606 struct val *r;
2608 if( !a )
2610 v1 = 0;
2612 else
2614 switch( a->type )
2616 case AST_EXPR_integer:
2617 if( a->u.i == 0 )
2618 v1 = 0;
2619 break;
2621 case AST_EXPR_string:
2622 if( a->u.s == 0 )
2623 v1 = 0;
2624 else
2626 if( a->u.s[0] == 0 )
2627 v1 = 0;
2628 else if (strlen(a->u.s) == 1 && a->u.s[0] == '0' )
2629 v1 = 0;
2631 break;
2633 case AST_EXPR_numeric_string:
2634 if( a->u.s == 0 )
2635 v1 = 0;
2636 else
2638 if( a->u.s[0] == 0 )
2639 v1 = 0;
2640 else if (strlen(a->u.s) == 1 && a->u.s[0] == '0' )
2641 v1 = 0;
2643 break;
2647 r = make_integer (!v1);
2648 free_value (a);
2649 return r;
2652 static int
2653 chk_times (quad_t a, quad_t b, quad_t r)
2655 /* special case: first operand is 0, no overflow possible */
2656 if (a == 0)
2657 return 0;
2658 /* cerify that result of division matches second operand */
2659 if (r / a != b)
2660 return 1;
2661 return 0;
2664 static struct val *
2665 op_times (struct val *a, struct val *b)
2667 struct val *r;
2669 if (!to_integer (a) || !to_integer (b)) {
2670 free_value(a);
2671 free_value(b);
2672 if( !extra_error_message_supplied )
2673 ast_log(LOG_WARNING, "non-numeric argument\n");
2674 return(make_integer(0));
2677 r = make_integer (/*(quad_t)*/(a->u.i * b->u.i));
2678 if (chk_times (a->u.i, b->u.i, r->u.i)) {
2679 ast_log(LOG_WARNING, "overflow\n");
2681 free_value (a);
2682 free_value (b);
2683 return (r);
2686 static int
2687 chk_div (quad_t a, quad_t b)
2689 /* div by zero has been taken care of before */
2690 /* only QUAD_MIN / -1 causes overflow */
2691 if (a == QUAD_MIN && b == -1)
2692 return 1;
2693 /* everything else is OK */
2694 return 0;
2697 static struct val *
2698 op_div (struct val *a, struct val *b)
2700 struct val *r;
2702 if (!to_integer (a)) {
2703 free_value(a);
2704 free_value(b);
2705 if( !extra_error_message_supplied )
2706 ast_log(LOG_WARNING, "non-numeric argument\n");
2707 return make_integer(0);
2708 } else if (!to_integer (b)) {
2709 free_value(a);
2710 free_value(b);
2711 if( !extra_error_message_supplied )
2712 ast_log(LOG_WARNING, "non-numeric argument\n");
2713 return make_integer(INT_MAX);
2716 if (b->u.i == 0) {
2717 ast_log(LOG_WARNING, "division by zero\n");
2718 free_value(a);
2719 free_value(b);
2720 return make_integer(INT_MAX);
2723 r = make_integer (/*(quad_t)*/(a->u.i / b->u.i));
2724 if (chk_div (a->u.i, b->u.i)) {
2725 ast_log(LOG_WARNING, "overflow\n");
2727 free_value (a);
2728 free_value (b);
2729 return r;
2732 static struct val *
2733 op_rem (struct val *a, struct val *b)
2735 struct val *r;
2737 if (!to_integer (a) || !to_integer (b)) {
2738 if( !extra_error_message_supplied )
2739 ast_log(LOG_WARNING, "non-numeric argument\n");
2740 free_value(a);
2741 free_value(b);
2742 return make_integer(0);
2745 if (b->u.i == 0) {
2746 ast_log(LOG_WARNING, "div by zero\n");
2747 free_value(a);
2748 return(b);
2751 r = make_integer (/*(quad_t)*/(a->u.i % b->u.i));
2752 /* chk_rem necessary ??? */
2753 free_value (a);
2754 free_value (b);
2755 return r;
2759 static struct val *
2760 op_colon (struct val *a, struct val *b)
2762 regex_t rp;
2763 regmatch_t rm[2];
2764 char errbuf[256];
2765 int eval;
2766 struct val *v;
2768 /* coerce to both arguments to strings */
2769 to_string(a);
2770 to_string(b);
2771 /* strip double quotes from both -- they'll screw up the pattern, and the search string starting at ^ */
2772 strip_quotes(a);
2773 strip_quotes(b);
2774 /* compile regular expression */
2775 if ((eval = regcomp (&rp, b->u.s, REG_EXTENDED)) != 0) {
2776 regerror (eval, &rp, errbuf, sizeof(errbuf));
2777 ast_log(LOG_WARNING,"regcomp() error : %s",errbuf);
2778 free_value(a);
2779 free_value(b);
2780 return make_str("");
2783 /* compare string against pattern */
2784 /* remember that patterns are anchored to the beginning of the line */
2785 if (regexec(&rp, a->u.s, (size_t)2, rm, 0) == 0 && rm[0].rm_so == 0) {
2786 if (rm[1].rm_so >= 0) {
2787 *(a->u.s + rm[1].rm_eo) = '\0';
2788 v = make_str (a->u.s + rm[1].rm_so);
2790 } else {
2791 v = make_integer ((quad_t)(rm[0].rm_eo - rm[0].rm_so));
2793 } else {
2794 if (rp.re_nsub == 0) {
2795 v = make_integer ((quad_t)0);
2796 } else {
2797 v = make_str ("");
2801 /* free arguments and pattern buffer */
2802 free_value (a);
2803 free_value (b);
2804 regfree (&rp);
2806 return v;
2810 static struct val *
2811 op_eqtilde (struct val *a, struct val *b)
2813 regex_t rp;
2814 regmatch_t rm[2];
2815 char errbuf[256];
2816 int eval;
2817 struct val *v;
2819 /* coerce to both arguments to strings */
2820 to_string(a);
2821 to_string(b);
2822 /* strip double quotes from both -- they'll screw up the pattern, and the search string starting at ^ */
2823 strip_quotes(a);
2824 strip_quotes(b);
2825 /* compile regular expression */
2826 if ((eval = regcomp (&rp, b->u.s, REG_EXTENDED)) != 0) {
2827 regerror (eval, &rp, errbuf, sizeof(errbuf));
2828 ast_log(LOG_WARNING,"regcomp() error : %s",errbuf);
2829 free_value(a);
2830 free_value(b);
2831 return make_str("");
2834 /* compare string against pattern */
2835 /* remember that patterns are anchored to the beginning of the line */
2836 if (regexec(&rp, a->u.s, (size_t)2, rm, 0) == 0 ) {
2837 if (rm[1].rm_so >= 0) {
2838 *(a->u.s + rm[1].rm_eo) = '\0';
2839 v = make_str (a->u.s + rm[1].rm_so);
2841 } else {
2842 v = make_integer ((quad_t)(rm[0].rm_eo - rm[0].rm_so));
2844 } else {
2845 if (rp.re_nsub == 0) {
2846 v = make_integer ((quad_t)0);
2847 } else {
2848 v = make_str ("");
2852 /* free arguments and pattern buffer */
2853 free_value (a);
2854 free_value (b);
2855 regfree (&rp);
2857 return v;