#define YYBISON 1
#define YYBISON_VERSION "2.7.12-4996"
#define YYSKELETON_NAME "yacc.c"
#define YYPURE 1
#define YYPUSH 0
#define YYPULL 1
#define yyparse __ktrfmt_parse
#define yylex __ktrfmt_lex
#define yyerror __ktrfmt_error
#define yylval __ktrfmt_lval
#define yychar __ktrfmt_char
#define yydebug __ktrfmt_debug
#define yynerrs __ktrfmt_nerrs
#line 1 "ktrfmt.y"
#include <assert.h>
#include <errno.h>
#include <stdarg.h>
#include <stdlib.h>
#include <string.h>
#include <sys/queue.h>
#include "evtr.h"
#include "tok.h"
#include "internal.h"
#include "ktrfmt.tab.h"
int __ktrfmtlex(YYSTYPE *);
#define __ktrfmt_lex __ktrfmtlex
void __ktrfmt_error (struct ktrfmt_parse_ctx *, const char *);
static void do_parse_err(struct ktrfmt_parse_ctx *, const char *, ...)
__printflike(2, 3);
static
void
do_parse_err(struct ktrfmt_parse_ctx *ctx, const char *fmt, ...)
{
va_list ap;
va_start(ap, fmt);
vsnprintf(ctx->errbuf, ctx->errbufsz, fmt, ap);
va_end(ap);
ctx->err = !0;
}
#define parse_err(fmt, ...) \
do { \
do_parse_err(ctx, fmt, ##__VA_ARGS__); \
YYABORT; \
} while (0)
static
struct evtr_variable *
evtr_var_new(const char *name)
{
struct evtr_variable *var;
var = calloc(1, sizeof(*var));
if (var) {
if (!(var->name = strdup(name))) {
free(var);
return NULL;
}
var->val.type = EVTR_VAL_NIL;
}
return var;
}
static
char *
uniq_varname(void)
{
static long serno;
static char buf[100];
serno++;
snprintf(buf, sizeof(buf), "@%ld", serno);
return &buf[0];
}
static
int
index_hash(struct ktrfmt_parse_ctx *ctx, const char *hashname,
evtr_variable_value_t val, evtr_var_t *_var)
{
evtr_var_t hsh, var;
uintptr_t ret, key;
hsh = symtab_find(ctx->symtab, hashname);
if (hsh->val.type == EVTR_VAL_NIL) {
printd(PARSE, "creating hash for %s\n", hsh->name);
hsh->val.type = EVTR_VAL_HASH;
hsh->val.hashtab = hash_new();
} else if (hsh->val.type != EVTR_VAL_HASH) {
printd(PARSE, "trying to use type %d as hash\n", hsh->val.type);
return !0;
}
if (val->type == EVTR_VAL_INT) {
key = val->num;
printd(PARSE, "looking up %s[%jd] in %p\n", hsh->name,
val->num, hsh->val.hashtab);
} else if (val->type == EVTR_VAL_STR) {
key = (uintptr_t)val->str;
printd(PARSE, "looking up %s[\"%s\"] in %p\n", hsh->name,
val->str, hsh->val.hashtab);
} else {
do_parse_err(ctx, "trying to index hash '%s' with "
"non-supported value", hashname);
return !0;
}
if (hash_find(hsh->val.hashtab, key, &ret)) {
printd(PARSE, "didn't find it\n");
var = evtr_var_new(uniq_varname());
if (var) {
printd(PARSE, "inserting it as %s\n", var->name);
if (!hash_insert(hsh->val.hashtab, key,
(uintptr_t)var)) {
do_parse_err(ctx, "can't insert temporary "
"variable into hash\n");
return !0;
}
symtab_insert(ctx->symtab, var->name, var);
} else {
do_parse_err(ctx, "out of memory");
}
} else {
var = (struct evtr_variable *)ret;
}
if (!var) {
fprintf(stderr, "no var!\n");
return !0;
}
*_var = var;
return 0;
}
#line 207 "ktrfmt.tab.c"
# ifndef YY_NULL
# if defined __cplusplus && 201103L <= __cplusplus
# define YY_NULL nullptr
# else
# define YY_NULL 0
# endif
# endif
#ifdef YYERROR_VERBOSE
# undef YYERROR_VERBOSE
# define YYERROR_VERBOSE 1
#else
# define YYERROR_VERBOSE 1
#endif
#ifndef YY__KTRFMT_KTRFMT_TAB_H_INCLUDED
# define YY__KTRFMT_KTRFMT_TAB_H_INCLUDED
#ifndef YYDEBUG
# define YYDEBUG 1
#endif
#if YYDEBUG
extern int __ktrfmt_debug;
#endif
#ifndef YYTOKENTYPE
# define YYTOKENTYPE
enum yytokentype {
TOK_ID = 258,
TOK_CTOR = 259,
TOK_INT = 260,
TOK_STR = 261,
TOK_EQ = 262,
TOK_LEFT_BRACK = 263,
TOK_RIGHT_BRACK = 264,
TOK_DOT = 265
};
#endif
#if ! defined YYSTYPE && ! defined YYSTYPE_IS_DECLARED
typedef union YYSTYPE
{
#line 140 "ktrfmt.y"
struct token *tok;
struct evtr_variable *var;
struct evtr_variable_value *val;
void *na;
#line 268 "ktrfmt.tab.c"
} YYSTYPE;
# define YYSTYPE_IS_TRIVIAL 1
# define yystype YYSTYPE
# define YYSTYPE_IS_DECLARED 1
#endif
#ifdef YYPARSE_PARAM
#if defined __STDC__ || defined __cplusplus
int __ktrfmt_parse (void *YYPARSE_PARAM);
#else
int __ktrfmt_parse ();
#endif
#else
#if defined __STDC__ || defined __cplusplus
int __ktrfmt_parse (struct ktrfmt_parse_ctx *ctx);
#else
int __ktrfmt_parse ();
#endif
#endif
#endif
#line 295 "ktrfmt.tab.c"
#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;
#endif
#ifdef YYTYPE_UINT16
typedef YYTYPE_UINT16 yytype_uint16;
#else
typedef unsigned short int yytype_uint16;
#endif
#ifdef YYTYPE_INT16
typedef YYTYPE_INT16 yytype_int16;
#else
typedef short int yytype_int16;
#endif
#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>
# define YYSIZE_T size_t
# else
# define YYSIZE_T unsigned int
# endif
#endif
#define YYSIZE_MAXIMUM ((YYSIZE_T) -1)
#ifndef YY_
# if defined YYENABLE_NLS && YYENABLE_NLS
# if ENABLE_NLS
# include <libintl.h>
# define YY_(Msgid) dgettext ("bison-runtime", Msgid)
# endif
# endif
# ifndef YY_
# define YY_(Msgid) Msgid
# endif
#endif
#ifndef __attribute__
# if (! defined __GNUC__ || __GNUC__ < 2 \
|| (__GNUC__ == 2 && __GNUC_MINOR__ < 5))
# define __attribute__(Spec)
# endif
#endif
#if ! defined lint || defined __GNUC__
# define YYUSE(E) ((void) (E))
#else
# define YYUSE(E)
#endif
#ifndef lint
# define YYID(N) (N)
#else
#if (defined __STDC__ || defined __C99__FUNC__ \
|| defined __cplusplus || defined _MSC_VER)
static int
YYID (int yyi)
#else
static int
YYID (yyi)
int yyi;
#endif
{
return yyi;
}
#endif
#if ! defined yyoverflow || YYERROR_VERBOSE
# ifdef YYSTACK_USE_ALLOCA
# if YYSTACK_USE_ALLOCA
# ifdef __GNUC__
# define YYSTACK_ALLOC __builtin_alloca
# elif defined __BUILTIN_VA_ARG_INCR
# include <alloca.h>
# elif defined _AIX
# define YYSTACK_ALLOC __alloca
# elif defined _MSC_VER
# include <malloc.h>
# define alloca _alloca
# else
# define YYSTACK_ALLOC alloca
# if ! defined _ALLOCA_H && ! defined EXIT_SUCCESS && (defined __STDC__ || defined __C99__FUNC__ \
|| defined __cplusplus || defined _MSC_VER)
# include <stdlib.h>
# ifndef EXIT_SUCCESS
# define EXIT_SUCCESS 0
# endif
# endif
# endif
# endif
# endif
# ifdef YYSTACK_ALLOC
# define YYSTACK_FREE(Ptr) do { ; } while (YYID (0))
# ifndef YYSTACK_ALLOC_MAXIMUM
# define YYSTACK_ALLOC_MAXIMUM 4032
# endif
# else
# define YYSTACK_ALLOC YYMALLOC
# define YYSTACK_FREE YYFREE
# ifndef YYSTACK_ALLOC_MAXIMUM
# define YYSTACK_ALLOC_MAXIMUM YYSIZE_MAXIMUM
# endif
# if (defined __cplusplus && ! defined EXIT_SUCCESS \
&& ! ((defined YYMALLOC || defined malloc) \
&& (defined YYFREE || defined free)))
# include <stdlib.h>
# ifndef EXIT_SUCCESS
# define EXIT_SUCCESS 0
# endif
# endif
# ifndef YYMALLOC
# define YYMALLOC malloc
# if ! defined malloc && ! defined EXIT_SUCCESS && (defined __STDC__ || defined __C99__FUNC__ \
|| defined __cplusplus || defined _MSC_VER)
void *malloc (YYSIZE_T);
# endif
# endif
# ifndef YYFREE
# define YYFREE free
# if ! defined free && ! defined EXIT_SUCCESS && (defined __STDC__ || defined __C99__FUNC__ \
|| defined __cplusplus || defined _MSC_VER)
void free (void *);
# endif
# endif
# endif
#endif
#if (! defined yyoverflow \
&& (! defined __cplusplus \
|| (defined YYSTYPE_IS_TRIVIAL && YYSTYPE_IS_TRIVIAL)))
union yyalloc
{
yytype_int16 yyss_alloc;
YYSTYPE yyvs_alloc;
};
# define YYSTACK_GAP_MAXIMUM (sizeof (union yyalloc) - 1)
# define YYSTACK_BYTES(N) \
((N) * (sizeof (yytype_int16) + sizeof (YYSTYPE)) \
+ YYSTACK_GAP_MAXIMUM)
# define YYCOPY_NEEDED 1
# define YYSTACK_RELOCATE(Stack_alloc, Stack) \
do \
{ \
YYSIZE_T yynewbytes; \
YYCOPY (&yyptr->Stack_alloc, Stack, yysize); \
Stack = &yyptr->Stack_alloc; \
yynewbytes = yystacksize * sizeof (*Stack) + YYSTACK_GAP_MAXIMUM; \
yyptr += yynewbytes / sizeof (*yyptr); \
} \
while (YYID (0))
#endif
#if defined YYCOPY_NEEDED && YYCOPY_NEEDED
# ifndef YYCOPY
# if defined __GNUC__ && 1 < __GNUC__
# define YYCOPY(Dst, Src, Count) \
__builtin_memcpy (Dst, Src, (Count) * sizeof (*(Src)))
# else
# define YYCOPY(Dst, Src, Count) \
do \
{ \
YYSIZE_T yyi; \
for (yyi = 0; yyi < (Count); yyi++) \
(Dst)[yyi] = (Src)[yyi]; \
} \
while (YYID (0))
# endif
# endif
#endif
#define YYFINAL 12
#define YYLAST 20
#define YYNTOKENS 11
#define YYNNTS 11
#define YYNRULES 19
#define YYNSTATES 25
#define YYUNDEFTOK 2
#define YYMAXUTOK 265
#define YYTRANSLATE(YYX) \
((unsigned int) (YYX) <= YYMAXUTOK ? yytranslate[YYX] : YYUNDEFTOK)
static const yytype_uint8 yytranslate[] =
{
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
};
#if YYDEBUG
static const yytype_uint8 yyprhs[] =
{
0, 0, 3, 5, 7, 9, 11, 13, 15, 18,
20, 23, 25, 27, 32, 36, 38, 40, 44, 48
};
static const yytype_int8 yyrhs[] =
{
12, 0, -1, 13, -1, 19, -1, 21, -1, 5,
-1, 6, -1, 14, -1, 14, 15, -1, 4, -1,
4, 15, -1, 3, -1, 14, -1, 18, 8, 18,
9, -1, 18, 10, 3, -1, 17, -1, 18, -1,
19, 7, 14, -1, 19, 7, 16, -1, 20, -1
};
static const yytype_uint16 yyrline[] =
{
0, 168, 168, 170, 173, 175, 189, 203, 212, 217,
230, 255, 273, 277, 284, 297, 301, 305, 312, 320
};
#endif
#if YYDEBUG || YYERROR_VERBOSE || 1
static const char *const yytname[] =
{
"$end", "error", "$undefined", "TOK_ID", "TOK_CTOR", "TOK_INT",
"TOK_STR", "TOK_EQ", "TOK_LEFT_BRACK", "TOK_RIGHT_BRACK", "TOK_DOT",
"$accept", "input", "stmt", "constant", "ctor_args", "construct_expr",
"primary_expr", "postfix_expr", "unary_expr", "assign_expr", "expr", YY_NULL
};
#endif
# ifdef YYPRINT
static const yytype_uint16 yytoknum[] =
{
0, 256, 257, 258, 259, 260, 261, 262, 263, 264,
265
};
# endif
static const yytype_uint8 yyr1[] =
{
0, 11, 12, 13, 13, 14, 14, 15, 15, 16,
16, 17, 17, 18, 18, 18, 19, 20, 20, 21
};
static const yytype_uint8 yyr2[] =
{
0, 2, 1, 1, 1, 1, 1, 1, 2, 1,
2, 1, 1, 4, 3, 1, 1, 3, 3, 1
};
static const yytype_uint8 yydefact[] =
{
0, 11, 5, 6, 0, 2, 12, 15, 16, 3,
19, 4, 1, 0, 0, 0, 0, 14, 9, 17,
18, 13, 7, 10, 8
};
static const yytype_int8 yydefgoto[] =
{
-1, 4, 5, 6, 23, 20, 7, 8, 9, 10,
11
};
#define YYPACT_NINF -17
static const yytype_int8 yypact[] =
{
-1, -17, -17, -17, 1, -17, -17, -17, 6, 8,
-17, -17, -17, -1, 16, 4, 3, -17, 12, -17,
-17, -17, 12, -17, -17
};
static const yytype_int8 yypgoto[] =
{
-17, -17, -17, -15, -16, -17, -17, 7, -17, -17,
-17
};
#define YYTABLE_NINF -1
static const yytype_uint8 yytable[] =
{
19, 12, 1, 22, 2, 3, 24, 22, 18, 2,
3, 13, 21, 14, 13, 15, 14, 2, 3, 17,
16
};
#define yypact_value_is_default(Yystate) \
(!!((Yystate) == (-17)))
#define yytable_value_is_error(Yytable_value) \
YYID (0)
static const yytype_uint8 yycheck[] =
{
15, 0, 3, 18, 5, 6, 22, 22, 4, 5,
6, 8, 9, 10, 8, 7, 10, 5, 6, 3,
13
};
static const yytype_uint8 yystos[] =
{
0, 3, 5, 6, 12, 13, 14, 17, 18, 19,
20, 21, 0, 8, 10, 7, 18, 3, 4, 14,
16, 9, 14, 15, 15
};
#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
#define YYFAIL goto yyerrlab
#if defined YYFAIL
#endif
#define YYRECOVERING() (!!yyerrstatus)
#define YYBACKUP(Token, Value) \
do \
if (yychar == YYEMPTY) \
{ \
yychar = (Token); \
yylval = (Value); \
YYPOPSTACK (yylen); \
yystate = *yyssp; \
goto yybackup; \
} \
else \
{ \
yyerror (ctx, YY_("syntax error: cannot back up")); \
YYERROR; \
} \
while (YYID (0))
#define YYTERROR 1
#define YYERRCODE 256
#ifndef YY_LOCATION_PRINT
# define YY_LOCATION_PRINT(File, Loc) ((void) 0)
#endif
#ifdef YYLEX_PARAM
# define YYLEX yylex (&yylval, YYLEX_PARAM)
#else
# define YYLEX yylex (&yylval)
#endif
#if YYDEBUG
# ifndef YYFPRINTF
# include <stdio.h>
# define YYFPRINTF fprintf
# endif
# define YYDPRINTF(Args) \
do { \
if (yydebug) \
YYFPRINTF Args; \
} while (YYID (0))
# define YY_SYMBOL_PRINT(Title, Type, Value, Location) \
do { \
if (yydebug) \
{ \
YYFPRINTF (stderr, "%s ", Title); \
yy_symbol_print (stderr, \
Type, Value, ctx); \
YYFPRINTF (stderr, "\n"); \
} \
} while (YYID (0))
#if (defined __STDC__ || defined __C99__FUNC__ \
|| defined __cplusplus || defined _MSC_VER)
static void
yy_symbol_value_print (FILE *yyoutput, int yytype, YYSTYPE const * const yyvaluep, struct ktrfmt_parse_ctx *ctx)
#else
static void
yy_symbol_value_print (yyoutput, yytype, yyvaluep, ctx)
FILE *yyoutput;
int yytype;
YYSTYPE const * const yyvaluep;
struct ktrfmt_parse_ctx *ctx;
#endif
{
FILE *yyo = yyoutput;
YYUSE (yyo);
if (!yyvaluep)
return;
YYUSE (ctx);
# ifdef YYPRINT
if (yytype < YYNTOKENS)
YYPRINT (yyoutput, yytoknum[yytype], *yyvaluep);
# else
YYUSE (yyoutput);
# endif
YYUSE (yytype);
}
#if (defined __STDC__ || defined __C99__FUNC__ \
|| defined __cplusplus || defined _MSC_VER)
static void
yy_symbol_print (FILE *yyoutput, int yytype, YYSTYPE const * const yyvaluep, struct ktrfmt_parse_ctx *ctx)
#else
static void
yy_symbol_print (yyoutput, yytype, yyvaluep, ctx)
FILE *yyoutput;
int yytype;
YYSTYPE const * const yyvaluep;
struct ktrfmt_parse_ctx *ctx;
#endif
{
if (yytype < YYNTOKENS)
YYFPRINTF (yyoutput, "token %s (", yytname[yytype]);
else
YYFPRINTF (yyoutput, "nterm %s (", yytname[yytype]);
yy_symbol_value_print (yyoutput, yytype, yyvaluep, ctx);
YYFPRINTF (yyoutput, ")");
}
#if (defined __STDC__ || defined __C99__FUNC__ \
|| defined __cplusplus || defined _MSC_VER)
static void
yy_stack_print (yytype_int16 *yybottom, yytype_int16 *yytop)
#else
static void
yy_stack_print (yybottom, yytop)
yytype_int16 *yybottom;
yytype_int16 *yytop;
#endif
{
YYFPRINTF (stderr, "Stack now");
for (; yybottom <= yytop; yybottom++)
{
int yybot = *yybottom;
YYFPRINTF (stderr, " %d", yybot);
}
YYFPRINTF (stderr, "\n");
}
# define YY_STACK_PRINT(Bottom, Top) \
do { \
if (yydebug) \
yy_stack_print ((Bottom), (Top)); \
} while (YYID (0))
#if (defined __STDC__ || defined __C99__FUNC__ \
|| defined __cplusplus || defined _MSC_VER)
static void
yy_reduce_print (YYSTYPE *yyvsp, int yyrule, struct ktrfmt_parse_ctx *ctx)
#else
static void
yy_reduce_print (yyvsp, yyrule, ctx)
YYSTYPE *yyvsp;
int yyrule;
struct ktrfmt_parse_ctx *ctx;
#endif
{
int yynrhs = yyr2[yyrule];
int yyi;
unsigned long int yylno = yyrline[yyrule];
YYFPRINTF (stderr, "Reducing stack by rule %d (line %lu):\n",
yyrule - 1, yylno);
for (yyi = 0; yyi < yynrhs; yyi++)
{
YYFPRINTF (stderr, " $%d = ", yyi + 1);
yy_symbol_print (stderr, yyrhs[yyprhs[yyrule] + yyi],
&(yyvsp[(yyi + 1) - (yynrhs)])
, ctx);
YYFPRINTF (stderr, "\n");
}
}
# define YY_REDUCE_PRINT(Rule) \
do { \
if (yydebug) \
yy_reduce_print (yyvsp, Rule, ctx); \
} while (YYID (0))
int yydebug;
#else
# define YYDPRINTF(Args)
# define YY_SYMBOL_PRINT(Title, Type, Value, Location)
# define YY_STACK_PRINT(Bottom, Top)
# define YY_REDUCE_PRINT(Rule)
#endif
#ifndef YYINITDEPTH
# define YYINITDEPTH 200
#endif
#ifndef YYMAXDEPTH
# define YYMAXDEPTH 10000
#endif
#if YYERROR_VERBOSE
# ifndef yystrlen
# if defined __GLIBC__ && defined _STRING_H
# define yystrlen strlen
# else
#if (defined __STDC__ || defined __C99__FUNC__ \
|| defined __cplusplus || defined _MSC_VER)
static YYSIZE_T
yystrlen (const char *yystr)
#else
static YYSIZE_T
yystrlen (yystr)
const char *yystr;
#endif
{
YYSIZE_T yylen;
for (yylen = 0; yystr[yylen]; yylen++)
continue;
return yylen;
}
# endif
# endif
# ifndef yystpcpy
# if defined __GLIBC__ && defined _STRING_H && defined _GNU_SOURCE
# define yystpcpy stpcpy
# else
#if (defined __STDC__ || defined __C99__FUNC__ \
|| defined __cplusplus || defined _MSC_VER)
static char *
yystpcpy (char *yydest, const char *yysrc)
#else
static char *
yystpcpy (yydest, yysrc)
char *yydest;
const char *yysrc;
#endif
{
char *yyd = yydest;
const char *yys = yysrc;
while ((*yyd++ = *yys++) != '\0')
continue;
return yyd - 1;
}
# endif
# endif
# ifndef yytnamerr
static YYSIZE_T
yytnamerr (char *yyres, const char *yystr)
{
if (*yystr == '"')
{
YYSIZE_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;
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
static int
yysyntax_error (YYSIZE_T *yymsg_alloc, char **yymsg,
yytype_int16 *yyssp, int yytoken)
{
YYSIZE_T yysize0 = yytnamerr (YY_NULL, yytname[yytoken]);
YYSIZE_T yysize = yysize0;
enum { YYERROR_VERBOSE_ARGS_MAXIMUM = 5 };
const char *yyformat = YY_NULL;
char const *yyarg[YYERROR_VERBOSE_ARGS_MAXIMUM];
int yycount = 0;
if (yytoken != YYEMPTY)
{
int yyn = yypact[*yyssp];
yyarg[yycount++] = yytname[yytoken];
if (!yypact_value_is_default (yyn))
{
int yyxbegin = yyn < 0 ? -yyn : 0;
int yychecklim = YYLAST - yyn + 1;
int yyxend = yychecklim < YYNTOKENS ? yychecklim : YYNTOKENS;
int yyx;
for (yyx = yyxbegin; yyx < yyxend; ++yyx)
if (yycheck[yyx + yyn] == yyx && yyx != YYTERROR
&& !yytable_value_is_error (yytable[yyx + yyn]))
{
if (yycount == YYERROR_VERBOSE_ARGS_MAXIMUM)
{
yycount = 1;
yysize = yysize0;
break;
}
yyarg[yycount++] = yytname[yyx];
{
YYSIZE_T yysize1 = yysize + yytnamerr (YY_NULL, yytname[yyx]);
if (! (yysize <= yysize1
&& yysize1 <= YYSTACK_ALLOC_MAXIMUM))
return 2;
yysize = yysize1;
}
}
}
}
switch (yycount)
{
# define YYCASE_(N, S) \
case N: \
yyformat = S; \
break
YYCASE_(0, YY_("syntax error"));
YYCASE_(1, YY_("syntax error, unexpected %s"));
YYCASE_(2, YY_("syntax error, unexpected %s, expecting %s"));
YYCASE_(3, YY_("syntax error, unexpected %s, expecting %s or %s"));
YYCASE_(4, YY_("syntax error, unexpected %s, expecting %s or %s or %s"));
YYCASE_(5, YY_("syntax error, unexpected %s, expecting %s or %s or %s or %s"));
# undef YYCASE_
}
{
YYSIZE_T yysize1 = yysize + yystrlen (yyformat);
if (! (yysize <= yysize1 && yysize1 <= YYSTACK_ALLOC_MAXIMUM))
return 2;
yysize = yysize1;
}
if (*yymsg_alloc < yysize)
{
*yymsg_alloc = 2 * yysize;
if (! (yysize <= *yymsg_alloc
&& *yymsg_alloc <= YYSTACK_ALLOC_MAXIMUM))
*yymsg_alloc = YYSTACK_ALLOC_MAXIMUM;
return 1;
}
{
char *yyp = *yymsg;
int yyi = 0;
while ((*yyp = *yyformat) != '\0')
if (*yyp == '%' && yyformat[1] == 's' && yyi < yycount)
{
yyp += yytnamerr (yyp, yyarg[yyi++]);
yyformat += 2;
}
else
{
yyp++;
yyformat++;
}
}
return 0;
}
#endif
#if (defined __STDC__ || defined __C99__FUNC__ \
|| defined __cplusplus || defined _MSC_VER)
static void
yydestruct (const char *yymsg, int yytype, YYSTYPE *yyvaluep, struct ktrfmt_parse_ctx *ctx)
#else
static void
yydestruct (yymsg, yytype, yyvaluep, ctx)
const char *yymsg;
int yytype;
YYSTYPE *yyvaluep;
struct ktrfmt_parse_ctx *ctx;
#endif
{
YYUSE (yyvaluep);
YYUSE (ctx);
if (!yymsg)
yymsg = "Deleting";
YY_SYMBOL_PRINT (yymsg, yytype, yyvaluep, yylocationp);
YYUSE (yytype);
}
#ifdef YYPARSE_PARAM
#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
#if (defined __STDC__ || defined __C99__FUNC__ \
|| defined __cplusplus || defined _MSC_VER)
int
yyparse (struct ktrfmt_parse_ctx *ctx)
#else
int
yyparse (ctx)
struct ktrfmt_parse_ctx *ctx;
#endif
#endif
{
int yychar;
#if defined __GNUC__ && 407 <= __GNUC__ * 100 + __GNUC_MINOR__
# define YY_IGNORE_MAYBE_UNINITIALIZED_BEGIN \
_Pragma ("GCC diagnostic push") \
_Pragma ("GCC diagnostic ignored \"-Wuninitialized\"")\
_Pragma ("GCC diagnostic ignored \"-Wmaybe-uninitialized\"")
# define YY_IGNORE_MAYBE_UNINITIALIZED_END \
_Pragma ("GCC diagnostic pop")
#else
static YYSTYPE yyval_default;
# define YY_INITIAL_VALUE(Value) = Value
#endif
#ifndef YY_IGNORE_MAYBE_UNINITIALIZED_BEGIN
# define YY_IGNORE_MAYBE_UNINITIALIZED_BEGIN
# define YY_IGNORE_MAYBE_UNINITIALIZED_END
#endif
#ifndef YY_INITIAL_VALUE
# define YY_INITIAL_VALUE(Value)
#endif
YYSTYPE yylval YY_INITIAL_VALUE(yyval_default);
int yynerrs;
int yystate;
int yyerrstatus;
yytype_int16 yyssa[YYINITDEPTH];
yytype_int16 *yyss;
yytype_int16 *yyssp;
YYSTYPE yyvsa[YYINITDEPTH];
YYSTYPE *yyvs;
YYSTYPE *yyvsp;
YYSIZE_T yystacksize;
int yyn;
int yyresult;
int yytoken = 0;
YYSTYPE yyval;
#if YYERROR_VERBOSE
char yymsgbuf[128];
char *yymsg = yymsgbuf;
YYSIZE_T yymsg_alloc = sizeof yymsgbuf;
#endif
#define YYPOPSTACK(N) (yyvsp -= (N), yyssp -= (N))
int yylen = 0;
yyssp = yyss = yyssa;
yyvsp = yyvs = yyvsa;
yystacksize = YYINITDEPTH;
YYDPRINTF ((stderr, "Starting parse\n"));
yystate = 0;
yyerrstatus = 0;
yynerrs = 0;
yychar = YYEMPTY;
goto yysetstate;
yynewstate:
yyssp++;
yysetstate:
*yyssp = yystate;
if (yyss + yystacksize - 1 <= yyssp)
{
YYSIZE_T yysize = yyssp - yyss + 1;
#ifdef yyoverflow
{
YYSTYPE *yyvs1 = yyvs;
yytype_int16 *yyss1 = yyss;
yyoverflow (YY_("memory exhausted"),
&yyss1, yysize * sizeof (*yyssp),
&yyvs1, yysize * sizeof (*yyvsp),
&yystacksize);
yyss = yyss1;
yyvs = yyvs1;
}
#else
# ifndef YYSTACK_RELOCATE
goto yyexhaustedlab;
# else
if (YYMAXDEPTH <= yystacksize)
goto yyexhaustedlab;
yystacksize *= 2;
if (YYMAXDEPTH < yystacksize)
yystacksize = YYMAXDEPTH;
{
yytype_int16 *yyss1 = yyss;
union yyalloc *yyptr =
(union yyalloc *) YYSTACK_ALLOC (YYSTACK_BYTES (yystacksize));
if (! yyptr)
goto yyexhaustedlab;
YYSTACK_RELOCATE (yyss_alloc, yyss);
YYSTACK_RELOCATE (yyvs_alloc, yyvs);
# undef YYSTACK_RELOCATE
if (yyss1 != yyssa)
YYSTACK_FREE (yyss1);
}
# endif
#endif
yyssp = yyss + yysize - 1;
yyvsp = yyvs + 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));
if (yystate == YYFINAL)
YYACCEPT;
goto yybackup;
yybackup:
yyn = yypact[yystate];
if (yypact_value_is_default (yyn))
goto yydefault;
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);
YY_SYMBOL_PRINT ("Next token is", yytoken, &yylval, &yylloc);
}
yyn += yytoken;
if (yyn < 0 || YYLAST < yyn || yycheck[yyn] != yytoken)
goto yydefault;
yyn = yytable[yyn];
if (yyn <= 0)
{
if (yytable_value_is_error (yyn))
goto yyerrlab;
yyn = -yyn;
goto yyreduce;
}
if (yyerrstatus)
yyerrstatus--;
YY_SYMBOL_PRINT ("Shifting", yytoken, &yylval, &yylloc);
yychar = YYEMPTY;
yystate = yyn;
YY_IGNORE_MAYBE_UNINITIALIZED_BEGIN
*++yyvsp = yylval;
YY_IGNORE_MAYBE_UNINITIALIZED_END
goto yynewstate;
yydefault:
yyn = yydefact[yystate];
if (yyn == 0)
goto yyerrlab;
goto yyreduce;
yyreduce:
yylen = yyr2[yyn];
yyval = yyvsp[1-yylen];
YY_REDUCE_PRINT (yyn);
switch (yyn)
{
case 3:
#line 170 "ktrfmt.y"
{
ctx->var = (yyvsp[(1) - (1)].var);
}
break;
case 5:
#line 175 "ktrfmt.y"
{
evtr_var_t var;
if (!(yyvsp[(1) - (1)].tok)->str)
parse_err("out of memory");
var = evtr_var_new(uniq_varname());
var->val.type = EVTR_VAL_INT;
errno = 0;
var->val.num = strtoll((yyvsp[(1) - (1)].tok)->str, NULL, 0);
if (errno) {
parse_err("Can't parse numeric constant '%s'", (yyvsp[(1) - (1)].tok)->str);
}
(yyval.var) = var;
tok_free((yyvsp[(1) - (1)].tok));
}
break;
case 6:
#line 189 "ktrfmt.y"
{
evtr_var_t var;
if (!(yyvsp[(1) - (1)].tok)->str)
parse_err("out of memory");
var = evtr_var_new(uniq_varname());
var->val.type = EVTR_VAL_STR;
var->val.str = (yyvsp[(1) - (1)].tok)->str;
if (!var->val.str) {
parse_err("out of memory");
}
(yyval.var) = var;
tok_free((yyvsp[(1) - (1)].tok));
}
break;
case 7:
#line 203 "ktrfmt.y"
{
evtr_var_t ctor;
ctor = evtr_var_new(uniq_varname());
ctor->val.type = EVTR_VAL_CTOR;
ctor->val.ctor.name = NULL;
TAILQ_INIT(&ctor->val.ctor.args);
TAILQ_INSERT_HEAD(&ctor->val.ctor.args, &(yyvsp[(1) - (1)].var)->val, link);
(yyval.var) = ctor;
}
break;
case 8:
#line 212 "ktrfmt.y"
{
TAILQ_INSERT_HEAD(&(yyvsp[(2) - (2)].var)->val.ctor.args, &(yyvsp[(1) - (2)].var)->val, link);
(yyval.var) = (yyvsp[(2) - (2)].var);
}
break;
case 9:
#line 217 "ktrfmt.y"
{
evtr_var_t var;
if (!(yyvsp[(1) - (1)].tok)->str)
parse_err("out of memory");
printd(PARSE, "TOK_CTOR\n");
printd(PARSE, "tok: %p, str = %p\n", (yyvsp[(1) - (1)].tok), (yyvsp[(1) - (1)].tok)->str);
var = evtr_var_new(uniq_varname());
var->val.type = EVTR_VAL_CTOR;
var->val.ctor.name = (yyvsp[(1) - (1)].tok)->str;
TAILQ_INIT(&var->val.ctor.args);
tok_free((yyvsp[(1) - (1)].tok));
(yyval.var) = var;
}
break;
case 10:
#line 230 "ktrfmt.y"
{
evtr_variable_value_t val;
if (!(yyvsp[(1) - (2)].tok)->str)
parse_err("out of memory");
printd(PARSE, "TOK_CTOR\n");
printd(PARSE, "tok: %p, str = %p\n", (yyvsp[(1) - (2)].tok), (yyvsp[(1) - (2)].tok)->str);
(yyvsp[(2) - (2)].var)->val.ctor.name = (yyvsp[(1) - (2)].tok)->str;
(yyval.var) = (yyvsp[(2) - (2)].var);
printd(PARSE, "CTOR: %s\n", (yyvsp[(1) - (2)].tok)->str);
TAILQ_FOREACH(val, &(yyvsp[(2) - (2)].var)->val.ctor.args, link) {
switch (val->type) {
case EVTR_VAL_INT:
printd(PARSE, "\t%jd\n", val->num);
break;
case EVTR_VAL_STR:
printd(PARSE, "\t\"%s\"\n", val->str);
break;
case EVTR_VAL_NIL:
assert(!"can't get here");
default:
;
}
}
}
break;
case 11:
#line 255 "ktrfmt.y"
{
evtr_var_t var;
if (!(yyvsp[(1) - (1)].tok)->str)
parse_err("out of memory");
printd(PARSE, "TOK_ID\n");
printd(PARSE, "tok: %p, str = %p\n", (yyvsp[(1) - (1)].tok), (yyvsp[(1) - (1)].tok)->str);
var = symtab_find(ctx->symtab, (yyvsp[(1) - (1)].tok)->str);
if (!var) {
if (!(var = evtr_var_new((yyvsp[(1) - (1)].tok)->str))) {
tok_free((yyvsp[(1) - (1)].tok));
parse_err("out of memory");
}
printd(PARSE, "creating var %s\n", (yyvsp[(1) - (1)].tok)->str);
symtab_insert(ctx->symtab, (yyvsp[(1) - (1)].tok)->str, var);
}
(yyval.var) = var;
tok_free((yyvsp[(1) - (1)].tok));
}
break;
case 12:
#line 273 "ktrfmt.y"
{
(yyval.var) = (yyvsp[(1) - (1)].var);
}
break;
case 13:
#line 277 "ktrfmt.y"
{
evtr_var_t var;
if (index_hash(ctx, (yyvsp[(1) - (4)].var)->name, &(yyvsp[(3) - (4)].var)->val, &var))
YYABORT;
(yyval.var) = var;
}
break;
case 14:
#line 284 "ktrfmt.y"
{
evtr_var_t var, tmp;
if (!(yyvsp[(3) - (3)].tok)->str)
parse_err("out of memory");
tmp = evtr_var_new(uniq_varname());
tmp->val.type = EVTR_VAL_STR;
tmp->val.str = (yyvsp[(3) - (3)].tok)->str;
if (index_hash(ctx, (yyvsp[(1) - (3)].var)->name, &tmp->val, &var))
YYABORT;
tok_free((yyvsp[(3) - (3)].tok));
(yyval.var) = var;
}
break;
case 15:
#line 297 "ktrfmt.y"
{
(yyval.var) = (yyvsp[(1) - (1)].var);
}
break;
case 16:
#line 301 "ktrfmt.y"
{
(yyval.var) = (yyvsp[(1) - (1)].var);
}
break;
case 17:
#line 305 "ktrfmt.y"
{
(yyvsp[(1) - (3)].var)->val = (yyvsp[(3) - (3)].var)->val;
ctx->ev->type = EVTR_TYPE_STMT;
ctx->ev->stmt.var = (yyvsp[(1) - (3)].var);
ctx->ev->stmt.val = &(yyvsp[(3) - (3)].var)->val;
ctx->ev->stmt.op = EVTR_OP_SET;
}
break;
case 18:
#line 312 "ktrfmt.y"
{
(yyvsp[(1) - (3)].var)->val = (yyvsp[(3) - (3)].var)->val;
ctx->ev->type = EVTR_TYPE_STMT;
ctx->ev->stmt.var = (yyvsp[(1) - (3)].var);
ctx->ev->stmt.val = &(yyvsp[(3) - (3)].var)->val;
ctx->ev->stmt.op = EVTR_OP_SET;
}
break;
case 19:
#line 320 "ktrfmt.y"
{
(yyval.na) = (yyvsp[(1) - (1)].na);
}
break;
#line 1737 "ktrfmt.tab.c"
default: break;
}
YY_SYMBOL_PRINT ("-> $$ =", yyr1[yyn], &yyval, &yyloc);
YYPOPSTACK (yylen);
yylen = 0;
YY_STACK_PRINT (yyss, yyssp);
*++yyvsp = yyval;
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:
yytoken = yychar == YYEMPTY ? YYEMPTY : YYTRANSLATE (yychar);
if (!yyerrstatus)
{
++yynerrs;
#if ! YYERROR_VERBOSE
yyerror (ctx, YY_("syntax error"));
#else
# define YYSYNTAX_ERROR yysyntax_error (&yymsg_alloc, &yymsg, \
yyssp, yytoken)
{
char const *yymsgp = YY_("syntax error");
int yysyntax_error_status;
yysyntax_error_status = YYSYNTAX_ERROR;
if (yysyntax_error_status == 0)
yymsgp = yymsg;
else if (yysyntax_error_status == 1)
{
if (yymsg != yymsgbuf)
YYSTACK_FREE (yymsg);
yymsg = (char *) YYSTACK_ALLOC (yymsg_alloc);
if (!yymsg)
{
yymsg = yymsgbuf;
yymsg_alloc = sizeof yymsgbuf;
yysyntax_error_status = 2;
}
else
{
yysyntax_error_status = YYSYNTAX_ERROR;
yymsgp = yymsg;
}
}
yyerror (ctx, yymsgp);
if (yysyntax_error_status == 2)
goto yyexhaustedlab;
}
# undef YYSYNTAX_ERROR
#endif
}
if (yyerrstatus == 3)
{
if (yychar <= YYEOF)
{
if (yychar == YYEOF)
YYABORT;
}
else
{
yydestruct ("Error: discarding",
yytoken, &yylval, ctx);
yychar = YYEMPTY;
}
}
goto yyerrlab1;
yyerrorlab:
if ( 0)
goto yyerrorlab;
YYPOPSTACK (yylen);
yylen = 0;
YY_STACK_PRINT (yyss, yyssp);
yystate = *yyssp;
goto yyerrlab1;
yyerrlab1:
yyerrstatus = 3;
for (;;)
{
yyn = yypact[yystate];
if (!yypact_value_is_default (yyn))
{
yyn += YYTERROR;
if (0 <= yyn && yyn <= YYLAST && yycheck[yyn] == YYTERROR)
{
yyn = yytable[yyn];
if (0 < yyn)
break;
}
}
if (yyssp == yyss)
YYABORT;
yydestruct ("Error: popping",
yystos[yystate], yyvsp, ctx);
YYPOPSTACK (1);
yystate = *yyssp;
YY_STACK_PRINT (yyss, yyssp);
}
YY_IGNORE_MAYBE_UNINITIALIZED_BEGIN
*++yyvsp = yylval;
YY_IGNORE_MAYBE_UNINITIALIZED_END
YY_SYMBOL_PRINT ("Shifting", yystos[yyn], yyvsp, yylsp);
yystate = yyn;
goto yynewstate;
yyacceptlab:
yyresult = 0;
goto yyreturn;
yyabortlab:
yyresult = 1;
goto yyreturn;
#if !defined yyoverflow || YYERROR_VERBOSE
yyexhaustedlab:
yyerror (ctx, YY_("memory exhausted"));
yyresult = 2;
#endif
yyreturn:
if (yychar != YYEMPTY)
{
yytoken = YYTRANSLATE (yychar);
yydestruct ("Cleanup: discarding lookahead",
yytoken, &yylval, ctx);
}
YYPOPSTACK (yylen);
YY_STACK_PRINT (yyss, yyssp);
while (yyssp != yyss)
{
yydestruct ("Cleanup: popping",
yystos[*yyssp], yyvsp, ctx);
YYPOPSTACK (1);
}
#ifndef yyoverflow
if (yyss != yyssa)
YYSTACK_FREE (yyss);
#endif
#if YYERROR_VERBOSE
if (yymsg != yymsgbuf)
YYSTACK_FREE (yymsg);
#endif
return YYID (yyresult);
}
#line 325 "ktrfmt.y"
void * __ktrfmt_scan_string(const char *);
void __ktrfmt_delete_buffer(void *);
void
__ktrfmt_error (struct ktrfmt_parse_ctx *ctx, const char *s)
{
do_parse_err(ctx, "%s", s);
}
int
parse_string(evtr_event_t ev, struct symtab *symtab, const char *str,
char *errbuf, size_t errbufsz)
{
void *bufstate;
int ret;
struct ktrfmt_parse_ctx ctx;
printd(PARSE, "parsing \"%s\"\n", str);
ctx.ev = ev;
ctx.symtab = symtab;
ctx.errbuf = errbuf;
ctx.errbuf[0] = '\0';
ctx.errbufsz = errbufsz;
ctx.err = 0;
bufstate = __ktrfmt_scan_string(str);
ret = __ktrfmt_parse(&ctx);
__ktrfmt_delete_buffer(bufstate);
return ret;
}
int
parse_var(const char *str, struct symtab *symtab, struct evtr_variable **var,
char *errbuf, size_t errbufsz)
{
void *bufstate;
int ret;
struct ktrfmt_parse_ctx ctx;
printd(PARSE, "parsing \"%s\"\n", str);
ctx.ev = NULL;
ctx.symtab = symtab;
ctx.var = NULL;
ctx.errbuf = errbuf;
ctx.errbuf[0] = '\0';
ctx.errbufsz = errbufsz;
ctx.err = 0;
bufstate = __ktrfmt_scan_string(str);
ret = __ktrfmt_parse(&ctx);
__ktrfmt_delete_buffer(bufstate);
*var = ctx.var;
return ret;
}