Merged revisions 30874 via svnmerge from
[asterisk-bristuff.git] / ast_expr2.c
blob0ddb1e4ff93a21cb64049b30d0fb57c4cd6b824f
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@e-tools.com)
125 * to add double-quoted strings, allow mult. spaces, improve
126 * error messages, and then to fold in a flex scanner for the
127 * yylex operation.
129 * $FreeBSD: src/bin/expr/expr.y,v 1.16 2000/07/22 10:59:36 se Exp $
132 #include <sys/types.h>
133 #include <stdio.h>
134 #include <stdlib.h>
135 #include <string.h>
136 #include <locale.h>
137 #include <unistd.h>
138 #include <ctype.h>
139 #if !defined(SOLARIS) && !defined(__CYGWIN__)
140 #include <err.h>
141 #else
142 #define quad_t int64_t
143 #endif
144 #include <errno.h>
145 #include <regex.h>
146 #include <limits.h>
148 #include "asterisk.h"
150 ASTERISK_FILE_VERSION(__FILE__, "$Revision$")
152 #include "asterisk/ast_expr.h"
153 #include "asterisk/logger.h"
155 #if defined(LONG_LONG_MIN) && !defined(QUAD_MIN)
156 #define QUAD_MIN LONG_LONG_MIN
157 #endif
158 #if defined(LONG_LONG_MAX) && !defined(QUAD_MAX)
159 #define QUAD_MAX LONG_LONG_MAX
160 #endif
162 # if ! defined(QUAD_MIN)
163 # define QUAD_MIN (-0x7fffffffffffffffLL-1)
164 # endif
165 # if ! defined(QUAD_MAX)
166 # define QUAD_MAX (0x7fffffffffffffffLL)
167 # endif
169 #define YYPARSE_PARAM parseio
170 #define YYLEX_PARAM ((struct parse_io *)parseio)->scanner
171 #define YYERROR_VERBOSE 1
172 extern char extra_error_message[4095];
173 extern int extra_error_message_supplied;
175 enum valtype {
176 AST_EXPR_integer, AST_EXPR_numeric_string, AST_EXPR_string
179 #ifdef STANDALONE
180 void ast_log(int level, const char *file, int line, const char *function, const char *fmt, ...) __attribute__ ((format (printf,5,6)));
181 #endif
183 struct val {
184 enum valtype type;
185 union {
186 char *s;
187 quad_t i;
188 } u;
191 typedef void *yyscan_t;
193 struct parse_io
195 char *string;
196 struct val *val;
197 yyscan_t scanner;
200 static int chk_div __P((quad_t, quad_t));
201 static int chk_minus __P((quad_t, quad_t, quad_t));
202 static int chk_plus __P((quad_t, quad_t, quad_t));
203 static int chk_times __P((quad_t, quad_t, quad_t));
204 static void free_value __P((struct val *));
205 static int is_zero_or_null __P((struct val *));
206 static int isstring __P((struct val *));
207 static struct val *make_integer __P((quad_t));
208 static struct val *make_str __P((const char *));
209 static struct val *op_and __P((struct val *, struct val *));
210 static struct val *op_colon __P((struct val *, struct val *));
211 static struct val *op_eqtilde __P((struct val *, struct val *));
212 static struct val *op_div __P((struct val *, struct val *));
213 static struct val *op_eq __P((struct val *, struct val *));
214 static struct val *op_ge __P((struct val *, struct val *));
215 static struct val *op_gt __P((struct val *, struct val *));
216 static struct val *op_le __P((struct val *, struct val *));
217 static struct val *op_lt __P((struct val *, struct val *));
218 static struct val *op_cond __P((struct val *, struct val *, struct val *));
219 static struct val *op_minus __P((struct val *, struct val *));
220 static struct val *op_negate __P((struct val *));
221 static struct val *op_compl __P((struct val *));
222 static struct val *op_ne __P((struct val *, struct val *));
223 static struct val *op_or __P((struct val *, struct val *));
224 static struct val *op_plus __P((struct val *, struct val *));
225 static struct val *op_rem __P((struct val *, struct val *));
226 static struct val *op_times __P((struct val *, struct val *));
227 static quad_t to_integer __P((struct val *));
228 static void to_string __P((struct val *));
230 /* uh, if I want to predeclare yylex with a YYLTYPE, I have to predeclare the yyltype... sigh */
231 typedef struct yyltype
233 int first_line;
234 int first_column;
236 int last_line;
237 int last_column;
238 } yyltype;
240 # define YYLTYPE yyltype
241 # define YYLTYPE_IS_TRIVIAL 1
243 /* we will get warning about no prototype for yylex! But we can't
244 define it here, we have no definition yet for YYSTYPE. */
246 int ast_yyerror(const char *,YYLTYPE *, struct parse_io *);
248 /* I wanted to add args to the yyerror routine, so I could print out
249 some useful info about the error. Not as easy as it looks, but it
250 is possible. */
251 #define ast_yyerror(x) ast_yyerror(x,&yyloc,parseio)
252 #define DESTROY(x) {if((x)->type == AST_EXPR_numeric_string || (x)->type == AST_EXPR_string) free((x)->u.s); (x)->u.s = 0; free(x);}
255 /* Enabling traces. */
256 #ifndef YYDEBUG
257 # define YYDEBUG 0
258 #endif
260 /* Enabling verbose error messages. */
261 #ifdef YYERROR_VERBOSE
262 # undef YYERROR_VERBOSE
263 # define YYERROR_VERBOSE 1
264 #else
265 # define YYERROR_VERBOSE 0
266 #endif
268 /* Enabling the token table. */
269 #ifndef YYTOKEN_TABLE
270 # define YYTOKEN_TABLE 0
271 #endif
273 #if ! defined YYSTYPE && ! defined YYSTYPE_IS_DECLARED
274 typedef union YYSTYPE
275 #line 140 "ast_expr2.y"
277 struct val *val;
279 /* Line 198 of yacc.c. */
280 #line 276 "ast_expr2.c"
281 YYSTYPE;
282 # define yystype YYSTYPE /* obsolescent; will be withdrawn */
283 # define YYSTYPE_IS_DECLARED 1
284 # define YYSTYPE_IS_TRIVIAL 1
285 #endif
287 #if ! defined YYLTYPE && ! defined YYLTYPE_IS_DECLARED
288 typedef struct YYLTYPE
290 int first_line;
291 int first_column;
292 int last_line;
293 int last_column;
294 } YYLTYPE;
295 # define yyltype YYLTYPE /* obsolescent; will be withdrawn */
296 # define YYLTYPE_IS_DECLARED 1
297 # define YYLTYPE_IS_TRIVIAL 1
298 #endif
301 /* Copy the second part of user declarations. */
302 #line 144 "ast_expr2.y"
304 extern int ast_yylex __P((YYSTYPE *, YYLTYPE *, yyscan_t));
307 /* Line 221 of yacc.c. */
308 #line 304 "ast_expr2.c"
310 #ifdef short
311 # undef short
312 #endif
314 #ifdef YYTYPE_UINT8
315 typedef YYTYPE_UINT8 yytype_uint8;
316 #else
317 typedef unsigned char yytype_uint8;
318 #endif
320 #ifdef YYTYPE_INT8
321 typedef YYTYPE_INT8 yytype_int8;
322 #elif (defined __STDC__ || defined __C99__FUNC__ \
323 || defined __cplusplus || defined _MSC_VER)
324 typedef signed char yytype_int8;
325 #else
326 typedef short int yytype_int8;
327 #endif
329 #ifdef YYTYPE_UINT16
330 typedef YYTYPE_UINT16 yytype_uint16;
331 #else
332 typedef unsigned short int yytype_uint16;
333 #endif
335 #ifdef YYTYPE_INT16
336 typedef YYTYPE_INT16 yytype_int16;
337 #else
338 typedef short int yytype_int16;
339 #endif
341 #ifndef YYSIZE_T
342 # ifdef __SIZE_TYPE__
343 # define YYSIZE_T __SIZE_TYPE__
344 # elif defined size_t
345 # define YYSIZE_T size_t
346 # elif ! defined YYSIZE_T && (defined __STDC__ || defined __C99__FUNC__ \
347 || defined __cplusplus || defined _MSC_VER)
348 # include <stddef.h> /* INFRINGES ON USER NAME SPACE */
349 # define YYSIZE_T size_t
350 # else
351 # define YYSIZE_T unsigned int
352 # endif
353 #endif
355 #define YYSIZE_MAXIMUM ((YYSIZE_T) -1)
357 #ifndef YY_
358 # if YYENABLE_NLS
359 # if ENABLE_NLS
360 # include <libintl.h> /* INFRINGES ON USER NAME SPACE */
361 # define YY_(msgid) dgettext ("bison-runtime", msgid)
362 # endif
363 # endif
364 # ifndef YY_
365 # define YY_(msgid) msgid
366 # endif
367 #endif
369 /* Suppress unused-variable warnings by "using" E. */
370 #if ! defined lint || defined __GNUC__
371 # define YYUSE(e) ((void) (e))
372 #else
373 # define YYUSE(e) /* empty */
374 #endif
376 /* Identity function, used to suppress warnings about constant conditions. */
377 #ifndef lint
378 # define YYID(n) (n)
379 #else
380 #if (defined __STDC__ || defined __C99__FUNC__ \
381 || defined __cplusplus || defined _MSC_VER)
382 static int
383 YYID (int i)
384 #else
385 static int
386 YYID (i)
387 int i;
388 #endif
390 return i;
392 #endif
394 #if ! defined yyoverflow || YYERROR_VERBOSE
396 /* The parser invokes alloca or malloc; define the necessary symbols. */
398 # ifdef YYSTACK_USE_ALLOCA
399 # if YYSTACK_USE_ALLOCA
400 # ifdef __GNUC__
401 # define YYSTACK_ALLOC __builtin_alloca
402 # elif defined __BUILTIN_VA_ARG_INCR
403 # include <alloca.h> /* INFRINGES ON USER NAME SPACE */
404 # elif defined _AIX
405 # define YYSTACK_ALLOC __alloca
406 # elif defined _MSC_VER
407 # include <malloc.h> /* INFRINGES ON USER NAME SPACE */
408 # define alloca _alloca
409 # else
410 # define YYSTACK_ALLOC alloca
411 # if ! defined _ALLOCA_H && ! defined _STDLIB_H && (defined __STDC__ || defined __C99__FUNC__ \
412 || defined __cplusplus || defined _MSC_VER)
413 # include <stdlib.h> /* INFRINGES ON USER NAME SPACE */
414 # ifndef _STDLIB_H
415 # define _STDLIB_H 1
416 # endif
417 # endif
418 # endif
419 # endif
420 # endif
422 # ifdef YYSTACK_ALLOC
423 /* Pacify GCC's `empty if-body' warning. */
424 # define YYSTACK_FREE(Ptr) do { /* empty */; } while (YYID (0))
425 # ifndef YYSTACK_ALLOC_MAXIMUM
426 /* The OS might guarantee only one guard page at the bottom of the stack,
427 and a page size can be as small as 4096 bytes. So we cannot safely
428 invoke alloca (N) if N exceeds 4096. Use a slightly smaller number
429 to allow for a few compiler-allocated temporary stack slots. */
430 # define YYSTACK_ALLOC_MAXIMUM 4032 /* reasonable circa 2006 */
431 # endif
432 # else
433 # define YYSTACK_ALLOC YYMALLOC
434 # define YYSTACK_FREE YYFREE
435 # ifndef YYSTACK_ALLOC_MAXIMUM
436 # define YYSTACK_ALLOC_MAXIMUM YYSIZE_MAXIMUM
437 # endif
438 # ifdef __cplusplus
439 extern "C" {
440 # endif
441 # ifndef YYMALLOC
442 # define YYMALLOC malloc
443 # if ! defined malloc && ! defined _STDLIB_H && (defined __STDC__ || defined __C99__FUNC__ \
444 || defined __cplusplus || defined _MSC_VER)
445 void *malloc (YYSIZE_T); /* INFRINGES ON USER NAME SPACE */
446 # endif
447 # endif
448 # ifndef YYFREE
449 # define YYFREE free
450 # if ! defined free && ! defined _STDLIB_H && (defined __STDC__ || defined __C99__FUNC__ \
451 || defined __cplusplus || defined _MSC_VER)
452 void free (void *); /* INFRINGES ON USER NAME SPACE */
453 # endif
454 # endif
455 # ifdef __cplusplus
457 # endif
458 # endif
459 #endif /* ! defined yyoverflow || YYERROR_VERBOSE */
462 #if (! defined yyoverflow \
463 && (! defined __cplusplus \
464 || (defined YYLTYPE_IS_TRIVIAL && YYLTYPE_IS_TRIVIAL \
465 && defined YYSTYPE_IS_TRIVIAL && YYSTYPE_IS_TRIVIAL)))
467 /* A type that is properly aligned for any stack member. */
468 union yyalloc
470 yytype_int16 yyss;
471 YYSTYPE yyvs;
472 YYLTYPE yyls;
475 /* The size of the maximum gap between one aligned stack and the next. */
476 # define YYSTACK_GAP_MAXIMUM (sizeof (union yyalloc) - 1)
478 /* The size of an array large to enough to hold all stacks, each with
479 N elements. */
480 # define YYSTACK_BYTES(N) \
481 ((N) * (sizeof (yytype_int16) + sizeof (YYSTYPE) + sizeof (YYLTYPE)) \
482 + 2 * YYSTACK_GAP_MAXIMUM)
484 /* Copy COUNT objects from FROM to TO. The source and destination do
485 not overlap. */
486 # ifndef YYCOPY
487 # if defined __GNUC__ && 1 < __GNUC__
488 # define YYCOPY(To, From, Count) \
489 __builtin_memcpy (To, From, (Count) * sizeof (*(From)))
490 # else
491 # define YYCOPY(To, From, Count) \
492 do \
494 YYSIZE_T yyi; \
495 for (yyi = 0; yyi < (Count); yyi++) \
496 (To)[yyi] = (From)[yyi]; \
498 while (YYID (0))
499 # endif
500 # endif
502 /* Relocate STACK from its old location to the new one. The
503 local variables YYSIZE and YYSTACKSIZE give the old and new number of
504 elements in the stack, and YYPTR gives the new location of the
505 stack. Advance YYPTR to a properly aligned location for the next
506 stack. */
507 # define YYSTACK_RELOCATE(Stack) \
508 do \
510 YYSIZE_T yynewbytes; \
511 YYCOPY (&yyptr->Stack, Stack, yysize); \
512 Stack = &yyptr->Stack; \
513 yynewbytes = yystacksize * sizeof (*Stack) + YYSTACK_GAP_MAXIMUM; \
514 yyptr += yynewbytes / sizeof (*yyptr); \
516 while (YYID (0))
518 #endif
520 /* YYFINAL -- State number of the termination state. */
521 #define YYFINAL 10
522 /* YYLAST -- Last index in YYTABLE. */
523 #define YYLAST 140
525 /* YYNTOKENS -- Number of terminals. */
526 #define YYNTOKENS 24
527 /* YYNNTS -- Number of nonterminals. */
528 #define YYNNTS 3
529 /* YYNRULES -- Number of rules. */
530 #define YYNRULES 23
531 /* YYNRULES -- Number of states. */
532 #define YYNSTATES 46
534 /* YYTRANSLATE(YYLEX) -- Bison symbol number corresponding to YYLEX. */
535 #define YYUNDEFTOK 2
536 #define YYMAXUTOK 278
538 #define YYTRANSLATE(YYX) \
539 ((unsigned int) (YYX) <= YYMAXUTOK ? yytranslate[YYX] : YYUNDEFTOK)
541 /* YYTRANSLATE[YYLEX] -- Bison symbol number corresponding to YYLEX. */
542 static const yytype_uint8 yytranslate[] =
544 0, 2, 2, 2, 2, 2, 2, 2, 2, 2,
545 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
546 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
547 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
548 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
549 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
550 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
551 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
552 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
553 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
554 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
555 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
556 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
557 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
558 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
559 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
560 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
561 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
562 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
563 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
564 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
565 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
566 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
567 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
568 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
569 2, 2, 2, 2, 2, 2, 1, 2, 3, 4,
570 5, 6, 7, 8, 9, 10, 11, 12, 13, 14,
571 15, 16, 17, 18, 19, 20, 21, 22, 23
574 #if YYDEBUG
575 /* YYPRHS[YYN] -- Index of the first RHS symbol of rule number YYN in
576 YYRHS. */
577 static const yytype_uint8 yyprhs[] =
579 0, 0, 3, 5, 6, 8, 12, 16, 20, 24,
580 28, 32, 36, 40, 44, 48, 52, 55, 58, 62,
581 66, 70, 74, 78
584 /* YYRHS -- A `-1'-separated list of the rules' RHS. */
585 static const yytype_int8 yyrhs[] =
587 25, 0, -1, 26, -1, -1, 23, -1, 21, 26,
588 22, -1, 26, 5, 26, -1, 26, 6, 26, -1,
589 26, 12, 26, -1, 26, 11, 26, -1, 26, 10,
590 26, -1, 26, 9, 26, -1, 26, 8, 26, -1,
591 26, 7, 26, -1, 26, 14, 26, -1, 26, 13,
592 26, -1, 13, 26, -1, 18, 26, -1, 26, 17,
593 26, -1, 26, 16, 26, -1, 26, 15, 26, -1,
594 26, 20, 26, -1, 26, 19, 26, -1, 26, 4,
595 26, 3, 26, -1
598 /* YYRLINE[YYN] -- source line where rule number YYN was defined. */
599 static const yytype_uint16 yyrline[] =
601 0, 168, 168, 176, 183, 184, 188, 192, 196, 200,
602 204, 208, 212, 216, 220, 224, 228, 232, 236, 240,
603 244, 248, 252, 256
605 #endif
607 #if YYDEBUG || YYERROR_VERBOSE || YYTOKEN_TABLE
608 /* YYTNAME[SYMBOL-NUM] -- String name of the symbol SYMBOL-NUM.
609 First, the terminals, then, starting at YYNTOKENS, nonterminals. */
610 static const char *const yytname[] =
612 "$end", "error", "$undefined", "TOK_COLONCOLON", "TOK_COND", "TOK_OR",
613 "TOK_AND", "TOK_NE", "TOK_LE", "TOK_GE", "TOK_LT", "TOK_GT", "TOK_EQ",
614 "TOK_MINUS", "TOK_PLUS", "TOK_MOD", "TOK_DIV", "TOK_MULT", "TOK_COMPL",
615 "TOK_EQTILDE", "TOK_COLON", "TOK_LP", "TOK_RP", "TOKEN", "$accept",
616 "start", "expr", 0
618 #endif
620 # ifdef YYPRINT
621 /* YYTOKNUM[YYLEX-NUM] -- Internal token number corresponding to
622 token YYLEX-NUM. */
623 static const yytype_uint16 yytoknum[] =
625 0, 256, 257, 258, 259, 260, 261, 262, 263, 264,
626 265, 266, 267, 268, 269, 270, 271, 272, 273, 274,
627 275, 276, 277, 278
629 # endif
631 /* YYR1[YYN] -- Symbol number of symbol that rule YYN derives. */
632 static const yytype_uint8 yyr1[] =
634 0, 24, 25, 25, 26, 26, 26, 26, 26, 26,
635 26, 26, 26, 26, 26, 26, 26, 26, 26, 26,
636 26, 26, 26, 26
639 /* YYR2[YYN] -- Number of symbols composing right hand side of rule YYN. */
640 static const yytype_uint8 yyr2[] =
642 0, 2, 1, 0, 1, 3, 3, 3, 3, 3,
643 3, 3, 3, 3, 3, 3, 2, 2, 3, 3,
644 3, 3, 3, 5
647 /* YYDEFACT[STATE-NAME] -- Default rule to reduce with in state
648 STATE-NUM when YYTABLE doesn't specify something else to do. Zero
649 means the default is an error. */
650 static const yytype_uint8 yydefact[] =
652 3, 0, 0, 0, 4, 0, 2, 16, 17, 0,
653 1, 0, 0, 0, 0, 0, 0, 0, 0, 0,
654 0, 0, 0, 0, 0, 0, 0, 5, 0, 6,
655 7, 13, 12, 11, 10, 9, 8, 15, 14, 20,
656 19, 18, 22, 21, 0, 23
659 /* YYDEFGOTO[NTERM-NUM]. */
660 static const yytype_int8 yydefgoto[] =
662 -1, 5, 6
665 /* YYPACT[STATE-NUM] -- Index in YYTABLE of the portion describing
666 STATE-NUM. */
667 #define YYPACT_NINF -13
668 static const yytype_int8 yypact[] =
670 109, 109, 109, 109, -13, 6, 59, 106, 106, 22,
671 -13, 109, 109, 109, 109, 109, 109, 109, 109, 109,
672 109, 109, 109, 109, 109, 109, 109, -13, 42, 90,
673 104, 120, 120, 120, 120, 120, 120, -12, -12, 106,
674 106, 106, -13, -13, 109, 75
677 /* YYPGOTO[NTERM-NUM]. */
678 static const yytype_int8 yypgoto[] =
680 -13, -13, -1
683 /* YYTABLE[YYPACT[STATE-NUM]]. What to do in state STATE-NUM. If
684 positive, shift that token. If negative, reduce the rule which
685 number is the opposite. If zero, do what YYDEFACT says.
686 If YYTABLE_NINF, syntax error. */
687 #define YYTABLE_NINF -1
688 static const yytype_uint8 yytable[] =
690 7, 8, 9, 22, 23, 24, 10, 25, 26, 0,
691 28, 29, 30, 31, 32, 33, 34, 35, 36, 37,
692 38, 39, 40, 41, 42, 43, 11, 12, 13, 14,
693 15, 16, 17, 18, 19, 20, 21, 22, 23, 24,
694 0, 25, 26, 45, 27, 44, 11, 12, 13, 14,
695 15, 16, 17, 18, 19, 20, 21, 22, 23, 24,
696 0, 25, 26, 11, 12, 13, 14, 15, 16, 17,
697 18, 19, 20, 21, 22, 23, 24, 0, 25, 26,
698 12, 13, 14, 15, 16, 17, 18, 19, 20, 21,
699 22, 23, 24, 0, 25, 26, 13, 14, 15, 16,
700 17, 18, 19, 20, 21, 22, 23, 24, 0, 25,
701 26, 14, 15, 16, 17, 18, 19, 20, 21, 22,
702 23, 24, 1, 25, 26, 25, 26, 2, 0, 0,
703 3, 0, 4, 20, 21, 22, 23, 24, 0, 25,
707 static const yytype_int8 yycheck[] =
709 1, 2, 3, 15, 16, 17, 0, 19, 20, -1,
710 11, 12, 13, 14, 15, 16, 17, 18, 19, 20,
711 21, 22, 23, 24, 25, 26, 4, 5, 6, 7,
712 8, 9, 10, 11, 12, 13, 14, 15, 16, 17,
713 -1, 19, 20, 44, 22, 3, 4, 5, 6, 7,
714 8, 9, 10, 11, 12, 13, 14, 15, 16, 17,
715 -1, 19, 20, 4, 5, 6, 7, 8, 9, 10,
716 11, 12, 13, 14, 15, 16, 17, -1, 19, 20,
717 5, 6, 7, 8, 9, 10, 11, 12, 13, 14,
718 15, 16, 17, -1, 19, 20, 6, 7, 8, 9,
719 10, 11, 12, 13, 14, 15, 16, 17, -1, 19,
720 20, 7, 8, 9, 10, 11, 12, 13, 14, 15,
721 16, 17, 13, 19, 20, 19, 20, 18, -1, -1,
722 21, -1, 23, 13, 14, 15, 16, 17, -1, 19,
726 /* YYSTOS[STATE-NUM] -- The (internal number of the) accessing
727 symbol of state STATE-NUM. */
728 static const yytype_uint8 yystos[] =
730 0, 13, 18, 21, 23, 25, 26, 26, 26, 26,
731 0, 4, 5, 6, 7, 8, 9, 10, 11, 12,
732 13, 14, 15, 16, 17, 19, 20, 22, 26, 26,
733 26, 26, 26, 26, 26, 26, 26, 26, 26, 26,
734 26, 26, 26, 26, 3, 26
737 #define yyerrok (yyerrstatus = 0)
738 #define yyclearin (yychar = YYEMPTY)
739 #define YYEMPTY (-2)
740 #define YYEOF 0
742 #define YYACCEPT goto yyacceptlab
743 #define YYABORT goto yyabortlab
744 #define YYERROR goto yyerrorlab
747 /* Like YYERROR except do call yyerror. This remains here temporarily
748 to ease the transition to the new meaning of YYERROR, for GCC.
749 Once GCC version 2 has supplanted version 1, this can go. */
751 #define YYFAIL goto yyerrlab
753 #define YYRECOVERING() (!!yyerrstatus)
755 #define YYBACKUP(Token, Value) \
756 do \
757 if (yychar == YYEMPTY && yylen == 1) \
759 yychar = (Token); \
760 yylval = (Value); \
761 yytoken = YYTRANSLATE (yychar); \
762 YYPOPSTACK (1); \
763 goto yybackup; \
765 else \
767 yyerror (YY_("syntax error: cannot back up")); \
768 YYERROR; \
770 while (YYID (0))
773 #define YYTERROR 1
774 #define YYERRCODE 256
777 /* YYLLOC_DEFAULT -- Set CURRENT to span from RHS[1] to RHS[N].
778 If N is 0, then set CURRENT to the empty location which ends
779 the previous symbol: RHS[0] (always defined). */
781 #define YYRHSLOC(Rhs, K) ((Rhs)[K])
782 #ifndef YYLLOC_DEFAULT
783 # define YYLLOC_DEFAULT(Current, Rhs, N) \
784 do \
785 if (YYID (N)) \
787 (Current).first_line = YYRHSLOC (Rhs, 1).first_line; \
788 (Current).first_column = YYRHSLOC (Rhs, 1).first_column; \
789 (Current).last_line = YYRHSLOC (Rhs, N).last_line; \
790 (Current).last_column = YYRHSLOC (Rhs, N).last_column; \
792 else \
794 (Current).first_line = (Current).last_line = \
795 YYRHSLOC (Rhs, 0).last_line; \
796 (Current).first_column = (Current).last_column = \
797 YYRHSLOC (Rhs, 0).last_column; \
799 while (YYID (0))
800 #endif
803 /* YY_LOCATION_PRINT -- Print the location on the stream.
804 This macro was not mandated originally: define only if we know
805 we won't break user code: when these are the locations we know. */
807 #ifndef YY_LOCATION_PRINT
808 # if YYLTYPE_IS_TRIVIAL
809 # define YY_LOCATION_PRINT(File, Loc) \
810 fprintf (File, "%d.%d-%d.%d", \
811 (Loc).first_line, (Loc).first_column, \
812 (Loc).last_line, (Loc).last_column)
813 # else
814 # define YY_LOCATION_PRINT(File, Loc) ((void) 0)
815 # endif
816 #endif
819 /* YYLEX -- calling `yylex' with the right arguments. */
821 #ifdef YYLEX_PARAM
822 # define YYLEX yylex (&yylval, &yylloc, YYLEX_PARAM)
823 #else
824 # define YYLEX yylex (&yylval, &yylloc)
825 #endif
827 /* Enable debugging if requested. */
828 #if YYDEBUG
830 # ifndef YYFPRINTF
831 # include <stdio.h> /* INFRINGES ON USER NAME SPACE */
832 # define YYFPRINTF fprintf
833 # endif
835 # define YYDPRINTF(Args) \
836 do { \
837 if (yydebug) \
838 YYFPRINTF Args; \
839 } while (YYID (0))
841 # define YY_SYMBOL_PRINT(Title, Type, Value, Location) \
842 do { \
843 if (yydebug) \
845 YYFPRINTF (stderr, "%s ", Title); \
846 yy_symbol_print (stderr, \
847 Type, Value, Location); \
848 YYFPRINTF (stderr, "\n"); \
850 } while (YYID (0))
853 /*--------------------------------.
854 | Print this symbol on YYOUTPUT. |
855 `--------------------------------*/
857 /*ARGSUSED*/
858 #if (defined __STDC__ || defined __C99__FUNC__ \
859 || defined __cplusplus || defined _MSC_VER)
860 static void
861 yy_symbol_value_print (FILE *yyoutput, int yytype, const YYSTYPE * const yyvaluep, const YYLTYPE * const yylocationp)
862 #else
863 static void
864 yy_symbol_value_print (yyoutput, yytype, yyvaluep, yylocationp)
865 FILE *yyoutput;
866 int yytype;
867 const YYSTYPE * const yyvaluep;
868 const YYLTYPE * const yylocationp;
869 #endif
871 if (!yyvaluep)
872 return;
873 YYUSE (yylocationp);
874 # ifdef YYPRINT
875 if (yytype < YYNTOKENS)
876 YYPRINT (yyoutput, yytoknum[yytype], *yyvaluep);
877 # else
878 YYUSE (yyoutput);
879 # endif
880 switch (yytype)
882 default:
883 break;
888 /*--------------------------------.
889 | Print this symbol on YYOUTPUT. |
890 `--------------------------------*/
892 #if (defined __STDC__ || defined __C99__FUNC__ \
893 || defined __cplusplus || defined _MSC_VER)
894 static void
895 yy_symbol_print (FILE *yyoutput, int yytype, const YYSTYPE * const yyvaluep, const YYLTYPE * const yylocationp)
896 #else
897 static void
898 yy_symbol_print (yyoutput, yytype, yyvaluep, yylocationp)
899 FILE *yyoutput;
900 int yytype;
901 const YYSTYPE * const yyvaluep;
902 const YYLTYPE * const yylocationp;
903 #endif
905 if (yytype < YYNTOKENS)
906 YYFPRINTF (yyoutput, "token %s (", yytname[yytype]);
907 else
908 YYFPRINTF (yyoutput, "nterm %s (", yytname[yytype]);
910 YY_LOCATION_PRINT (yyoutput, *yylocationp);
911 YYFPRINTF (yyoutput, ": ");
912 yy_symbol_value_print (yyoutput, yytype, yyvaluep, yylocationp);
913 YYFPRINTF (yyoutput, ")");
916 /*------------------------------------------------------------------.
917 | yy_stack_print -- Print the state stack from its BOTTOM up to its |
918 | TOP (included). |
919 `------------------------------------------------------------------*/
921 #if (defined __STDC__ || defined __C99__FUNC__ \
922 || defined __cplusplus || defined _MSC_VER)
923 static void
924 yy_stack_print (yytype_int16 *bottom, yytype_int16 *top)
925 #else
926 static void
927 yy_stack_print (bottom, top)
928 yytype_int16 *bottom;
929 yytype_int16 *top;
930 #endif
932 YYFPRINTF (stderr, "Stack now");
933 for (; bottom <= top; ++bottom)
934 YYFPRINTF (stderr, " %d", *bottom);
935 YYFPRINTF (stderr, "\n");
938 # define YY_STACK_PRINT(Bottom, Top) \
939 do { \
940 if (yydebug) \
941 yy_stack_print ((Bottom), (Top)); \
942 } while (YYID (0))
945 /*------------------------------------------------.
946 | Report that the YYRULE is going to be reduced. |
947 `------------------------------------------------*/
949 #if (defined __STDC__ || defined __C99__FUNC__ \
950 || defined __cplusplus || defined _MSC_VER)
951 static void
952 yy_reduce_print (YYSTYPE *yyvsp, YYLTYPE *yylsp, int yyrule)
953 #else
954 static void
955 yy_reduce_print (yyvsp, yylsp, yyrule
957 YYSTYPE *yyvsp;
958 YYLTYPE *yylsp;
959 int yyrule;
960 #endif
962 int yynrhs = yyr2[yyrule];
963 int yyi;
964 unsigned long int yylno = yyrline[yyrule];
965 YYFPRINTF (stderr, "Reducing stack by rule %d (line %lu):\n",
966 yyrule - 1, yylno);
967 /* The symbols being reduced. */
968 for (yyi = 0; yyi < yynrhs; yyi++)
970 fprintf (stderr, " $%d = ", yyi + 1);
971 yy_symbol_print (stderr, yyrhs[yyprhs[yyrule] + yyi],
972 &(yyvsp[(yyi + 1) - (yynrhs)])
973 , &(yylsp[(yyi + 1) - (yynrhs)]) );
974 fprintf (stderr, "\n");
978 # define YY_REDUCE_PRINT(Rule) \
979 do { \
980 if (yydebug) \
981 yy_reduce_print (yyvsp, yylsp, Rule); \
982 } while (YYID (0))
984 /* Nonzero means print parse trace. It is left uninitialized so that
985 multiple parsers can coexist. */
986 int yydebug;
987 #else /* !YYDEBUG */
988 # define YYDPRINTF(Args)
989 # define YY_SYMBOL_PRINT(Title, Type, Value, Location)
990 # define YY_STACK_PRINT(Bottom, Top)
991 # define YY_REDUCE_PRINT(Rule)
992 #endif /* !YYDEBUG */
995 /* YYINITDEPTH -- initial size of the parser's stacks. */
996 #ifndef YYINITDEPTH
997 # define YYINITDEPTH 200
998 #endif
1000 /* YYMAXDEPTH -- maximum size the stacks can grow to (effective only
1001 if the built-in stack extension method is used).
1003 Do not make this value too large; the results are undefined if
1004 YYSTACK_ALLOC_MAXIMUM < YYSTACK_BYTES (YYMAXDEPTH)
1005 evaluated with infinite-precision integer arithmetic. */
1007 #ifndef YYMAXDEPTH
1008 # define YYMAXDEPTH 10000
1009 #endif
1013 #if YYERROR_VERBOSE
1015 # ifndef yystrlen
1016 # if defined __GLIBC__ && defined _STRING_H
1017 # define yystrlen strlen
1018 # else
1019 /* Return the length of YYSTR. */
1020 #if (defined __STDC__ || defined __C99__FUNC__ \
1021 || defined __cplusplus || defined _MSC_VER)
1022 static YYSIZE_T
1023 yystrlen (const char *yystr)
1024 #else
1025 static YYSIZE_T
1026 yystrlen (yystr)
1027 const char *yystr;
1028 #endif
1030 YYSIZE_T yylen;
1031 for (yylen = 0; yystr[yylen]; yylen++)
1032 continue;
1033 return yylen;
1035 # endif
1036 # endif
1038 # ifndef yystpcpy
1039 # if defined __GLIBC__ && defined _STRING_H && defined _GNU_SOURCE
1040 # define yystpcpy stpcpy
1041 # else
1042 /* Copy YYSRC to YYDEST, returning the address of the terminating '\0' in
1043 YYDEST. */
1044 #if (defined __STDC__ || defined __C99__FUNC__ \
1045 || defined __cplusplus || defined _MSC_VER)
1046 static char *
1047 yystpcpy (char *yydest, const char *yysrc)
1048 #else
1049 static char *
1050 yystpcpy (yydest, yysrc)
1051 char *yydest;
1052 const char *yysrc;
1053 #endif
1055 char *yyd = yydest;
1056 const char *yys = yysrc;
1058 while ((*yyd++ = *yys++) != '\0')
1059 continue;
1061 return yyd - 1;
1063 # endif
1064 # endif
1066 # ifndef yytnamerr
1067 /* Copy to YYRES the contents of YYSTR after stripping away unnecessary
1068 quotes and backslashes, so that it's suitable for yyerror. The
1069 heuristic is that double-quoting is unnecessary unless the string
1070 contains an apostrophe, a comma, or backslash (other than
1071 backslash-backslash). YYSTR is taken from yytname. If YYRES is
1072 null, do not copy; instead, return the length of what the result
1073 would have been. */
1074 static YYSIZE_T
1075 yytnamerr (char *yyres, const char *yystr)
1077 if (*yystr == '"')
1079 size_t yyn = 0;
1080 char const *yyp = yystr;
1082 for (;;)
1083 switch (*++yyp)
1085 case '\'':
1086 case ',':
1087 goto do_not_strip_quotes;
1089 case '\\':
1090 if (*++yyp != '\\')
1091 goto do_not_strip_quotes;
1092 /* Fall through. */
1093 default:
1094 if (yyres)
1095 yyres[yyn] = *yyp;
1096 yyn++;
1097 break;
1099 case '"':
1100 if (yyres)
1101 yyres[yyn] = '\0';
1102 return yyn;
1104 do_not_strip_quotes: ;
1107 if (! yyres)
1108 return yystrlen (yystr);
1110 return yystpcpy (yyres, yystr) - yyres;
1112 # endif
1114 /* Copy into YYRESULT an error message about the unexpected token
1115 YYCHAR while in state YYSTATE. Return the number of bytes copied,
1116 including the terminating null byte. If YYRESULT is null, do not
1117 copy anything; just return the number of bytes that would be
1118 copied. As a special case, return 0 if an ordinary "syntax error"
1119 message will do. Return YYSIZE_MAXIMUM if overflow occurs during
1120 size calculation. */
1121 static YYSIZE_T
1122 yysyntax_error (char *yyresult, int yystate, int yychar)
1124 int yyn = yypact[yystate];
1126 if (! (YYPACT_NINF < yyn && yyn < YYLAST))
1127 return 0;
1128 else
1130 int yytype = YYTRANSLATE (yychar);
1131 YYSIZE_T yysize0 = yytnamerr (0, yytname[yytype]);
1132 YYSIZE_T yysize = yysize0;
1133 YYSIZE_T yysize1;
1134 int yysize_overflow = 0;
1135 enum { YYERROR_VERBOSE_ARGS_MAXIMUM = 5 };
1136 char const *yyarg[YYERROR_VERBOSE_ARGS_MAXIMUM];
1137 int yyx;
1139 # if 0
1140 /* This is so xgettext sees the translatable formats that are
1141 constructed on the fly. */
1142 YY_("syntax error, unexpected %s");
1143 YY_("syntax error, unexpected %s, expecting %s");
1144 YY_("syntax error, unexpected %s, expecting %s or %s");
1145 YY_("syntax error, unexpected %s, expecting %s or %s or %s");
1146 YY_("syntax error, unexpected %s, expecting %s or %s or %s or %s");
1147 # endif
1148 char *yyfmt;
1149 char const *yyf;
1150 static char const yyunexpected[] = "syntax error, unexpected %s";
1151 static char const yyexpecting[] = ", expecting %s";
1152 static char const yyor[] = " or %s";
1153 char yyformat[sizeof yyunexpected
1154 + sizeof yyexpecting - 1
1155 + ((YYERROR_VERBOSE_ARGS_MAXIMUM - 2)
1156 * (sizeof yyor - 1))];
1157 char const *yyprefix = yyexpecting;
1159 /* Start YYX at -YYN if negative to avoid negative indexes in
1160 YYCHECK. */
1161 int yyxbegin = yyn < 0 ? -yyn : 0;
1163 /* Stay within bounds of both yycheck and yytname. */
1164 int yychecklim = YYLAST - yyn;
1165 int yyxend = yychecklim < YYNTOKENS ? yychecklim : YYNTOKENS;
1166 int yycount = 1;
1168 yyarg[0] = yytname[yytype];
1169 yyfmt = yystpcpy (yyformat, yyunexpected);
1171 for (yyx = yyxbegin; yyx < yyxend; ++yyx)
1172 if (yycheck[yyx + yyn] == yyx && yyx != YYTERROR)
1174 if (yycount == YYERROR_VERBOSE_ARGS_MAXIMUM)
1176 yycount = 1;
1177 yysize = yysize0;
1178 yyformat[sizeof yyunexpected - 1] = '\0';
1179 break;
1181 yyarg[yycount++] = yytname[yyx];
1182 yysize1 = yysize + yytnamerr (0, yytname[yyx]);
1183 yysize_overflow |= (yysize1 < yysize);
1184 yysize = yysize1;
1185 yyfmt = yystpcpy (yyfmt, yyprefix);
1186 yyprefix = yyor;
1189 yyf = YY_(yyformat);
1190 yysize1 = yysize + yystrlen (yyf);
1191 yysize_overflow |= (yysize1 < yysize);
1192 yysize = yysize1;
1194 if (yysize_overflow)
1195 return YYSIZE_MAXIMUM;
1197 if (yyresult)
1199 /* Avoid sprintf, as that infringes on the user's name space.
1200 Don't have undefined behavior even if the translation
1201 produced a string with the wrong number of "%s"s. */
1202 char *yyp = yyresult;
1203 int yyi = 0;
1204 while ((*yyp = *yyf) != '\0')
1206 if (*yyp == '%' && yyf[1] == 's' && yyi < yycount)
1208 yyp += yytnamerr (yyp, yyarg[yyi++]);
1209 yyf += 2;
1211 else
1213 yyp++;
1214 yyf++;
1218 return yysize;
1221 #endif /* YYERROR_VERBOSE */
1224 /*-----------------------------------------------.
1225 | Release the memory associated to this symbol. |
1226 `-----------------------------------------------*/
1228 /*ARGSUSED*/
1229 #if (defined __STDC__ || defined __C99__FUNC__ \
1230 || defined __cplusplus || defined _MSC_VER)
1231 static void
1232 yydestruct (const char *yymsg, int yytype, YYSTYPE *yyvaluep, YYLTYPE *yylocationp)
1233 #else
1234 static void
1235 yydestruct (yymsg, yytype, yyvaluep, yylocationp)
1236 const char *yymsg;
1237 int yytype;
1238 YYSTYPE *yyvaluep;
1239 YYLTYPE *yylocationp;
1240 #endif
1242 YYUSE (yyvaluep);
1243 YYUSE (yylocationp);
1245 if (!yymsg)
1246 yymsg = "Deleting";
1247 YY_SYMBOL_PRINT (yymsg, yytype, yyvaluep, yylocationp);
1249 switch (yytype)
1251 case 3: /* "TOK_COLONCOLON" */
1252 #line 162 "ast_expr2.y"
1253 { free_value((yyvaluep->val)); };
1254 #line 1250 "ast_expr2.c"
1255 break;
1256 case 4: /* "TOK_COND" */
1257 #line 162 "ast_expr2.y"
1258 { free_value((yyvaluep->val)); };
1259 #line 1255 "ast_expr2.c"
1260 break;
1261 case 5: /* "TOK_OR" */
1262 #line 162 "ast_expr2.y"
1263 { free_value((yyvaluep->val)); };
1264 #line 1260 "ast_expr2.c"
1265 break;
1266 case 6: /* "TOK_AND" */
1267 #line 162 "ast_expr2.y"
1268 { free_value((yyvaluep->val)); };
1269 #line 1265 "ast_expr2.c"
1270 break;
1271 case 7: /* "TOK_NE" */
1272 #line 162 "ast_expr2.y"
1273 { free_value((yyvaluep->val)); };
1274 #line 1270 "ast_expr2.c"
1275 break;
1276 case 8: /* "TOK_LE" */
1277 #line 162 "ast_expr2.y"
1278 { free_value((yyvaluep->val)); };
1279 #line 1275 "ast_expr2.c"
1280 break;
1281 case 9: /* "TOK_GE" */
1282 #line 162 "ast_expr2.y"
1283 { free_value((yyvaluep->val)); };
1284 #line 1280 "ast_expr2.c"
1285 break;
1286 case 10: /* "TOK_LT" */
1287 #line 162 "ast_expr2.y"
1288 { free_value((yyvaluep->val)); };
1289 #line 1285 "ast_expr2.c"
1290 break;
1291 case 11: /* "TOK_GT" */
1292 #line 162 "ast_expr2.y"
1293 { free_value((yyvaluep->val)); };
1294 #line 1290 "ast_expr2.c"
1295 break;
1296 case 12: /* "TOK_EQ" */
1297 #line 162 "ast_expr2.y"
1298 { free_value((yyvaluep->val)); };
1299 #line 1295 "ast_expr2.c"
1300 break;
1301 case 13: /* "TOK_MINUS" */
1302 #line 162 "ast_expr2.y"
1303 { free_value((yyvaluep->val)); };
1304 #line 1300 "ast_expr2.c"
1305 break;
1306 case 14: /* "TOK_PLUS" */
1307 #line 162 "ast_expr2.y"
1308 { free_value((yyvaluep->val)); };
1309 #line 1305 "ast_expr2.c"
1310 break;
1311 case 15: /* "TOK_MOD" */
1312 #line 162 "ast_expr2.y"
1313 { free_value((yyvaluep->val)); };
1314 #line 1310 "ast_expr2.c"
1315 break;
1316 case 16: /* "TOK_DIV" */
1317 #line 162 "ast_expr2.y"
1318 { free_value((yyvaluep->val)); };
1319 #line 1315 "ast_expr2.c"
1320 break;
1321 case 17: /* "TOK_MULT" */
1322 #line 162 "ast_expr2.y"
1323 { free_value((yyvaluep->val)); };
1324 #line 1320 "ast_expr2.c"
1325 break;
1326 case 18: /* "TOK_COMPL" */
1327 #line 162 "ast_expr2.y"
1328 { free_value((yyvaluep->val)); };
1329 #line 1325 "ast_expr2.c"
1330 break;
1331 case 19: /* "TOK_EQTILDE" */
1332 #line 162 "ast_expr2.y"
1333 { free_value((yyvaluep->val)); };
1334 #line 1330 "ast_expr2.c"
1335 break;
1336 case 20: /* "TOK_COLON" */
1337 #line 162 "ast_expr2.y"
1338 { free_value((yyvaluep->val)); };
1339 #line 1335 "ast_expr2.c"
1340 break;
1341 case 21: /* "TOK_LP" */
1342 #line 162 "ast_expr2.y"
1343 { free_value((yyvaluep->val)); };
1344 #line 1340 "ast_expr2.c"
1345 break;
1346 case 22: /* "TOK_RP" */
1347 #line 162 "ast_expr2.y"
1348 { free_value((yyvaluep->val)); };
1349 #line 1345 "ast_expr2.c"
1350 break;
1351 case 23: /* "TOKEN" */
1352 #line 162 "ast_expr2.y"
1353 { free_value((yyvaluep->val)); };
1354 #line 1350 "ast_expr2.c"
1355 break;
1356 case 26: /* "expr" */
1357 #line 162 "ast_expr2.y"
1358 { free_value((yyvaluep->val)); };
1359 #line 1355 "ast_expr2.c"
1360 break;
1362 default:
1363 break;
1368 /* Prevent warnings from -Wmissing-prototypes. */
1370 #ifdef YYPARSE_PARAM
1371 #if defined __STDC__ || defined __cplusplus
1372 int yyparse (void *YYPARSE_PARAM);
1373 #else
1374 int yyparse ();
1375 #endif
1376 #else /* ! YYPARSE_PARAM */
1377 #if defined __STDC__ || defined __cplusplus
1378 int yyparse (void);
1379 #else
1380 int yyparse ();
1381 #endif
1382 #endif /* ! YYPARSE_PARAM */
1389 /*----------.
1390 | yyparse. |
1391 `----------*/
1393 #ifdef YYPARSE_PARAM
1394 #if (defined __STDC__ || defined __C99__FUNC__ \
1395 || defined __cplusplus || defined _MSC_VER)
1397 yyparse (void *YYPARSE_PARAM)
1398 #else
1400 yyparse (YYPARSE_PARAM)
1401 void *YYPARSE_PARAM;
1402 #endif
1403 #else /* ! YYPARSE_PARAM */
1404 #if (defined __STDC__ || defined __C99__FUNC__ \
1405 || defined __cplusplus || defined _MSC_VER)
1407 yyparse (void)
1408 #else
1410 yyparse ()
1412 #endif
1413 #endif
1415 /* The look-ahead symbol. */
1416 int yychar;
1418 /* The semantic value of the look-ahead symbol. */
1419 YYSTYPE yylval;
1421 /* Number of syntax errors so far. */
1422 int yynerrs;
1423 /* Location data for the look-ahead symbol. */
1424 YYLTYPE yylloc;
1426 int yystate;
1427 int yyn;
1428 int yyresult;
1429 /* Number of tokens to shift before error messages enabled. */
1430 int yyerrstatus;
1431 /* Look-ahead token as an internal (translated) token number. */
1432 int yytoken = 0;
1433 #if YYERROR_VERBOSE
1434 /* Buffer for error messages, and its allocated size. */
1435 char yymsgbuf[128];
1436 char *yymsg = yymsgbuf;
1437 YYSIZE_T yymsg_alloc = sizeof yymsgbuf;
1438 #endif
1440 /* Three stacks and their tools:
1441 `yyss': related to states,
1442 `yyvs': related to semantic values,
1443 `yyls': related to locations.
1445 Refer to the stacks thru separate pointers, to allow yyoverflow
1446 to reallocate them elsewhere. */
1448 /* The state stack. */
1449 yytype_int16 yyssa[YYINITDEPTH];
1450 yytype_int16 *yyss = yyssa;
1451 yytype_int16 *yyssp;
1453 /* The semantic value stack. */
1454 YYSTYPE yyvsa[YYINITDEPTH];
1455 YYSTYPE *yyvs = yyvsa;
1456 YYSTYPE *yyvsp;
1458 /* The location stack. */
1459 YYLTYPE yylsa[YYINITDEPTH];
1460 YYLTYPE *yyls = yylsa;
1461 YYLTYPE *yylsp;
1462 /* The locations where the error started and ended. */
1463 YYLTYPE yyerror_range[2];
1465 #define YYPOPSTACK(N) (yyvsp -= (N), yyssp -= (N), yylsp -= (N))
1467 YYSIZE_T yystacksize = YYINITDEPTH;
1469 /* The variables used to return semantic value and location from the
1470 action routines. */
1471 YYSTYPE yyval;
1472 YYLTYPE yyloc;
1474 /* The number of symbols on the RHS of the reduced rule.
1475 Keep to zero when no symbol should be popped. */
1476 int yylen = 0;
1478 YYDPRINTF ((stderr, "Starting parse\n"));
1480 yystate = 0;
1481 yyerrstatus = 0;
1482 yynerrs = 0;
1483 yychar = YYEMPTY; /* Cause a token to be read. */
1485 /* Initialize stack pointers.
1486 Waste one element of value and location stack
1487 so that they stay on the same level as the state stack.
1488 The wasted elements are never initialized. */
1490 yyssp = yyss;
1491 yyvsp = yyvs;
1492 yylsp = yyls;
1493 #if YYLTYPE_IS_TRIVIAL
1494 /* Initialize the default location before parsing starts. */
1495 yylloc.first_line = yylloc.last_line = 1;
1496 yylloc.first_column = yylloc.last_column = 0;
1497 #endif
1499 goto yysetstate;
1501 /*------------------------------------------------------------.
1502 | yynewstate -- Push a new state, which is found in yystate. |
1503 `------------------------------------------------------------*/
1504 yynewstate:
1505 /* In all cases, when you get here, the value and location stacks
1506 have just been pushed. So pushing a state here evens the stacks. */
1507 yyssp++;
1509 yysetstate:
1510 *yyssp = yystate;
1512 if (yyss + yystacksize - 1 <= yyssp)
1514 /* Get the current used size of the three stacks, in elements. */
1515 YYSIZE_T yysize = yyssp - yyss + 1;
1517 #ifdef yyoverflow
1519 /* Give user a chance to reallocate the stack. Use copies of
1520 these so that the &'s don't force the real ones into
1521 memory. */
1522 YYSTYPE *yyvs1 = yyvs;
1523 yytype_int16 *yyss1 = yyss;
1524 YYLTYPE *yyls1 = yyls;
1526 /* Each stack pointer address is followed by the size of the
1527 data in use in that stack, in bytes. This used to be a
1528 conditional around just the two extra args, but that might
1529 be undefined if yyoverflow is a macro. */
1530 yyoverflow (YY_("memory exhausted"),
1531 &yyss1, yysize * sizeof (*yyssp),
1532 &yyvs1, yysize * sizeof (*yyvsp),
1533 &yyls1, yysize * sizeof (*yylsp),
1534 &yystacksize);
1535 yyls = yyls1;
1536 yyss = yyss1;
1537 yyvs = yyvs1;
1539 #else /* no yyoverflow */
1540 # ifndef YYSTACK_RELOCATE
1541 goto yyexhaustedlab;
1542 # else
1543 /* Extend the stack our own way. */
1544 if (YYMAXDEPTH <= yystacksize)
1545 goto yyexhaustedlab;
1546 yystacksize *= 2;
1547 if (YYMAXDEPTH < yystacksize)
1548 yystacksize = YYMAXDEPTH;
1551 yytype_int16 *yyss1 = yyss;
1552 union yyalloc *yyptr =
1553 (union yyalloc *) YYSTACK_ALLOC (YYSTACK_BYTES (yystacksize));
1554 if (! yyptr)
1555 goto yyexhaustedlab;
1556 YYSTACK_RELOCATE (yyss);
1557 YYSTACK_RELOCATE (yyvs);
1558 YYSTACK_RELOCATE (yyls);
1559 # undef YYSTACK_RELOCATE
1560 if (yyss1 != yyssa)
1561 YYSTACK_FREE (yyss1);
1563 # endif
1564 #endif /* no yyoverflow */
1566 yyssp = yyss + yysize - 1;
1567 yyvsp = yyvs + yysize - 1;
1568 yylsp = yyls + yysize - 1;
1570 YYDPRINTF ((stderr, "Stack size increased to %lu\n",
1571 (unsigned long int) yystacksize));
1573 if (yyss + yystacksize - 1 <= yyssp)
1574 YYABORT;
1577 YYDPRINTF ((stderr, "Entering state %d\n", yystate));
1579 goto yybackup;
1581 /*-----------.
1582 | yybackup. |
1583 `-----------*/
1584 yybackup:
1586 /* Do appropriate processing given the current state. Read a
1587 look-ahead token if we need one and don't already have one. */
1589 /* First try to decide what to do without reference to look-ahead token. */
1590 yyn = yypact[yystate];
1591 if (yyn == YYPACT_NINF)
1592 goto yydefault;
1594 /* Not known => get a look-ahead token if don't already have one. */
1596 /* YYCHAR is either YYEMPTY or YYEOF or a valid look-ahead symbol. */
1597 if (yychar == YYEMPTY)
1599 YYDPRINTF ((stderr, "Reading a token: "));
1600 yychar = YYLEX;
1603 if (yychar <= YYEOF)
1605 yychar = yytoken = YYEOF;
1606 YYDPRINTF ((stderr, "Now at end of input.\n"));
1608 else
1610 yytoken = YYTRANSLATE (yychar);
1611 YY_SYMBOL_PRINT ("Next token is", yytoken, &yylval, &yylloc);
1614 /* If the proper action on seeing token YYTOKEN is to reduce or to
1615 detect an error, take that action. */
1616 yyn += yytoken;
1617 if (yyn < 0 || YYLAST < yyn || yycheck[yyn] != yytoken)
1618 goto yydefault;
1619 yyn = yytable[yyn];
1620 if (yyn <= 0)
1622 if (yyn == 0 || yyn == YYTABLE_NINF)
1623 goto yyerrlab;
1624 yyn = -yyn;
1625 goto yyreduce;
1628 if (yyn == YYFINAL)
1629 YYACCEPT;
1631 /* Count tokens shifted since error; after three, turn off error
1632 status. */
1633 if (yyerrstatus)
1634 yyerrstatus--;
1636 /* Shift the look-ahead token. */
1637 YY_SYMBOL_PRINT ("Shifting", yytoken, &yylval, &yylloc);
1639 /* Discard the shifted token unless it is eof. */
1640 if (yychar != YYEOF)
1641 yychar = YYEMPTY;
1643 yystate = yyn;
1644 *++yyvsp = yylval;
1645 *++yylsp = yylloc;
1646 goto yynewstate;
1649 /*-----------------------------------------------------------.
1650 | yydefault -- do the default action for the current state. |
1651 `-----------------------------------------------------------*/
1652 yydefault:
1653 yyn = yydefact[yystate];
1654 if (yyn == 0)
1655 goto yyerrlab;
1656 goto yyreduce;
1659 /*-----------------------------.
1660 | yyreduce -- Do a reduction. |
1661 `-----------------------------*/
1662 yyreduce:
1663 /* yyn is the number of a rule to reduce with. */
1664 yylen = yyr2[yyn];
1666 /* If YYLEN is nonzero, implement the default value of the action:
1667 `$$ = $1'.
1669 Otherwise, the following line sets YYVAL to garbage.
1670 This behavior is undocumented and Bison
1671 users should not rely upon it. Assigning to YYVAL
1672 unconditionally makes the parser a bit smaller, and it avoids a
1673 GCC warning that YYVAL may be used uninitialized. */
1674 yyval = yyvsp[1-yylen];
1676 /* Default location. */
1677 YYLLOC_DEFAULT (yyloc, (yylsp - yylen), yylen);
1678 YY_REDUCE_PRINT (yyn);
1679 switch (yyn)
1681 case 2:
1682 #line 168 "ast_expr2.y"
1683 { ((struct parse_io *)parseio)->val = (struct val *)calloc(sizeof(struct val),1);
1684 ((struct parse_io *)parseio)->val->type = (yyvsp[(1) - (1)].val)->type;
1685 if( (yyvsp[(1) - (1)].val)->type == AST_EXPR_integer )
1686 ((struct parse_io *)parseio)->val->u.i = (yyvsp[(1) - (1)].val)->u.i;
1687 else
1688 ((struct parse_io *)parseio)->val->u.s = (yyvsp[(1) - (1)].val)->u.s;
1689 free((yyvsp[(1) - (1)].val));
1691 break;
1693 case 3:
1694 #line 176 "ast_expr2.y"
1695 {/* nothing */ ((struct parse_io *)parseio)->val = (struct val *)calloc(sizeof(struct val),1);
1696 ((struct parse_io *)parseio)->val->type = AST_EXPR_string;
1697 ((struct parse_io *)parseio)->val->u.s = strdup("");
1699 break;
1701 case 4:
1702 #line 183 "ast_expr2.y"
1703 { (yyval.val)= (yyvsp[(1) - (1)].val);;}
1704 break;
1706 case 5:
1707 #line 184 "ast_expr2.y"
1708 { (yyval.val) = (yyvsp[(2) - (3)].val);
1709 (yyloc).first_column = (yylsp[(1) - (3)]).first_column; (yyloc).last_column = (yylsp[(3) - (3)]).last_column;
1710 (yyloc).first_line=0; (yyloc).last_line=0;
1711 DESTROY((yyvsp[(1) - (3)].val)); DESTROY((yyvsp[(3) - (3)].val)); ;}
1712 break;
1714 case 6:
1715 #line 188 "ast_expr2.y"
1716 { (yyval.val) = op_or ((yyvsp[(1) - (3)].val), (yyvsp[(3) - (3)].val));
1717 DESTROY((yyvsp[(2) - (3)].val));
1718 (yyloc).first_column = (yylsp[(1) - (3)]).first_column; (yyloc).last_column = (yylsp[(3) - (3)]).last_column;
1719 (yyloc).first_line=0; (yyloc).last_line=0;;}
1720 break;
1722 case 7:
1723 #line 192 "ast_expr2.y"
1724 { (yyval.val) = op_and ((yyvsp[(1) - (3)].val), (yyvsp[(3) - (3)].val));
1725 DESTROY((yyvsp[(2) - (3)].val));
1726 (yyloc).first_column = (yylsp[(1) - (3)]).first_column; (yyloc).last_column = (yylsp[(3) - (3)]).last_column;
1727 (yyloc).first_line=0; (yyloc).last_line=0;;}
1728 break;
1730 case 8:
1731 #line 196 "ast_expr2.y"
1732 { (yyval.val) = op_eq ((yyvsp[(1) - (3)].val), (yyvsp[(3) - (3)].val));
1733 DESTROY((yyvsp[(2) - (3)].val));
1734 (yyloc).first_column = (yylsp[(1) - (3)]).first_column; (yyloc).last_column = (yylsp[(3) - (3)]).last_column;
1735 (yyloc).first_line=0; (yyloc).last_line=0;;}
1736 break;
1738 case 9:
1739 #line 200 "ast_expr2.y"
1740 { (yyval.val) = op_gt ((yyvsp[(1) - (3)].val), (yyvsp[(3) - (3)].val));
1741 DESTROY((yyvsp[(2) - (3)].val));
1742 (yyloc).first_column = (yylsp[(1) - (3)]).first_column; (yyloc).last_column = (yylsp[(3) - (3)]).last_column;
1743 (yyloc).first_line=0; (yyloc).last_line=0;;}
1744 break;
1746 case 10:
1747 #line 204 "ast_expr2.y"
1748 { (yyval.val) = op_lt ((yyvsp[(1) - (3)].val), (yyvsp[(3) - (3)].val));
1749 DESTROY((yyvsp[(2) - (3)].val));
1750 (yyloc).first_column = (yylsp[(1) - (3)]).first_column; (yyloc).last_column = (yylsp[(3) - (3)]).last_column;
1751 (yyloc).first_line=0; (yyloc).last_line=0;;}
1752 break;
1754 case 11:
1755 #line 208 "ast_expr2.y"
1756 { (yyval.val) = op_ge ((yyvsp[(1) - (3)].val), (yyvsp[(3) - (3)].val));
1757 DESTROY((yyvsp[(2) - (3)].val));
1758 (yyloc).first_column = (yylsp[(1) - (3)]).first_column; (yyloc).last_column = (yylsp[(3) - (3)]).last_column;
1759 (yyloc).first_line=0; (yyloc).last_line=0;;}
1760 break;
1762 case 12:
1763 #line 212 "ast_expr2.y"
1764 { (yyval.val) = op_le ((yyvsp[(1) - (3)].val), (yyvsp[(3) - (3)].val));
1765 DESTROY((yyvsp[(2) - (3)].val));
1766 (yyloc).first_column = (yylsp[(1) - (3)]).first_column; (yyloc).last_column = (yylsp[(3) - (3)]).last_column;
1767 (yyloc).first_line=0; (yyloc).last_line=0;;}
1768 break;
1770 case 13:
1771 #line 216 "ast_expr2.y"
1772 { (yyval.val) = op_ne ((yyvsp[(1) - (3)].val), (yyvsp[(3) - (3)].val));
1773 DESTROY((yyvsp[(2) - (3)].val));
1774 (yyloc).first_column = (yylsp[(1) - (3)]).first_column; (yyloc).last_column = (yylsp[(3) - (3)]).last_column;
1775 (yyloc).first_line=0; (yyloc).last_line=0;;}
1776 break;
1778 case 14:
1779 #line 220 "ast_expr2.y"
1780 { (yyval.val) = op_plus ((yyvsp[(1) - (3)].val), (yyvsp[(3) - (3)].val));
1781 DESTROY((yyvsp[(2) - (3)].val));
1782 (yyloc).first_column = (yylsp[(1) - (3)]).first_column; (yyloc).last_column = (yylsp[(3) - (3)]).last_column;
1783 (yyloc).first_line=0; (yyloc).last_line=0;;}
1784 break;
1786 case 15:
1787 #line 224 "ast_expr2.y"
1788 { (yyval.val) = op_minus ((yyvsp[(1) - (3)].val), (yyvsp[(3) - (3)].val));
1789 DESTROY((yyvsp[(2) - (3)].val));
1790 (yyloc).first_column = (yylsp[(1) - (3)]).first_column; (yyloc).last_column = (yylsp[(3) - (3)]).last_column;
1791 (yyloc).first_line=0; (yyloc).last_line=0;;}
1792 break;
1794 case 16:
1795 #line 228 "ast_expr2.y"
1796 { (yyval.val) = op_negate ((yyvsp[(2) - (2)].val));
1797 DESTROY((yyvsp[(1) - (2)].val));
1798 (yyloc).first_column = (yylsp[(1) - (2)]).first_column; (yyloc).last_column = (yylsp[(2) - (2)]).last_column;
1799 (yyloc).first_line=0; (yyloc).last_line=0;;}
1800 break;
1802 case 17:
1803 #line 232 "ast_expr2.y"
1804 { (yyval.val) = op_compl ((yyvsp[(2) - (2)].val));
1805 DESTROY((yyvsp[(1) - (2)].val));
1806 (yyloc).first_column = (yylsp[(1) - (2)]).first_column; (yyloc).last_column = (yylsp[(2) - (2)]).last_column;
1807 (yyloc).first_line=0; (yyloc).last_line=0;;}
1808 break;
1810 case 18:
1811 #line 236 "ast_expr2.y"
1812 { (yyval.val) = op_times ((yyvsp[(1) - (3)].val), (yyvsp[(3) - (3)].val));
1813 DESTROY((yyvsp[(2) - (3)].val));
1814 (yyloc).first_column = (yylsp[(1) - (3)]).first_column; (yyloc).last_column = (yylsp[(3) - (3)]).last_column;
1815 (yyloc).first_line=0; (yyloc).last_line=0;;}
1816 break;
1818 case 19:
1819 #line 240 "ast_expr2.y"
1820 { (yyval.val) = op_div ((yyvsp[(1) - (3)].val), (yyvsp[(3) - (3)].val));
1821 DESTROY((yyvsp[(2) - (3)].val));
1822 (yyloc).first_column = (yylsp[(1) - (3)]).first_column; (yyloc).last_column = (yylsp[(3) - (3)]).last_column;
1823 (yyloc).first_line=0; (yyloc).last_line=0;;}
1824 break;
1826 case 20:
1827 #line 244 "ast_expr2.y"
1828 { (yyval.val) = op_rem ((yyvsp[(1) - (3)].val), (yyvsp[(3) - (3)].val));
1829 DESTROY((yyvsp[(2) - (3)].val));
1830 (yyloc).first_column = (yylsp[(1) - (3)]).first_column; (yyloc).last_column = (yylsp[(3) - (3)]).last_column;
1831 (yyloc).first_line=0; (yyloc).last_line=0;;}
1832 break;
1834 case 21:
1835 #line 248 "ast_expr2.y"
1836 { (yyval.val) = op_colon ((yyvsp[(1) - (3)].val), (yyvsp[(3) - (3)].val));
1837 DESTROY((yyvsp[(2) - (3)].val));
1838 (yyloc).first_column = (yylsp[(1) - (3)]).first_column; (yyloc).last_column = (yylsp[(3) - (3)]).last_column;
1839 (yyloc).first_line=0; (yyloc).last_line=0;;}
1840 break;
1842 case 22:
1843 #line 252 "ast_expr2.y"
1844 { (yyval.val) = op_eqtilde ((yyvsp[(1) - (3)].val), (yyvsp[(3) - (3)].val));
1845 DESTROY((yyvsp[(2) - (3)].val));
1846 (yyloc).first_column = (yylsp[(1) - (3)]).first_column; (yyloc).last_column = (yylsp[(3) - (3)]).last_column;
1847 (yyloc).first_line=0; (yyloc).last_line=0;;}
1848 break;
1850 case 23:
1851 #line 256 "ast_expr2.y"
1852 { (yyval.val) = op_cond ((yyvsp[(1) - (5)].val), (yyvsp[(3) - (5)].val), (yyvsp[(5) - (5)].val));
1853 DESTROY((yyvsp[(2) - (5)].val));
1854 DESTROY((yyvsp[(4) - (5)].val));
1855 (yyloc).first_column = (yylsp[(1) - (5)]).first_column; (yyloc).last_column = (yylsp[(3) - (5)]).last_column;
1856 (yyloc).first_line=0; (yyloc).last_line=0;;}
1857 break;
1860 /* Line 1270 of yacc.c. */
1861 #line 1857 "ast_expr2.c"
1862 default: break;
1864 YY_SYMBOL_PRINT ("-> $$ =", yyr1[yyn], &yyval, &yyloc);
1866 YYPOPSTACK (yylen);
1867 yylen = 0;
1868 YY_STACK_PRINT (yyss, yyssp);
1870 *++yyvsp = yyval;
1871 *++yylsp = yyloc;
1873 /* Now `shift' the result of the reduction. Determine what state
1874 that goes to, based on the state we popped back to and the rule
1875 number reduced by. */
1877 yyn = yyr1[yyn];
1879 yystate = yypgoto[yyn - YYNTOKENS] + *yyssp;
1880 if (0 <= yystate && yystate <= YYLAST && yycheck[yystate] == *yyssp)
1881 yystate = yytable[yystate];
1882 else
1883 yystate = yydefgoto[yyn - YYNTOKENS];
1885 goto yynewstate;
1888 /*------------------------------------.
1889 | yyerrlab -- here on detecting error |
1890 `------------------------------------*/
1891 yyerrlab:
1892 /* If not already recovering from an error, report this error. */
1893 if (!yyerrstatus)
1895 ++yynerrs;
1896 #if ! YYERROR_VERBOSE
1897 yyerror (YY_("syntax error"));
1898 #else
1900 YYSIZE_T yysize = yysyntax_error (0, yystate, yychar);
1901 if (yymsg_alloc < yysize && yymsg_alloc < YYSTACK_ALLOC_MAXIMUM)
1903 YYSIZE_T yyalloc = 2 * yysize;
1904 if (! (yysize <= yyalloc && yyalloc <= YYSTACK_ALLOC_MAXIMUM))
1905 yyalloc = YYSTACK_ALLOC_MAXIMUM;
1906 if (yymsg != yymsgbuf)
1907 YYSTACK_FREE (yymsg);
1908 yymsg = (char *) YYSTACK_ALLOC (yyalloc);
1909 if (yymsg)
1910 yymsg_alloc = yyalloc;
1911 else
1913 yymsg = yymsgbuf;
1914 yymsg_alloc = sizeof yymsgbuf;
1918 if (0 < yysize && yysize <= yymsg_alloc)
1920 (void) yysyntax_error (yymsg, yystate, yychar);
1921 yyerror (yymsg);
1923 else
1925 yyerror (YY_("syntax error"));
1926 if (yysize != 0)
1927 goto yyexhaustedlab;
1930 #endif
1933 yyerror_range[0] = yylloc;
1935 if (yyerrstatus == 3)
1937 /* If just tried and failed to reuse look-ahead token after an
1938 error, discard it. */
1940 if (yychar <= YYEOF)
1942 /* Return failure if at end of input. */
1943 if (yychar == YYEOF)
1944 YYABORT;
1946 else
1948 yydestruct ("Error: discarding",
1949 yytoken, &yylval, &yylloc);
1950 yychar = YYEMPTY;
1954 /* Else will try to reuse look-ahead token after shifting the error
1955 token. */
1956 goto yyerrlab1;
1959 /*---------------------------------------------------.
1960 | yyerrorlab -- error raised explicitly by YYERROR. |
1961 `---------------------------------------------------*/
1962 yyerrorlab:
1964 /* Pacify compilers like GCC when the user code never invokes
1965 YYERROR and the label yyerrorlab therefore never appears in user
1966 code. */
1967 if (/*CONSTCOND*/ 0)
1968 goto yyerrorlab;
1970 yyerror_range[0] = yylsp[1-yylen];
1971 /* Do not reclaim the symbols of the rule which action triggered
1972 this YYERROR. */
1973 YYPOPSTACK (yylen);
1974 yylen = 0;
1975 YY_STACK_PRINT (yyss, yyssp);
1976 yystate = *yyssp;
1977 goto yyerrlab1;
1980 /*-------------------------------------------------------------.
1981 | yyerrlab1 -- common code for both syntax error and YYERROR. |
1982 `-------------------------------------------------------------*/
1983 yyerrlab1:
1984 yyerrstatus = 3; /* Each real token shifted decrements this. */
1986 for (;;)
1988 yyn = yypact[yystate];
1989 if (yyn != YYPACT_NINF)
1991 yyn += YYTERROR;
1992 if (0 <= yyn && yyn <= YYLAST && yycheck[yyn] == YYTERROR)
1994 yyn = yytable[yyn];
1995 if (0 < yyn)
1996 break;
2000 /* Pop the current state because it cannot handle the error token. */
2001 if (yyssp == yyss)
2002 YYABORT;
2004 yyerror_range[0] = *yylsp;
2005 yydestruct ("Error: popping",
2006 yystos[yystate], yyvsp, yylsp);
2007 YYPOPSTACK (1);
2008 yystate = *yyssp;
2009 YY_STACK_PRINT (yyss, yyssp);
2012 if (yyn == YYFINAL)
2013 YYACCEPT;
2015 *++yyvsp = yylval;
2017 yyerror_range[1] = yylloc;
2018 /* Using YYLLOC is tempting, but would change the location of
2019 the look-ahead. YYLOC is available though. */
2020 YYLLOC_DEFAULT (yyloc, (yyerror_range - 1), 2);
2021 *++yylsp = yyloc;
2023 /* Shift the error token. */
2024 YY_SYMBOL_PRINT ("Shifting", yystos[yyn], yyvsp, yylsp);
2026 yystate = yyn;
2027 goto yynewstate;
2030 /*-------------------------------------.
2031 | yyacceptlab -- YYACCEPT comes here. |
2032 `-------------------------------------*/
2033 yyacceptlab:
2034 yyresult = 0;
2035 goto yyreturn;
2037 /*-----------------------------------.
2038 | yyabortlab -- YYABORT comes here. |
2039 `-----------------------------------*/
2040 yyabortlab:
2041 yyresult = 1;
2042 goto yyreturn;
2044 #ifndef yyoverflow
2045 /*-------------------------------------------------.
2046 | yyexhaustedlab -- memory exhaustion comes here. |
2047 `-------------------------------------------------*/
2048 yyexhaustedlab:
2049 yyerror (YY_("memory exhausted"));
2050 yyresult = 2;
2051 /* Fall through. */
2052 #endif
2054 yyreturn:
2055 if (yychar != YYEOF && yychar != YYEMPTY)
2056 yydestruct ("Cleanup: discarding lookahead",
2057 yytoken, &yylval, &yylloc);
2058 /* Do not reclaim the symbols of the rule which action triggered
2059 this YYABORT or YYACCEPT. */
2060 YYPOPSTACK (yylen);
2061 YY_STACK_PRINT (yyss, yyssp);
2062 while (yyssp != yyss)
2064 yydestruct ("Cleanup: popping",
2065 yystos[*yyssp], yyvsp, yylsp);
2066 YYPOPSTACK (1);
2068 #ifndef yyoverflow
2069 if (yyss != yyssa)
2070 YYSTACK_FREE (yyss);
2071 #endif
2072 #if YYERROR_VERBOSE
2073 if (yymsg != yymsgbuf)
2074 YYSTACK_FREE (yymsg);
2075 #endif
2076 return yyresult;
2080 #line 263 "ast_expr2.y"
2083 static struct val *
2084 make_integer (quad_t i)
2086 struct val *vp;
2088 vp = (struct val *) malloc (sizeof (*vp));
2089 if (vp == NULL) {
2090 ast_log(LOG_WARNING, "malloc() failed\n");
2091 return(NULL);
2094 vp->type = AST_EXPR_integer;
2095 vp->u.i = i;
2096 return vp;
2099 static struct val *
2100 make_str (const char *s)
2102 struct val *vp;
2103 size_t i;
2104 int isint;
2106 vp = (struct val *) malloc (sizeof (*vp));
2107 if (vp == NULL || ((vp->u.s = strdup (s)) == NULL)) {
2108 ast_log(LOG_WARNING,"malloc() failed\n");
2109 return(NULL);
2112 for(i = 1, isint = isdigit(s[0]) || s[0] == '-';
2113 isint && i < strlen(s);
2114 i++)
2116 if(!isdigit(s[i]))
2117 isint = 0;
2120 if (isint)
2121 vp->type = AST_EXPR_numeric_string;
2122 else
2123 vp->type = AST_EXPR_string;
2125 return vp;
2129 static void
2130 free_value (struct val *vp)
2132 if (vp==NULL) {
2133 return;
2135 if (vp->type == AST_EXPR_string || vp->type == AST_EXPR_numeric_string)
2136 free (vp->u.s);
2137 free(vp);
2141 static quad_t
2142 to_integer (struct val *vp)
2144 quad_t i;
2146 if (vp == NULL) {
2147 ast_log(LOG_WARNING,"vp==NULL in to_integer()\n");
2148 return(0);
2151 if (vp->type == AST_EXPR_integer)
2152 return 1;
2154 if (vp->type == AST_EXPR_string)
2155 return 0;
2157 /* vp->type == AST_EXPR_numeric_string, make it numeric */
2158 errno = 0;
2159 i = strtoll(vp->u.s, (char**)NULL, 10);
2160 if (errno != 0) {
2161 ast_log(LOG_WARNING,"Conversion of %s to integer under/overflowed!\n", vp->u.s);
2162 free(vp->u.s);
2163 vp->u.s = 0;
2164 return(0);
2166 free (vp->u.s);
2167 vp->u.i = i;
2168 vp->type = AST_EXPR_integer;
2169 return 1;
2172 static void
2173 strip_quotes(struct val *vp)
2175 if (vp->type != AST_EXPR_string && vp->type != AST_EXPR_numeric_string)
2176 return;
2178 if( vp->u.s[0] == '"' && vp->u.s[strlen(vp->u.s)-1] == '"' )
2180 char *f, *t;
2181 f = vp->u.s;
2182 t = vp->u.s;
2184 while( *f )
2186 if( *f && *f != '"' )
2187 *t++ = *f++;
2188 else
2189 f++;
2191 *t = *f;
2195 static void
2196 to_string (struct val *vp)
2198 char *tmp;
2200 if (vp->type == AST_EXPR_string || vp->type == AST_EXPR_numeric_string)
2201 return;
2203 tmp = malloc ((size_t)25);
2204 if (tmp == NULL) {
2205 ast_log(LOG_WARNING,"malloc() failed\n");
2206 return;
2209 sprintf(tmp, "%ld", (long int) vp->u.i);
2210 vp->type = AST_EXPR_string;
2211 vp->u.s = tmp;
2215 static int
2216 isstring (struct val *vp)
2218 /* only TRUE if this string is not a valid integer */
2219 return (vp->type == AST_EXPR_string);
2223 static int
2224 is_zero_or_null (struct val *vp)
2226 if (vp->type == AST_EXPR_integer) {
2227 return (vp->u.i == 0);
2228 } else {
2229 return (*vp->u.s == 0 || (to_integer (vp) && vp->u.i == 0));
2231 /* NOTREACHED */
2234 #ifdef STANDALONE
2236 void ast_log(int level, const char *file, int line, const char *function, const char *fmt, ...)
2238 va_list vars;
2239 va_start(vars,fmt);
2241 printf("LOG: lev:%d file:%s line:%d func: %s ",
2242 level, file, line, function);
2243 vprintf(fmt, vars);
2244 fflush(stdout);
2245 va_end(vars);
2249 int main(int argc,char **argv) {
2250 char s[4096];
2251 char out[4096];
2252 FILE *infile;
2254 if( !argv[1] )
2255 exit(20);
2257 if( access(argv[1],F_OK)== 0 )
2259 int ret;
2261 infile = fopen(argv[1],"r");
2262 if( !infile )
2264 printf("Sorry, couldn't open %s for reading!\n", argv[1]);
2265 exit(10);
2267 while( fgets(s,sizeof(s),infile) )
2269 if( s[strlen(s)-1] == '\n' )
2270 s[strlen(s)-1] = 0;
2272 ret = ast_expr(s, out, sizeof(out));
2273 printf("Expression: %s Result: [%d] '%s'\n",
2274 s, ret, out);
2276 fclose(infile);
2278 else
2280 if (ast_expr(argv[1], s, sizeof(s)))
2281 printf("=====%s======\n",s);
2282 else
2283 printf("No result\n");
2287 #endif
2289 #undef ast_yyerror
2290 #define ast_yyerror(x) ast_yyerror(x, YYLTYPE *yylloc, struct parse_io *parseio)
2292 /* I put the ast_yyerror func in the flex input file,
2293 because it refers to the buffer state. Best to
2294 let it access the BUFFER stuff there and not trying
2295 define all the structs, macros etc. in this file! */
2298 static struct val *
2299 op_or (struct val *a, struct val *b)
2301 if (is_zero_or_null (a)) {
2302 free_value (a);
2303 return (b);
2304 } else {
2305 free_value (b);
2306 return (a);
2310 static struct val *
2311 op_and (struct val *a, struct val *b)
2313 if (is_zero_or_null (a) || is_zero_or_null (b)) {
2314 free_value (a);
2315 free_value (b);
2316 return (make_integer ((quad_t)0));
2317 } else {
2318 free_value (b);
2319 return (a);
2323 static struct val *
2324 op_eq (struct val *a, struct val *b)
2326 struct val *r;
2328 if (isstring (a) || isstring (b)) {
2329 to_string (a);
2330 to_string (b);
2331 r = make_integer ((quad_t)(strcoll (a->u.s, b->u.s) == 0));
2332 } else {
2333 #ifdef DEBUG_FOR_CONVERSIONS
2334 char buffer[2000];
2335 sprintf(buffer,"Converting '%s' and '%s' ", a->u.s, b->u.s);
2336 #endif
2337 (void)to_integer(a);
2338 (void)to_integer(b);
2339 #ifdef DEBUG_FOR_CONVERSIONS
2340 ast_log(LOG_WARNING,"%s to '%lld' and '%lld'\n", buffer, a->u.i, b->u.i);
2341 #endif
2342 r = make_integer ((quad_t)(a->u.i == b->u.i));
2345 free_value (a);
2346 free_value (b);
2347 return r;
2350 static struct val *
2351 op_gt (struct val *a, struct val *b)
2353 struct val *r;
2355 if (isstring (a) || isstring (b)) {
2356 to_string (a);
2357 to_string (b);
2358 r = make_integer ((quad_t)(strcoll (a->u.s, b->u.s) > 0));
2359 } else {
2360 (void)to_integer(a);
2361 (void)to_integer(b);
2362 r = make_integer ((quad_t)(a->u.i > b->u.i));
2365 free_value (a);
2366 free_value (b);
2367 return r;
2370 static struct val *
2371 op_lt (struct val *a, struct val *b)
2373 struct val *r;
2375 if (isstring (a) || isstring (b)) {
2376 to_string (a);
2377 to_string (b);
2378 r = make_integer ((quad_t)(strcoll (a->u.s, b->u.s) < 0));
2379 } else {
2380 (void)to_integer(a);
2381 (void)to_integer(b);
2382 r = make_integer ((quad_t)(a->u.i < b->u.i));
2385 free_value (a);
2386 free_value (b);
2387 return r;
2390 static struct val *
2391 op_ge (struct val *a, struct val *b)
2393 struct val *r;
2395 if (isstring (a) || isstring (b)) {
2396 to_string (a);
2397 to_string (b);
2398 r = make_integer ((quad_t)(strcoll (a->u.s, b->u.s) >= 0));
2399 } else {
2400 (void)to_integer(a);
2401 (void)to_integer(b);
2402 r = make_integer ((quad_t)(a->u.i >= b->u.i));
2405 free_value (a);
2406 free_value (b);
2407 return r;
2410 static struct val *
2411 op_le (struct val *a, struct val *b)
2413 struct val *r;
2415 if (isstring (a) || isstring (b)) {
2416 to_string (a);
2417 to_string (b);
2418 r = make_integer ((quad_t)(strcoll (a->u.s, b->u.s) <= 0));
2419 } else {
2420 (void)to_integer(a);
2421 (void)to_integer(b);
2422 r = make_integer ((quad_t)(a->u.i <= b->u.i));
2425 free_value (a);
2426 free_value (b);
2427 return r;
2430 static struct val *
2431 op_cond (struct val *a, struct val *b, struct val *c)
2433 struct val *r;
2435 if( isstring(a) )
2437 if( strlen(a->u.s) && strcmp(a->u.s, "\"\"") != 0 && strcmp(a->u.s,"0") != 0 )
2439 free_value(a);
2440 free_value(c);
2441 r = b;
2443 else
2445 free_value(a);
2446 free_value(b);
2447 r = c;
2450 else
2452 (void)to_integer(a);
2453 if( a->u.i )
2455 free_value(a);
2456 free_value(c);
2457 r = b;
2459 else
2461 free_value(a);
2462 free_value(b);
2463 r = c;
2466 return r;
2469 static struct val *
2470 op_ne (struct val *a, struct val *b)
2472 struct val *r;
2474 if (isstring (a) || isstring (b)) {
2475 to_string (a);
2476 to_string (b);
2477 r = make_integer ((quad_t)(strcoll (a->u.s, b->u.s) != 0));
2478 } else {
2479 (void)to_integer(a);
2480 (void)to_integer(b);
2481 r = make_integer ((quad_t)(a->u.i != b->u.i));
2484 free_value (a);
2485 free_value (b);
2486 return r;
2489 static int
2490 chk_plus (quad_t a, quad_t b, quad_t r)
2492 /* sum of two positive numbers must be positive */
2493 if (a > 0 && b > 0 && r <= 0)
2494 return 1;
2495 /* sum of two negative numbers must be negative */
2496 if (a < 0 && b < 0 && r >= 0)
2497 return 1;
2498 /* all other cases are OK */
2499 return 0;
2502 static struct val *
2503 op_plus (struct val *a, struct val *b)
2505 struct val *r;
2507 if (!to_integer (a)) {
2508 if( !extra_error_message_supplied )
2509 ast_log(LOG_WARNING,"non-numeric argument\n");
2510 if (!to_integer (b)) {
2511 free_value(a);
2512 free_value(b);
2513 return make_integer(0);
2514 } else {
2515 free_value(a);
2516 return (b);
2518 } else if (!to_integer(b)) {
2519 free_value(b);
2520 return (a);
2523 r = make_integer (/*(quad_t)*/(a->u.i + b->u.i));
2524 if (chk_plus (a->u.i, b->u.i, r->u.i)) {
2525 ast_log(LOG_WARNING,"overflow\n");
2527 free_value (a);
2528 free_value (b);
2529 return r;
2532 static int
2533 chk_minus (quad_t a, quad_t b, quad_t r)
2535 /* special case subtraction of QUAD_MIN */
2536 if (b == QUAD_MIN) {
2537 if (a >= 0)
2538 return 1;
2539 else
2540 return 0;
2542 /* this is allowed for b != QUAD_MIN */
2543 return chk_plus (a, -b, r);
2546 static struct val *
2547 op_minus (struct val *a, struct val *b)
2549 struct val *r;
2551 if (!to_integer (a)) {
2552 if( !extra_error_message_supplied )
2553 ast_log(LOG_WARNING, "non-numeric argument\n");
2554 if (!to_integer (b)) {
2555 free_value(a);
2556 free_value(b);
2557 return make_integer(0);
2558 } else {
2559 r = make_integer(0 - b->u.i);
2560 free_value(a);
2561 free_value(b);
2562 return (r);
2564 } else if (!to_integer(b)) {
2565 if( !extra_error_message_supplied )
2566 ast_log(LOG_WARNING, "non-numeric argument\n");
2567 free_value(b);
2568 return (a);
2571 r = make_integer (/*(quad_t)*/(a->u.i - b->u.i));
2572 if (chk_minus (a->u.i, b->u.i, r->u.i)) {
2573 ast_log(LOG_WARNING, "overflow\n");
2575 free_value (a);
2576 free_value (b);
2577 return r;
2580 static struct val *
2581 op_negate (struct val *a)
2583 struct val *r;
2585 if (!to_integer (a) ) {
2586 free_value(a);
2587 if( !extra_error_message_supplied )
2588 ast_log(LOG_WARNING, "non-numeric argument\n");
2589 return make_integer(0);
2592 r = make_integer (/*(quad_t)*/(- a->u.i));
2593 if (chk_minus (0, a->u.i, r->u.i)) {
2594 ast_log(LOG_WARNING, "overflow\n");
2596 free_value (a);
2597 return r;
2600 static struct val *
2601 op_compl (struct val *a)
2603 int v1 = 1;
2604 struct val *r;
2606 if( !a )
2608 v1 = 0;
2610 else
2612 switch( a->type )
2614 case AST_EXPR_integer:
2615 if( a->u.i == 0 )
2616 v1 = 0;
2617 break;
2619 case AST_EXPR_string:
2620 if( a->u.s == 0 )
2621 v1 = 0;
2622 else
2624 if( a->u.s[0] == 0 )
2625 v1 = 0;
2626 else if (strlen(a->u.s) == 1 && a->u.s[0] == '0' )
2627 v1 = 0;
2629 break;
2631 case AST_EXPR_numeric_string:
2632 if( a->u.s == 0 )
2633 v1 = 0;
2634 else
2636 if( a->u.s[0] == 0 )
2637 v1 = 0;
2638 else if (strlen(a->u.s) == 1 && a->u.s[0] == '0' )
2639 v1 = 0;
2641 break;
2645 r = make_integer (!v1);
2646 free_value (a);
2647 return r;
2650 static int
2651 chk_times (quad_t a, quad_t b, quad_t r)
2653 /* special case: first operand is 0, no overflow possible */
2654 if (a == 0)
2655 return 0;
2656 /* cerify that result of division matches second operand */
2657 if (r / a != b)
2658 return 1;
2659 return 0;
2662 static struct val *
2663 op_times (struct val *a, struct val *b)
2665 struct val *r;
2667 if (!to_integer (a) || !to_integer (b)) {
2668 free_value(a);
2669 free_value(b);
2670 if( !extra_error_message_supplied )
2671 ast_log(LOG_WARNING, "non-numeric argument\n");
2672 return(make_integer(0));
2675 r = make_integer (/*(quad_t)*/(a->u.i * b->u.i));
2676 if (chk_times (a->u.i, b->u.i, r->u.i)) {
2677 ast_log(LOG_WARNING, "overflow\n");
2679 free_value (a);
2680 free_value (b);
2681 return (r);
2684 static int
2685 chk_div (quad_t a, quad_t b)
2687 /* div by zero has been taken care of before */
2688 /* only QUAD_MIN / -1 causes overflow */
2689 if (a == QUAD_MIN && b == -1)
2690 return 1;
2691 /* everything else is OK */
2692 return 0;
2695 static struct val *
2696 op_div (struct val *a, struct val *b)
2698 struct val *r;
2700 if (!to_integer (a)) {
2701 free_value(a);
2702 free_value(b);
2703 if( !extra_error_message_supplied )
2704 ast_log(LOG_WARNING, "non-numeric argument\n");
2705 return make_integer(0);
2706 } else if (!to_integer (b)) {
2707 free_value(a);
2708 free_value(b);
2709 if( !extra_error_message_supplied )
2710 ast_log(LOG_WARNING, "non-numeric argument\n");
2711 return make_integer(INT_MAX);
2714 if (b->u.i == 0) {
2715 ast_log(LOG_WARNING, "division by zero\n");
2716 free_value(a);
2717 free_value(b);
2718 return make_integer(INT_MAX);
2721 r = make_integer (/*(quad_t)*/(a->u.i / b->u.i));
2722 if (chk_div (a->u.i, b->u.i)) {
2723 ast_log(LOG_WARNING, "overflow\n");
2725 free_value (a);
2726 free_value (b);
2727 return r;
2730 static struct val *
2731 op_rem (struct val *a, struct val *b)
2733 struct val *r;
2735 if (!to_integer (a) || !to_integer (b)) {
2736 if( !extra_error_message_supplied )
2737 ast_log(LOG_WARNING, "non-numeric argument\n");
2738 free_value(a);
2739 free_value(b);
2740 return make_integer(0);
2743 if (b->u.i == 0) {
2744 ast_log(LOG_WARNING, "div by zero\n");
2745 free_value(a);
2746 return(b);
2749 r = make_integer (/*(quad_t)*/(a->u.i % b->u.i));
2750 /* chk_rem necessary ??? */
2751 free_value (a);
2752 free_value (b);
2753 return r;
2757 static struct val *
2758 op_colon (struct val *a, struct val *b)
2760 regex_t rp;
2761 regmatch_t rm[2];
2762 char errbuf[256];
2763 int eval;
2764 struct val *v;
2766 /* coerce to both arguments to strings */
2767 to_string(a);
2768 to_string(b);
2769 /* strip double quotes from both -- they'll screw up the pattern, and the search string starting at ^ */
2770 strip_quotes(a);
2771 strip_quotes(b);
2772 /* compile regular expression */
2773 if ((eval = regcomp (&rp, b->u.s, REG_EXTENDED)) != 0) {
2774 regerror (eval, &rp, errbuf, sizeof(errbuf));
2775 ast_log(LOG_WARNING,"regcomp() error : %s",errbuf);
2776 free_value(a);
2777 free_value(b);
2778 return make_str("");
2781 /* compare string against pattern */
2782 /* remember that patterns are anchored to the beginning of the line */
2783 if (regexec(&rp, a->u.s, (size_t)2, rm, 0) == 0 && rm[0].rm_so == 0) {
2784 if (rm[1].rm_so >= 0) {
2785 *(a->u.s + rm[1].rm_eo) = '\0';
2786 v = make_str (a->u.s + rm[1].rm_so);
2788 } else {
2789 v = make_integer ((quad_t)(rm[0].rm_eo - rm[0].rm_so));
2791 } else {
2792 if (rp.re_nsub == 0) {
2793 v = make_integer ((quad_t)0);
2794 } else {
2795 v = make_str ("");
2799 /* free arguments and pattern buffer */
2800 free_value (a);
2801 free_value (b);
2802 regfree (&rp);
2804 return v;
2808 static struct val *
2809 op_eqtilde (struct val *a, struct val *b)
2811 regex_t rp;
2812 regmatch_t rm[2];
2813 char errbuf[256];
2814 int eval;
2815 struct val *v;
2817 /* coerce to both arguments to strings */
2818 to_string(a);
2819 to_string(b);
2820 /* strip double quotes from both -- they'll screw up the pattern, and the search string starting at ^ */
2821 strip_quotes(a);
2822 strip_quotes(b);
2823 /* compile regular expression */
2824 if ((eval = regcomp (&rp, b->u.s, REG_EXTENDED)) != 0) {
2825 regerror (eval, &rp, errbuf, sizeof(errbuf));
2826 ast_log(LOG_WARNING,"regcomp() error : %s",errbuf);
2827 free_value(a);
2828 free_value(b);
2829 return make_str("");
2832 /* compare string against pattern */
2833 /* remember that patterns are anchored to the beginning of the line */
2834 if (regexec(&rp, a->u.s, (size_t)2, rm, 0) == 0 ) {
2835 if (rm[1].rm_so >= 0) {
2836 *(a->u.s + rm[1].rm_eo) = '\0';
2837 v = make_str (a->u.s + rm[1].rm_so);
2839 } else {
2840 v = make_integer ((quad_t)(rm[0].rm_eo - rm[0].rm_so));
2842 } else {
2843 if (rp.re_nsub == 0) {
2844 v = make_integer ((quad_t)0);
2845 } else {
2846 v = make_str ("");
2850 /* free arguments and pattern buffer */
2851 free_value (a);
2852 free_value (b);
2853 regfree (&rp);
2855 return v;