Newer
Older
Kevin P. Fleming
committed
/* A Bison parser, made by GNU Bison 2.1a. */
/* Skeleton parser for Yacc-like parsing with Bison,
Kevin P. Fleming
committed
Copyright (C) 1984, 1989, 1990, 2000, 2001, 2002, 2003, 2004, 2005, 2006 Free Software Foundation, Inc.
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2, or (at your option)
any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor,
Boston, MA 02110-1301, USA. */
/* As a special exception, when this file is copied by Bison into a
Bison output file, you may use that output file without restriction.
This special exception was added by the Free Software Foundation
in version 1.24 of Bison. */
Kevin P. Fleming
committed
/* C LALR(1) parser skeleton written by Richard Stallman, by
simplifying the original so-called "semantic" parser. */
/* All symbols defined below should begin with yy or YY, to avoid
infringing on user name space. This should be done even for local
variables, as they might otherwise be expanded by user macros.
There are some unavoidable exceptions within include files to
define necessary library symbols; they are noted "INFRINGES ON
USER NAME SPACE" below. */
/* Identify Bison output. */
#define YYBISON 1
Kevin P. Fleming
committed
#define YYBISON_VERSION "2.1a"
/* Skeleton name. */
#define YYSKELETON_NAME "yacc.c"
/* Pure parsers. */
#define YYPURE 1
/* Using locations. */
#define YYLSP_NEEDED 1
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
#define yyparse ast_yyparse
#define yylex ast_yylex
#define yyerror ast_yyerror
#define yylval ast_yylval
#define yychar ast_yychar
#define yydebug ast_yydebug
#define yynerrs ast_yynerrs
#define yylloc ast_yylloc
/* Tokens. */
#ifndef YYTOKENTYPE
# define YYTOKENTYPE
/* Put the tokens into the symbol table, so that GDB and other debuggers
know about them. */
enum yytokentype {
TOK_COLONCOLON = 258,
TOK_COND = 259,
TOK_OR = 260,
TOK_AND = 261,
TOK_NE = 262,
TOK_LE = 263,
TOK_GE = 264,
TOK_LT = 265,
TOK_GT = 266,
TOK_EQ = 267,
TOK_MINUS = 268,
TOK_PLUS = 269,
TOK_MOD = 270,
TOK_DIV = 271,
TOK_MULT = 272,
TOK_COMPL = 273,
TOK_EQTILDE = 274,
TOK_COLON = 275,
TOK_LP = 276,
TOK_RP = 277,
TOKEN = 278
};
#endif
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
#define TOK_COLONCOLON 258
#define TOK_COND 259
#define TOK_OR 260
#define TOK_AND 261
#define TOK_NE 262
#define TOK_LE 263
#define TOK_GE 264
#define TOK_LT 265
#define TOK_GT 266
#define TOK_EQ 267
#define TOK_MINUS 268
#define TOK_PLUS 269
#define TOK_MOD 270
#define TOK_DIV 271
#define TOK_MULT 272
#define TOK_COMPL 273
#define TOK_EQTILDE 274
#define TOK_COLON 275
#define TOK_LP 276
#define TOK_RP 277
#define TOKEN 278
/* Copy the first part of user declarations. */
#line 1 "ast_expr2.y"
/* Written by Pace Willisson (pace@blitz.com)
* and placed in the public domain.
*
* Largely rewritten by J.T. Conklin (jtc@wimsey.com)
*
* And then overhauled twice by Steve Murphy (murf@e-tools.com)
* to add double-quoted strings, allow mult. spaces, improve
* error messages, and then to fold in a flex scanner for the
* yylex operation.
*
* $FreeBSD: src/bin/expr/expr.y,v 1.16 2000/07/22 10:59:36 se Exp $
*/
#include <sys/types.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <locale.h>
Kevin P. Fleming
committed
#include <unistd.h>
#include <ctype.h>
#include <err.h>
#else
#define quad_t int64_t
#endif
#include <errno.h>
#include <regex.h>
#include <limits.h>
Kevin P. Fleming
committed
#include "asterisk.h"
ASTERISK_FILE_VERSION(__FILE__, "$Revision$")
#include "asterisk/ast_expr.h"
#include "asterisk/logger.h"
#if defined(LONG_LONG_MIN) && !defined(QUAD_MIN)
#define QUAD_MIN LONG_LONG_MIN
#endif
#if defined(LONG_LONG_MAX) && !defined(QUAD_MAX)
#define QUAD_MAX LONG_LONG_MAX
#endif
# if ! defined(QUAD_MIN)
# define QUAD_MIN (-0x7fffffffffffffffLL-1)
# endif
# if ! defined(QUAD_MAX)
# define QUAD_MAX (0x7fffffffffffffffLL)
# endif
#define YYPARSE_PARAM parseio
#define YYLEX_PARAM ((struct parse_io *)parseio)->scanner
#define YYERROR_VERBOSE 1
Kevin P. Fleming
committed
extern char extra_error_message[4095];
extern int extra_error_message_supplied;
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
enum valtype {
AST_EXPR_integer, AST_EXPR_numeric_string, AST_EXPR_string
} ;
#ifdef STANDALONE
void ast_log(int level, const char *file, int line, const char *function, const char *fmt, ...) __attribute__ ((format (printf,5,6)));
#endif
struct val {
enum valtype type;
union {
char *s;
quad_t i;
} u;
} ;
typedef void *yyscan_t;
struct parse_io
{
char *string;
struct val *val;
yyscan_t scanner;
};
static int chk_div __P((quad_t, quad_t));
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
static int chk_minus __P((quad_t, quad_t, quad_t));
static int chk_plus __P((quad_t, quad_t, quad_t));
static int chk_times __P((quad_t, quad_t, quad_t));
static void free_value __P((struct val *));
static int is_zero_or_null __P((struct val *));
static int isstring __P((struct val *));
static struct val *make_integer __P((quad_t));
static struct val *make_str __P((const char *));
static struct val *op_and __P((struct val *, struct val *));
static struct val *op_colon __P((struct val *, struct val *));
static struct val *op_eqtilde __P((struct val *, struct val *));
static struct val *op_div __P((struct val *, struct val *));
static struct val *op_eq __P((struct val *, struct val *));
static struct val *op_ge __P((struct val *, struct val *));
static struct val *op_gt __P((struct val *, struct val *));
static struct val *op_le __P((struct val *, struct val *));
static struct val *op_lt __P((struct val *, struct val *));
static struct val *op_cond __P((struct val *, struct val *, struct val *));
static struct val *op_minus __P((struct val *, struct val *));
static struct val *op_negate __P((struct val *));
static struct val *op_compl __P((struct val *));
static struct val *op_ne __P((struct val *, struct val *));
static struct val *op_or __P((struct val *, struct val *));
static struct val *op_plus __P((struct val *, struct val *));
static struct val *op_rem __P((struct val *, struct val *));
static struct val *op_times __P((struct val *, struct val *));
static quad_t to_integer __P((struct val *));
static void to_string __P((struct val *));
/* uh, if I want to predeclare yylex with a YYLTYPE, I have to predeclare the yyltype... sigh */
typedef struct yyltype
{
int first_line;
int first_column;
int last_line;
int last_column;
} yyltype;
# define YYLTYPE yyltype
# define YYLTYPE_IS_TRIVIAL 1
/* we will get warning about no prototype for yylex! But we can't
define it here, we have no definition yet for YYSTYPE. */
int ast_yyerror(const char *,YYLTYPE *, struct parse_io *);
/* I wanted to add args to the yyerror routine, so I could print out
some useful info about the error. Not as easy as it looks, but it
is possible. */
#define ast_yyerror(x) ast_yyerror(x,&yyloc,parseio)
Kevin P. Fleming
committed
#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);}
/* Enabling traces. */
#ifndef YYDEBUG
# define YYDEBUG 0
#endif
/* Enabling verbose error messages. */
#ifdef YYERROR_VERBOSE
# undef YYERROR_VERBOSE
# define YYERROR_VERBOSE 1
#else
# define YYERROR_VERBOSE 0
#endif
/* Enabling the token table. */
#ifndef YYTOKEN_TABLE
# define YYTOKEN_TABLE 0
#endif
Kevin P. Fleming
committed
#if ! defined YYSTYPE && ! defined YYSTYPE_IS_DECLARED
typedef union YYSTYPE
#line 140 "ast_expr2.y"
{
struct val *val;
Kevin P. Fleming
committed
}
/* Line 198 of yacc.c. */
#line 276 "ast_expr2.c"
YYSTYPE;
# define yystype YYSTYPE /* obsolescent; will be withdrawn */
# define YYSTYPE_IS_DECLARED 1
# define YYSTYPE_IS_TRIVIAL 1
#endif
Kevin P. Fleming
committed
#if ! defined YYLTYPE && ! defined YYLTYPE_IS_DECLARED
typedef struct YYLTYPE
{
int first_line;
int first_column;
int last_line;
int last_column;
} YYLTYPE;
# define yyltype YYLTYPE /* obsolescent; will be withdrawn */
# define YYLTYPE_IS_DECLARED 1
# define YYLTYPE_IS_TRIVIAL 1
#endif
/* Copy the second part of user declarations. */
Kevin P. Fleming
committed
#line 144 "ast_expr2.y"
extern int ast_yylex __P((YYSTYPE *, YYLTYPE *, yyscan_t));
Kevin P. Fleming
committed
/* Line 221 of yacc.c. */
Kevin P. Fleming
committed
#ifdef short
# undef short
#endif
#ifdef YYTYPE_UINT8
typedef YYTYPE_UINT8 yytype_uint8;
#else
typedef unsigned char yytype_uint8;
#endif
#ifdef YYTYPE_INT8
typedef YYTYPE_INT8 yytype_int8;
#elif (defined __STDC__ || defined __C99__FUNC__ \
|| defined __cplusplus || defined _MSC_VER)
typedef signed char yytype_int8;
#else
typedef short int yytype_int8;
Kevin P. Fleming
committed
#ifdef YYTYPE_UINT16
typedef YYTYPE_UINT16 yytype_uint16;
#else
typedef unsigned short int yytype_uint16;
Kevin P. Fleming
committed
#ifdef YYTYPE_INT16
typedef YYTYPE_INT16 yytype_int16;
#else
typedef short int yytype_int16;
Kevin P. Fleming
committed
#ifndef YYSIZE_T
# ifdef __SIZE_TYPE__
# define YYSIZE_T __SIZE_TYPE__
# elif defined size_t
# define YYSIZE_T size_t
# elif ! defined YYSIZE_T && (defined __STDC__ || defined __C99__FUNC__ \
|| defined __cplusplus || defined _MSC_VER)
# include <stddef.h> /* INFRINGES ON USER NAME SPACE */
# define YYSIZE_T size_t
# else
# define YYSIZE_T unsigned int
# endif
Kevin P. Fleming
committed
#define YYSIZE_MAXIMUM ((YYSIZE_T) -1)
#ifndef YY_
# if YYENABLE_NLS
# if ENABLE_NLS
# include <libintl.h> /* INFRINGES ON USER NAME SPACE */
# define YY_(msgid) dgettext ("bison-runtime", msgid)
# endif
# endif
# ifndef YY_
# define YY_(msgid) msgid
# endif
Kevin P. Fleming
committed
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
/* Suppress unused-variable warnings by "using" E. */
#if ! defined lint || defined __GNUC__
# define YYUSE(e) ((void) (e))
#else
# define YYUSE(e) /* empty */
#endif
/* Identity function, used to suppress warnings about constant conditions. */
#ifndef lint
# define YYID(n) (n)
#else
#if (defined __STDC__ || defined __C99__FUNC__ \
|| defined __cplusplus || defined _MSC_VER)
static int
YYID (int i)
#else
static int
YYID (i)
int i;
#endif
{
return i;
}
#endif
#if ! defined yyoverflow || YYERROR_VERBOSE
/* The parser invokes alloca or malloc; define the necessary symbols. */
# ifdef YYSTACK_USE_ALLOCA
# if YYSTACK_USE_ALLOCA
# ifdef __GNUC__
# define YYSTACK_ALLOC __builtin_alloca
Kevin P. Fleming
committed
# elif defined __BUILTIN_VA_ARG_INCR
# include <alloca.h> /* INFRINGES ON USER NAME SPACE */
# elif defined _AIX
# define YYSTACK_ALLOC __alloca
# elif defined _MSC_VER
# include <malloc.h> /* INFRINGES ON USER NAME SPACE */
# define alloca _alloca
Kevin P. Fleming
committed
# if ! defined _ALLOCA_H && ! defined _STDLIB_H && (defined __STDC__ || defined __C99__FUNC__ \
|| defined __cplusplus || defined _MSC_VER)
# include <stdlib.h> /* INFRINGES ON USER NAME SPACE */
Kevin P. Fleming
committed
# ifndef _STDLIB_H
# define _STDLIB_H 1
# endif
# endif
# endif
# endif
# ifdef YYSTACK_ALLOC
Kevin P. Fleming
committed
/* Pacify GCC's `empty if-body' warning. */
# define YYSTACK_FREE(Ptr) do { /* empty */; } while (YYID (0))
# ifndef YYSTACK_ALLOC_MAXIMUM
/* The OS might guarantee only one guard page at the bottom of the stack,
and a page size can be as small as 4096 bytes. So we cannot safely
invoke alloca (N) if N exceeds 4096. Use a slightly smaller number
to allow for a few compiler-allocated temporary stack slots. */
Kevin P. Fleming
committed
# define YYSTACK_ALLOC_MAXIMUM 4032 /* reasonable circa 2006 */
# endif
# define YYSTACK_ALLOC YYMALLOC
# define YYSTACK_FREE YYFREE
# ifndef YYSTACK_ALLOC_MAXIMUM
Kevin P. Fleming
committed
# define YYSTACK_ALLOC_MAXIMUM YYSIZE_MAXIMUM
# endif
# ifdef __cplusplus
extern "C" {
# endif
# ifndef YYMALLOC
# define YYMALLOC malloc
Kevin P. Fleming
committed
# if ! defined malloc && ! defined _STDLIB_H && (defined __STDC__ || defined __C99__FUNC__ \
|| defined __cplusplus || defined _MSC_VER)
void *malloc (YYSIZE_T); /* INFRINGES ON USER NAME SPACE */
# endif
# endif
# ifndef YYFREE
# define YYFREE free
Kevin P. Fleming
committed
# if ! defined free && ! defined _STDLIB_H && (defined __STDC__ || defined __C99__FUNC__ \
|| defined __cplusplus || defined _MSC_VER)
void free (void *); /* INFRINGES ON USER NAME SPACE */
# endif
# endif
# ifdef __cplusplus
}
# endif
# endif
Kevin P. Fleming
committed
#endif /* ! defined yyoverflow || YYERROR_VERBOSE */
Kevin P. Fleming
committed
#if (! defined yyoverflow \
&& (! defined __cplusplus \
|| (defined YYLTYPE_IS_TRIVIAL && YYLTYPE_IS_TRIVIAL \
&& defined YYSTYPE_IS_TRIVIAL && YYSTYPE_IS_TRIVIAL)))
/* A type that is properly aligned for any stack member. */
union yyalloc
{
Kevin P. Fleming
committed
yytype_int16 yyss;
YYSTYPE yyvs;
YYLTYPE yyls;
};
/* The size of the maximum gap between one aligned stack and the next. */
# define YYSTACK_GAP_MAXIMUM (sizeof (union yyalloc) - 1)
/* The size of an array large to enough to hold all stacks, each with
N elements. */
# define YYSTACK_BYTES(N) \
Kevin P. Fleming
committed
((N) * (sizeof (yytype_int16) + sizeof (YYSTYPE) + sizeof (YYLTYPE)) \
+ 2 * YYSTACK_GAP_MAXIMUM)
/* Copy COUNT objects from FROM to TO. The source and destination do
not overlap. */
# ifndef YYCOPY
Kevin P. Fleming
committed
# if defined __GNUC__ && 1 < __GNUC__
# define YYCOPY(To, From, Count) \
__builtin_memcpy (To, From, (Count) * sizeof (*(From)))
# else
# define YYCOPY(To, From, Count) \
do \
{ \
for (yyi = 0; yyi < (Count); yyi++) \
(To)[yyi] = (From)[yyi]; \
} \
Kevin P. Fleming
committed
while (YYID (0))
# endif
# endif
/* Relocate STACK from its old location to the new one. The
local variables YYSIZE and YYSTACKSIZE give the old and new number of
elements in the stack, and YYPTR gives the new location of the
stack. Advance YYPTR to a properly aligned location for the next
stack. */
# define YYSTACK_RELOCATE(Stack) \
do \
{ \
YYSIZE_T yynewbytes; \
YYCOPY (&yyptr->Stack, Stack, yysize); \
Stack = &yyptr->Stack; \
yynewbytes = yystacksize * sizeof (*Stack) + YYSTACK_GAP_MAXIMUM; \
yyptr += yynewbytes / sizeof (*yyptr); \
} \
Kevin P. Fleming
committed
while (YYID (0))
#endif
Kevin P. Fleming
committed
/* YYFINAL -- State number of the termination state. */
#define YYFINAL 10
/* YYLAST -- Last index in YYTABLE. */
#define YYLAST 140
Kevin P. Fleming
committed
/* YYNTOKENS -- Number of terminals. */
#define YYNTOKENS 24
Kevin P. Fleming
committed
/* YYNNTS -- Number of nonterminals. */
#define YYNNTS 3
Kevin P. Fleming
committed
/* YYNRULES -- Number of rules. */
#define YYNRULES 23
/* YYNRULES -- Number of states. */
#define YYNSTATES 46
/* YYTRANSLATE(YYLEX) -- Bison symbol number corresponding to YYLEX. */
#define YYUNDEFTOK 2
#define YYMAXUTOK 278
((unsigned int) (YYX) <= YYMAXUTOK ? yytranslate[YYX] : YYUNDEFTOK)
/* YYTRANSLATE[YYLEX] -- Bison symbol number corresponding to YYLEX. */
Kevin P. Fleming
committed
static const yytype_uint8 yytranslate[] =
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
{
0, 2, 2, 2, 2, 2, 2, 2, 2, 2,
2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
2, 2, 2, 2, 2, 2, 1, 2, 3, 4,
5, 6, 7, 8, 9, 10, 11, 12, 13, 14,
15, 16, 17, 18, 19, 20, 21, 22, 23
};
#if YYDEBUG
/* YYPRHS[YYN] -- Index of the first RHS symbol of rule number YYN in
YYRHS. */
Kevin P. Fleming
committed
static const yytype_uint8 yyprhs[] =
Kevin P. Fleming
committed
0, 0, 3, 5, 6, 8, 12, 16, 20, 24,
28, 32, 36, 40, 44, 48, 52, 55, 58, 62,
66, 70, 74, 78
};
Kevin P. Fleming
committed
/* YYRHS -- A `-1'-separated list of the rules' RHS. */
static const yytype_int8 yyrhs[] =
Kevin P. Fleming
committed
25, 0, -1, 26, -1, -1, 23, -1, 21, 26,
22, -1, 26, 5, 26, -1, 26, 6, 26, -1,
26, 12, 26, -1, 26, 11, 26, -1, 26, 10,
26, -1, 26, 9, 26, -1, 26, 8, 26, -1,
26, 7, 26, -1, 26, 14, 26, -1, 26, 13,
26, -1, 13, 26, -1, 18, 26, -1, 26, 17,
26, -1, 26, 16, 26, -1, 26, 15, 26, -1,
26, 20, 26, -1, 26, 19, 26, -1, 26, 4,
26, 3, 26, -1
};
/* YYRLINE[YYN] -- source line where rule number YYN was defined. */
Kevin P. Fleming
committed
static const yytype_uint16 yyrline[] =
Kevin P. Fleming
committed
0, 168, 168, 176, 183, 184, 188, 192, 196, 200,
204, 208, 212, 216, 220, 224, 228, 232, 236, 240,
244, 248, 252, 256
};
#endif
#if YYDEBUG || YYERROR_VERBOSE || YYTOKEN_TABLE
/* YYTNAME[SYMBOL-NUM] -- String name of the symbol SYMBOL-NUM.
Kevin P. Fleming
committed
First, the terminals, then, starting at YYNTOKENS, nonterminals. */
static const char *const yytname[] =
{
"$end", "error", "$undefined", "TOK_COLONCOLON", "TOK_COND", "TOK_OR",
"TOK_AND", "TOK_NE", "TOK_LE", "TOK_GE", "TOK_LT", "TOK_GT", "TOK_EQ",
"TOK_MINUS", "TOK_PLUS", "TOK_MOD", "TOK_DIV", "TOK_MULT", "TOK_COMPL",
"TOK_EQTILDE", "TOK_COLON", "TOK_LP", "TOK_RP", "TOKEN", "$accept",
"start", "expr", 0
};
#endif
# ifdef YYPRINT
/* YYTOKNUM[YYLEX-NUM] -- Internal token number corresponding to
token YYLEX-NUM. */
Kevin P. Fleming
committed
static const yytype_uint16 yytoknum[] =
{
0, 256, 257, 258, 259, 260, 261, 262, 263, 264,
265, 266, 267, 268, 269, 270, 271, 272, 273, 274,
275, 276, 277, 278
};
# endif
/* YYR1[YYN] -- Symbol number of symbol that rule YYN derives. */
Kevin P. Fleming
committed
static const yytype_uint8 yyr1[] =
Kevin P. Fleming
committed
0, 24, 25, 25, 26, 26, 26, 26, 26, 26,
26, 26, 26, 26, 26, 26, 26, 26, 26, 26,
Kevin P. Fleming
committed
26, 26, 26, 26
};
/* YYR2[YYN] -- Number of symbols composing right hand side of rule YYN. */
Kevin P. Fleming
committed
static const yytype_uint8 yyr2[] =
Kevin P. Fleming
committed
0, 2, 1, 0, 1, 3, 3, 3, 3, 3,
3, 3, 3, 3, 3, 3, 2, 2, 3, 3,
3, 3, 3, 5
};
/* YYDEFACT[STATE-NAME] -- Default rule to reduce with in state
STATE-NUM when YYTABLE doesn't specify something else to do. Zero
means the default is an error. */
Kevin P. Fleming
committed
static const yytype_uint8 yydefact[] =
Kevin P. Fleming
committed
3, 0, 0, 0, 4, 0, 2, 16, 17, 0,
1, 0, 0, 0, 0, 0, 0, 0, 0, 0,
Kevin P. Fleming
committed
0, 0, 0, 0, 0, 0, 0, 5, 0, 6,
7, 13, 12, 11, 10, 9, 8, 15, 14, 20,
19, 18, 22, 21, 0, 23
};
Kevin P. Fleming
committed
/* YYDEFGOTO[NTERM-NUM]. */
static const yytype_int8 yydefgoto[] =
{
-1, 5, 6
};
/* YYPACT[STATE-NUM] -- Index in YYTABLE of the portion describing
STATE-NUM. */
#define YYPACT_NINF -13
Kevin P. Fleming
committed
static const yytype_int8 yypact[] =
{
109, 109, 109, 109, -13, 6, 59, 106, 106, 22,
-13, 109, 109, 109, 109, 109, 109, 109, 109, 109,
109, 109, 109, 109, 109, 109, 109, -13, 42, 90,
104, 120, 120, 120, 120, 120, 120, -12, -12, 106,
106, 106, -13, -13, 109, 75
};
/* YYPGOTO[NTERM-NUM]. */
Kevin P. Fleming
committed
static const yytype_int8 yypgoto[] =
{
-13, -13, -1
};
/* YYTABLE[YYPACT[STATE-NUM]]. What to do in state STATE-NUM. If
positive, shift that token. If negative, reduce the rule which
number is the opposite. If zero, do what YYDEFACT says.
If YYTABLE_NINF, syntax error. */
#define YYTABLE_NINF -1
Kevin P. Fleming
committed
static const yytype_uint8 yytable[] =
{
7, 8, 9, 22, 23, 24, 10, 25, 26, 0,
28, 29, 30, 31, 32, 33, 34, 35, 36, 37,
38, 39, 40, 41, 42, 43, 11, 12, 13, 14,
15, 16, 17, 18, 19, 20, 21, 22, 23, 24,
0, 25, 26, 45, 27, 44, 11, 12, 13, 14,
15, 16, 17, 18, 19, 20, 21, 22, 23, 24,
0, 25, 26, 11, 12, 13, 14, 15, 16, 17,
18, 19, 20, 21, 22, 23, 24, 0, 25, 26,
12, 13, 14, 15, 16, 17, 18, 19, 20, 21,
22, 23, 24, 0, 25, 26, 13, 14, 15, 16,
17, 18, 19, 20, 21, 22, 23, 24, 0, 25,
26, 14, 15, 16, 17, 18, 19, 20, 21, 22,
23, 24, 1, 25, 26, 25, 26, 2, 0, 0,
3, 0, 4, 20, 21, 22, 23, 24, 0, 25,
26
};
Kevin P. Fleming
committed
static const yytype_int8 yycheck[] =
{
1, 2, 3, 15, 16, 17, 0, 19, 20, -1,
11, 12, 13, 14, 15, 16, 17, 18, 19, 20,
21, 22, 23, 24, 25, 26, 4, 5, 6, 7,
8, 9, 10, 11, 12, 13, 14, 15, 16, 17,
-1, 19, 20, 44, 22, 3, 4, 5, 6, 7,
8, 9, 10, 11, 12, 13, 14, 15, 16, 17,
-1, 19, 20, 4, 5, 6, 7, 8, 9, 10,
11, 12, 13, 14, 15, 16, 17, -1, 19, 20,
5, 6, 7, 8, 9, 10, 11, 12, 13, 14,
15, 16, 17, -1, 19, 20, 6, 7, 8, 9,
10, 11, 12, 13, 14, 15, 16, 17, -1, 19,
20, 7, 8, 9, 10, 11, 12, 13, 14, 15,
16, 17, 13, 19, 20, 19, 20, 18, -1, -1,
21, -1, 23, 13, 14, 15, 16, 17, -1, 19,
20
};
/* YYSTOS[STATE-NUM] -- The (internal number of the) accessing
symbol of state STATE-NUM. */
Kevin P. Fleming
committed
static const yytype_uint8 yystos[] =
{
0, 13, 18, 21, 23, 25, 26, 26, 26, 26,
0, 4, 5, 6, 7, 8, 9, 10, 11, 12,
13, 14, 15, 16, 17, 19, 20, 22, 26, 26,
26, 26, 26, 26, 26, 26, 26, 26, 26, 26,
26, 26, 26, 26, 3, 26
};
#define yyerrok (yyerrstatus = 0)
#define yyclearin (yychar = YYEMPTY)
#define YYEMPTY (-2)
#define YYEOF 0
#define YYACCEPT goto yyacceptlab
#define YYABORT goto yyabortlab
#define YYERROR goto yyerrorlab
/* Like YYERROR except do call yyerror. This remains here temporarily
to ease the transition to the new meaning of YYERROR, for GCC.
Once GCC version 2 has supplanted version 1, this can go. */
#define YYFAIL goto yyerrlab
#define YYRECOVERING() (!!yyerrstatus)
#define YYBACKUP(Token, Value) \
do \
if (yychar == YYEMPTY && yylen == 1) \
{ \
yychar = (Token); \
yylval = (Value); \
yytoken = YYTRANSLATE (yychar); \
Kevin P. Fleming
committed
YYPOPSTACK (1); \
goto yybackup; \
} \
else \
{ \
yyerror (YY_("syntax error: cannot back up")); \
YYERROR; \
} \
Kevin P. Fleming
committed
while (YYID (0))
#define YYTERROR 1
#define YYERRCODE 256
/* YYLLOC_DEFAULT -- Set CURRENT to span from RHS[1] to RHS[N].
If N is 0, then set CURRENT to the empty location which ends
the previous symbol: RHS[0] (always defined). */
#define YYRHSLOC(Rhs, K) ((Rhs)[K])
#ifndef YYLLOC_DEFAULT
Kevin P. Fleming
committed
if (YYID (N)) \
{ \
(Current).first_line = YYRHSLOC (Rhs, 1).first_line; \
(Current).first_column = YYRHSLOC (Rhs, 1).first_column; \
(Current).last_line = YYRHSLOC (Rhs, N).last_line; \
(Current).last_column = YYRHSLOC (Rhs, N).last_column; \
} \
else \
{ \
(Current).first_line = (Current).last_line = \
YYRHSLOC (Rhs, 0).last_line; \
(Current).first_column = (Current).last_column = \
YYRHSLOC (Rhs, 0).last_column; \
} \
Kevin P. Fleming
committed
while (YYID (0))
#endif
/* YY_LOCATION_PRINT -- Print the location on the stream.
This macro was not mandated originally: define only if we know
we won't break user code: when these are the locations we know. */
#ifndef YY_LOCATION_PRINT
# if YYLTYPE_IS_TRIVIAL
# define YY_LOCATION_PRINT(File, Loc) \
fprintf (File, "%d.%d-%d.%d", \
Kevin P. Fleming
committed
(Loc).first_line, (Loc).first_column, \
(Loc).last_line, (Loc).last_column)
# else
# define YY_LOCATION_PRINT(File, Loc) ((void) 0)
# endif
#endif
/* YYLEX -- calling `yylex' with the right arguments. */
#ifdef YYLEX_PARAM
# define YYLEX yylex (&yylval, &yylloc, YYLEX_PARAM)
#else
# define YYLEX yylex (&yylval, &yylloc)
#endif
/* Enable debugging if requested. */
#if YYDEBUG
# ifndef YYFPRINTF
# include <stdio.h> /* INFRINGES ON USER NAME SPACE */
# define YYFPRINTF fprintf
# endif
# define YYDPRINTF(Args) \
do { \
if (yydebug) \
YYFPRINTF Args; \
Kevin P. Fleming
committed
} while (YYID (0))
# define YY_SYMBOL_PRINT(Title, Type, Value, Location) \
do { \
if (yydebug) \
{ \
YYFPRINTF (stderr, "%s ", Title); \
yy_symbol_print (stderr, \
Type, Value, Location); \
YYFPRINTF (stderr, "\n"); \
} \
} while (YYID (0))
Kevin P. Fleming
committed
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
/*--------------------------------.
| Print this symbol on YYOUTPUT. |
`--------------------------------*/
/*ARGSUSED*/
#if (defined __STDC__ || defined __C99__FUNC__ \
|| defined __cplusplus || defined _MSC_VER)
static void
yy_symbol_value_print (FILE *yyoutput, int yytype, const YYSTYPE * const yyvaluep, const YYLTYPE * const yylocationp)
#else
static void
yy_symbol_value_print (yyoutput, yytype, yyvaluep, yylocationp)
FILE *yyoutput;
int yytype;
const YYSTYPE * const yyvaluep;
const YYLTYPE * const yylocationp;
#endif
{
if (!yyvaluep)
return;
YYUSE (yylocationp);
# ifdef YYPRINT
if (yytype < YYNTOKENS)
YYPRINT (yyoutput, yytoknum[yytype], *yyvaluep);
# else
YYUSE (yyoutput);
# endif
switch (yytype)
{
default:
break;
}
}
/*--------------------------------.
| Print this symbol on YYOUTPUT. |
`--------------------------------*/
#if (defined __STDC__ || defined __C99__FUNC__ \
|| defined __cplusplus || defined _MSC_VER)
static void
yy_symbol_print (FILE *yyoutput, int yytype, const YYSTYPE * const yyvaluep, const YYLTYPE * const yylocationp)
#else
static void
yy_symbol_print (yyoutput, yytype, yyvaluep, yylocationp)
FILE *yyoutput;
int yytype;
const YYSTYPE * const yyvaluep;
const YYLTYPE * const yylocationp;
#endif
{
if (yytype < YYNTOKENS)
YYFPRINTF (yyoutput, "token %s (", yytname[yytype]);
else
YYFPRINTF (yyoutput, "nterm %s (", yytname[yytype]);
YY_LOCATION_PRINT (yyoutput, *yylocationp);
YYFPRINTF (yyoutput, ": ");
yy_symbol_value_print (yyoutput, yytype, yyvaluep, yylocationp);
YYFPRINTF (yyoutput, ")");
}
/*------------------------------------------------------------------.
| yy_stack_print -- Print the state stack from its BOTTOM up to its |
| TOP (included). |
`------------------------------------------------------------------*/
Kevin P. Fleming
committed
#if (defined __STDC__ || defined __C99__FUNC__ \
|| defined __cplusplus || defined _MSC_VER)
static void
Kevin P. Fleming
committed
yy_stack_print (yytype_int16 *bottom, yytype_int16 *top)
#else
static void
yy_stack_print (bottom, top)
Kevin P. Fleming
committed
yytype_int16 *bottom;
yytype_int16 *top;
#endif
{
YYFPRINTF (stderr, "Stack now");
Kevin P. Fleming
committed
for (; bottom <= top; ++bottom)
YYFPRINTF (stderr, " %d", *bottom);
YYFPRINTF (stderr, "\n");
}
# define YY_STACK_PRINT(Bottom, Top) \
do { \
if (yydebug) \
yy_stack_print ((Bottom), (Top)); \
Kevin P. Fleming
committed
} while (YYID (0))
/*------------------------------------------------.
| Report that the YYRULE is going to be reduced. |
`------------------------------------------------*/
Kevin P. Fleming
committed
#if (defined __STDC__ || defined __C99__FUNC__ \
|| defined __cplusplus || defined _MSC_VER)
static void
Kevin P. Fleming
committed
yy_reduce_print (YYSTYPE *yyvsp, YYLTYPE *yylsp, int yyrule)
#else
static void
Kevin P. Fleming
committed
yy_reduce_print (yyvsp, yylsp, yyrule
)
YYSTYPE *yyvsp;
YYLTYPE *yylsp;
int yyrule;
#endif
{
Kevin P. Fleming
committed
int yynrhs = yyr2[yyrule];
int yyi;
unsigned long int yylno = yyrline[yyrule];
Kevin P. Fleming
committed
YYFPRINTF (stderr, "Reducing stack by rule %d (line %lu):\n",
yyrule - 1, yylno);
/* The symbols being reduced. */
for (yyi = 0; yyi < yynrhs; yyi++)
{
fprintf (stderr, " $%d = ", yyi + 1);
yy_symbol_print (stderr, yyrhs[yyprhs[yyrule] + yyi],
&(yyvsp[(yyi + 1) - (yynrhs)])
, &(yylsp[(yyi + 1) - (yynrhs)]) );
fprintf (stderr, "\n");
}
}
# define YY_REDUCE_PRINT(Rule) \
do { \
if (yydebug) \
Kevin P. Fleming
committed
yy_reduce_print (yyvsp, yylsp, Rule); \
} while (YYID (0))
/* Nonzero means print parse trace. It is left uninitialized so that
multiple parsers can coexist. */
int yydebug;
#else /* !YYDEBUG */
# define YYDPRINTF(Args)
# define YY_STACK_PRINT(Bottom, Top)
# define YY_REDUCE_PRINT(Rule)
#endif /* !YYDEBUG */
/* YYINITDEPTH -- initial size of the parser's stacks. */
#ifndef YYINITDEPTH
# define YYINITDEPTH 200
#endif
/* YYMAXDEPTH -- maximum size the stacks can grow to (effective only
if the built-in stack extension method is used).
Do not make this value too large; the results are undefined if
YYSTACK_ALLOC_MAXIMUM < YYSTACK_BYTES (YYMAXDEPTH)
evaluated with infinite-precision integer arithmetic. */
#ifndef YYMAXDEPTH
# define YYMAXDEPTH 10000
#endif
#if YYERROR_VERBOSE
# ifndef yystrlen
Kevin P. Fleming
committed
# if defined __GLIBC__ && defined _STRING_H
# define yystrlen strlen
# else
/* Return the length of YYSTR. */
Kevin P. Fleming
committed
#if (defined __STDC__ || defined __C99__FUNC__ \
|| defined __cplusplus || defined _MSC_VER)
static YYSIZE_T
yystrlen (const char *yystr)
Kevin P. Fleming
committed
#else
static YYSIZE_T
yystrlen (yystr)
Kevin P. Fleming
committed
const char *yystr;
#endif
Kevin P. Fleming
committed
YYSIZE_T yylen;
for (yylen = 0; yystr[yylen]; yylen++)
continue;
Kevin P. Fleming
committed
return yylen;
}
# endif
# endif
# ifndef yystpcpy
Kevin P. Fleming
committed
# if defined __GLIBC__ && defined _STRING_H && defined _GNU_SOURCE
# define yystpcpy stpcpy
# else
/* Copy YYSRC to YYDEST, returning the address of the terminating '\0' in
YYDEST. */
Kevin P. Fleming
committed
#if (defined __STDC__ || defined __C99__FUNC__ \
|| defined __cplusplus || defined _MSC_VER)
static char *
yystpcpy (char *yydest, const char *yysrc)
Kevin P. Fleming
committed
#else
static char *
yystpcpy (yydest, yysrc)
Kevin P. Fleming
committed
char *yydest;
const char *yysrc;
#endif
char *yyd = yydest;
const char *yys = yysrc;
while ((*yyd++ = *yys++) != '\0')
continue;
return yyd - 1;
}
# endif
# endif
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
# ifndef yytnamerr
/* Copy to YYRES the contents of YYSTR after stripping away unnecessary
quotes and backslashes, so that it's suitable for yyerror. The
heuristic is that double-quoting is unnecessary unless the string
contains an apostrophe, a comma, or backslash (other than
backslash-backslash). YYSTR is taken from yytname. If YYRES is
null, do not copy; instead, return the length of what the result
would have been. */
static YYSIZE_T
yytnamerr (char *yyres, const char *yystr)
{
if (*yystr == '"')
{
size_t yyn = 0;
char const *yyp = yystr;
for (;;)
switch (*++yyp)
{
case '\'':
case ',':
goto do_not_strip_quotes;
case '\\':
if (*++yyp != '\\')
goto do_not_strip_quotes;
/* Fall through. */
default:
if (yyres)
yyres[yyn] = *yyp;
yyn++;
break;
case '"':
if (yyres)
yyres[yyn] = '\0';
return yyn;
}
do_not_strip_quotes: ;
}
if (! yyres)
return yystrlen (yystr);
return yystpcpy (yyres, yystr) - yyres;
}
# endif
Kevin P. Fleming
committed
/* Copy into YYRESULT an error message about the unexpected token
YYCHAR while in state YYSTATE. Return the number of bytes copied,
including the terminating null byte. If YYRESULT is null, do not
copy anything; just return the number of bytes that would be
copied. As a special case, return 0 if an ordinary "syntax error"
message will do. Return YYSIZE_MAXIMUM if overflow occurs during
size calculation. */
static YYSIZE_T
yysyntax_error (char *yyresult, int yystate, int yychar)
Kevin P. Fleming
committed
int yyn = yypact[yystate];
Kevin P. Fleming
committed
if (! (YYPACT_NINF < yyn && yyn < YYLAST))
return 0;
else
Kevin P. Fleming
committed
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
{
int yytype = YYTRANSLATE (yychar);
YYSIZE_T yysize0 = yytnamerr (0, yytname[yytype]);
YYSIZE_T yysize = yysize0;
YYSIZE_T yysize1;
int yysize_overflow = 0;
enum { YYERROR_VERBOSE_ARGS_MAXIMUM = 5 };
char const *yyarg[YYERROR_VERBOSE_ARGS_MAXIMUM];
int yyx;
# if 0
/* This is so xgettext sees the translatable formats that are
constructed on the fly. */
YY_("syntax error, unexpected %s");
YY_("syntax error, unexpected %s, expecting %s");
YY_("syntax error, unexpected %s, expecting %s or %s");
YY_("syntax error, unexpected %s, expecting %s or %s or %s");
YY_("syntax error, unexpected %s, expecting %s or %s or %s or %s");
# endif
char *yyfmt;
char const *yyf;
static char const yyunexpected[] = "syntax error, unexpected %s";
static char const yyexpecting[] = ", expecting %s";
static char const yyor[] = " or %s";
char yyformat[sizeof yyunexpected
+ sizeof yyexpecting - 1
+ ((YYERROR_VERBOSE_ARGS_MAXIMUM - 2)
* (sizeof yyor - 1))];
char const *yyprefix = yyexpecting;
/* Start YYX at -YYN if negative to avoid negative indexes in
YYCHECK. */
int yyxbegin = yyn < 0 ? -yyn : 0;
/* Stay within bounds of both yycheck and yytname. */
int yychecklim = YYLAST - yyn;
int yyxend = yychecklim < YYNTOKENS ? yychecklim : YYNTOKENS;
int yycount = 1;
yyarg[0] = yytname[yytype];
yyfmt = yystpcpy (yyformat, yyunexpected);
for (yyx = yyxbegin; yyx < yyxend; ++yyx)
if (yycheck[yyx + yyn] == yyx && yyx != YYTERROR)
{
if (yycount == YYERROR_VERBOSE_ARGS_MAXIMUM)
{
yycount = 1;
yysize = yysize0;
yyformat[sizeof yyunexpected - 1] = '\0';
break;
}
yyarg[yycount++] = yytname[yyx];
yysize1 = yysize + yytnamerr (0, yytname[yyx]);
yysize_overflow |= (yysize1 < yysize);
yysize = yysize1;
yyfmt = yystpcpy (yyfmt, yyprefix);
yyprefix = yyor;
}
Kevin P. Fleming
committed
yyf = YY_(yyformat);
yysize1 = yysize + yystrlen (yyf);
yysize_overflow |= (yysize1 < yysize);
yysize = yysize1;
Kevin P. Fleming
committed
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
if (yysize_overflow)
return YYSIZE_MAXIMUM;
if (yyresult)
{
/* Avoid sprintf, as that infringes on the user's name space.
Don't have undefined behavior even if the translation
produced a string with the wrong number of "%s"s. */
char *yyp = yyresult;
int yyi = 0;
while ((*yyp = *yyf) != '\0')
{
if (*yyp == '%' && yyf[1] == 's' && yyi < yycount)
{
yyp += yytnamerr (yyp, yyarg[yyi++]);
yyf += 2;
}
else
{
yyp++;
yyf++;
}
}
}
return yysize;
}
}
Kevin P. Fleming
committed
#endif /* YYERROR_VERBOSE */
/*-----------------------------------------------.
| Release the memory associated to this symbol. |
`-----------------------------------------------*/
Kevin P. Fleming
committed
/*ARGSUSED*/
#if (defined __STDC__ || defined __C99__FUNC__ \
|| defined __cplusplus || defined _MSC_VER)
static void
yydestruct (const char *yymsg, int yytype, YYSTYPE *yyvaluep, YYLTYPE *yylocationp)
#else
static void
yydestruct (yymsg, yytype, yyvaluep, yylocationp)
const char *yymsg;
int yytype;
YYSTYPE *yyvaluep;
YYLTYPE *yylocationp;
#endif
{
Kevin P. Fleming
committed
YYUSE (yyvaluep);
YYUSE (yylocationp);
if (!yymsg)
yymsg = "Deleting";
YY_SYMBOL_PRINT (yymsg, yytype, yyvaluep, yylocationp);
switch (yytype)
{
Kevin P. Fleming
committed
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
case 3: /* "TOK_COLONCOLON" */
#line 162 "ast_expr2.y"
{ free_value((yyvaluep->val)); };
#line 1250 "ast_expr2.c"
break;
case 4: /* "TOK_COND" */
#line 162 "ast_expr2.y"
{ free_value((yyvaluep->val)); };
#line 1255 "ast_expr2.c"
break;
case 5: /* "TOK_OR" */
#line 162 "ast_expr2.y"
{ free_value((yyvaluep->val)); };
#line 1260 "ast_expr2.c"
break;
case 6: /* "TOK_AND" */
#line 162 "ast_expr2.y"
{ free_value((yyvaluep->val)); };
#line 1265 "ast_expr2.c"
break;
case 7: /* "TOK_NE" */
#line 162 "ast_expr2.y"
{ free_value((yyvaluep->val)); };
#line 1270 "ast_expr2.c"
break;
case 8: /* "TOK_LE" */
#line 162 "ast_expr2.y"
{ free_value((yyvaluep->val)); };
#line 1275 "ast_expr2.c"
break;
case 9: /* "TOK_GE" */
#line 162 "ast_expr2.y"
{ free_value((yyvaluep->val)); };
#line 1280 "ast_expr2.c"
break;
case 10: /* "TOK_LT" */
#line 162 "ast_expr2.y"
{ free_value((yyvaluep->val)); };
#line 1285 "ast_expr2.c"
break;
case 11: /* "TOK_GT" */
#line 162 "ast_expr2.y"
{ free_value((yyvaluep->val)); };
#line 1290 "ast_expr2.c"
break;
case 12: /* "TOK_EQ" */
#line 162 "ast_expr2.y"
{ free_value((yyvaluep->val)); };
#line 1295 "ast_expr2.c"
break;
case 13: /* "TOK_MINUS" */
#line 162 "ast_expr2.y"
{ free_value((yyvaluep->val)); };
#line 1300 "ast_expr2.c"
break;
case 14: /* "TOK_PLUS" */
#line 162 "ast_expr2.y"
{ free_value((yyvaluep->val)); };
#line 1305 "ast_expr2.c"
break;
case 15: /* "TOK_MOD" */
#line 162 "ast_expr2.y"
{ free_value((yyvaluep->val)); };
#line 1310 "ast_expr2.c"
break;
case 16: /* "TOK_DIV" */
#line 162 "ast_expr2.y"
{ free_value((yyvaluep->val)); };
#line 1315 "ast_expr2.c"
break;
case 17: /* "TOK_MULT" */
#line 162 "ast_expr2.y"
{ free_value((yyvaluep->val)); };
#line 1320 "ast_expr2.c"
break;
case 18: /* "TOK_COMPL" */
#line 162 "ast_expr2.y"
{ free_value((yyvaluep->val)); };
#line 1325 "ast_expr2.c"
break;
case 19: /* "TOK_EQTILDE" */
#line 162 "ast_expr2.y"
{ free_value((yyvaluep->val)); };
#line 1330 "ast_expr2.c"
break;
case 20: /* "TOK_COLON" */
#line 162 "ast_expr2.y"
{ free_value((yyvaluep->val)); };
#line 1335 "ast_expr2.c"
break;
case 21: /* "TOK_LP" */
#line 162 "ast_expr2.y"
{ free_value((yyvaluep->val)); };
#line 1340 "ast_expr2.c"
break;
case 22: /* "TOK_RP" */
#line 162 "ast_expr2.y"
{ free_value((yyvaluep->val)); };
#line 1345 "ast_expr2.c"
break;
case 23: /* "TOKEN" */
#line 162 "ast_expr2.y"
{ free_value((yyvaluep->val)); };
#line 1350 "ast_expr2.c"
break;
case 26: /* "expr" */
#line 162 "ast_expr2.y"
{ free_value((yyvaluep->val)); };
#line 1355 "ast_expr2.c"
break;
default:
Kevin P. Fleming
committed
break;
}
}
/* Prevent warnings from -Wmissing-prototypes. */
#ifdef YYPARSE_PARAM
Kevin P. Fleming
committed
#if defined __STDC__ || defined __cplusplus
int yyparse (void *YYPARSE_PARAM);
Kevin P. Fleming
committed
#else
int yyparse ();
Kevin P. Fleming
committed
#endif
#else /* ! YYPARSE_PARAM */
Kevin P. Fleming
committed
#if defined __STDC__ || defined __cplusplus
int yyparse (void);
#else
int yyparse ();
#endif
#endif /* ! YYPARSE_PARAM */
/*----------.
| yyparse. |
`----------*/
#ifdef YYPARSE_PARAM
Kevin P. Fleming
committed
#if (defined __STDC__ || defined __C99__FUNC__ \
|| defined __cplusplus || defined _MSC_VER)
int
yyparse (void *YYPARSE_PARAM)
#else
int
yyparse (YYPARSE_PARAM)
void *YYPARSE_PARAM;
#endif
#else /* ! YYPARSE_PARAM */
Kevin P. Fleming
committed
#if (defined __STDC__ || defined __C99__FUNC__ \
|| defined __cplusplus || defined _MSC_VER)
int
yyparse (void)
#else
int
yyparse ()
Kevin P. Fleming
committed
#endif
#endif
{
int yychar;
YYSTYPE yylval;
/* Number of syntax errors so far. */
int yynerrs;
YYLTYPE yylloc;
int yyresult;
/* Number of tokens to shift before error messages enabled. */
int yyerrstatus;
int yytoken = 0;
Kevin P. Fleming
committed
#if YYERROR_VERBOSE
/* Buffer for error messages, and its allocated size. */
char yymsgbuf[128];
char *yymsg = yymsgbuf;
YYSIZE_T yymsg_alloc = sizeof yymsgbuf;
#endif
/* Three stacks and their tools:
`yyss': related to states,
`yyvs': related to semantic values,
`yyls': related to locations.
Refer to the stacks thru separate pointers, to allow yyoverflow
to reallocate them elsewhere. */
/* The state stack. */
Kevin P. Fleming
committed
yytype_int16 yyssa[YYINITDEPTH];
yytype_int16 *yyss = yyssa;
yytype_int16 *yyssp;
/* The semantic value stack. */
YYSTYPE yyvsa[YYINITDEPTH];
YYSTYPE *yyvs = yyvsa;
/* The location stack. */
YYLTYPE yylsa[YYINITDEPTH];
YYLTYPE *yyls = yylsa;
YYLTYPE *yylsp;
Kevin P. Fleming
committed
/* The locations where the error started and ended. */
Kevin P. Fleming
committed
#define YYPOPSTACK(N) (yyvsp -= (N), yyssp -= (N), yylsp -= (N))
YYSIZE_T yystacksize = YYINITDEPTH;
/* The variables used to return semantic value and location from the
action routines. */
YYSTYPE yyval;
YYLTYPE yyloc;
Kevin P. Fleming
committed
/* The number of symbols on the RHS of the reduced rule.
Keep to zero when no symbol should be popped. */
int yylen = 0;
YYDPRINTF ((stderr, "Starting parse\n"));
yystate = 0;
yyerrstatus = 0;
yynerrs = 0;
yychar = YYEMPTY; /* Cause a token to be read. */
/* Initialize stack pointers.
Waste one element of value and location stack
so that they stay on the same level as the state stack.
The wasted elements are never initialized. */
yyssp = yyss;
yyvsp = yyvs;
yylsp = yyls;
#if YYLTYPE_IS_TRIVIAL
/* Initialize the default location before parsing starts. */
yylloc.first_line = yylloc.last_line = 1;
yylloc.first_column = yylloc.last_column = 0;
#endif
goto yysetstate;
/*------------------------------------------------------------.
| yynewstate -- Push a new state, which is found in yystate. |
`------------------------------------------------------------*/
yynewstate:
/* In all cases, when you get here, the value and location stacks
Kevin P. Fleming
committed
have just been pushed. So pushing a state here evens the stacks. */
yyssp++;
yysetstate:
*yyssp = yystate;
if (yyss + yystacksize - 1 <= yyssp)
{
/* Get the current used size of the three stacks, in elements. */
YYSIZE_T yysize = yyssp - yyss + 1;
#ifdef yyoverflow
{
Kevin P. Fleming
committed
/* Give user a chance to reallocate the stack. Use copies of
these so that the &'s don't force the real ones into
memory. */
YYSTYPE *yyvs1 = yyvs;
Kevin P. Fleming
committed
yytype_int16 *yyss1 = yyss;
YYLTYPE *yyls1 = yyls;
/* Each stack pointer address is followed by the size of the
data in use in that stack, in bytes. This used to be a
conditional around just the two extra args, but that might
be undefined if yyoverflow is a macro. */
yyoverflow (YY_("memory exhausted"),
&yyss1, yysize * sizeof (*yyssp),
&yyvs1, yysize * sizeof (*yyvsp),
&yyls1, yysize * sizeof (*yylsp),
&yystacksize);
yyls = yyls1;
yyss = yyss1;
yyvs = yyvs1;
}
#else /* no yyoverflow */
# ifndef YYSTACK_RELOCATE
# else
/* Extend the stack our own way. */
if (YYMAXDEPTH <= yystacksize)
yystacksize *= 2;
if (YYMAXDEPTH < yystacksize)
yystacksize = YYMAXDEPTH;
{
Kevin P. Fleming
committed
yytype_int16 *yyss1 = yyss;
union yyalloc *yyptr =
(union yyalloc *) YYSTACK_ALLOC (YYSTACK_BYTES (yystacksize));
if (! yyptr)
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
1585
YYSTACK_RELOCATE (yyss);
YYSTACK_RELOCATE (yyvs);
YYSTACK_RELOCATE (yyls);
# undef YYSTACK_RELOCATE
if (yyss1 != yyssa)
YYSTACK_FREE (yyss1);
}
# endif
#endif /* no yyoverflow */
yyssp = yyss + yysize - 1;
yyvsp = yyvs + yysize - 1;
yylsp = yyls + yysize - 1;
YYDPRINTF ((stderr, "Stack size increased to %lu\n",
(unsigned long int) yystacksize));
if (yyss + yystacksize - 1 <= yyssp)
YYABORT;
}
YYDPRINTF ((stderr, "Entering state %d\n", yystate));
goto yybackup;
/*-----------.
| yybackup. |
`-----------*/
yybackup:
Kevin P. Fleming
committed
/* Do appropriate processing given the current state. Read a
look-ahead token if we need one and don't already have one. */
/* First try to decide what to do without reference to look-ahead token. */
yyn = yypact[yystate];
if (yyn == YYPACT_NINF)
goto yydefault;
/* YYCHAR is either YYEMPTY or YYEOF or a valid look-ahead symbol. */
if (yychar == YYEMPTY)
{
YYDPRINTF ((stderr, "Reading a token: "));
yychar = YYLEX;
}
if (yychar <= YYEOF)
{
yychar = yytoken = YYEOF;
YYDPRINTF ((stderr, "Now at end of input.\n"));
}
else
{
yytoken = YYTRANSLATE (yychar);
}
/* If the proper action on seeing token YYTOKEN is to reduce or to
detect an error, take that action. */
yyn += yytoken;
if (yyn < 0 || YYLAST < yyn || yycheck[yyn] != yytoken)
goto yydefault;
yyn = yytable[yyn];
if (yyn <= 0)
{
if (yyn == 0 || yyn == YYTABLE_NINF)
goto yyerrlab;
yyn = -yyn;
goto yyreduce;
}
if (yyn == YYFINAL)
YYACCEPT;
Kevin P. Fleming
committed
/* Count tokens shifted since error; after three, turn off error
status. */
if (yyerrstatus)
yyerrstatus--;
/* Shift the look-ahead token. */
YY_SYMBOL_PRINT ("Shifting", yytoken, &yylval, &yylloc);
Kevin P. Fleming
committed
/* Discard the shifted token unless it is eof. */
if (yychar != YYEOF)
yychar = YYEMPTY;
Kevin P. Fleming
committed
yystate = yyn;
1644
1645
1646
1647
1648
1649
1650
1651
1652
1653
1654
1655
1656
1657
1658
1659
1660
1661
1662
1663
1664
1665
1666
1667
1668
1669
1670
1671
1672
1673
1674
1675
*++yyvsp = yylval;
*++yylsp = yylloc;
goto yynewstate;
/*-----------------------------------------------------------.
| yydefault -- do the default action for the current state. |
`-----------------------------------------------------------*/
yydefault:
yyn = yydefact[yystate];
if (yyn == 0)
goto yyerrlab;
goto yyreduce;
/*-----------------------------.
| yyreduce -- Do a reduction. |
`-----------------------------*/
yyreduce:
/* yyn is the number of a rule to reduce with. */
yylen = yyr2[yyn];
/* If YYLEN is nonzero, implement the default value of the action:
`$$ = $1'.
Otherwise, the following line sets YYVAL to garbage.
This behavior is undocumented and Bison
users should not rely upon it. Assigning to YYVAL
unconditionally makes the parser a bit smaller, and it avoids a
GCC warning that YYVAL may be used uninitialized. */
yyval = yyvsp[1-yylen];
Kevin P. Fleming
committed
/* Default location. */
YYLLOC_DEFAULT (yyloc, (yylsp - yylen), yylen);
YY_REDUCE_PRINT (yyn);
switch (yyn)
{
case 2:
Kevin P. Fleming
committed
#line 168 "ast_expr2.y"
{ ((struct parse_io *)parseio)->val = (struct val *)calloc(sizeof(struct val),1);
Kevin P. Fleming
committed
((struct parse_io *)parseio)->val->type = (yyvsp[(1) - (1)].val)->type;
if( (yyvsp[(1) - (1)].val)->type == AST_EXPR_integer )
((struct parse_io *)parseio)->val->u.i = (yyvsp[(1) - (1)].val)->u.i;
Kevin P. Fleming
committed
((struct parse_io *)parseio)->val->u.s = (yyvsp[(1) - (1)].val)->u.s;
free((yyvsp[(1) - (1)].val));
break;
case 3:
Kevin P. Fleming
committed
#line 176 "ast_expr2.y"
{/* nothing */ ((struct parse_io *)parseio)->val = (struct val *)calloc(sizeof(struct val),1);
((struct parse_io *)parseio)->val->type = AST_EXPR_string;
((struct parse_io *)parseio)->val->u.s = strdup("");
;}
break;
case 4:
Kevin P. Fleming
committed
#line 183 "ast_expr2.y"
{ (yyval.val)= (yyvsp[(1) - (1)].val);;}
break;
case 5:
Kevin P. Fleming
committed
#line 184 "ast_expr2.y"
{ (yyval.val) = (yyvsp[(2) - (3)].val);
(yyloc).first_column = (yylsp[(1) - (3)]).first_column; (yyloc).last_column = (yylsp[(3) - (3)]).last_column;
(yyloc).first_line=0; (yyloc).last_line=0;
DESTROY((yyvsp[(1) - (3)].val)); DESTROY((yyvsp[(3) - (3)].val)); ;}
break;
case 6:
Kevin P. Fleming
committed
#line 188 "ast_expr2.y"
{ (yyval.val) = op_or ((yyvsp[(1) - (3)].val), (yyvsp[(3) - (3)].val));
DESTROY((yyvsp[(2) - (3)].val));
(yyloc).first_column = (yylsp[(1) - (3)]).first_column; (yyloc).last_column = (yylsp[(3) - (3)]).last_column;
(yyloc).first_line=0; (yyloc).last_line=0;;}
break;
case 7:
Kevin P. Fleming
committed
#line 192 "ast_expr2.y"
{ (yyval.val) = op_and ((yyvsp[(1) - (3)].val), (yyvsp[(3) - (3)].val));
DESTROY((yyvsp[(2) - (3)].val));
(yyloc).first_column = (yylsp[(1) - (3)]).first_column; (yyloc).last_column = (yylsp[(3) - (3)]).last_column;
(yyloc).first_line=0; (yyloc).last_line=0;;}
break;
case 8:
Kevin P. Fleming
committed
#line 196 "ast_expr2.y"
{ (yyval.val) = op_eq ((yyvsp[(1) - (3)].val), (yyvsp[(3) - (3)].val));
DESTROY((yyvsp[(2) - (3)].val));
(yyloc).first_column = (yylsp[(1) - (3)]).first_column; (yyloc).last_column = (yylsp[(3) - (3)]).last_column;
break;
case 9:
Kevin P. Fleming
committed
#line 200 "ast_expr2.y"
{ (yyval.val) = op_gt ((yyvsp[(1) - (3)].val), (yyvsp[(3) - (3)].val));
DESTROY((yyvsp[(2) - (3)].val));
(yyloc).first_column = (yylsp[(1) - (3)]).first_column; (yyloc).last_column = (yylsp[(3) - (3)]).last_column;
break;
case 10:
Kevin P. Fleming
committed
#line 204 "ast_expr2.y"
{ (yyval.val) = op_lt ((yyvsp[(1) - (3)].val), (yyvsp[(3) - (3)].val));
DESTROY((yyvsp[(2) - (3)].val));
(yyloc).first_column = (yylsp[(1) - (3)]).first_column; (yyloc).last_column = (yylsp[(3) - (3)]).last_column;
(yyloc).first_line=0; (yyloc).last_line=0;;}
break;
case 11:
Kevin P. Fleming
committed
#line 208 "ast_expr2.y"
{ (yyval.val) = op_ge ((yyvsp[(1) - (3)].val), (yyvsp[(3) - (3)].val));
DESTROY((yyvsp[(2) - (3)].val));
(yyloc).first_column = (yylsp[(1) - (3)]).first_column; (yyloc).last_column = (yylsp[(3) - (3)]).last_column;
break;
case 12:
Kevin P. Fleming
committed
#line 212 "ast_expr2.y"
{ (yyval.val) = op_le ((yyvsp[(1) - (3)].val), (yyvsp[(3) - (3)].val));
DESTROY((yyvsp[(2) - (3)].val));
(yyloc).first_column = (yylsp[(1) - (3)]).first_column; (yyloc).last_column = (yylsp[(3) - (3)]).last_column;
break;
case 13:
Kevin P. Fleming
committed
#line 216 "ast_expr2.y"
{ (yyval.val) = op_ne ((yyvsp[(1) - (3)].val), (yyvsp[(3) - (3)].val));
DESTROY((yyvsp[(2) - (3)].val));
(yyloc).first_column = (yylsp[(1) - (3)]).first_column; (yyloc).last_column = (yylsp[(3) - (3)]).last_column;
(yyloc).first_line=0; (yyloc).last_line=0;;}
break;
case 14:
Kevin P. Fleming
committed
#line 220 "ast_expr2.y"
{ (yyval.val) = op_plus ((yyvsp[(1) - (3)].val), (yyvsp[(3) - (3)].val));
DESTROY((yyvsp[(2) - (3)].val));
(yyloc).first_column = (yylsp[(1) - (3)]).first_column; (yyloc).last_column = (yylsp[(3) - (3)]).last_column;
(yyloc).first_line=0; (yyloc).last_line=0;;}
break;
case 15:
Kevin P. Fleming
committed
#line 224 "ast_expr2.y"
{ (yyval.val) = op_minus ((yyvsp[(1) - (3)].val), (yyvsp[(3) - (3)].val));
DESTROY((yyvsp[(2) - (3)].val));
(yyloc).first_column = (yylsp[(1) - (3)]).first_column; (yyloc).last_column = (yylsp[(3) - (3)]).last_column;
break;
case 16:
Kevin P. Fleming
committed
#line 228 "ast_expr2.y"
{ (yyval.val) = op_negate ((yyvsp[(2) - (2)].val));
DESTROY((yyvsp[(1) - (2)].val));
(yyloc).first_column = (yylsp[(1) - (2)]).first_column; (yyloc).last_column = (yylsp[(2) - (2)]).last_column;
break;
case 17:
Kevin P. Fleming
committed
#line 232 "ast_expr2.y"
{ (yyval.val) = op_compl ((yyvsp[(2) - (2)].val));
DESTROY((yyvsp[(1) - (2)].val));
(yyloc).first_column = (yylsp[(1) - (2)]).first_column; (yyloc).last_column = (yylsp[(2) - (2)]).last_column;
(yyloc).first_line=0; (yyloc).last_line=0;;}
break;
case 18:
Kevin P. Fleming
committed
#line 236 "ast_expr2.y"
{ (yyval.val) = op_times ((yyvsp[(1) - (3)].val), (yyvsp[(3) - (3)].val));
DESTROY((yyvsp[(2) - (3)].val));
(yyloc).first_column = (yylsp[(1) - (3)]).first_column; (yyloc).last_column = (yylsp[(3) - (3)]).last_column;
(yyloc).first_line=0; (yyloc).last_line=0;;}
break;
case 19:
Kevin P. Fleming
committed
#line 240 "ast_expr2.y"
{ (yyval.val) = op_div ((yyvsp[(1) - (3)].val), (yyvsp[(3) - (3)].val));
DESTROY((yyvsp[(2) - (3)].val));
(yyloc).first_column = (yylsp[(1) - (3)]).first_column; (yyloc).last_column = (yylsp[(3) - (3)]).last_column;
break;
case 20:
Kevin P. Fleming
committed
#line 244 "ast_expr2.y"
{ (yyval.val) = op_rem ((yyvsp[(1) - (3)].val), (yyvsp[(3) - (3)].val));
DESTROY((yyvsp[(2) - (3)].val));
(yyloc).first_column = (yylsp[(1) - (3)]).first_column; (yyloc).last_column = (yylsp[(3) - (3)]).last_column;
(yyloc).first_line=0; (yyloc).last_line=0;;}
break;
case 21:
Kevin P. Fleming
committed
#line 248 "ast_expr2.y"
{ (yyval.val) = op_colon ((yyvsp[(1) - (3)].val), (yyvsp[(3) - (3)].val));
DESTROY((yyvsp[(2) - (3)].val));
(yyloc).first_column = (yylsp[(1) - (3)]).first_column; (yyloc).last_column = (yylsp[(3) - (3)]).last_column;
break;
case 22:
Kevin P. Fleming
committed
#line 252 "ast_expr2.y"
{ (yyval.val) = op_eqtilde ((yyvsp[(1) - (3)].val), (yyvsp[(3) - (3)].val));
DESTROY((yyvsp[(2) - (3)].val));
(yyloc).first_column = (yylsp[(1) - (3)]).first_column; (yyloc).last_column = (yylsp[(3) - (3)]).last_column;
(yyloc).first_line=0; (yyloc).last_line=0;;}
break;
case 23:
#line 256 "ast_expr2.y"
{ (yyval.val) = op_cond ((yyvsp[(1) - (5)].val), (yyvsp[(3) - (5)].val), (yyvsp[(5) - (5)].val));
DESTROY((yyvsp[(2) - (5)].val));
DESTROY((yyvsp[(4) - (5)].val));
(yyloc).first_column = (yylsp[(1) - (5)]).first_column; (yyloc).last_column = (yylsp[(3) - (5)]).last_column;
break;
Kevin P. Fleming
committed
/* Line 1270 of yacc.c. */
#line 1857 "ast_expr2.c"
Kevin P. Fleming
committed
YY_SYMBOL_PRINT ("-> $$ =", yyr1[yyn], &yyval, &yyloc);
Kevin P. Fleming
committed
YYPOPSTACK (yylen);
yylen = 0;
1868
1869
1870
1871
1872
1873
1874
1875
1876
1877
1878
1879
1880
1881
1882
1883
1884
1885
1886
1887
1888
1889
1890
1891
1892
1893
1894
1895
YY_STACK_PRINT (yyss, yyssp);
*++yyvsp = yyval;
*++yylsp = yyloc;
/* Now `shift' the result of the reduction. Determine what state
that goes to, based on the state we popped back to and the rule
number reduced by. */
yyn = yyr1[yyn];
yystate = yypgoto[yyn - YYNTOKENS] + *yyssp;
if (0 <= yystate && yystate <= YYLAST && yycheck[yystate] == *yyssp)
yystate = yytable[yystate];
else
yystate = yydefgoto[yyn - YYNTOKENS];
goto yynewstate;
/*------------------------------------.
| yyerrlab -- here on detecting error |
`------------------------------------*/
yyerrlab:
/* If not already recovering from an error, report this error. */
if (!yyerrstatus)
{
++yynerrs;
Kevin P. Fleming
committed
#if ! YYERROR_VERBOSE
yyerror (YY_("syntax error"));
#else
{
YYSIZE_T yysize = yysyntax_error (0, yystate, yychar);
if (yymsg_alloc < yysize && yymsg_alloc < YYSTACK_ALLOC_MAXIMUM)
{
YYSIZE_T yyalloc = 2 * yysize;
if (! (yysize <= yyalloc && yyalloc <= YYSTACK_ALLOC_MAXIMUM))
yyalloc = YYSTACK_ALLOC_MAXIMUM;
if (yymsg != yymsgbuf)
YYSTACK_FREE (yymsg);
yymsg = (char *) YYSTACK_ALLOC (yyalloc);
if (yymsg)
yymsg_alloc = yyalloc;
else
{
Kevin P. Fleming
committed
yymsg = yymsgbuf;
yymsg_alloc = sizeof yymsgbuf;
}
Kevin P. Fleming
committed
}
Kevin P. Fleming
committed
if (0 < yysize && yysize <= yymsg_alloc)
{
(void) yysyntax_error (yymsg, yystate, yychar);
yyerror (yymsg);
}
else
{
yyerror (YY_("syntax error"));
if (yysize != 0)
Kevin P. Fleming
committed
}
}
#endif
}
if (yyerrstatus == 3)
{
error, discard it. */
if (yychar <= YYEOF)
Kevin P. Fleming
committed
{
/* Return failure if at end of input. */
if (yychar == YYEOF)
Kevin P. Fleming
committed
}
else
{
Kevin P. Fleming
committed
yydestruct ("Error: discarding",
yytoken, &yylval, &yylloc);
yychar = YYEMPTY;
}
}
token. */
goto yyerrlab1;
/*---------------------------------------------------.
| yyerrorlab -- error raised explicitly by YYERROR. |
`---------------------------------------------------*/
yyerrorlab:
/* Pacify compilers like GCC when the user code never invokes
YYERROR and the label yyerrorlab therefore never appears in user
code. */
Kevin P. Fleming
committed
if (/*CONSTCOND*/ 0)
goto yyerrorlab;
Kevin P. Fleming
committed
/* Do not reclaim the symbols of the rule which action triggered
this YYERROR. */
YYPOPSTACK (yylen);
yylen = 0;
YY_STACK_PRINT (yyss, yyssp);
yystate = *yyssp;
goto yyerrlab1;
/*-------------------------------------------------------------.
| yyerrlab1 -- common code for both syntax error and YYERROR. |
`-------------------------------------------------------------*/
yyerrlab1:
yyerrstatus = 3; /* Each real token shifted decrements this. */
for (;;)
{
yyn = yypact[yystate];
if (yyn != YYPACT_NINF)
{
yyn += YYTERROR;
if (0 <= yyn && yyn <= YYLAST && yycheck[yyn] == YYTERROR)
{
yyn = yytable[yyn];
if (0 < yyn)
break;
}
}
/* Pop the current state because it cannot handle the error token. */
if (yyssp == yyss)
YYABORT;
Kevin P. Fleming
committed
yydestruct ("Error: popping",
yystos[yystate], yyvsp, yylsp);
YYPOPSTACK (1);
yystate = *yyssp;
YY_STACK_PRINT (yyss, yyssp);
}
if (yyn == YYFINAL)
YYACCEPT;
*++yyvsp = yylval;
yyerror_range[1] = yylloc;
/* Using YYLLOC is tempting, but would change the location of
Kevin P. Fleming
committed
the look-ahead. YYLOC is available though. */
YYLLOC_DEFAULT (yyloc, (yyerror_range - 1), 2);
*++yylsp = yyloc;
Kevin P. Fleming
committed
/* Shift the error token. */
yystate = yyn;
goto yynewstate;
/*-------------------------------------.
| yyacceptlab -- YYACCEPT comes here. |
`-------------------------------------*/
yyacceptlab:
yyresult = 0;
goto yyreturn;
/*-----------------------------------.
| yyabortlab -- YYABORT comes here. |
`-----------------------------------*/
yyabortlab:
yyresult = 1;
goto yyreturn;
#ifndef yyoverflow
/*-------------------------------------------------.
| yyexhaustedlab -- memory exhaustion comes here. |
`-------------------------------------------------*/
yyexhaustedlab:
yyerror (YY_("memory exhausted"));
yyresult = 2;
/* Fall through. */
#endif
yyreturn:
if (yychar != YYEOF && yychar != YYEMPTY)
yydestruct ("Cleanup: discarding lookahead",
yytoken, &yylval, &yylloc);
Kevin P. Fleming
committed
/* Do not reclaim the symbols of the rule which action triggered
this YYABORT or YYACCEPT. */
YYPOPSTACK (yylen);
YY_STACK_PRINT (yyss, yyssp);
while (yyssp != yyss)
{
yydestruct ("Cleanup: popping",
yystos[*yyssp], yyvsp, yylsp);
Kevin P. Fleming
committed
YYPOPSTACK (1);
#ifndef yyoverflow
if (yyss != yyssa)
YYSTACK_FREE (yyss);
Kevin P. Fleming
committed
#endif
#if YYERROR_VERBOSE
if (yymsg != yymsgbuf)
YYSTACK_FREE (yymsg);
#endif
return yyresult;
}
Kevin P. Fleming
committed
#line 263 "ast_expr2.y"
2081
2082
2083
2084
2085
2086
2087
2088
2089
2090
2091
2092
2093
2094
2095
2096
2097
2098
2099
2100
2101
2102
2103
2104
2105
2106
2107
2108
2109
2110
2111
2112
2113
2114
2115
2116
2117
2118
2119
2120
2121
2122
2123
2124
2125
2126
2127
2128
2129
2130
2131
2132
2133
2134
2135
2136
static struct val *
make_integer (quad_t i)
{
struct val *vp;
vp = (struct val *) malloc (sizeof (*vp));
if (vp == NULL) {
ast_log(LOG_WARNING, "malloc() failed\n");
return(NULL);
}
vp->type = AST_EXPR_integer;
vp->u.i = i;
return vp;
}
static struct val *
make_str (const char *s)
{
struct val *vp;
size_t i;
int isint;
vp = (struct val *) malloc (sizeof (*vp));
if (vp == NULL || ((vp->u.s = strdup (s)) == NULL)) {
ast_log(LOG_WARNING,"malloc() failed\n");
return(NULL);
}
for(i = 1, isint = isdigit(s[0]) || s[0] == '-';
isint && i < strlen(s);
i++)
{
if(!isdigit(s[i]))
isint = 0;
}
if (isint)
vp->type = AST_EXPR_numeric_string;
else
vp->type = AST_EXPR_string;
return vp;
}
static void
free_value (struct val *vp)
{
if (vp==NULL) {
return;
}
if (vp->type == AST_EXPR_string || vp->type == AST_EXPR_numeric_string)
free (vp->u.s);
2138
2139
2140
2141
2142
2143
2144
2145
2146
2147
2148
2149
2150
2151
2152
2153
2154
2155
2156
2157
2158
2159
2160
2161
2162
2163
2164
2165
2166
2167
2168
2169
2170
2171
2172
2173
2174
2175
2176
2177
2178
2179
2180
2181
2182
2183
2184
2185
2186
2187
2188
2189
2190
2191
2192
2193
2194
2195
2196
2197
2198
2199
2200
}
static quad_t
to_integer (struct val *vp)
{
quad_t i;
if (vp == NULL) {
ast_log(LOG_WARNING,"vp==NULL in to_integer()\n");
return(0);
}
if (vp->type == AST_EXPR_integer)
return 1;
if (vp->type == AST_EXPR_string)
return 0;
/* vp->type == AST_EXPR_numeric_string, make it numeric */
errno = 0;
i = strtoll(vp->u.s, (char**)NULL, 10);
if (errno != 0) {
ast_log(LOG_WARNING,"Conversion of %s to integer under/overflowed!\n", vp->u.s);
free(vp->u.s);
vp->u.s = 0;
return(0);
}
free (vp->u.s);
vp->u.i = i;
vp->type = AST_EXPR_integer;
return 1;
}
static void
strip_quotes(struct val *vp)
{
if (vp->type != AST_EXPR_string && vp->type != AST_EXPR_numeric_string)
return;
if( vp->u.s[0] == '"' && vp->u.s[strlen(vp->u.s)-1] == '"' )
{
char *f, *t;
f = vp->u.s;
t = vp->u.s;
while( *f )
{
if( *f && *f != '"' )
*t++ = *f++;
else
f++;
}
*t = *f;
}
}
static void
to_string (struct val *vp)
{
char *tmp;
if (vp->type == AST_EXPR_string || vp->type == AST_EXPR_numeric_string)
return;
tmp = malloc ((size_t)25);
if (tmp == NULL) {
ast_log(LOG_WARNING,"malloc() failed\n");
return;
}
sprintf(tmp, "%ld", (long int) vp->u.i);
2210
2211
2212
2213
2214
2215
2216
2217
2218
2219
2220
2221
2222
2223
2224
2225
2226
2227
2228
2229
2230
2231
2232
2233
2234
2235
2236
2237
2238
2239
2240
2241
2242
2243
2244
2245
2246
2247
2248
2249
vp->type = AST_EXPR_string;
vp->u.s = tmp;
}
static int
isstring (struct val *vp)
{
/* only TRUE if this string is not a valid integer */
return (vp->type == AST_EXPR_string);
}
static int
is_zero_or_null (struct val *vp)
{
if (vp->type == AST_EXPR_integer) {
return (vp->u.i == 0);
} else {
return (*vp->u.s == 0 || (to_integer (vp) && vp->u.i == 0));
}
/* NOTREACHED */
}
#ifdef STANDALONE
void ast_log(int level, const char *file, int line, const char *function, const char *fmt, ...)
{
va_list vars;
va_start(vars,fmt);
printf("LOG: lev:%d file:%s line:%d func: %s ",
level, file, line, function);
vprintf(fmt, vars);
fflush(stdout);
va_end(vars);
}
int main(int argc,char **argv) {
char s[4096];
Kevin P. Fleming
committed
char out[4096];
FILE *infile;
Kevin P. Fleming
committed
2254
2255
2256
2257
2258
2259
2260
2261
2262
2263
2264
2265
2266
2267
2268
2269
2270
2271
2272
2273
2274
2275
2276
2277
if( !argv[1] )
exit(20);
if( access(argv[1],F_OK)== 0 )
{
int ret;
infile = fopen(argv[1],"r");
if( !infile )
{
printf("Sorry, couldn't open %s for reading!\n", argv[1]);
exit(10);
}
while( fgets(s,sizeof(s),infile) )
{
if( s[strlen(s)-1] == '\n' )
s[strlen(s)-1] = 0;
ret = ast_expr(s, out, sizeof(out));
printf("Expression: %s Result: [%d] '%s'\n",
s, ret, out);
}
fclose(infile);
}
else
Kevin P. Fleming
committed
{
if (ast_expr(argv[1], s, sizeof(s)))
printf("=====%s======\n",s);
else
printf("No result\n");
}
2285
2286
2287
2288
2289
2290
2291
2292
2293
2294
2295
2296
2297
2298
2299
2300
2301
2302
2303
2304
2305
2306
2307
2308
2309
2310
2311
2312
2313
2314
2315
2316
2317
2318
2319
2320
2321
2322
2323
2324
2325
2326
2327
2328
2329
2330
2331
2332
2333
2334
2335
2336
2337
2338
2339
2340
2341
2342
2343
2344
2345
2346
2347
2348
2349
2350
2351
2352
2353
2354
2355
2356
2357
2358
2359
2360
2361
2362
2363
2364
2365
2366
2367
2368
2369
2370
2371
2372
2373
2374
2375
2376
2377
2378
2379
2380
2381
2382
2383
2384
2385
2386
2387
2388
2389
2390
2391
2392
2393
2394
2395
2396
2397
2398
2399
2400
2401
2402
2403
2404
2405
2406
2407
2408
2409
2410
2411
2412
2413
2414
2415
2416
2417
2418
2419
2420
2421
2422
2423
2424
2425
2426
2427
2428
2429
2430
2431
2432
2433
2434
2435
2436
2437
2438
2439
2440
2441
2442
2443
2444
2445
2446
2447
2448
2449
2450
2451
2452
2453
2454
2455
2456
2457
2458
2459
2460
2461
2462
2463
2464
2465
2466
2467
2468
2469
2470
2471
2472
2473
2474
2475
2476
2477
2478
2479
2480
2481
2482
2483
2484
2485
2486
2487
2488
2489
2490
2491
2492
2493
2494
2495
2496
2497
2498
2499
2500
2501
2502
2503
2504
2505
2506
2507
}
#endif
#undef ast_yyerror
#define ast_yyerror(x) ast_yyerror(x, YYLTYPE *yylloc, struct parse_io *parseio)
/* I put the ast_yyerror func in the flex input file,
because it refers to the buffer state. Best to
let it access the BUFFER stuff there and not trying
define all the structs, macros etc. in this file! */
static struct val *
op_or (struct val *a, struct val *b)
{
if (is_zero_or_null (a)) {
free_value (a);
return (b);
} else {
free_value (b);
return (a);
}
}
static struct val *
op_and (struct val *a, struct val *b)
{
if (is_zero_or_null (a) || is_zero_or_null (b)) {
free_value (a);
free_value (b);
return (make_integer ((quad_t)0));
} else {
free_value (b);
return (a);
}
}
static struct val *
op_eq (struct val *a, struct val *b)
{
struct val *r;
if (isstring (a) || isstring (b)) {
to_string (a);
to_string (b);
r = make_integer ((quad_t)(strcoll (a->u.s, b->u.s) == 0));
} else {
#ifdef DEBUG_FOR_CONVERSIONS
char buffer[2000];
sprintf(buffer,"Converting '%s' and '%s' ", a->u.s, b->u.s);
#endif
(void)to_integer(a);
(void)to_integer(b);
#ifdef DEBUG_FOR_CONVERSIONS
ast_log(LOG_WARNING,"%s to '%lld' and '%lld'\n", buffer, a->u.i, b->u.i);
#endif
r = make_integer ((quad_t)(a->u.i == b->u.i));
}
free_value (a);
free_value (b);
return r;
}
static struct val *
op_gt (struct val *a, struct val *b)
{
struct val *r;
if (isstring (a) || isstring (b)) {
to_string (a);
to_string (b);
r = make_integer ((quad_t)(strcoll (a->u.s, b->u.s) > 0));
} else {
(void)to_integer(a);
(void)to_integer(b);
r = make_integer ((quad_t)(a->u.i > b->u.i));
}
free_value (a);
free_value (b);
return r;
}
static struct val *
op_lt (struct val *a, struct val *b)
{
struct val *r;
if (isstring (a) || isstring (b)) {
to_string (a);
to_string (b);
r = make_integer ((quad_t)(strcoll (a->u.s, b->u.s) < 0));
} else {
(void)to_integer(a);
(void)to_integer(b);
r = make_integer ((quad_t)(a->u.i < b->u.i));
}
free_value (a);
free_value (b);
return r;
}
static struct val *
op_ge (struct val *a, struct val *b)
{
struct val *r;
if (isstring (a) || isstring (b)) {
to_string (a);
to_string (b);
r = make_integer ((quad_t)(strcoll (a->u.s, b->u.s) >= 0));
} else {
(void)to_integer(a);
(void)to_integer(b);
r = make_integer ((quad_t)(a->u.i >= b->u.i));
}
free_value (a);
free_value (b);
return r;
}
static struct val *
op_le (struct val *a, struct val *b)
{
struct val *r;
if (isstring (a) || isstring (b)) {
to_string (a);
to_string (b);
r = make_integer ((quad_t)(strcoll (a->u.s, b->u.s) <= 0));
} else {
(void)to_integer(a);
(void)to_integer(b);
r = make_integer ((quad_t)(a->u.i <= b->u.i));
}
free_value (a);
free_value (b);
return r;
}
static struct val *
op_cond (struct val *a, struct val *b, struct val *c)
{
struct val *r;
if( isstring(a) )
{
if( strlen(a->u.s) && strcmp(a->u.s, "\"\"") != 0 && strcmp(a->u.s,"0") != 0 )
{
free_value(a);
free_value(c);
r = b;
}
else
{
free_value(a);
free_value(b);
r = c;
}
}
else
{
(void)to_integer(a);
if( a->u.i )
{
free_value(a);
free_value(c);
r = b;
}
else
{
free_value(a);
free_value(b);
r = c;
}
}
return r;
}
static struct val *
op_ne (struct val *a, struct val *b)
{
struct val *r;
if (isstring (a) || isstring (b)) {
to_string (a);
to_string (b);
r = make_integer ((quad_t)(strcoll (a->u.s, b->u.s) != 0));
} else {
(void)to_integer(a);
(void)to_integer(b);
r = make_integer ((quad_t)(a->u.i != b->u.i));
}
free_value (a);
free_value (b);
return r;
}
static int
chk_plus (quad_t a, quad_t b, quad_t r)
{
/* sum of two positive numbers must be positive */
if (a > 0 && b > 0 && r <= 0)
return 1;
/* sum of two negative numbers must be negative */
if (a < 0 && b < 0 && r >= 0)
return 1;
/* all other cases are OK */
return 0;
}
static struct val *
op_plus (struct val *a, struct val *b)
{
struct val *r;
if (!to_integer (a)) {
Kevin P. Fleming
committed
if( !extra_error_message_supplied )
ast_log(LOG_WARNING,"non-numeric argument\n");
2510
2511
2512
2513
2514
2515
2516
2517
2518
2519
2520
2521
2522
2523
2524
2525
2526
2527
2528
2529
2530
2531
2532
2533
2534
2535
2536
2537
2538
2539
2540
2541
2542
2543
2544
2545
2546
2547
2548
2549
2550
2551
if (!to_integer (b)) {
free_value(a);
free_value(b);
return make_integer(0);
} else {
free_value(a);
return (b);
}
} else if (!to_integer(b)) {
free_value(b);
return (a);
}
r = make_integer (/*(quad_t)*/(a->u.i + b->u.i));
if (chk_plus (a->u.i, b->u.i, r->u.i)) {
ast_log(LOG_WARNING,"overflow\n");
}
free_value (a);
free_value (b);
return r;
}
static int
chk_minus (quad_t a, quad_t b, quad_t r)
{
/* special case subtraction of QUAD_MIN */
if (b == QUAD_MIN) {
if (a >= 0)
return 1;
else
return 0;
}
/* this is allowed for b != QUAD_MIN */
return chk_plus (a, -b, r);
}
static struct val *
op_minus (struct val *a, struct val *b)
{
struct val *r;
if (!to_integer (a)) {
Kevin P. Fleming
committed
if( !extra_error_message_supplied )
ast_log(LOG_WARNING, "non-numeric argument\n");
if (!to_integer (b)) {
free_value(a);
free_value(b);
return make_integer(0);
} else {
r = make_integer(0 - b->u.i);
free_value(a);
free_value(b);
return (r);
}
} else if (!to_integer(b)) {
Kevin P. Fleming
committed
if( !extra_error_message_supplied )
ast_log(LOG_WARNING, "non-numeric argument\n");
free_value(b);
return (a);
}
r = make_integer (/*(quad_t)*/(a->u.i - b->u.i));
if (chk_minus (a->u.i, b->u.i, r->u.i)) {
ast_log(LOG_WARNING, "overflow\n");
}
free_value (a);
free_value (b);
return r;
}
static struct val *
op_negate (struct val *a)
{
struct val *r;
if (!to_integer (a) ) {
free_value(a);
Kevin P. Fleming
committed
if( !extra_error_message_supplied )
ast_log(LOG_WARNING, "non-numeric argument\n");
2589
2590
2591
2592
2593
2594
2595
2596
2597
2598
2599
2600
2601
2602
2603
2604
2605
2606
2607
2608
2609
2610
2611
2612
2613
2614
2615
2616
2617
2618
2619
2620
2621
2622
2623
2624
2625
2626
2627
2628
2629
2630
2631
2632
2633
2634
2635
2636
2637
2638
2639
2640
2641
2642
2643
2644
2645
2646
2647
2648
2649
2650
2651
2652
2653
2654
2655
2656
2657
2658
2659
2660
2661
2662
2663
2664
2665
2666
2667
2668
2669
return make_integer(0);
}
r = make_integer (/*(quad_t)*/(- a->u.i));
if (chk_minus (0, a->u.i, r->u.i)) {
ast_log(LOG_WARNING, "overflow\n");
}
free_value (a);
return r;
}
static struct val *
op_compl (struct val *a)
{
int v1 = 1;
struct val *r;
if( !a )
{
v1 = 0;
}
else
{
switch( a->type )
{
case AST_EXPR_integer:
if( a->u.i == 0 )
v1 = 0;
break;
case AST_EXPR_string:
if( a->u.s == 0 )
v1 = 0;
else
{
if( a->u.s[0] == 0 )
v1 = 0;
else if (strlen(a->u.s) == 1 && a->u.s[0] == '0' )
v1 = 0;
}
break;
case AST_EXPR_numeric_string:
if( a->u.s == 0 )
v1 = 0;
else
{
if( a->u.s[0] == 0 )
v1 = 0;
else if (strlen(a->u.s) == 1 && a->u.s[0] == '0' )
v1 = 0;
}
break;
}
}
r = make_integer (!v1);
free_value (a);
return r;
}
static int
chk_times (quad_t a, quad_t b, quad_t r)
{
/* special case: first operand is 0, no overflow possible */
if (a == 0)
return 0;
/* cerify that result of division matches second operand */
if (r / a != b)
return 1;
return 0;
}
static struct val *
op_times (struct val *a, struct val *b)
{
struct val *r;
if (!to_integer (a) || !to_integer (b)) {
free_value(a);
free_value(b);
Kevin P. Fleming
committed
if( !extra_error_message_supplied )
ast_log(LOG_WARNING, "non-numeric argument\n");
2672
2673
2674
2675
2676
2677
2678
2679
2680
2681
2682
2683
2684
2685
2686
2687
2688
2689
2690
2691
2692
2693
2694
2695
2696
2697
2698
2699
2700
2701
2702
return(make_integer(0));
}
r = make_integer (/*(quad_t)*/(a->u.i * b->u.i));
if (chk_times (a->u.i, b->u.i, r->u.i)) {
ast_log(LOG_WARNING, "overflow\n");
}
free_value (a);
free_value (b);
return (r);
}
static int
chk_div (quad_t a, quad_t b)
{
/* div by zero has been taken care of before */
/* only QUAD_MIN / -1 causes overflow */
if (a == QUAD_MIN && b == -1)
return 1;
/* everything else is OK */
return 0;
}
static struct val *
op_div (struct val *a, struct val *b)
{
struct val *r;
if (!to_integer (a)) {
free_value(a);
free_value(b);
Kevin P. Fleming
committed
if( !extra_error_message_supplied )
ast_log(LOG_WARNING, "non-numeric argument\n");
return make_integer(0);
} else if (!to_integer (b)) {
free_value(a);
free_value(b);
Kevin P. Fleming
committed
if( !extra_error_message_supplied )
ast_log(LOG_WARNING, "non-numeric argument\n");
2711
2712
2713
2714
2715
2716
2717
2718
2719
2720
2721
2722
2723
2724
2725
2726
2727
2728
2729
2730
2731
2732
2733
2734
2735
return make_integer(INT_MAX);
}
if (b->u.i == 0) {
ast_log(LOG_WARNING, "division by zero\n");
free_value(a);
free_value(b);
return make_integer(INT_MAX);
}
r = make_integer (/*(quad_t)*/(a->u.i / b->u.i));
if (chk_div (a->u.i, b->u.i)) {
ast_log(LOG_WARNING, "overflow\n");
}
free_value (a);
free_value (b);
return r;
}
static struct val *
op_rem (struct val *a, struct val *b)
{
struct val *r;
if (!to_integer (a) || !to_integer (b)) {
Kevin P. Fleming
committed
if( !extra_error_message_supplied )
ast_log(LOG_WARNING, "non-numeric argument\n");
2738
2739
2740
2741
2742
2743
2744
2745
2746
2747
2748
2749
2750
2751
2752
2753
2754
2755
2756
2757
2758
2759
2760
2761
2762
2763
2764
2765
2766
2767
2768
2769
2770
2771
2772
2773
2774
2775
2776
2777
2778
2779
2780
2781
2782
2783
2784
2785
2786
2787
2788
2789
2790
2791
2792
2793
2794
2795
2796
2797
2798
2799
2800
2801
2802
2803
2804
2805
2806
2807
2808
2809
2810
2811
2812
2813
2814
2815
2816
2817
2818
2819
2820
2821
2822
2823
2824
2825
2826
2827
2828
2829
2830
2831
2832
2833
2834
2835
2836
2837
2838
2839
2840
2841
2842
2843
2844
2845
2846
2847
2848
2849
2850
2851
2852
2853
2854
2855
2856
2857
free_value(a);
free_value(b);
return make_integer(0);
}
if (b->u.i == 0) {
ast_log(LOG_WARNING, "div by zero\n");
free_value(a);
return(b);
}
r = make_integer (/*(quad_t)*/(a->u.i % b->u.i));
/* chk_rem necessary ??? */
free_value (a);
free_value (b);
return r;
}
static struct val *
op_colon (struct val *a, struct val *b)
{
regex_t rp;
regmatch_t rm[2];
char errbuf[256];
int eval;
struct val *v;
/* coerce to both arguments to strings */
to_string(a);
to_string(b);
/* strip double quotes from both -- they'll screw up the pattern, and the search string starting at ^ */
strip_quotes(a);
strip_quotes(b);
/* compile regular expression */
if ((eval = regcomp (&rp, b->u.s, REG_EXTENDED)) != 0) {
regerror (eval, &rp, errbuf, sizeof(errbuf));
ast_log(LOG_WARNING,"regcomp() error : %s",errbuf);
free_value(a);
free_value(b);
return make_str("");
}
/* compare string against pattern */
/* remember that patterns are anchored to the beginning of the line */
if (regexec(&rp, a->u.s, (size_t)2, rm, 0) == 0 && rm[0].rm_so == 0) {
if (rm[1].rm_so >= 0) {
*(a->u.s + rm[1].rm_eo) = '\0';
v = make_str (a->u.s + rm[1].rm_so);
} else {
v = make_integer ((quad_t)(rm[0].rm_eo - rm[0].rm_so));
}
} else {
if (rp.re_nsub == 0) {
v = make_integer ((quad_t)0);
} else {
v = make_str ("");
}
}
/* free arguments and pattern buffer */
free_value (a);
free_value (b);
regfree (&rp);
return v;
}
static struct val *
op_eqtilde (struct val *a, struct val *b)
{
regex_t rp;
regmatch_t rm[2];
char errbuf[256];
int eval;
struct val *v;
/* coerce to both arguments to strings */
to_string(a);
to_string(b);
/* strip double quotes from both -- they'll screw up the pattern, and the search string starting at ^ */
strip_quotes(a);
strip_quotes(b);
/* compile regular expression */
if ((eval = regcomp (&rp, b->u.s, REG_EXTENDED)) != 0) {
regerror (eval, &rp, errbuf, sizeof(errbuf));
ast_log(LOG_WARNING,"regcomp() error : %s",errbuf);
free_value(a);
free_value(b);
return make_str("");
}
/* compare string against pattern */
/* remember that patterns are anchored to the beginning of the line */
if (regexec(&rp, a->u.s, (size_t)2, rm, 0) == 0 ) {
if (rm[1].rm_so >= 0) {
*(a->u.s + rm[1].rm_eo) = '\0';
v = make_str (a->u.s + rm[1].rm_so);
} else {
v = make_integer ((quad_t)(rm[0].rm_eo - rm[0].rm_so));
}
} else {
if (rp.re_nsub == 0) {
v = make_integer ((quad_t)0);
} else {
v = make_str ("");
}
}
/* free arguments and pattern buffer */
free_value (a);
free_value (b);
regfree (&rp);
return v;
}