Coverage Report

Created: 2025-08-26 06:32

/src/yara/libyara/grammar.c
Line
Count
Source (jump to first uncovered line)
1
/* A Bison parser, made by GNU Bison 3.8.2.  */
2
3
/* Bison implementation for Yacc-like parsers in C
4
5
   Copyright (C) 1984, 1989-1990, 2000-2015, 2018-2021 Free Software Foundation,
6
   Inc.
7
8
   This program is free software: you can redistribute it and/or modify
9
   it under the terms of the GNU General Public License as published by
10
   the Free Software Foundation, either version 3 of the License, or
11
   (at your option) any later version.
12
13
   This program is distributed in the hope that it will be useful,
14
   but WITHOUT ANY WARRANTY; without even the implied warranty of
15
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16
   GNU General Public License for more details.
17
18
   You should have received a copy of the GNU General Public License
19
   along with this program.  If not, see <https://www.gnu.org/licenses/>.  */
20
21
/* As a special exception, you may create a larger work that contains
22
   part or all of the Bison parser skeleton and distribute that work
23
   under terms of your choice, so long as that work isn't itself a
24
   parser generator using the skeleton or a modified version thereof
25
   as a parser skeleton.  Alternatively, if you modify or redistribute
26
   the parser skeleton itself, you may (at your option) remove this
27
   special exception, which will cause the skeleton and the resulting
28
   Bison output files to be licensed under the GNU General Public
29
   License without this special exception.
30
31
   This special exception was added by the Free Software Foundation in
32
   version 2.2 of Bison.  */
33
34
/* C LALR(1) parser skeleton written by Richard Stallman, by
35
   simplifying the original so-called "semantic" parser.  */
36
37
/* DO NOT RELY ON FEATURES THAT ARE NOT DOCUMENTED in the manual,
38
   especially those whose name start with YY_ or yy_.  They are
39
   private implementation details that can be changed or removed.  */
40
41
/* All symbols defined below should begin with yy or YY, to avoid
42
   infringing on user name space.  This should be done even for local
43
   variables, as they might otherwise be expanded by user macros.
44
   There are some unavoidable exceptions within include files to
45
   define necessary library symbols; they are noted "INFRINGES ON
46
   USER NAME SPACE" below.  */
47
48
/* Identify Bison output, and Bison version.  */
49
#define YYBISON 30802
50
51
/* Bison version string.  */
52
#define YYBISON_VERSION "3.8.2"
53
54
/* Skeleton name.  */
55
#define YYSKELETON_NAME "yacc.c"
56
57
/* Pure parsers.  */
58
#define YYPURE 1
59
60
/* Push parsers.  */
61
#define YYPUSH 0
62
63
/* Pull parsers.  */
64
#define YYPULL 1
65
66
67
/* Substitute the variable and function names.  */
68
#define yyparse         yara_yyparse
69
#define yylex           yara_yylex
70
#define yyerror         yara_yyerror
71
#define yydebug         yara_yydebug
72
#define yynerrs         yara_yynerrs
73
74
/* First part of user prologue.  */
75
#line 32 "libyara/grammar.y"
76
77
78
#include <assert.h>
79
#include <inttypes.h>
80
#include <stdio.h>
81
#include <string.h>
82
#include <limits.h>
83
#include <stdlib.h>
84
#include <stddef.h>
85
86
#include <yara/arena.h>
87
#include <yara/integers.h>
88
#include <yara/utils.h>
89
#include <yara/strutils.h>
90
#include <yara/compiler.h>
91
#include <yara/object.h>
92
#include <yara/sizedstr.h>
93
#include <yara/exec.h>
94
#include <yara/error.h>
95
#include <yara/mem.h>
96
#include <yara/lexer.h>
97
#include <yara/parser.h>
98
99
#if defined(_MSC_VER)
100
#define llabs _abs64
101
#endif
102
103
#define YYERROR_VERBOSE
104
105
#define YYMALLOC yr_malloc
106
0
#define YYFREE yr_free
107
108
0
#define FOR_EXPRESSION_ALL  1
109
0
#define FOR_EXPRESSION_ANY  2
110
0
#define FOR_EXPRESSION_NONE 3
111
112
0
#define FOR_ITERATION_ITERATOR   1
113
0
#define FOR_ITERATION_STRING_SET 2
114
115
// fail_with_error() is used in parser actions for aborting the parsing with
116
// an error. If the error is recoverable (like syntax errors), the parser will
117
// report the error and continue parsing the next rule. If the error is a
118
// fatal, non-recoverable error, the parser will be completely aborted.
119
#define fail_with_error(e) \
120
0
    { \
121
0
      compiler->last_error = e; \
122
0
      yyerror(yyscanner, compiler, NULL); \
123
0
      switch (e) \
124
0
      { \
125
0
      case ERROR_INSUFFICIENT_MEMORY: \
126
0
        YYABORT; \
127
0
      default: \
128
0
        YYERROR; \
129
0
      } \
130
0
    }
131
132
// fail_if_error() is used in parser actions for aborting the parsing if an
133
// error has occurred. See fail_with_error for details.
134
#define fail_if_error(e) \
135
2
    if (e != ERROR_SUCCESS && e != ERROR_UNKNOWN_ESCAPE_SEQUENCE) \
136
2
    { \
137
0
      fail_with_error(e); \
138
0
    }
139
140
141
// check_type(expression, EXPRESSION_TYPE_INTEGER | EXPRESSION_TYPE_FLOAT) is
142
// used to ensure that the type of "expression" is either integer or float,
143
// the cleanup statements are executed if the condition is not met.
144
#define check_type_with_cleanup(expression, expected_type, op, cleanup) \
145
0
    if (((expression.type) & (expected_type)) == 0) \
146
0
    { \
147
0
      switch(expression.type) \
148
0
      { \
149
0
        case EXPRESSION_TYPE_INTEGER: \
150
0
          yr_compiler_set_error_extra_info( \
151
0
              compiler, "wrong type \"integer\" for " op " operator"); \
152
0
          break; \
153
0
        case EXPRESSION_TYPE_FLOAT: \
154
0
          yr_compiler_set_error_extra_info( \
155
0
              compiler, "wrong type \"float\" for " op " operator"); \
156
0
          break; \
157
0
        case EXPRESSION_TYPE_STRING: \
158
0
          yr_compiler_set_error_extra_info( \
159
0
              compiler, "wrong type \"string\" for " op " operator"); \
160
0
          break; \
161
0
        case EXPRESSION_TYPE_BOOLEAN: \
162
0
          yr_compiler_set_error_extra_info( \
163
0
              compiler, "wrong type \"boolean\" for " op " operator"); \
164
0
          break; \
165
0
      } \
166
0
      cleanup; \
167
0
      compiler->last_error = ERROR_WRONG_TYPE; \
168
0
      yyerror(yyscanner, compiler, NULL); \
169
0
      YYERROR; \
170
0
    }
171
172
// check_type(expression, EXPRESSION_TYPE_INTEGER | EXPRESSION_TYPE_FLOAT) is
173
// used to ensure that the type of "expression" is either integer or float.
174
#define check_type(expression, expected_type, op) \
175
0
    check_type_with_cleanup(expression, expected_type, op, )
176
177
178
#define loop_vars_cleanup(loop_index) \
179
0
    {  \
180
0
      YR_LOOP_CONTEXT* loop_ctx = &compiler->loop[loop_index]; \
181
0
      for (int i = 0; i < loop_ctx->vars_count; i++) \
182
0
      { \
183
0
        yr_free((void*) loop_ctx->vars[i].identifier.ptr); \
184
0
        loop_ctx->vars[i].identifier.ptr = NULL; \
185
0
        loop_ctx->vars[i].identifier.ref = YR_ARENA_NULL_REF; \
186
0
      } \
187
0
      loop_ctx->vars_count = 0; \
188
0
    } \
189
190
191
// Given a YR_EXPRESSION returns its identifier. It returns identifier.ptr if
192
// not NULL and relies on identifier.ref if otherwise.
193
#define expression_identifier(expr) \
194
    ((expr).identifier.ptr != NULL ? \
195
     (expr).identifier.ptr : \
196
     (const char*) yr_arena_ref_to_ptr(compiler->arena, &(expr).identifier.ref))
197
198
199
#define DEFAULT_BASE64_ALPHABET \
200
0
    "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/"
201
202
203
#line 204 "libyara/grammar.c"
204
205
# ifndef YY_CAST
206
#  ifdef __cplusplus
207
#   define YY_CAST(Type, Val) static_cast<Type> (Val)
208
#   define YY_REINTERPRET_CAST(Type, Val) reinterpret_cast<Type> (Val)
209
#  else
210
22
#   define YY_CAST(Type, Val) ((Type) (Val))
211
#   define YY_REINTERPRET_CAST(Type, Val) ((Type) (Val))
212
#  endif
213
# endif
214
# ifndef YY_NULLPTR
215
#  if defined __cplusplus
216
#   if 201103L <= __cplusplus
217
#    define YY_NULLPTR nullptr
218
#   else
219
#    define YY_NULLPTR 0
220
#   endif
221
#  else
222
0
#   define YY_NULLPTR ((void*)0)
223
#  endif
224
# endif
225
226
/* Use api.header.include to #include this header
227
   instead of duplicating it here.  */
228
#ifndef YY_YARA_YY_LIBYARA_GRAMMAR_H_INCLUDED
229
# define YY_YARA_YY_LIBYARA_GRAMMAR_H_INCLUDED
230
/* Debug traces.  */
231
#ifndef YYDEBUG
232
# define YYDEBUG 0
233
#endif
234
#if YYDEBUG
235
extern int yara_yydebug;
236
#endif
237
238
/* Token kinds.  */
239
#ifndef YYTOKENTYPE
240
# define YYTOKENTYPE
241
  enum yytokentype
242
  {
243
    YYEMPTY = -2,
244
    _END_OF_FILE_ = 0,             /* "end of file"  */
245
    YYerror = 256,                 /* error  */
246
    YYUNDEF = 257,                 /* "invalid token"  */
247
    _END_OF_INCLUDED_FILE_ = 258,  /* "end of included file"  */
248
    _DOT_DOT_ = 259,               /* ".."  */
249
    _RULE_ = 260,                  /* "<rule>"  */
250
    _PRIVATE_ = 261,               /* "<private>"  */
251
    _GLOBAL_ = 262,                /* "<global>"  */
252
    _META_ = 263,                  /* "<meta>"  */
253
    _STRINGS_ = 264,               /* "<strings>"  */
254
    _CONDITION_ = 265,             /* "<condition>"  */
255
    _IDENTIFIER_ = 266,            /* "identifier"  */
256
    _STRING_IDENTIFIER_ = 267,     /* "string identifier"  */
257
    _STRING_COUNT_ = 268,          /* "string count"  */
258
    _STRING_OFFSET_ = 269,         /* "string offset"  */
259
    _STRING_LENGTH_ = 270,         /* "string length"  */
260
    _STRING_IDENTIFIER_WITH_WILDCARD_ = 271, /* "string identifier with wildcard"  */
261
    _NUMBER_ = 272,                /* "integer number"  */
262
    _DOUBLE_ = 273,                /* "floating point number"  */
263
    _INTEGER_FUNCTION_ = 274,      /* "integer function"  */
264
    _TEXT_STRING_ = 275,           /* "text string"  */
265
    _HEX_STRING_ = 276,            /* "hex string"  */
266
    _REGEXP_ = 277,                /* "regular expression"  */
267
    _ASCII_ = 278,                 /* "<ascii>"  */
268
    _WIDE_ = 279,                  /* "<wide>"  */
269
    _XOR_ = 280,                   /* "<xor>"  */
270
    _BASE64_ = 281,                /* "<base64>"  */
271
    _BASE64_WIDE_ = 282,           /* "<base64wide>"  */
272
    _NOCASE_ = 283,                /* "<nocase>"  */
273
    _FULLWORD_ = 284,              /* "<fullword>"  */
274
    _AT_ = 285,                    /* "<at>"  */
275
    _FILESIZE_ = 286,              /* "<filesize>"  */
276
    _ENTRYPOINT_ = 287,            /* "<entrypoint>"  */
277
    _ALL_ = 288,                   /* "<all>"  */
278
    _ANY_ = 289,                   /* "<any>"  */
279
    _NONE_ = 290,                  /* "<none>"  */
280
    _IN_ = 291,                    /* "<in>"  */
281
    _OF_ = 292,                    /* "<of>"  */
282
    _FOR_ = 293,                   /* "<for>"  */
283
    _THEM_ = 294,                  /* "<them>"  */
284
    _MATCHES_ = 295,               /* "<matches>"  */
285
    _CONTAINS_ = 296,              /* "<contains>"  */
286
    _STARTSWITH_ = 297,            /* "<startswith>"  */
287
    _ENDSWITH_ = 298,              /* "<endswith>"  */
288
    _ICONTAINS_ = 299,             /* "<icontains>"  */
289
    _ISTARTSWITH_ = 300,           /* "<istartswith>"  */
290
    _IENDSWITH_ = 301,             /* "<iendswith>"  */
291
    _IEQUALS_ = 302,               /* "<iequals>"  */
292
    _IMPORT_ = 303,                /* "<import>"  */
293
    _TRUE_ = 304,                  /* "<true>"  */
294
    _FALSE_ = 305,                 /* "<false>"  */
295
    _OR_ = 306,                    /* "<or>"  */
296
    _AND_ = 307,                   /* "<and>"  */
297
    _NOT_ = 308,                   /* "<not>"  */
298
    _DEFINED_ = 309,               /* "<defined>"  */
299
    _EQ_ = 310,                    /* "=="  */
300
    _NEQ_ = 311,                   /* "!="  */
301
    _LT_ = 312,                    /* "<"  */
302
    _LE_ = 313,                    /* "<="  */
303
    _GT_ = 314,                    /* ">"  */
304
    _GE_ = 315,                    /* ">="  */
305
    _SHIFT_LEFT_ = 316,            /* "<<"  */
306
    _SHIFT_RIGHT_ = 317,           /* ">>"  */
307
    UNARY_MINUS = 318              /* UNARY_MINUS  */
308
  };
309
  typedef enum yytokentype yytoken_kind_t;
310
#endif
311
/* Token kinds.  */
312
16
#define YYEMPTY -2
313
8
#define _END_OF_FILE_ 0
314
4
#define YYerror 256
315
0
#define YYUNDEF 257
316
#define _END_OF_INCLUDED_FILE_ 258
317
#define _DOT_DOT_ 259
318
#define _RULE_ 260
319
#define _PRIVATE_ 261
320
#define _GLOBAL_ 262
321
#define _META_ 263
322
#define _STRINGS_ 264
323
#define _CONDITION_ 265
324
#define _IDENTIFIER_ 266
325
#define _STRING_IDENTIFIER_ 267
326
#define _STRING_COUNT_ 268
327
#define _STRING_OFFSET_ 269
328
#define _STRING_LENGTH_ 270
329
#define _STRING_IDENTIFIER_WITH_WILDCARD_ 271
330
#define _NUMBER_ 272
331
#define _DOUBLE_ 273
332
#define _INTEGER_FUNCTION_ 274
333
#define _TEXT_STRING_ 275
334
#define _HEX_STRING_ 276
335
#define _REGEXP_ 277
336
#define _ASCII_ 278
337
#define _WIDE_ 279
338
#define _XOR_ 280
339
#define _BASE64_ 281
340
#define _BASE64_WIDE_ 282
341
#define _NOCASE_ 283
342
#define _FULLWORD_ 284
343
#define _AT_ 285
344
#define _FILESIZE_ 286
345
#define _ENTRYPOINT_ 287
346
#define _ALL_ 288
347
#define _ANY_ 289
348
#define _NONE_ 290
349
#define _IN_ 291
350
#define _OF_ 292
351
#define _FOR_ 293
352
#define _THEM_ 294
353
#define _MATCHES_ 295
354
#define _CONTAINS_ 296
355
#define _STARTSWITH_ 297
356
#define _ENDSWITH_ 298
357
#define _ICONTAINS_ 299
358
#define _ISTARTSWITH_ 300
359
#define _IENDSWITH_ 301
360
#define _IEQUALS_ 302
361
#define _IMPORT_ 303
362
#define _TRUE_ 304
363
#define _FALSE_ 305
364
#define _OR_ 306
365
#define _AND_ 307
366
#define _NOT_ 308
367
#define _DEFINED_ 309
368
#define _EQ_ 310
369
#define _NEQ_ 311
370
#define _LT_ 312
371
#define _LE_ 313
372
#define _GT_ 314
373
#define _GE_ 315
374
#define _SHIFT_LEFT_ 316
375
#define _SHIFT_RIGHT_ 317
376
#define UNARY_MINUS 318
377
378
/* Value type.  */
379
#if ! defined YYSTYPE && ! defined YYSTYPE_IS_DECLARED
380
union YYSTYPE
381
{
382
#line 346 "libyara/grammar.y"
383
384
  YR_EXPRESSION   expression;
385
  SIZED_STRING*   sized_string;
386
  char*           c_string;
387
  int64_t         integer;
388
  double          double_;
389
  YR_MODIFIER     modifier;
390
  YR_ENUMERATION  enumeration;
391
  YR_STRING_SET   string_set;
392
393
  YR_ARENA_REF tag;
394
  YR_ARENA_REF rule;
395
  YR_ARENA_REF meta;
396
  YR_ARENA_REF string;
397
398
#line 399 "libyara/grammar.c"
399
400
};
401
typedef union YYSTYPE YYSTYPE;
402
# define YYSTYPE_IS_TRIVIAL 1
403
# define YYSTYPE_IS_DECLARED 1
404
#endif
405
406
407
408
409
int yara_yyparse (void *yyscanner, YR_COMPILER* compiler);
410
411
412
#endif /* !YY_YARA_YY_LIBYARA_GRAMMAR_H_INCLUDED  */
413
/* Symbol kind.  */
414
enum yysymbol_kind_t
415
{
416
  YYSYMBOL_YYEMPTY = -2,
417
  YYSYMBOL_YYEOF = 0,                      /* "end of file"  */
418
  YYSYMBOL_YYerror = 1,                    /* error  */
419
  YYSYMBOL_YYUNDEF = 2,                    /* "invalid token"  */
420
  YYSYMBOL__END_OF_INCLUDED_FILE_ = 3,     /* "end of included file"  */
421
  YYSYMBOL__DOT_DOT_ = 4,                  /* ".."  */
422
  YYSYMBOL__RULE_ = 5,                     /* "<rule>"  */
423
  YYSYMBOL__PRIVATE_ = 6,                  /* "<private>"  */
424
  YYSYMBOL__GLOBAL_ = 7,                   /* "<global>"  */
425
  YYSYMBOL__META_ = 8,                     /* "<meta>"  */
426
  YYSYMBOL__STRINGS_ = 9,                  /* "<strings>"  */
427
  YYSYMBOL__CONDITION_ = 10,               /* "<condition>"  */
428
  YYSYMBOL__IDENTIFIER_ = 11,              /* "identifier"  */
429
  YYSYMBOL__STRING_IDENTIFIER_ = 12,       /* "string identifier"  */
430
  YYSYMBOL__STRING_COUNT_ = 13,            /* "string count"  */
431
  YYSYMBOL__STRING_OFFSET_ = 14,           /* "string offset"  */
432
  YYSYMBOL__STRING_LENGTH_ = 15,           /* "string length"  */
433
  YYSYMBOL__STRING_IDENTIFIER_WITH_WILDCARD_ = 16, /* "string identifier with wildcard"  */
434
  YYSYMBOL__NUMBER_ = 17,                  /* "integer number"  */
435
  YYSYMBOL__DOUBLE_ = 18,                  /* "floating point number"  */
436
  YYSYMBOL__INTEGER_FUNCTION_ = 19,        /* "integer function"  */
437
  YYSYMBOL__TEXT_STRING_ = 20,             /* "text string"  */
438
  YYSYMBOL__HEX_STRING_ = 21,              /* "hex string"  */
439
  YYSYMBOL__REGEXP_ = 22,                  /* "regular expression"  */
440
  YYSYMBOL__ASCII_ = 23,                   /* "<ascii>"  */
441
  YYSYMBOL__WIDE_ = 24,                    /* "<wide>"  */
442
  YYSYMBOL__XOR_ = 25,                     /* "<xor>"  */
443
  YYSYMBOL__BASE64_ = 26,                  /* "<base64>"  */
444
  YYSYMBOL__BASE64_WIDE_ = 27,             /* "<base64wide>"  */
445
  YYSYMBOL__NOCASE_ = 28,                  /* "<nocase>"  */
446
  YYSYMBOL__FULLWORD_ = 29,                /* "<fullword>"  */
447
  YYSYMBOL__AT_ = 30,                      /* "<at>"  */
448
  YYSYMBOL__FILESIZE_ = 31,                /* "<filesize>"  */
449
  YYSYMBOL__ENTRYPOINT_ = 32,              /* "<entrypoint>"  */
450
  YYSYMBOL__ALL_ = 33,                     /* "<all>"  */
451
  YYSYMBOL__ANY_ = 34,                     /* "<any>"  */
452
  YYSYMBOL__NONE_ = 35,                    /* "<none>"  */
453
  YYSYMBOL__IN_ = 36,                      /* "<in>"  */
454
  YYSYMBOL__OF_ = 37,                      /* "<of>"  */
455
  YYSYMBOL__FOR_ = 38,                     /* "<for>"  */
456
  YYSYMBOL__THEM_ = 39,                    /* "<them>"  */
457
  YYSYMBOL__MATCHES_ = 40,                 /* "<matches>"  */
458
  YYSYMBOL__CONTAINS_ = 41,                /* "<contains>"  */
459
  YYSYMBOL__STARTSWITH_ = 42,              /* "<startswith>"  */
460
  YYSYMBOL__ENDSWITH_ = 43,                /* "<endswith>"  */
461
  YYSYMBOL__ICONTAINS_ = 44,               /* "<icontains>"  */
462
  YYSYMBOL__ISTARTSWITH_ = 45,             /* "<istartswith>"  */
463
  YYSYMBOL__IENDSWITH_ = 46,               /* "<iendswith>"  */
464
  YYSYMBOL__IEQUALS_ = 47,                 /* "<iequals>"  */
465
  YYSYMBOL__IMPORT_ = 48,                  /* "<import>"  */
466
  YYSYMBOL__TRUE_ = 49,                    /* "<true>"  */
467
  YYSYMBOL__FALSE_ = 50,                   /* "<false>"  */
468
  YYSYMBOL__OR_ = 51,                      /* "<or>"  */
469
  YYSYMBOL__AND_ = 52,                     /* "<and>"  */
470
  YYSYMBOL__NOT_ = 53,                     /* "<not>"  */
471
  YYSYMBOL__DEFINED_ = 54,                 /* "<defined>"  */
472
  YYSYMBOL__EQ_ = 55,                      /* "=="  */
473
  YYSYMBOL__NEQ_ = 56,                     /* "!="  */
474
  YYSYMBOL__LT_ = 57,                      /* "<"  */
475
  YYSYMBOL__LE_ = 58,                      /* "<="  */
476
  YYSYMBOL__GT_ = 59,                      /* ">"  */
477
  YYSYMBOL__GE_ = 60,                      /* ">="  */
478
  YYSYMBOL__SHIFT_LEFT_ = 61,              /* "<<"  */
479
  YYSYMBOL__SHIFT_RIGHT_ = 62,             /* ">>"  */
480
  YYSYMBOL_63_ = 63,                       /* '|'  */
481
  YYSYMBOL_64_ = 64,                       /* '^'  */
482
  YYSYMBOL_65_ = 65,                       /* '&'  */
483
  YYSYMBOL_66_ = 66,                       /* '+'  */
484
  YYSYMBOL_67_ = 67,                       /* '-'  */
485
  YYSYMBOL_68_ = 68,                       /* '*'  */
486
  YYSYMBOL_69_ = 69,                       /* '\\'  */
487
  YYSYMBOL_70_ = 70,                       /* '%'  */
488
  YYSYMBOL_71_ = 71,                       /* '~'  */
489
  YYSYMBOL_UNARY_MINUS = 72,               /* UNARY_MINUS  */
490
  YYSYMBOL_73_include_ = 73,               /* "include"  */
491
  YYSYMBOL_74_ = 74,                       /* '{'  */
492
  YYSYMBOL_75_ = 75,                       /* '}'  */
493
  YYSYMBOL_76_ = 76,                       /* ':'  */
494
  YYSYMBOL_77_ = 77,                       /* '='  */
495
  YYSYMBOL_78_ = 78,                       /* '('  */
496
  YYSYMBOL_79_ = 79,                       /* ')'  */
497
  YYSYMBOL_80_ = 80,                       /* '.'  */
498
  YYSYMBOL_81_ = 81,                       /* '['  */
499
  YYSYMBOL_82_ = 82,                       /* ']'  */
500
  YYSYMBOL_83_ = 83,                       /* ','  */
501
  YYSYMBOL_YYACCEPT = 84,                  /* $accept  */
502
  YYSYMBOL_rules = 85,                     /* rules  */
503
  YYSYMBOL_import = 86,                    /* import  */
504
  YYSYMBOL_rule = 87,                      /* rule  */
505
  YYSYMBOL_88_1 = 88,                      /* @1  */
506
  YYSYMBOL_89_2 = 89,                      /* $@2  */
507
  YYSYMBOL_meta = 90,                      /* meta  */
508
  YYSYMBOL_strings = 91,                   /* strings  */
509
  YYSYMBOL_condition = 92,                 /* condition  */
510
  YYSYMBOL_rule_modifiers = 93,            /* rule_modifiers  */
511
  YYSYMBOL_rule_modifier = 94,             /* rule_modifier  */
512
  YYSYMBOL_tags = 95,                      /* tags  */
513
  YYSYMBOL_tag_list = 96,                  /* tag_list  */
514
  YYSYMBOL_meta_declarations = 97,         /* meta_declarations  */
515
  YYSYMBOL_meta_declaration = 98,          /* meta_declaration  */
516
  YYSYMBOL_string_declarations = 99,       /* string_declarations  */
517
  YYSYMBOL_string_declaration = 100,       /* string_declaration  */
518
  YYSYMBOL_101_3 = 101,                    /* $@3  */
519
  YYSYMBOL_102_4 = 102,                    /* $@4  */
520
  YYSYMBOL_103_5 = 103,                    /* $@5  */
521
  YYSYMBOL_string_modifiers = 104,         /* string_modifiers  */
522
  YYSYMBOL_string_modifier = 105,          /* string_modifier  */
523
  YYSYMBOL_regexp_modifiers = 106,         /* regexp_modifiers  */
524
  YYSYMBOL_regexp_modifier = 107,          /* regexp_modifier  */
525
  YYSYMBOL_hex_modifiers = 108,            /* hex_modifiers  */
526
  YYSYMBOL_hex_modifier = 109,             /* hex_modifier  */
527
  YYSYMBOL_identifier = 110,               /* identifier  */
528
  YYSYMBOL_arguments = 111,                /* arguments  */
529
  YYSYMBOL_arguments_list = 112,           /* arguments_list  */
530
  YYSYMBOL_regexp = 113,                   /* regexp  */
531
  YYSYMBOL_boolean_expression = 114,       /* boolean_expression  */
532
  YYSYMBOL_expression = 115,               /* expression  */
533
  YYSYMBOL_116_6 = 116,                    /* $@6  */
534
  YYSYMBOL_117_7 = 117,                    /* $@7  */
535
  YYSYMBOL_118_8 = 118,                    /* $@8  */
536
  YYSYMBOL_119_9 = 119,                    /* $@9  */
537
  YYSYMBOL_for_iteration = 120,            /* for_iteration  */
538
  YYSYMBOL_for_variables = 121,            /* for_variables  */
539
  YYSYMBOL_iterator = 122,                 /* iterator  */
540
  YYSYMBOL_set = 123,                      /* set  */
541
  YYSYMBOL_range = 124,                    /* range  */
542
  YYSYMBOL_enumeration = 125,              /* enumeration  */
543
  YYSYMBOL_string_iterator = 126,          /* string_iterator  */
544
  YYSYMBOL_string_set = 127,               /* string_set  */
545
  YYSYMBOL_128_10 = 128,                   /* $@10  */
546
  YYSYMBOL_string_enumeration = 129,       /* string_enumeration  */
547
  YYSYMBOL_string_enumeration_item = 130,  /* string_enumeration_item  */
548
  YYSYMBOL_rule_set = 131,                 /* rule_set  */
549
  YYSYMBOL_132_11 = 132,                   /* $@11  */
550
  YYSYMBOL_rule_enumeration = 133,         /* rule_enumeration  */
551
  YYSYMBOL_rule_enumeration_item = 134,    /* rule_enumeration_item  */
552
  YYSYMBOL_for_expression = 135,           /* for_expression  */
553
  YYSYMBOL_for_quantifier = 136,           /* for_quantifier  */
554
  YYSYMBOL_primary_expression = 137        /* primary_expression  */
555
};
556
typedef enum yysymbol_kind_t yysymbol_kind_t;
557
558
559
560
561
#ifdef short
562
# undef short
563
#endif
564
565
/* On compilers that do not define __PTRDIFF_MAX__ etc., make sure
566
   <limits.h> and (if available) <stdint.h> are included
567
   so that the code can choose integer types of a good width.  */
568
569
#ifndef __PTRDIFF_MAX__
570
# include <limits.h> /* INFRINGES ON USER NAME SPACE */
571
# if defined __STDC_VERSION__ && 199901 <= __STDC_VERSION__
572
#  include <stdint.h> /* INFRINGES ON USER NAME SPACE */
573
#  define YY_STDINT_H
574
# endif
575
#endif
576
577
/* Narrow types that promote to a signed type and that can represent a
578
   signed or unsigned integer of at least N bits.  In tables they can
579
   save space and decrease cache pressure.  Promoting to a signed type
580
   helps avoid bugs in integer arithmetic.  */
581
582
#ifdef __INT_LEAST8_MAX__
583
typedef __INT_LEAST8_TYPE__ yytype_int8;
584
#elif defined YY_STDINT_H
585
typedef int_least8_t yytype_int8;
586
#else
587
typedef signed char yytype_int8;
588
#endif
589
590
#ifdef __INT_LEAST16_MAX__
591
typedef __INT_LEAST16_TYPE__ yytype_int16;
592
#elif defined YY_STDINT_H
593
typedef int_least16_t yytype_int16;
594
#else
595
typedef short yytype_int16;
596
#endif
597
598
/* Work around bug in HP-UX 11.23, which defines these macros
599
   incorrectly for preprocessor constants.  This workaround can likely
600
   be removed in 2023, as HPE has promised support for HP-UX 11.23
601
   (aka HP-UX 11i v2) only through the end of 2022; see Table 2 of
602
   <https://h20195.www2.hpe.com/V2/getpdf.aspx/4AA4-7673ENW.pdf>.  */
603
#ifdef __hpux
604
# undef UINT_LEAST8_MAX
605
# undef UINT_LEAST16_MAX
606
# define UINT_LEAST8_MAX 255
607
# define UINT_LEAST16_MAX 65535
608
#endif
609
610
#if defined __UINT_LEAST8_MAX__ && __UINT_LEAST8_MAX__ <= __INT_MAX__
611
typedef __UINT_LEAST8_TYPE__ yytype_uint8;
612
#elif (!defined __UINT_LEAST8_MAX__ && defined YY_STDINT_H \
613
       && UINT_LEAST8_MAX <= INT_MAX)
614
typedef uint_least8_t yytype_uint8;
615
#elif !defined __UINT_LEAST8_MAX__ && UCHAR_MAX <= INT_MAX
616
typedef unsigned char yytype_uint8;
617
#else
618
typedef short yytype_uint8;
619
#endif
620
621
#if defined __UINT_LEAST16_MAX__ && __UINT_LEAST16_MAX__ <= __INT_MAX__
622
typedef __UINT_LEAST16_TYPE__ yytype_uint16;
623
#elif (!defined __UINT_LEAST16_MAX__ && defined YY_STDINT_H \
624
       && UINT_LEAST16_MAX <= INT_MAX)
625
typedef uint_least16_t yytype_uint16;
626
#elif !defined __UINT_LEAST16_MAX__ && USHRT_MAX <= INT_MAX
627
typedef unsigned short yytype_uint16;
628
#else
629
typedef int yytype_uint16;
630
#endif
631
632
#ifndef YYPTRDIFF_T
633
# if defined __PTRDIFF_TYPE__ && defined __PTRDIFF_MAX__
634
4
#  define YYPTRDIFF_T __PTRDIFF_TYPE__
635
#  define YYPTRDIFF_MAXIMUM __PTRDIFF_MAX__
636
# elif defined PTRDIFF_MAX
637
#  ifndef ptrdiff_t
638
#   include <stddef.h> /* INFRINGES ON USER NAME SPACE */
639
#  endif
640
#  define YYPTRDIFF_T ptrdiff_t
641
#  define YYPTRDIFF_MAXIMUM PTRDIFF_MAX
642
# else
643
#  define YYPTRDIFF_T long
644
#  define YYPTRDIFF_MAXIMUM LONG_MAX
645
# endif
646
#endif
647
648
#ifndef YYSIZE_T
649
# ifdef __SIZE_TYPE__
650
#  define YYSIZE_T __SIZE_TYPE__
651
# elif defined size_t
652
#  define YYSIZE_T size_t
653
# elif defined __STDC_VERSION__ && 199901 <= __STDC_VERSION__
654
#  include <stddef.h> /* INFRINGES ON USER NAME SPACE */
655
#  define YYSIZE_T size_t
656
# else
657
#  define YYSIZE_T unsigned
658
# endif
659
#endif
660
661
#define YYSIZE_MAXIMUM                                  \
662
0
  YY_CAST (YYPTRDIFF_T,                                 \
663
           (YYPTRDIFF_MAXIMUM < YY_CAST (YYSIZE_T, -1)  \
664
            ? YYPTRDIFF_MAXIMUM                         \
665
            : YY_CAST (YYSIZE_T, -1)))
666
667
0
#define YYSIZEOF(X) YY_CAST (YYPTRDIFF_T, sizeof (X))
668
669
670
/* Stored state numbers (used for stacks). */
671
typedef yytype_int16 yy_state_t;
672
673
/* State numbers in computations.  */
674
typedef int yy_state_fast_t;
675
676
#ifndef YY_
677
# if defined YYENABLE_NLS && YYENABLE_NLS
678
#  if ENABLE_NLS
679
#   include <libintl.h> /* INFRINGES ON USER NAME SPACE */
680
#   define YY_(Msgid) dgettext ("bison-runtime", Msgid)
681
#  endif
682
# endif
683
# ifndef YY_
684
0
#  define YY_(Msgid) Msgid
685
# endif
686
#endif
687
688
689
#ifndef YY_ATTRIBUTE_PURE
690
# if defined __GNUC__ && 2 < __GNUC__ + (96 <= __GNUC_MINOR__)
691
#  define YY_ATTRIBUTE_PURE __attribute__ ((__pure__))
692
# else
693
#  define YY_ATTRIBUTE_PURE
694
# endif
695
#endif
696
697
#ifndef YY_ATTRIBUTE_UNUSED
698
# if defined __GNUC__ && 2 < __GNUC__ + (7 <= __GNUC_MINOR__)
699
#  define YY_ATTRIBUTE_UNUSED __attribute__ ((__unused__))
700
# else
701
#  define YY_ATTRIBUTE_UNUSED
702
# endif
703
#endif
704
705
/* Suppress unused-variable warnings by "using" E.  */
706
#if ! defined lint || defined __GNUC__
707
12
# define YY_USE(E) ((void) (E))
708
#else
709
# define YY_USE(E) /* empty */
710
#endif
711
712
/* Suppress an incorrect diagnostic about yylval being uninitialized.  */
713
#if defined __GNUC__ && ! defined __ICC && 406 <= __GNUC__ * 100 + __GNUC_MINOR__
714
# if __GNUC__ * 100 + __GNUC_MINOR__ < 407
715
#  define YY_IGNORE_MAYBE_UNINITIALIZED_BEGIN                           \
716
    _Pragma ("GCC diagnostic push")                                     \
717
    _Pragma ("GCC diagnostic ignored \"-Wuninitialized\"")
718
# else
719
#  define YY_IGNORE_MAYBE_UNINITIALIZED_BEGIN                           \
720
    _Pragma ("GCC diagnostic push")                                     \
721
    _Pragma ("GCC diagnostic ignored \"-Wuninitialized\"")              \
722
    _Pragma ("GCC diagnostic ignored \"-Wmaybe-uninitialized\"")
723
# endif
724
# define YY_IGNORE_MAYBE_UNINITIALIZED_END      \
725
    _Pragma ("GCC diagnostic pop")
726
#else
727
4
# define YY_INITIAL_VALUE(Value) Value
728
#endif
729
#ifndef YY_IGNORE_MAYBE_UNINITIALIZED_BEGIN
730
# define YY_IGNORE_MAYBE_UNINITIALIZED_BEGIN
731
# define YY_IGNORE_MAYBE_UNINITIALIZED_END
732
#endif
733
#ifndef YY_INITIAL_VALUE
734
# define YY_INITIAL_VALUE(Value) /* Nothing. */
735
#endif
736
737
#if defined __cplusplus && defined __GNUC__ && ! defined __ICC && 6 <= __GNUC__
738
# define YY_IGNORE_USELESS_CAST_BEGIN                          \
739
    _Pragma ("GCC diagnostic push")                            \
740
    _Pragma ("GCC diagnostic ignored \"-Wuseless-cast\"")
741
# define YY_IGNORE_USELESS_CAST_END            \
742
    _Pragma ("GCC diagnostic pop")
743
#endif
744
#ifndef YY_IGNORE_USELESS_CAST_BEGIN
745
# define YY_IGNORE_USELESS_CAST_BEGIN
746
# define YY_IGNORE_USELESS_CAST_END
747
#endif
748
749
750
14
#define YY_ASSERT(E) ((void) (0 && (E)))
751
752
#if 1
753
754
/* The parser invokes alloca or malloc; define the necessary symbols.  */
755
756
# ifdef YYSTACK_USE_ALLOCA
757
#  if YYSTACK_USE_ALLOCA
758
#   ifdef __GNUC__
759
#    define YYSTACK_ALLOC __builtin_alloca
760
#   elif defined __BUILTIN_VA_ARG_INCR
761
#    include <alloca.h> /* INFRINGES ON USER NAME SPACE */
762
#   elif defined _AIX
763
#    define YYSTACK_ALLOC __alloca
764
#   elif defined _MSC_VER
765
#    include <malloc.h> /* INFRINGES ON USER NAME SPACE */
766
#    define alloca _alloca
767
#   else
768
#    define YYSTACK_ALLOC alloca
769
#    if ! defined _ALLOCA_H && ! defined EXIT_SUCCESS
770
#     include <stdlib.h> /* INFRINGES ON USER NAME SPACE */
771
      /* Use EXIT_SUCCESS as a witness for stdlib.h.  */
772
#     ifndef EXIT_SUCCESS
773
#      define EXIT_SUCCESS 0
774
#     endif
775
#    endif
776
#   endif
777
#  endif
778
# endif
779
780
# ifdef YYSTACK_ALLOC
781
   /* Pacify GCC's 'empty if-body' warning.  */
782
#  define YYSTACK_FREE(Ptr) do { /* empty */; } while (0)
783
#  ifndef YYSTACK_ALLOC_MAXIMUM
784
    /* The OS might guarantee only one guard page at the bottom of the stack,
785
       and a page size can be as small as 4096 bytes.  So we cannot safely
786
       invoke alloca (N) if N exceeds 4096.  Use a slightly smaller number
787
       to allow for a few compiler-allocated temporary stack slots.  */
788
#   define YYSTACK_ALLOC_MAXIMUM 4032 /* reasonable circa 2006 */
789
#  endif
790
# else
791
#  define YYSTACK_ALLOC YYMALLOC
792
0
#  define YYSTACK_FREE YYFREE
793
#  ifndef YYSTACK_ALLOC_MAXIMUM
794
0
#   define YYSTACK_ALLOC_MAXIMUM YYSIZE_MAXIMUM
795
#  endif
796
#  if (defined __cplusplus && ! defined EXIT_SUCCESS \
797
       && ! ((defined YYMALLOC || defined malloc) \
798
             && (defined YYFREE || defined free)))
799
#   include <stdlib.h> /* INFRINGES ON USER NAME SPACE */
800
#   ifndef EXIT_SUCCESS
801
#    define EXIT_SUCCESS 0
802
#   endif
803
#  endif
804
#  ifndef YYMALLOC
805
#   define YYMALLOC malloc
806
#   if ! defined malloc && ! defined EXIT_SUCCESS
807
void *malloc (YYSIZE_T); /* INFRINGES ON USER NAME SPACE */
808
#   endif
809
#  endif
810
#  ifndef YYFREE
811
#   define YYFREE free
812
#   if ! defined free && ! defined EXIT_SUCCESS
813
void free (void *); /* INFRINGES ON USER NAME SPACE */
814
#   endif
815
#  endif
816
# endif
817
#endif /* 1 */
818
819
#if (! defined yyoverflow \
820
     && (! defined __cplusplus \
821
         || (defined YYSTYPE_IS_TRIVIAL && YYSTYPE_IS_TRIVIAL)))
822
823
/* A type that is properly aligned for any stack member.  */
824
union yyalloc
825
{
826
  yy_state_t yyss_alloc;
827
  YYSTYPE yyvs_alloc;
828
};
829
830
/* The size of the maximum gap between one aligned stack and the next.  */
831
0
# define YYSTACK_GAP_MAXIMUM (YYSIZEOF (union yyalloc) - 1)
832
833
/* The size of an array large to enough to hold all stacks, each with
834
   N elements.  */
835
# define YYSTACK_BYTES(N) \
836
     ((N) * (YYSIZEOF (yy_state_t) + YYSIZEOF (YYSTYPE)) \
837
      + YYSTACK_GAP_MAXIMUM)
838
839
# define YYCOPY_NEEDED 1
840
841
/* Relocate STACK from its old location to the new one.  The
842
   local variables YYSIZE and YYSTACKSIZE give the old and new number of
843
   elements in the stack, and YYPTR gives the new location of the
844
   stack.  Advance YYPTR to a properly aligned location for the next
845
   stack.  */
846
# define YYSTACK_RELOCATE(Stack_alloc, Stack)                           \
847
0
    do                                                                  \
848
0
      {                                                                 \
849
0
        YYPTRDIFF_T yynewbytes;                                         \
850
0
        YYCOPY (&yyptr->Stack_alloc, Stack, yysize);                    \
851
0
        Stack = &yyptr->Stack_alloc;                                    \
852
0
        yynewbytes = yystacksize * YYSIZEOF (*Stack) + YYSTACK_GAP_MAXIMUM; \
853
0
        yyptr += yynewbytes / YYSIZEOF (*yyptr);                        \
854
0
      }                                                                 \
855
0
    while (0)
856
857
#endif
858
859
#if defined YYCOPY_NEEDED && YYCOPY_NEEDED
860
/* Copy COUNT objects from SRC to DST.  The source and destination do
861
   not overlap.  */
862
# ifndef YYCOPY
863
#  if defined __GNUC__ && 1 < __GNUC__
864
#   define YYCOPY(Dst, Src, Count) \
865
0
      __builtin_memcpy (Dst, Src, YY_CAST (YYSIZE_T, (Count)) * sizeof (*(Src)))
866
#  else
867
#   define YYCOPY(Dst, Src, Count)              \
868
      do                                        \
869
        {                                       \
870
          YYPTRDIFF_T yyi;                      \
871
          for (yyi = 0; yyi < (Count); yyi++)   \
872
            (Dst)[yyi] = (Src)[yyi];            \
873
        }                                       \
874
      while (0)
875
#  endif
876
# endif
877
#endif /* !YYCOPY_NEEDED */
878
879
/* YYFINAL -- State number of the termination state.  */
880
14
#define YYFINAL  2
881
/* YYLAST -- Last index in YYTABLE.  */
882
14
#define YYLAST   480
883
884
/* YYNTOKENS -- Number of terminals.  */
885
6
#define YYNTOKENS  84
886
/* YYNNTS -- Number of nonterminals.  */
887
#define YYNNTS  54
888
/* YYNRULES -- Number of rules.  */
889
#define YYNRULES  169
890
/* YYNSTATES -- Number of states.  */
891
#define YYNSTATES  276
892
893
/* YYMAXUTOK -- Last valid token kind.  */
894
4
#define YYMAXUTOK   319
895
896
897
/* YYTRANSLATE(TOKEN-NUM) -- Symbol number corresponding to TOKEN-NUM
898
   as returned by yylex, with out-of-bounds checking.  */
899
#define YYTRANSLATE(YYX)                                \
900
4
  (0 <= (YYX) && (YYX) <= YYMAXUTOK                     \
901
4
   ? YY_CAST (yysymbol_kind_t, yytranslate[YYX])        \
902
4
   : YYSYMBOL_YYUNDEF)
903
904
/* YYTRANSLATE[TOKEN-NUM] -- Symbol number corresponding to TOKEN-NUM
905
   as returned by yylex.  */
906
static const yytype_int8 yytranslate[] =
907
{
908
       0,     2,     2,     2,     2,     2,     2,     2,     2,     2,
909
       2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
910
       2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
911
       2,     2,     2,     2,     2,     2,     2,    70,    65,     2,
912
      78,    79,    68,    66,    83,    67,    80,     2,     2,     2,
913
       2,     2,     2,     2,     2,     2,     2,     2,    76,     2,
914
       2,    77,     2,     2,     2,     2,     2,     2,     2,     2,
915
       2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
916
       2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
917
       2,    81,    69,    82,    64,     2,     2,     2,     2,     2,
918
       2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
919
       2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
920
       2,     2,     2,    74,    63,    75,    71,     2,     2,     2,
921
       2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
922
       2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
923
       2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
924
       2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
925
       2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
926
       2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
927
       2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
928
       2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
929
       2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
930
       2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
931
       2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
932
       2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
933
       2,     2,     2,     2,     2,     2,     1,     2,     3,     4,
934
       5,     6,     7,     8,     9,    10,    11,    12,    13,    14,
935
      15,    16,    17,    18,    19,    20,    21,    22,    23,    24,
936
      25,    26,    27,    28,    29,    30,    31,    32,    33,    34,
937
      35,    36,    37,    38,    39,    40,    41,    42,    43,    44,
938
      45,    46,    47,    48,    49,    50,    51,    52,    53,    54,
939
      55,    56,    57,    58,    59,    60,    61,    62,    72,    73
940
};
941
942
#if YYDEBUG
943
/* YYRLINE[YYN] -- Source line where rule number YYN was defined.  */
944
static const yytype_int16 yyrline[] =
945
{
946
       0,   366,   366,   367,   368,   369,   370,   371,   372,   376,
947
     384,   397,   402,   396,   433,   436,   452,   455,   470,   478,
948
     479,   484,   485,   491,   494,   510,   519,   561,   562,   567,
949
     584,   598,   612,   626,   644,   645,   651,   650,   667,   666,
950
     687,   686,   711,   717,   777,   778,   779,   780,   781,   782,
951
     788,   809,   840,   845,   862,   867,   887,   888,   902,   903,
952
     904,   905,   906,   910,   911,   925,   929,  1025,  1073,  1134,
953
    1179,  1180,  1184,  1219,  1272,  1327,  1358,  1365,  1372,  1385,
954
    1396,  1407,  1418,  1429,  1440,  1451,  1462,  1477,  1493,  1505,
955
    1580,  1618,  1522,  1747,  1771,  1783,  1813,  1832,  1859,  1912,
956
    1919,  1926,  1925,  1972,  1971,  2022,  2030,  2038,  2046,  2054,
957
    2062,  2070,  2074,  2082,  2083,  2108,  2128,  2156,  2230,  2262,
958
    2280,  2291,  2334,  2350,  2370,  2381,  2380,  2389,  2403,  2404,
959
    2419,  2429,  2444,  2443,  2456,  2457,  2462,  2495,  2520,  2576,
960
    2583,  2589,  2595,  2605,  2609,  2617,  2629,  2643,  2650,  2657,
961
    2682,  2694,  2706,  2718,  2733,  2745,  2760,  2803,  2824,  2859,
962
    2894,  2928,  2953,  2970,  2980,  2990,  3000,  3010,  3030,  3050
963
};
964
#endif
965
966
/** Accessing symbol of state STATE.  */
967
4
#define YY_ACCESSING_SYMBOL(State) YY_CAST (yysymbol_kind_t, yystos[State])
968
969
#if 1
970
/* The user-facing name of the symbol whose (internal) number is
971
   YYSYMBOL.  No bounds checking.  */
972
static const char *yysymbol_name (yysymbol_kind_t yysymbol) YY_ATTRIBUTE_UNUSED;
973
974
/* YYTNAME[SYMBOL-NUM] -- String name of the symbol SYMBOL-NUM.
975
   First, the terminals, then, starting at YYNTOKENS, nonterminals.  */
976
static const char *const yytname[] =
977
{
978
  "\"end of file\"", "error", "\"invalid token\"",
979
  "\"end of included file\"", "\"..\"", "\"<rule>\"", "\"<private>\"",
980
  "\"<global>\"", "\"<meta>\"", "\"<strings>\"", "\"<condition>\"",
981
  "\"identifier\"", "\"string identifier\"", "\"string count\"",
982
  "\"string offset\"", "\"string length\"",
983
  "\"string identifier with wildcard\"", "\"integer number\"",
984
  "\"floating point number\"", "\"integer function\"", "\"text string\"",
985
  "\"hex string\"", "\"regular expression\"", "\"<ascii>\"", "\"<wide>\"",
986
  "\"<xor>\"", "\"<base64>\"", "\"<base64wide>\"", "\"<nocase>\"",
987
  "\"<fullword>\"", "\"<at>\"", "\"<filesize>\"", "\"<entrypoint>\"",
988
  "\"<all>\"", "\"<any>\"", "\"<none>\"", "\"<in>\"", "\"<of>\"",
989
  "\"<for>\"", "\"<them>\"", "\"<matches>\"", "\"<contains>\"",
990
  "\"<startswith>\"", "\"<endswith>\"", "\"<icontains>\"",
991
  "\"<istartswith>\"", "\"<iendswith>\"", "\"<iequals>\"", "\"<import>\"",
992
  "\"<true>\"", "\"<false>\"", "\"<or>\"", "\"<and>\"", "\"<not>\"",
993
  "\"<defined>\"", "\"==\"", "\"!=\"", "\"<\"", "\"<=\"", "\">\"",
994
  "\">=\"", "\"<<\"", "\">>\"", "'|'", "'^'", "'&'", "'+'", "'-'", "'*'",
995
  "'\\\\'", "'%'", "'~'", "UNARY_MINUS", "\"include\"", "'{'", "'}'",
996
  "':'", "'='", "'('", "')'", "'.'", "'['", "']'", "','", "$accept",
997
  "rules", "import", "rule", "@1", "$@2", "meta", "strings", "condition",
998
  "rule_modifiers", "rule_modifier", "tags", "tag_list",
999
  "meta_declarations", "meta_declaration", "string_declarations",
1000
  "string_declaration", "$@3", "$@4", "$@5", "string_modifiers",
1001
  "string_modifier", "regexp_modifiers", "regexp_modifier",
1002
  "hex_modifiers", "hex_modifier", "identifier", "arguments",
1003
  "arguments_list", "regexp", "boolean_expression", "expression", "$@6",
1004
  "$@7", "$@8", "$@9", "for_iteration", "for_variables", "iterator", "set",
1005
  "range", "enumeration", "string_iterator", "string_set", "$@10",
1006
  "string_enumeration", "string_enumeration_item", "rule_set", "$@11",
1007
  "rule_enumeration", "rule_enumeration_item", "for_expression",
1008
  "for_quantifier", "primary_expression", YY_NULLPTR
1009
};
1010
1011
static const char *
1012
yysymbol_name (yysymbol_kind_t yysymbol)
1013
0
{
1014
0
  return yytname[yysymbol];
1015
0
}
1016
#endif
1017
1018
12
#define YYPACT_NINF (-170)
1019
1020
#define yypact_value_is_default(Yyn) \
1021
12
  ((Yyn) == YYPACT_NINF)
1022
1023
#define YYTABLE_NINF (-139)
1024
1025
#define yytable_value_is_error(Yyn) \
1026
0
  0
1027
1028
/* YYPACT[STATE-NUM] -- Index in YYTABLE of the portion describing
1029
   STATE-NUM.  */
1030
static const yytype_int16 yypact[] =
1031
{
1032
    -170,    32,  -170,    28,  -170,     0,  -170,  -170,   137,  -170,
1033
    -170,  -170,  -170,  -170,    11,  -170,  -170,  -170,  -170,   -40,
1034
      59,     1,  -170,    83,    91,  -170,    39,    99,   106,    53,
1035
    -170,    46,   106,  -170,   122,   127,    54,  -170,    71,   122,
1036
    -170,    74,    77,  -170,  -170,  -170,  -170,   148,   118,  -170,
1037
      78,  -170,  -170,   134,   158,   165,  -170,    42,   131,   110,
1038
     119,  -170,  -170,   121,  -170,  -170,  -170,  -170,  -170,  -170,
1039
    -170,   144,  -170,  -170,    78,    78,   212,   212,    78,    55,
1040
    -170,    95,  -170,   166,  -170,   291,  -170,  -170,  -170,   212,
1041
     130,   130,   212,   212,   212,   212,     7,   390,  -170,  -170,
1042
    -170,  -170,    95,   125,   251,    78,   194,   212,  -170,  -170,
1043
     -35,   187,   212,   212,   212,   212,   212,   212,   212,   212,
1044
     212,   212,   212,   212,   212,   212,   212,   212,   212,   212,
1045
     212,   212,   212,   212,   170,   145,    96,   204,   390,   212,
1046
    -170,  -170,   199,   301,   333,   352,  -170,    68,   212,  -170,
1047
    -170,   149,   141,   146,  -170,   311,    78,    78,  -170,   222,
1048
      47,  -170,  -170,   390,   390,   390,   390,   390,   390,   390,
1049
     390,   390,   390,   390,   390,   390,    18,    18,   400,   151,
1050
     410,   126,   126,  -170,  -170,   -35,  -170,  -170,  -170,  -170,
1051
     157,   160,   161,  -170,  -170,  -170,  -170,  -170,  -170,  -170,
1052
    -170,  -170,  -170,  -170,   189,  -170,  -170,  -170,  -170,   -33,
1053
     164,    -2,  -170,    78,  -170,   184,  -170,    -3,   231,   212,
1054
     130,  -170,  -170,   228,   226,   227,   212,  -170,  -170,  -170,
1055
    -170,    -9,   238,   146,  -170,  -170,   -62,  -170,   202,    35,
1056
    -170,   390,  -170,   -60,   192,   193,   371,   195,   212,    55,
1057
    -170,  -170,  -170,  -170,  -170,    -3,  -170,  -170,   231,   257,
1058
    -170,  -170,  -170,  -170,    78,    43,   189,  -170,  -170,   196,
1059
     -37,  -170,   212,  -170,  -170,   390
1060
};
1061
1062
/* YYDEFACT[STATE-NUM] -- Default reduction number in state STATE-NUM.
1063
   Performed when YYTABLE does not specify something else to do.  Zero
1064
   means the default is an error.  */
1065
static const yytype_uint8 yydefact[] =
1066
{
1067
       2,     0,     1,    19,     8,     0,     4,     3,     0,     9,
1068
       7,     6,     5,    10,     0,    21,    22,    20,    11,    23,
1069
       0,     0,    25,    24,    14,    26,     0,    16,     0,     0,
1070
      12,     0,    15,    27,     0,     0,     0,    28,     0,    17,
1071
      34,     0,     0,    30,    29,    32,    33,     0,    36,    35,
1072
       0,    13,    31,     0,     0,     0,    66,    86,   151,   153,
1073
     155,   147,   148,     0,   149,    74,   144,   145,   140,   141,
1074
     142,     0,    76,    77,     0,     0,     0,     0,     0,   156,
1075
     169,    18,    75,     0,   139,   111,    42,    56,    63,     0,
1076
       0,     0,     0,     0,     0,     0,     0,   138,    99,   100,
1077
     157,   166,     0,    75,   111,    70,     0,     0,   103,   101,
1078
       0,     0,     0,     0,     0,     0,     0,     0,     0,     0,
1079
       0,     0,     0,     0,     0,     0,     0,     0,     0,     0,
1080
       0,     0,     0,     0,     0,    37,    39,    41,    87,     0,
1081
      88,   150,     0,     0,     0,     0,    89,     0,     0,   112,
1082
     143,     0,    71,    72,    67,     0,     0,     0,   127,   125,
1083
      93,    94,    78,    79,    81,    83,    80,    82,    84,    85,
1084
     109,   110,   105,   107,   106,   108,   167,   168,   165,   163,
1085
     164,   158,   159,   160,   161,     0,   162,    48,    45,    44,
1086
      49,    52,    54,    46,    47,    43,    62,    59,    58,    60,
1087
      61,    57,    65,    64,     0,   152,   154,   146,   115,     0,
1088
       0,     0,    69,     0,    68,   104,   102,     0,     0,     0,
1089
       0,    95,    96,     0,     0,     0,     0,   125,   114,   124,
1090
      91,     0,     0,    73,   130,   131,     0,   128,   136,     0,
1091
     134,    98,    97,     0,     0,     0,     0,     0,     0,   117,
1092
     113,   118,   120,   116,   126,     0,   137,   133,     0,     0,
1093
      50,    53,    55,   121,     0,     0,   122,   129,   135,     0,
1094
       0,   119,     0,    51,    92,   123
1095
};
1096
1097
/* YYPGOTO[NTERM-NUM].  */
1098
static const yytype_int16 yypgoto[] =
1099
{
1100
    -170,  -170,   273,   274,  -170,  -170,  -170,  -170,  -170,  -170,
1101
    -170,  -170,  -170,  -170,   246,  -170,   241,  -170,  -170,  -170,
1102
    -170,  -170,  -170,  -170,  -170,  -170,    51,  -170,  -170,   173,
1103
     -50,   -75,  -170,  -170,  -170,  -170,  -170,  -170,  -170,  -170,
1104
     -90,  -170,  -170,  -169,  -170,  -170,    30,   101,  -170,  -170,
1105
      29,   218,  -170,   -66
1106
};
1107
1108
/* YYDEFGOTO[NTERM-NUM].  */
1109
static const yytype_int16 yydefgoto[] =
1110
{
1111
       0,     1,     6,     7,    19,    35,    27,    30,    42,     8,
1112
      17,    21,    23,    32,    33,    39,    40,    53,    54,    55,
1113
     135,   195,   136,   201,   137,   203,    79,   151,   152,    80,
1114
     102,    82,   147,   247,   157,   156,   210,   211,   250,   251,
1115
     140,   265,   228,   160,   217,   236,   237,   161,   218,   239,
1116
     240,    83,    84,    85
1117
};
1118
1119
/* YYTABLE[YYPACT[STATE-NUM]] -- What to do in state STATE-NUM.  If
1120
   positive, shift that token.  If negative, reduce the rule whose
1121
   number is the opposite.  If YYTABLE_NINF, syntax error.  */
1122
static const yytype_int16 yytable[] =
1123
{
1124
      81,   141,    56,   103,   158,    97,   158,   259,   146,   234,
1125
     100,   101,   104,   235,   108,   109,   221,   254,   -90,   260,
1126
      13,   255,    18,   138,    98,    99,   142,   143,   144,   145,
1127
     153,     9,     2,     3,   231,     4,    20,   -19,   -19,   -19,
1128
     229,   155,   274,   159,   -90,   227,   163,   164,   165,   166,
1129
     167,   168,   169,   170,   171,   172,   173,   174,   175,   176,
1130
     177,   178,   179,   180,   181,   182,   183,   184,   186,   248,
1131
      22,    43,    89,   204,    44,    24,     5,   219,    90,   208,
1132
       5,   232,   186,   220,   130,   131,   132,   133,   148,    56,
1133
      57,    58,    59,    60,    25,    61,    62,    63,    64,    26,
1134
      65,    10,   196,    45,    46,   209,   215,   216,    29,    66,
1135
      67,    68,    69,    70,   257,    28,    71,    31,   258,   197,
1136
     198,    47,   271,    36,   199,   200,   272,    72,    73,    34,
1137
     242,    74,    75,   105,    38,   106,   107,    41,   233,   -40,
1138
     -38,   252,    14,    15,    16,    76,   108,   109,    48,    77,
1139
      50,   187,    51,   241,    86,    56,    78,    58,    59,    60,
1140
     246,    61,    62,    63,    64,    52,    65,    91,   188,   189,
1141
     190,   191,   192,   193,   194,    66,    67,    68,    69,    70,
1142
      87,    56,   266,    58,    59,    60,    88,    61,    62,    63,
1143
      64,    92,    65,   226,   132,   133,   148,   -75,   -75,    94,
1144
      93,    66,    67,   110,   149,   154,   275,   185,   139,    65,
1145
     202,    76,   125,   126,   270,    77,   129,   130,   131,   132,
1146
     133,   148,    95,    56,   213,    58,    59,    60,   212,    61,
1147
      62,    63,    64,  -132,    65,   223,   109,    76,   224,   225,
1148
     230,    77,   238,    66,    67,   243,   244,   245,    95,   253,
1149
     125,   126,   127,   128,   129,   130,   131,   132,   133,   148,
1150
     125,   126,   127,   128,   129,   130,   131,   132,   133,   148,
1151
     256,   261,   262,   264,   269,   273,    11,    12,    37,    76,
1152
      49,   205,   249,    77,   162,   267,   222,   268,  -138,    96,
1153
      95,   111,   112,   113,   114,   115,   116,   117,   118,     0,
1154
       0,     0,     0,     0,     0,     0,   119,   120,   121,   122,
1155
     123,   124,   125,   126,   127,   128,   129,   130,   131,   132,
1156
     133,   134,     0,     0,     0,     0,     0,     0,  -138,     0,
1157
     150,   111,   112,   113,   114,   115,   116,   117,   118,     0,
1158
       0,     0,     0,     0,     0,     0,   119,   120,   121,   122,
1159
     123,   124,   125,   126,   127,   128,   129,   130,   131,   132,
1160
     133,   134,   125,   126,   127,   128,   129,   130,   131,   132,
1161
     133,   148,   125,   126,   127,   128,   129,   130,   131,   132,
1162
     133,   148,     0,   206,     0,     0,     0,     0,     0,     0,
1163
       0,     0,     0,   214,   125,   126,   127,   128,   129,   130,
1164
     131,   132,   133,   148,     0,     0,     0,     0,     0,     0,
1165
       0,     0,   207,   125,   126,   127,   128,   129,   130,   131,
1166
     132,   133,   148,     0,     0,     0,     0,     0,     0,     0,
1167
       0,   150,   125,   126,   127,   128,   129,   130,   131,   132,
1168
     133,   148,     0,     0,     0,     0,     0,     0,     0,     0,
1169
     263,   125,   126,   127,   128,   129,   130,   131,   132,   133,
1170
     148,   125,   126,     0,   128,   129,   130,   131,   132,   133,
1171
     148,   125,   126,     0,     0,     0,   130,   131,   132,   133,
1172
     148
1173
};
1174
1175
static const yytype_int16 yycheck[] =
1176
{
1177
      50,    91,    11,    78,    39,    71,    39,    67,     1,    12,
1178
      76,    77,    78,    16,    51,    52,   185,    79,    11,    79,
1179
      20,    83,    11,    89,    74,    75,    92,    93,    94,    95,
1180
     105,     3,     0,     1,    36,     3,    76,     5,     6,     7,
1181
     209,   107,    79,    78,    37,    78,   112,   113,   114,   115,
1182
     116,   117,   118,   119,   120,   121,   122,   123,   124,   125,
1183
     126,   127,   128,   129,   130,   131,   132,   133,   134,    78,
1184
      11,    17,    30,   139,    20,    74,    48,    30,    36,    11,
1185
      48,    83,   148,    36,    66,    67,    68,    69,    70,    11,
1186
      12,    13,    14,    15,    11,    17,    18,    19,    20,     8,
1187
      22,    73,     6,    49,    50,    37,   156,   157,     9,    31,
1188
      32,    33,    34,    35,    79,    76,    38,    11,    83,    23,
1189
      24,    67,    79,    77,    28,    29,    83,    49,    50,    76,
1190
     220,    53,    54,    78,    12,    80,    81,    10,   213,    21,
1191
      22,   231,     5,     6,     7,    67,    51,    52,    77,    71,
1192
      76,     6,    75,   219,    20,    11,    78,    13,    14,    15,
1193
     226,    17,    18,    19,    20,    17,    22,    36,    23,    24,
1194
      25,    26,    27,    28,    29,    31,    32,    33,    34,    35,
1195
      22,    11,   248,    13,    14,    15,    21,    17,    18,    19,
1196
      20,    81,    22,     4,    68,    69,    70,    51,    52,    78,
1197
      81,    31,    32,    37,    79,    11,   272,    37,    78,    22,
1198
       6,    67,    61,    62,   264,    71,    65,    66,    67,    68,
1199
      69,    70,    78,    11,    83,    13,    14,    15,    79,    17,
1200
      18,    19,    20,    11,    22,    78,    52,    67,    78,    78,
1201
      76,    71,    11,    31,    32,    17,    20,    20,    78,    11,
1202
      61,    62,    63,    64,    65,    66,    67,    68,    69,    70,
1203
      61,    62,    63,    64,    65,    66,    67,    68,    69,    70,
1204
      68,    79,    79,    78,    17,    79,     3,     3,    32,    67,
1205
      39,    82,   231,    71,   111,   255,   185,   258,    37,    71,
1206
      78,    40,    41,    42,    43,    44,    45,    46,    47,    -1,
1207
      -1,    -1,    -1,    -1,    -1,    -1,    55,    56,    57,    58,
1208
      59,    60,    61,    62,    63,    64,    65,    66,    67,    68,
1209
      69,    70,    -1,    -1,    -1,    -1,    -1,    -1,    37,    -1,
1210
      79,    40,    41,    42,    43,    44,    45,    46,    47,    -1,
1211
      -1,    -1,    -1,    -1,    -1,    -1,    55,    56,    57,    58,
1212
      59,    60,    61,    62,    63,    64,    65,    66,    67,    68,
1213
      69,    70,    61,    62,    63,    64,    65,    66,    67,    68,
1214
      69,    70,    61,    62,    63,    64,    65,    66,    67,    68,
1215
      69,    70,    -1,    82,    -1,    -1,    -1,    -1,    -1,    -1,
1216
      -1,    -1,    -1,    82,    61,    62,    63,    64,    65,    66,
1217
      67,    68,    69,    70,    -1,    -1,    -1,    -1,    -1,    -1,
1218
      -1,    -1,    79,    61,    62,    63,    64,    65,    66,    67,
1219
      68,    69,    70,    -1,    -1,    -1,    -1,    -1,    -1,    -1,
1220
      -1,    79,    61,    62,    63,    64,    65,    66,    67,    68,
1221
      69,    70,    -1,    -1,    -1,    -1,    -1,    -1,    -1,    -1,
1222
      79,    61,    62,    63,    64,    65,    66,    67,    68,    69,
1223
      70,    61,    62,    -1,    64,    65,    66,    67,    68,    69,
1224
      70,    61,    62,    -1,    -1,    -1,    66,    67,    68,    69,
1225
      70
1226
};
1227
1228
/* YYSTOS[STATE-NUM] -- The symbol kind of the accessing symbol of
1229
   state STATE-NUM.  */
1230
static const yytype_uint8 yystos[] =
1231
{
1232
       0,    85,     0,     1,     3,    48,    86,    87,    93,     3,
1233
      73,    86,    87,    20,     5,     6,     7,    94,    11,    88,
1234
      76,    95,    11,    96,    74,    11,     8,    90,    76,     9,
1235
      91,    11,    97,    98,    76,    89,    77,    98,    12,    99,
1236
     100,    10,    92,    17,    20,    49,    50,    67,    77,   100,
1237
      76,    75,    17,   101,   102,   103,    11,    12,    13,    14,
1238
      15,    17,    18,    19,    20,    22,    31,    32,    33,    34,
1239
      35,    38,    49,    50,    53,    54,    67,    71,    78,   110,
1240
     113,   114,   115,   135,   136,   137,    20,    22,    21,    30,
1241
      36,    36,    81,    81,    78,    78,   135,   137,   114,   114,
1242
     137,   137,   114,   115,   137,    78,    80,    81,    51,    52,
1243
      37,    40,    41,    42,    43,    44,    45,    46,    47,    55,
1244
      56,    57,    58,    59,    60,    61,    62,    63,    64,    65,
1245
      66,    67,    68,    69,    70,   104,   106,   108,   137,    78,
1246
     124,   124,   137,   137,   137,   137,     1,   116,    70,    79,
1247
      79,   111,   112,   115,    11,   137,   119,   118,    39,    78,
1248
     127,   131,   113,   137,   137,   137,   137,   137,   137,   137,
1249
     137,   137,   137,   137,   137,   137,   137,   137,   137,   137,
1250
     137,   137,   137,   137,   137,    37,   137,     6,    23,    24,
1251
      25,    26,    27,    28,    29,   105,     6,    23,    24,    28,
1252
      29,   107,     6,   109,   137,    82,    82,    79,    11,    37,
1253
     120,   121,    79,    83,    82,   114,   114,   128,   132,    30,
1254
      36,   127,   131,    78,    78,    78,     4,    78,   126,   127,
1255
      76,    36,    83,   115,    12,    16,   129,   130,    11,   133,
1256
     134,   137,   124,    17,    20,    20,   137,   117,    78,   110,
1257
     122,   123,   124,    11,    79,    83,    68,    79,    83,    67,
1258
      79,    79,    79,    79,    78,   125,   137,   130,   134,    17,
1259
     114,    79,    83,    79,    79,   137
1260
};
1261
1262
/* YYR1[RULE-NUM] -- Symbol kind of the left-hand side of rule RULE-NUM.  */
1263
static const yytype_uint8 yyr1[] =
1264
{
1265
       0,    84,    85,    85,    85,    85,    85,    85,    85,    85,
1266
      86,    88,    89,    87,    90,    90,    91,    91,    92,    93,
1267
      93,    94,    94,    95,    95,    96,    96,    97,    97,    98,
1268
      98,    98,    98,    98,    99,    99,   101,   100,   102,   100,
1269
     103,   100,   104,   104,   105,   105,   105,   105,   105,   105,
1270
     105,   105,   105,   105,   105,   105,   106,   106,   107,   107,
1271
     107,   107,   107,   108,   108,   109,   110,   110,   110,   110,
1272
     111,   111,   112,   112,   113,   114,   115,   115,   115,   115,
1273
     115,   115,   115,   115,   115,   115,   115,   115,   115,   115,
1274
     116,   117,   115,   115,   115,   115,   115,   115,   115,   115,
1275
     115,   118,   115,   119,   115,   115,   115,   115,   115,   115,
1276
     115,   115,   115,   120,   120,   121,   121,   122,   122,   123,
1277
     123,   124,   125,   125,   126,   128,   127,   127,   129,   129,
1278
     130,   130,   132,   131,   133,   133,   134,   134,   135,   135,
1279
     136,   136,   136,   137,   137,   137,   137,   137,   137,   137,
1280
     137,   137,   137,   137,   137,   137,   137,   137,   137,   137,
1281
     137,   137,   137,   137,   137,   137,   137,   137,   137,   137
1282
};
1283
1284
/* YYR2[RULE-NUM] -- Number of symbols on the right-hand side of rule RULE-NUM.  */
1285
static const yytype_int8 yyr2[] =
1286
{
1287
       0,     2,     0,     2,     2,     3,     3,     3,     2,     3,
1288
       2,     0,     0,    11,     0,     3,     0,     3,     3,     0,
1289
       2,     1,     1,     0,     2,     1,     2,     1,     2,     3,
1290
       3,     4,     3,     3,     1,     2,     0,     5,     0,     5,
1291
       0,     5,     0,     2,     1,     1,     1,     1,     1,     1,
1292
       4,     6,     1,     4,     1,     4,     0,     2,     1,     1,
1293
       1,     1,     1,     0,     2,     1,     1,     3,     4,     4,
1294
       0,     1,     1,     3,     1,     1,     1,     1,     3,     3,
1295
       3,     3,     3,     3,     3,     3,     1,     3,     3,     3,
1296
       0,     0,     9,     3,     3,     4,     4,     5,     5,     2,
1297
       2,     0,     4,     0,     4,     3,     3,     3,     3,     3,
1298
       3,     1,     3,     3,     2,     1,     3,     1,     1,     3,
1299
       1,     5,     1,     3,     1,     0,     4,     1,     1,     3,
1300
       1,     1,     0,     4,     1,     3,     1,     2,     1,     1,
1301
       1,     1,     1,     3,     1,     1,     4,     1,     1,     1,
1302
       3,     1,     4,     1,     4,     1,     1,     2,     3,     3,
1303
       3,     3,     3,     3,     3,     3,     2,     3,     3,     1
1304
};
1305
1306
1307
enum { YYENOMEM = -2 };
1308
1309
#define yyerrok         (yyerrstatus = 0)
1310
#define yyclearin       (yychar = YYEMPTY)
1311
1312
2
#define YYACCEPT        goto yyacceptlab
1313
0
#define YYABORT         goto yyabortlab
1314
0
#define YYERROR         goto yyerrorlab
1315
0
#define YYNOMEM         goto yyexhaustedlab
1316
1317
1318
#define YYRECOVERING()  (!!yyerrstatus)
1319
1320
#define YYBACKUP(Token, Value)                                    \
1321
  do                                                              \
1322
    if (yychar == YYEMPTY)                                        \
1323
      {                                                           \
1324
        yychar = (Token);                                         \
1325
        yylval = (Value);                                         \
1326
        YYPOPSTACK (yylen);                                       \
1327
        yystate = *yyssp;                                         \
1328
        goto yybackup;                                            \
1329
      }                                                           \
1330
    else                                                          \
1331
      {                                                           \
1332
        yyerror (yyscanner, compiler, YY_("syntax error: cannot back up")); \
1333
        YYERROR;                                                  \
1334
      }                                                           \
1335
  while (0)
1336
1337
/* Backward compatibility with an undocumented macro.
1338
   Use YYerror or YYUNDEF. */
1339
#define YYERRCODE YYUNDEF
1340
1341
1342
/* Enable debugging if requested.  */
1343
#if YYDEBUG
1344
1345
# ifndef YYFPRINTF
1346
#  include <stdio.h> /* INFRINGES ON USER NAME SPACE */
1347
#  define YYFPRINTF fprintf
1348
# endif
1349
1350
# define YYDPRINTF(Args)                        \
1351
do {                                            \
1352
  if (yydebug)                                  \
1353
    YYFPRINTF Args;                             \
1354
} while (0)
1355
1356
1357
1358
1359
# define YY_SYMBOL_PRINT(Title, Kind, Value, Location)                    \
1360
do {                                                                      \
1361
  if (yydebug)                                                            \
1362
    {                                                                     \
1363
      YYFPRINTF (stderr, "%s ", Title);                                   \
1364
      yy_symbol_print (stderr,                                            \
1365
                  Kind, Value, yyscanner, compiler); \
1366
      YYFPRINTF (stderr, "\n");                                           \
1367
    }                                                                     \
1368
} while (0)
1369
1370
1371
/*-----------------------------------.
1372
| Print this symbol's value on YYO.  |
1373
`-----------------------------------*/
1374
1375
static void
1376
yy_symbol_value_print (FILE *yyo,
1377
                       yysymbol_kind_t yykind, YYSTYPE const * const yyvaluep, void *yyscanner, YR_COMPILER* compiler)
1378
{
1379
  FILE *yyoutput = yyo;
1380
  YY_USE (yyoutput);
1381
  YY_USE (yyscanner);
1382
  YY_USE (compiler);
1383
  if (!yyvaluep)
1384
    return;
1385
  YY_IGNORE_MAYBE_UNINITIALIZED_BEGIN
1386
  YY_USE (yykind);
1387
  YY_IGNORE_MAYBE_UNINITIALIZED_END
1388
}
1389
1390
1391
/*---------------------------.
1392
| Print this symbol on YYO.  |
1393
`---------------------------*/
1394
1395
static void
1396
yy_symbol_print (FILE *yyo,
1397
                 yysymbol_kind_t yykind, YYSTYPE const * const yyvaluep, void *yyscanner, YR_COMPILER* compiler)
1398
{
1399
  YYFPRINTF (yyo, "%s %s (",
1400
             yykind < YYNTOKENS ? "token" : "nterm", yysymbol_name (yykind));
1401
1402
  yy_symbol_value_print (yyo, yykind, yyvaluep, yyscanner, compiler);
1403
  YYFPRINTF (yyo, ")");
1404
}
1405
1406
/*------------------------------------------------------------------.
1407
| yy_stack_print -- Print the state stack from its BOTTOM up to its |
1408
| TOP (included).                                                   |
1409
`------------------------------------------------------------------*/
1410
1411
static void
1412
yy_stack_print (yy_state_t *yybottom, yy_state_t *yytop)
1413
{
1414
  YYFPRINTF (stderr, "Stack now");
1415
  for (; yybottom <= yytop; yybottom++)
1416
    {
1417
      int yybot = *yybottom;
1418
      YYFPRINTF (stderr, " %d", yybot);
1419
    }
1420
  YYFPRINTF (stderr, "\n");
1421
}
1422
1423
# define YY_STACK_PRINT(Bottom, Top)                            \
1424
do {                                                            \
1425
  if (yydebug)                                                  \
1426
    yy_stack_print ((Bottom), (Top));                           \
1427
} while (0)
1428
1429
1430
/*------------------------------------------------.
1431
| Report that the YYRULE is going to be reduced.  |
1432
`------------------------------------------------*/
1433
1434
static void
1435
yy_reduce_print (yy_state_t *yyssp, YYSTYPE *yyvsp,
1436
                 int yyrule, void *yyscanner, YR_COMPILER* compiler)
1437
{
1438
  int yylno = yyrline[yyrule];
1439
  int yynrhs = yyr2[yyrule];
1440
  int yyi;
1441
  YYFPRINTF (stderr, "Reducing stack by rule %d (line %d):\n",
1442
             yyrule - 1, yylno);
1443
  /* The symbols being reduced.  */
1444
  for (yyi = 0; yyi < yynrhs; yyi++)
1445
    {
1446
      YYFPRINTF (stderr, "   $%d = ", yyi + 1);
1447
      yy_symbol_print (stderr,
1448
                       YY_ACCESSING_SYMBOL (+yyssp[yyi + 1 - yynrhs]),
1449
                       &yyvsp[(yyi + 1) - (yynrhs)], yyscanner, compiler);
1450
      YYFPRINTF (stderr, "\n");
1451
    }
1452
}
1453
1454
# define YY_REDUCE_PRINT(Rule)          \
1455
do {                                    \
1456
  if (yydebug)                          \
1457
    yy_reduce_print (yyssp, yyvsp, Rule, yyscanner, compiler); \
1458
} while (0)
1459
1460
/* Nonzero means print parse trace.  It is left uninitialized so that
1461
   multiple parsers can coexist.  */
1462
int yydebug;
1463
#else /* !YYDEBUG */
1464
24
# define YYDPRINTF(Args) ((void) 0)
1465
# define YY_SYMBOL_PRINT(Title, Kind, Value, Location)
1466
# define YY_STACK_PRINT(Bottom, Top)
1467
# define YY_REDUCE_PRINT(Rule)
1468
#endif /* !YYDEBUG */
1469
1470
1471
/* YYINITDEPTH -- initial size of the parser's stacks.  */
1472
#ifndef YYINITDEPTH
1473
2
# define YYINITDEPTH 200
1474
#endif
1475
1476
/* YYMAXDEPTH -- maximum size the stacks can grow to (effective only
1477
   if the built-in stack extension method is used).
1478
1479
   Do not make this value too large; the results are undefined if
1480
   YYSTACK_ALLOC_MAXIMUM < YYSTACK_BYTES (YYMAXDEPTH)
1481
   evaluated with infinite-precision integer arithmetic.  */
1482
1483
#ifndef YYMAXDEPTH
1484
0
# define YYMAXDEPTH 10000
1485
#endif
1486
1487
1488
/* Context of a parse error.  */
1489
typedef struct
1490
{
1491
  yy_state_t *yyssp;
1492
  yysymbol_kind_t yytoken;
1493
} yypcontext_t;
1494
1495
/* Put in YYARG at most YYARGN of the expected tokens given the
1496
   current YYCTX, and return the number of tokens stored in YYARG.  If
1497
   YYARG is null, return the number of expected tokens (guaranteed to
1498
   be less than YYNTOKENS).  Return YYENOMEM on memory exhaustion.
1499
   Return 0 if there are more than YYARGN expected tokens, yet fill
1500
   YYARG up to YYARGN. */
1501
static int
1502
yypcontext_expected_tokens (const yypcontext_t *yyctx,
1503
                            yysymbol_kind_t yyarg[], int yyargn)
1504
0
{
1505
  /* Actual size of YYARG. */
1506
0
  int yycount = 0;
1507
0
  int yyn = yypact[+*yyctx->yyssp];
1508
0
  if (!yypact_value_is_default (yyn))
1509
0
    {
1510
      /* Start YYX at -YYN if negative to avoid negative indexes in
1511
         YYCHECK.  In other words, skip the first -YYN actions for
1512
         this state because they are default actions.  */
1513
0
      int yyxbegin = yyn < 0 ? -yyn : 0;
1514
      /* Stay within bounds of both yycheck and yytname.  */
1515
0
      int yychecklim = YYLAST - yyn + 1;
1516
0
      int yyxend = yychecklim < YYNTOKENS ? yychecklim : YYNTOKENS;
1517
0
      int yyx;
1518
0
      for (yyx = yyxbegin; yyx < yyxend; ++yyx)
1519
0
        if (yycheck[yyx + yyn] == yyx && yyx != YYSYMBOL_YYerror
1520
0
            && !yytable_value_is_error (yytable[yyx + yyn]))
1521
0
          {
1522
0
            if (!yyarg)
1523
0
              ++yycount;
1524
0
            else if (yycount == yyargn)
1525
0
              return 0;
1526
0
            else
1527
0
              yyarg[yycount++] = YY_CAST (yysymbol_kind_t, yyx);
1528
0
          }
1529
0
    }
1530
0
  if (yyarg && yycount == 0 && 0 < yyargn)
1531
0
    yyarg[0] = YYSYMBOL_YYEMPTY;
1532
0
  return yycount;
1533
0
}
1534
1535
1536
1537
1538
#ifndef yystrlen
1539
# if defined __GLIBC__ && defined _STRING_H
1540
0
#  define yystrlen(S) (YY_CAST (YYPTRDIFF_T, strlen (S)))
1541
# else
1542
/* Return the length of YYSTR.  */
1543
static YYPTRDIFF_T
1544
yystrlen (const char *yystr)
1545
{
1546
  YYPTRDIFF_T yylen;
1547
  for (yylen = 0; yystr[yylen]; yylen++)
1548
    continue;
1549
  return yylen;
1550
}
1551
# endif
1552
#endif
1553
1554
#ifndef yystpcpy
1555
# if defined __GLIBC__ && defined _STRING_H && defined _GNU_SOURCE
1556
0
#  define yystpcpy stpcpy
1557
# else
1558
/* Copy YYSRC to YYDEST, returning the address of the terminating '\0' in
1559
   YYDEST.  */
1560
static char *
1561
yystpcpy (char *yydest, const char *yysrc)
1562
{
1563
  char *yyd = yydest;
1564
  const char *yys = yysrc;
1565
1566
  while ((*yyd++ = *yys++) != '\0')
1567
    continue;
1568
1569
  return yyd - 1;
1570
}
1571
# endif
1572
#endif
1573
1574
#ifndef yytnamerr
1575
/* Copy to YYRES the contents of YYSTR after stripping away unnecessary
1576
   quotes and backslashes, so that it's suitable for yyerror.  The
1577
   heuristic is that double-quoting is unnecessary unless the string
1578
   contains an apostrophe, a comma, or backslash (other than
1579
   backslash-backslash).  YYSTR is taken from yytname.  If YYRES is
1580
   null, do not copy; instead, return the length of what the result
1581
   would have been.  */
1582
static YYPTRDIFF_T
1583
yytnamerr (char *yyres, const char *yystr)
1584
0
{
1585
0
  if (*yystr == '"')
1586
0
    {
1587
0
      YYPTRDIFF_T yyn = 0;
1588
0
      char const *yyp = yystr;
1589
0
      for (;;)
1590
0
        switch (*++yyp)
1591
0
          {
1592
0
          case '\'':
1593
0
          case ',':
1594
0
            goto do_not_strip_quotes;
1595
1596
0
          case '\\':
1597
0
            if (*++yyp != '\\')
1598
0
              goto do_not_strip_quotes;
1599
0
            else
1600
0
              goto append;
1601
1602
0
          append:
1603
0
          default:
1604
0
            if (yyres)
1605
0
              yyres[yyn] = *yyp;
1606
0
            yyn++;
1607
0
            break;
1608
1609
0
          case '"':
1610
0
            if (yyres)
1611
0
              yyres[yyn] = '\0';
1612
0
            return yyn;
1613
0
          }
1614
0
    do_not_strip_quotes: ;
1615
0
    }
1616
1617
0
  if (yyres)
1618
0
    return yystpcpy (yyres, yystr) - yyres;
1619
0
  else
1620
0
    return yystrlen (yystr);
1621
0
}
1622
#endif
1623
1624
1625
static int
1626
yy_syntax_error_arguments (const yypcontext_t *yyctx,
1627
                           yysymbol_kind_t yyarg[], int yyargn)
1628
0
{
1629
  /* Actual size of YYARG. */
1630
0
  int yycount = 0;
1631
  /* There are many possibilities here to consider:
1632
     - If this state is a consistent state with a default action, then
1633
       the only way this function was invoked is if the default action
1634
       is an error action.  In that case, don't check for expected
1635
       tokens because there are none.
1636
     - The only way there can be no lookahead present (in yychar) is if
1637
       this state is a consistent state with a default action.  Thus,
1638
       detecting the absence of a lookahead is sufficient to determine
1639
       that there is no unexpected or expected token to report.  In that
1640
       case, just report a simple "syntax error".
1641
     - Don't assume there isn't a lookahead just because this state is a
1642
       consistent state with a default action.  There might have been a
1643
       previous inconsistent state, consistent state with a non-default
1644
       action, or user semantic action that manipulated yychar.
1645
     - Of course, the expected token list depends on states to have
1646
       correct lookahead information, and it depends on the parser not
1647
       to perform extra reductions after fetching a lookahead from the
1648
       scanner and before detecting a syntax error.  Thus, state merging
1649
       (from LALR or IELR) and default reductions corrupt the expected
1650
       token list.  However, the list is correct for canonical LR with
1651
       one exception: it will still contain any token that will not be
1652
       accepted due to an error action in a later state.
1653
  */
1654
0
  if (yyctx->yytoken != YYSYMBOL_YYEMPTY)
1655
0
    {
1656
0
      int yyn;
1657
0
      if (yyarg)
1658
0
        yyarg[yycount] = yyctx->yytoken;
1659
0
      ++yycount;
1660
0
      yyn = yypcontext_expected_tokens (yyctx,
1661
0
                                        yyarg ? yyarg + 1 : yyarg, yyargn - 1);
1662
0
      if (yyn == YYENOMEM)
1663
0
        return YYENOMEM;
1664
0
      else
1665
0
        yycount += yyn;
1666
0
    }
1667
0
  return yycount;
1668
0
}
1669
1670
/* Copy into *YYMSG, which is of size *YYMSG_ALLOC, an error message
1671
   about the unexpected token YYTOKEN for the state stack whose top is
1672
   YYSSP.
1673
1674
   Return 0 if *YYMSG was successfully written.  Return -1 if *YYMSG is
1675
   not large enough to hold the message.  In that case, also set
1676
   *YYMSG_ALLOC to the required number of bytes.  Return YYENOMEM if the
1677
   required number of bytes is too large to store.  */
1678
static int
1679
yysyntax_error (YYPTRDIFF_T *yymsg_alloc, char **yymsg,
1680
                const yypcontext_t *yyctx)
1681
0
{
1682
0
  enum { YYARGS_MAX = 5 };
1683
  /* Internationalized format string. */
1684
0
  const char *yyformat = YY_NULLPTR;
1685
  /* Arguments of yyformat: reported tokens (one for the "unexpected",
1686
     one per "expected"). */
1687
0
  yysymbol_kind_t yyarg[YYARGS_MAX];
1688
  /* Cumulated lengths of YYARG.  */
1689
0
  YYPTRDIFF_T yysize = 0;
1690
1691
  /* Actual size of YYARG. */
1692
0
  int yycount = yy_syntax_error_arguments (yyctx, yyarg, YYARGS_MAX);
1693
0
  if (yycount == YYENOMEM)
1694
0
    return YYENOMEM;
1695
1696
0
  switch (yycount)
1697
0
    {
1698
0
#define YYCASE_(N, S)                       \
1699
0
      case N:                               \
1700
0
        yyformat = S;                       \
1701
0
        break
1702
0
    default: /* Avoid compiler warnings. */
1703
0
      YYCASE_(0, YY_("syntax error"));
1704
0
      YYCASE_(1, YY_("syntax error, unexpected %s"));
1705
0
      YYCASE_(2, YY_("syntax error, unexpected %s, expecting %s"));
1706
0
      YYCASE_(3, YY_("syntax error, unexpected %s, expecting %s or %s"));
1707
0
      YYCASE_(4, YY_("syntax error, unexpected %s, expecting %s or %s or %s"));
1708
0
      YYCASE_(5, YY_("syntax error, unexpected %s, expecting %s or %s or %s or %s"));
1709
0
#undef YYCASE_
1710
0
    }
1711
1712
  /* Compute error message size.  Don't count the "%s"s, but reserve
1713
     room for the terminator.  */
1714
0
  yysize = yystrlen (yyformat) - 2 * yycount + 1;
1715
0
  {
1716
0
    int yyi;
1717
0
    for (yyi = 0; yyi < yycount; ++yyi)
1718
0
      {
1719
0
        YYPTRDIFF_T yysize1
1720
0
          = yysize + yytnamerr (YY_NULLPTR, yytname[yyarg[yyi]]);
1721
0
        if (yysize <= yysize1 && yysize1 <= YYSTACK_ALLOC_MAXIMUM)
1722
0
          yysize = yysize1;
1723
0
        else
1724
0
          return YYENOMEM;
1725
0
      }
1726
0
  }
1727
1728
0
  if (*yymsg_alloc < yysize)
1729
0
    {
1730
0
      *yymsg_alloc = 2 * yysize;
1731
0
      if (! (yysize <= *yymsg_alloc
1732
0
             && *yymsg_alloc <= YYSTACK_ALLOC_MAXIMUM))
1733
0
        *yymsg_alloc = YYSTACK_ALLOC_MAXIMUM;
1734
0
      return -1;
1735
0
    }
1736
1737
  /* Avoid sprintf, as that infringes on the user's name space.
1738
     Don't have undefined behavior even if the translation
1739
     produced a string with the wrong number of "%s"s.  */
1740
0
  {
1741
0
    char *yyp = *yymsg;
1742
0
    int yyi = 0;
1743
0
    while ((*yyp = *yyformat) != '\0')
1744
0
      if (*yyp == '%' && yyformat[1] == 's' && yyi < yycount)
1745
0
        {
1746
0
          yyp += yytnamerr (yyp, yytname[yyarg[yyi++]]);
1747
0
          yyformat += 2;
1748
0
        }
1749
0
      else
1750
0
        {
1751
0
          ++yyp;
1752
0
          ++yyformat;
1753
0
        }
1754
0
  }
1755
0
  return 0;
1756
0
}
1757
1758
1759
/*-----------------------------------------------.
1760
| Release the memory associated to this symbol.  |
1761
`-----------------------------------------------*/
1762
1763
static void
1764
yydestruct (const char *yymsg,
1765
            yysymbol_kind_t yykind, YYSTYPE *yyvaluep, void *yyscanner, YR_COMPILER* compiler)
1766
4
{
1767
4
  YY_USE (yyvaluep);
1768
4
  YY_USE (yyscanner);
1769
4
  YY_USE (compiler);
1770
4
  if (!yymsg)
1771
0
    yymsg = "Deleting";
1772
4
  YY_SYMBOL_PRINT (yymsg, yykind, yyvaluep, yylocationp);
1773
1774
4
  YY_IGNORE_MAYBE_UNINITIALIZED_BEGIN
1775
4
  switch (yykind)
1776
4
    {
1777
0
    case YYSYMBOL__IDENTIFIER_: /* "identifier"  */
1778
0
#line 313 "libyara/grammar.y"
1779
0
            { yr_free(((*yyvaluep).c_string)); ((*yyvaluep).c_string) = NULL; }
1780
0
#line 1781 "libyara/grammar.c"
1781
0
        break;
1782
1783
0
    case YYSYMBOL__STRING_IDENTIFIER_: /* "string identifier"  */
1784
0
#line 317 "libyara/grammar.y"
1785
0
            { yr_free(((*yyvaluep).c_string)); ((*yyvaluep).c_string) = NULL; }
1786
0
#line 1787 "libyara/grammar.c"
1787
0
        break;
1788
1789
0
    case YYSYMBOL__STRING_COUNT_: /* "string count"  */
1790
0
#line 314 "libyara/grammar.y"
1791
0
            { yr_free(((*yyvaluep).c_string)); ((*yyvaluep).c_string) = NULL; }
1792
0
#line 1793 "libyara/grammar.c"
1793
0
        break;
1794
1795
0
    case YYSYMBOL__STRING_OFFSET_: /* "string offset"  */
1796
0
#line 315 "libyara/grammar.y"
1797
0
            { yr_free(((*yyvaluep).c_string)); ((*yyvaluep).c_string) = NULL; }
1798
0
#line 1799 "libyara/grammar.c"
1799
0
        break;
1800
1801
0
    case YYSYMBOL__STRING_LENGTH_: /* "string length"  */
1802
0
#line 316 "libyara/grammar.y"
1803
0
            { yr_free(((*yyvaluep).c_string)); ((*yyvaluep).c_string) = NULL; }
1804
0
#line 1805 "libyara/grammar.c"
1805
0
        break;
1806
1807
0
    case YYSYMBOL__STRING_IDENTIFIER_WITH_WILDCARD_: /* "string identifier with wildcard"  */
1808
0
#line 318 "libyara/grammar.y"
1809
0
            { yr_free(((*yyvaluep).c_string)); ((*yyvaluep).c_string) = NULL; }
1810
0
#line 1811 "libyara/grammar.c"
1811
0
        break;
1812
1813
0
    case YYSYMBOL__TEXT_STRING_: /* "text string"  */
1814
0
#line 319 "libyara/grammar.y"
1815
0
            { yr_free(((*yyvaluep).sized_string)); ((*yyvaluep).sized_string) = NULL; }
1816
0
#line 1817 "libyara/grammar.c"
1817
0
        break;
1818
1819
0
    case YYSYMBOL__HEX_STRING_: /* "hex string"  */
1820
0
#line 320 "libyara/grammar.y"
1821
0
            { yr_free(((*yyvaluep).sized_string)); ((*yyvaluep).sized_string) = NULL; }
1822
0
#line 1823 "libyara/grammar.c"
1823
0
        break;
1824
1825
0
    case YYSYMBOL__REGEXP_: /* "regular expression"  */
1826
0
#line 321 "libyara/grammar.y"
1827
0
            { yr_free(((*yyvaluep).sized_string)); ((*yyvaluep).sized_string) = NULL; }
1828
0
#line 1829 "libyara/grammar.c"
1829
0
        break;
1830
1831
0
    case YYSYMBOL_string_modifiers: /* string_modifiers  */
1832
0
#line 337 "libyara/grammar.y"
1833
0
            {
1834
0
  if (((*yyvaluep).modifier).alphabet != NULL)
1835
0
  {
1836
0
    yr_free(((*yyvaluep).modifier).alphabet);
1837
0
    ((*yyvaluep).modifier).alphabet = NULL;
1838
0
  }
1839
0
}
1840
0
#line 1841 "libyara/grammar.c"
1841
0
        break;
1842
1843
0
    case YYSYMBOL_string_modifier: /* string_modifier  */
1844
0
#line 329 "libyara/grammar.y"
1845
0
            {
1846
0
  if (((*yyvaluep).modifier).alphabet != NULL)
1847
0
  {
1848
0
    yr_free(((*yyvaluep).modifier).alphabet);
1849
0
    ((*yyvaluep).modifier).alphabet = NULL;
1850
0
  }
1851
0
}
1852
0
#line 1853 "libyara/grammar.c"
1853
0
        break;
1854
1855
0
    case YYSYMBOL_arguments: /* arguments  */
1856
0
#line 326 "libyara/grammar.y"
1857
0
            { yr_free(((*yyvaluep).c_string)); ((*yyvaluep).c_string) = NULL; }
1858
0
#line 1859 "libyara/grammar.c"
1859
0
        break;
1860
1861
0
    case YYSYMBOL_arguments_list: /* arguments_list  */
1862
0
#line 327 "libyara/grammar.y"
1863
0
            { yr_free(((*yyvaluep).c_string)); ((*yyvaluep).c_string) = NULL; }
1864
0
#line 1865 "libyara/grammar.c"
1865
0
        break;
1866
1867
0
    case YYSYMBOL_string_set: /* string_set  */
1868
0
#line 325 "libyara/grammar.y"
1869
0
            { yr_string_set_destroy(((*yyvaluep).string_set)); ((*yyvaluep).string_set).head = NULL; }
1870
0
#line 1871 "libyara/grammar.c"
1871
0
        break;
1872
1873
0
    case YYSYMBOL_string_enumeration: /* string_enumeration  */
1874
0
#line 323 "libyara/grammar.y"
1875
0
            { yr_string_set_destroy(((*yyvaluep).string_set)); ((*yyvaluep).string_set).head = NULL; }
1876
0
#line 1877 "libyara/grammar.c"
1877
0
        break;
1878
1879
0
    case YYSYMBOL_string_enumeration_item: /* string_enumeration_item  */
1880
0
#line 324 "libyara/grammar.y"
1881
0
            { yr_string_set_destroy(((*yyvaluep).string_set)); ((*yyvaluep).string_set).head = NULL; }
1882
0
#line 1883 "libyara/grammar.c"
1883
0
        break;
1884
1885
4
      default:
1886
4
        break;
1887
4
    }
1888
4
  YY_IGNORE_MAYBE_UNINITIALIZED_END
1889
4
}
1890
1891
1892
1893
1894
1895
1896
/*----------.
1897
| yyparse.  |
1898
`----------*/
1899
1900
int
1901
yyparse (void *yyscanner, YR_COMPILER* compiler)
1902
2
{
1903
/* Lookahead token kind.  */
1904
2
int yychar;
1905
1906
1907
/* The semantic value of the lookahead symbol.  */
1908
/* Default value used for initialization, for pacifying older GCCs
1909
   or non-GCC compilers.  */
1910
2
YY_INITIAL_VALUE (static YYSTYPE yyval_default;)
1911
2
YYSTYPE yylval YY_INITIAL_VALUE (= yyval_default);
1912
1913
    /* Number of syntax errors so far.  */
1914
2
    int yynerrs = 0;
1915
1916
2
    yy_state_fast_t yystate = 0;
1917
    /* Number of tokens to shift before error messages enabled.  */
1918
2
    int yyerrstatus = 0;
1919
1920
    /* Refer to the stacks through separate pointers, to allow yyoverflow
1921
       to reallocate them elsewhere.  */
1922
1923
    /* Their size.  */
1924
2
    YYPTRDIFF_T yystacksize = YYINITDEPTH;
1925
1926
    /* The state stack: array, bottom, top.  */
1927
2
    yy_state_t yyssa[YYINITDEPTH];
1928
2
    yy_state_t *yyss = yyssa;
1929
2
    yy_state_t *yyssp = yyss;
1930
1931
    /* The semantic value stack: array, bottom, top.  */
1932
2
    YYSTYPE yyvsa[YYINITDEPTH];
1933
2
    YYSTYPE *yyvs = yyvsa;
1934
2
    YYSTYPE *yyvsp = yyvs;
1935
1936
2
  int yyn;
1937
  /* The return value of yyparse.  */
1938
2
  int yyresult;
1939
  /* Lookahead symbol kind.  */
1940
2
  yysymbol_kind_t yytoken = YYSYMBOL_YYEMPTY;
1941
  /* The variables used to return semantic value and location from the
1942
     action routines.  */
1943
2
  YYSTYPE yyval;
1944
1945
  /* Buffer for error messages, and its allocated size.  */
1946
2
  char yymsgbuf[128];
1947
2
  char *yymsg = yymsgbuf;
1948
2
  YYPTRDIFF_T yymsg_alloc = sizeof yymsgbuf;
1949
1950
12
#define YYPOPSTACK(N)   (yyvsp -= (N), yyssp -= (N))
1951
1952
  /* The number of symbols on the RHS of the reduced rule.
1953
     Keep to zero when no symbol should be popped.  */
1954
2
  int yylen = 0;
1955
1956
2
  YYDPRINTF ((stderr, "Starting parse\n"));
1957
1958
2
  yychar = YYEMPTY; /* Cause a token to be read.  */
1959
1960
2
  goto yysetstate;
1961
1962
1963
/*------------------------------------------------------------.
1964
| yynewstate -- push a new state, which is found in yystate.  |
1965
`------------------------------------------------------------*/
1966
12
yynewstate:
1967
  /* In all cases, when you get here, the value and location stacks
1968
     have just been pushed.  So pushing a state here evens the stacks.  */
1969
12
  yyssp++;
1970
1971
1972
/*--------------------------------------------------------------------.
1973
| yysetstate -- set current state (the top of the stack) to yystate.  |
1974
`--------------------------------------------------------------------*/
1975
14
yysetstate:
1976
14
  YYDPRINTF ((stderr, "Entering state %d\n", yystate));
1977
14
  YY_ASSERT (0 <= yystate && yystate < YYNSTATES);
1978
14
  YY_IGNORE_USELESS_CAST_BEGIN
1979
14
  *yyssp = YY_CAST (yy_state_t, yystate);
1980
14
  YY_IGNORE_USELESS_CAST_END
1981
14
  YY_STACK_PRINT (yyss, yyssp);
1982
1983
14
  if (yyss + yystacksize - 1 <= yyssp)
1984
#if !defined yyoverflow && !defined YYSTACK_RELOCATE
1985
    YYNOMEM;
1986
#else
1987
0
    {
1988
      /* Get the current used size of the three stacks, in elements.  */
1989
0
      YYPTRDIFF_T yysize = yyssp - yyss + 1;
1990
1991
# if defined yyoverflow
1992
      {
1993
        /* Give user a chance to reallocate the stack.  Use copies of
1994
           these so that the &'s don't force the real ones into
1995
           memory.  */
1996
        yy_state_t *yyss1 = yyss;
1997
        YYSTYPE *yyvs1 = yyvs;
1998
1999
        /* Each stack pointer address is followed by the size of the
2000
           data in use in that stack, in bytes.  This used to be a
2001
           conditional around just the two extra args, but that might
2002
           be undefined if yyoverflow is a macro.  */
2003
        yyoverflow (YY_("memory exhausted"),
2004
                    &yyss1, yysize * YYSIZEOF (*yyssp),
2005
                    &yyvs1, yysize * YYSIZEOF (*yyvsp),
2006
                    &yystacksize);
2007
        yyss = yyss1;
2008
        yyvs = yyvs1;
2009
      }
2010
# else /* defined YYSTACK_RELOCATE */
2011
      /* Extend the stack our own way.  */
2012
0
      if (YYMAXDEPTH <= yystacksize)
2013
0
        YYNOMEM;
2014
0
      yystacksize *= 2;
2015
0
      if (YYMAXDEPTH < yystacksize)
2016
0
        yystacksize = YYMAXDEPTH;
2017
2018
0
      {
2019
0
        yy_state_t *yyss1 = yyss;
2020
0
        union yyalloc *yyptr =
2021
0
          YY_CAST (union yyalloc *,
2022
0
                   YYSTACK_ALLOC (YY_CAST (YYSIZE_T, YYSTACK_BYTES (yystacksize))));
2023
0
        if (! yyptr)
2024
0
          YYNOMEM;
2025
0
        YYSTACK_RELOCATE (yyss_alloc, yyss);
2026
0
        YYSTACK_RELOCATE (yyvs_alloc, yyvs);
2027
0
#  undef YYSTACK_RELOCATE
2028
0
        if (yyss1 != yyssa)
2029
0
          YYSTACK_FREE (yyss1);
2030
0
      }
2031
0
# endif
2032
2033
0
      yyssp = yyss + yysize - 1;
2034
0
      yyvsp = yyvs + yysize - 1;
2035
2036
0
      YY_IGNORE_USELESS_CAST_BEGIN
2037
0
      YYDPRINTF ((stderr, "Stack size increased to %ld\n",
2038
0
                  YY_CAST (long, yystacksize)));
2039
0
      YY_IGNORE_USELESS_CAST_END
2040
2041
0
      if (yyss + yystacksize - 1 <= yyssp)
2042
0
        YYABORT;
2043
0
    }
2044
14
#endif /* !defined yyoverflow && !defined YYSTACK_RELOCATE */
2045
2046
2047
14
  if (yystate == YYFINAL)
2048
2
    YYACCEPT;
2049
2050
12
  goto yybackup;
2051
2052
2053
/*-----------.
2054
| yybackup.  |
2055
`-----------*/
2056
12
yybackup:
2057
  /* Do appropriate processing given the current state.  Read a
2058
     lookahead token if we need one and don't already have one.  */
2059
2060
  /* First try to decide what to do without reference to lookahead token.  */
2061
12
  yyn = yypact[yystate];
2062
12
  if (yypact_value_is_default (yyn))
2063
6
    goto yydefault;
2064
2065
  /* Not known => get a lookahead token if don't already have one.  */
2066
2067
  /* YYCHAR is either empty, or end-of-input, or a valid lookahead.  */
2068
6
  if (yychar == YYEMPTY)
2069
6
    {
2070
6
      YYDPRINTF ((stderr, "Reading a token\n"));
2071
6
      yychar = yylex (&yylval, yyscanner, compiler);
2072
6
    }
2073
2074
6
  if (yychar <= _END_OF_FILE_)
2075
2
    {
2076
2
      yychar = _END_OF_FILE_;
2077
2
      yytoken = YYSYMBOL_YYEOF;
2078
2
      YYDPRINTF ((stderr, "Now at end of input.\n"));
2079
2
    }
2080
4
  else if (yychar == YYerror)
2081
0
    {
2082
      /* The scanner already issued an error message, process directly
2083
         to error recovery.  But do not keep the error token as
2084
         lookahead, it is too special and may lead us to an endless
2085
         loop in error recovery. */
2086
0
      yychar = YYUNDEF;
2087
0
      yytoken = YYSYMBOL_YYerror;
2088
0
      goto yyerrlab1;
2089
0
    }
2090
4
  else
2091
4
    {
2092
4
      yytoken = YYTRANSLATE (yychar);
2093
4
      YY_SYMBOL_PRINT ("Next token is", yytoken, &yylval, &yylloc);
2094
4
    }
2095
2096
  /* If the proper action on seeing token YYTOKEN is to reduce or to
2097
     detect an error, take that action.  */
2098
6
  yyn += yytoken;
2099
6
  if (yyn < 0 || YYLAST < yyn || yycheck[yyn] != yytoken)
2100
0
    goto yydefault;
2101
6
  yyn = yytable[yyn];
2102
6
  if (yyn <= 0)
2103
0
    {
2104
0
      if (yytable_value_is_error (yyn))
2105
0
        goto yyerrlab;
2106
0
      yyn = -yyn;
2107
0
      goto yyreduce;
2108
0
    }
2109
2110
  /* Count tokens shifted since error; after three, turn off error
2111
     status.  */
2112
6
  if (yyerrstatus)
2113
0
    yyerrstatus--;
2114
2115
  /* Shift the lookahead token.  */
2116
6
  YY_SYMBOL_PRINT ("Shifting", yytoken, &yylval, &yylloc);
2117
6
  yystate = yyn;
2118
6
  YY_IGNORE_MAYBE_UNINITIALIZED_BEGIN
2119
6
  *++yyvsp = yylval;
2120
6
  YY_IGNORE_MAYBE_UNINITIALIZED_END
2121
2122
  /* Discard the shifted token.  */
2123
6
  yychar = YYEMPTY;
2124
6
  goto yynewstate;
2125
2126
2127
/*-----------------------------------------------------------.
2128
| yydefault -- do the default action for the current state.  |
2129
`-----------------------------------------------------------*/
2130
6
yydefault:
2131
6
  yyn = yydefact[yystate];
2132
6
  if (yyn == 0)
2133
0
    goto yyerrlab;
2134
6
  goto yyreduce;
2135
2136
2137
/*-----------------------------.
2138
| yyreduce -- do a reduction.  |
2139
`-----------------------------*/
2140
6
yyreduce:
2141
  /* yyn is the number of a rule to reduce with.  */
2142
6
  yylen = yyr2[yyn];
2143
2144
  /* If YYLEN is nonzero, implement the default value of the action:
2145
     '$$ = $1'.
2146
2147
     Otherwise, the following line sets YYVAL to garbage.
2148
     This behavior is undocumented and Bison
2149
     users should not rely upon it.  Assigning to YYVAL
2150
     unconditionally makes the parser a bit smaller, and it avoids a
2151
     GCC warning that YYVAL may be used uninitialized.  */
2152
6
  yyval = yyvsp[1-yylen];
2153
2154
2155
6
  YY_REDUCE_PRINT (yyn);
2156
6
  switch (yyn)
2157
6
    {
2158
0
  case 8: /* rules: rules "end of included file"  */
2159
0
#line 373 "libyara/grammar.y"
2160
0
      {
2161
0
        _yr_compiler_pop_file_name(compiler);
2162
0
      }
2163
0
#line 2164 "libyara/grammar.c"
2164
0
    break;
2165
2166
0
  case 9: /* rules: rules error "end of included file"  */
2167
0
#line 377 "libyara/grammar.y"
2168
0
      {
2169
0
        _yr_compiler_pop_file_name(compiler);
2170
0
      }
2171
0
#line 2172 "libyara/grammar.c"
2172
0
    break;
2173
2174
2
  case 10: /* import: "<import>" "text string"  */
2175
2
#line 385 "libyara/grammar.y"
2176
2
      {
2177
2
        int result = yr_parser_reduce_import(yyscanner, (yyvsp[0].sized_string));
2178
2179
2
        yr_free((yyvsp[0].sized_string));
2180
2181
2
        fail_if_error(result);
2182
2
      }
2183
0
#line 2184 "libyara/grammar.c"
2184
0
    break;
2185
2186
0
  case 11: /* @1: %empty  */
2187
0
#line 397 "libyara/grammar.y"
2188
0
      {
2189
0
        fail_if_error(yr_parser_reduce_rule_declaration_phase_1(
2190
0
            yyscanner, (int32_t) (yyvsp[-2].integer), (yyvsp[0].c_string), &(yyval.rule)));
2191
0
      }
2192
0
#line 2193 "libyara/grammar.c"
2193
0
    break;
2194
2195
0
  case 12: /* $@2: %empty  */
2196
0
#line 402 "libyara/grammar.y"
2197
0
      {
2198
0
        YR_RULE* rule = (YR_RULE*) yr_arena_ref_to_ptr(
2199
0
            compiler->arena, &(yyvsp[-4].rule));
2200
2201
0
        rule->tags = (char*) yr_arena_ref_to_ptr(
2202
0
            compiler->arena, &(yyvsp[-3].tag));
2203
2204
0
        rule->metas = (YR_META*) yr_arena_ref_to_ptr(
2205
0
            compiler->arena, &(yyvsp[-1].meta));
2206
2207
0
        rule->strings = (YR_STRING*) yr_arena_ref_to_ptr(
2208
0
            compiler->arena, &(yyvsp[0].string));
2209
0
      }
2210
0
#line 2211 "libyara/grammar.c"
2211
0
    break;
2212
2213
0
  case 13: /* rule: rule_modifiers "<rule>" "identifier" @1 tags '{' meta strings $@2 condition '}'  */
2214
0
#line 416 "libyara/grammar.y"
2215
0
      {
2216
0
        YR_RULE* rule = (YR_RULE*) yr_arena_ref_to_ptr(
2217
0
            compiler->arena, &(yyvsp[-7].rule));
2218
0
        rule->required_strings = (yyvsp[-1].expression).required_strings.count;
2219
2220
0
        int result = yr_parser_reduce_rule_declaration_phase_2(
2221
0
            yyscanner, &(yyvsp[-7].rule)); // rule created in phase 1
2222
2223
0
        yr_free((yyvsp[-8].c_string));
2224
2225
0
        fail_if_error(result);
2226
0
      }
2227
0
#line 2228 "libyara/grammar.c"
2228
0
    break;
2229
2230
0
  case 14: /* meta: %empty  */
2231
0
#line 433 "libyara/grammar.y"
2232
0
      {
2233
0
        (yyval.meta) = YR_ARENA_NULL_REF;
2234
0
      }
2235
0
#line 2236 "libyara/grammar.c"
2236
0
    break;
2237
2238
0
  case 15: /* meta: "<meta>" ':' meta_declarations  */
2239
0
#line 437 "libyara/grammar.y"
2240
0
      {
2241
0
        YR_META* meta = yr_arena_get_ptr(
2242
0
            compiler->arena,
2243
0
            YR_METAS_TABLE,
2244
0
            (compiler->current_meta_idx - 1) * sizeof(YR_META));
2245
2246
0
        meta->flags |= META_FLAGS_LAST_IN_RULE;
2247
2248
0
        (yyval.meta) = (yyvsp[0].meta);
2249
0
      }
2250
0
#line 2251 "libyara/grammar.c"
2251
0
    break;
2252
2253
0
  case 16: /* strings: %empty  */
2254
0
#line 452 "libyara/grammar.y"
2255
0
      {
2256
0
        (yyval.string) = YR_ARENA_NULL_REF;
2257
0
      }
2258
0
#line 2259 "libyara/grammar.c"
2259
0
    break;
2260
2261
0
  case 17: /* strings: "<strings>" ':' string_declarations  */
2262
0
#line 456 "libyara/grammar.y"
2263
0
      {
2264
0
        YR_STRING* string = (YR_STRING*) yr_arena_get_ptr(
2265
0
            compiler->arena,
2266
0
            YR_STRINGS_TABLE,
2267
0
            (compiler->current_string_idx - 1) * sizeof(YR_STRING));
2268
2269
0
        string->flags |= STRING_FLAGS_LAST_IN_RULE;
2270
2271
0
        (yyval.string) = (yyvsp[0].string);
2272
0
      }
2273
0
#line 2274 "libyara/grammar.c"
2274
0
    break;
2275
2276
0
  case 18: /* condition: "<condition>" ':' boolean_expression  */
2277
0
#line 471 "libyara/grammar.y"
2278
0
      {
2279
0
        (yyval.expression) = (yyvsp[0].expression);
2280
0
      }
2281
0
#line 2282 "libyara/grammar.c"
2282
0
    break;
2283
2284
0
  case 19: /* rule_modifiers: %empty  */
2285
0
#line 478 "libyara/grammar.y"
2286
0
                                       { (yyval.integer) = 0;  }
2287
0
#line 2288 "libyara/grammar.c"
2288
0
    break;
2289
2290
0
  case 20: /* rule_modifiers: rule_modifiers rule_modifier  */
2291
0
#line 479 "libyara/grammar.y"
2292
0
                                       { (yyval.integer) = (yyvsp[-1].integer) | (yyvsp[0].integer); }
2293
0
#line 2294 "libyara/grammar.c"
2294
0
    break;
2295
2296
0
  case 21: /* rule_modifier: "<private>"  */
2297
0
#line 484 "libyara/grammar.y"
2298
0
                     { (yyval.integer) = RULE_FLAGS_PRIVATE; }
2299
0
#line 2300 "libyara/grammar.c"
2300
0
    break;
2301
2302
0
  case 22: /* rule_modifier: "<global>"  */
2303
0
#line 485 "libyara/grammar.y"
2304
0
                     { (yyval.integer) = RULE_FLAGS_GLOBAL; }
2305
0
#line 2306 "libyara/grammar.c"
2306
0
    break;
2307
2308
0
  case 23: /* tags: %empty  */
2309
0
#line 491 "libyara/grammar.y"
2310
0
      {
2311
0
        (yyval.tag) = YR_ARENA_NULL_REF;
2312
0
      }
2313
0
#line 2314 "libyara/grammar.c"
2314
0
    break;
2315
2316
0
  case 24: /* tags: ':' tag_list  */
2317
0
#line 495 "libyara/grammar.y"
2318
0
      {
2319
        // Tags list is represented in the arena as a sequence
2320
        // of null-terminated strings, the sequence ends with an
2321
        // additional null character. Here we write the ending null
2322
        //character. Example: tag1\0tag2\0tag3\0\0
2323
2324
0
        fail_if_error(yr_arena_write_string(
2325
0
            yyget_extra(yyscanner)->arena, YR_SZ_POOL, "", NULL));
2326
2327
0
        (yyval.tag) = (yyvsp[0].tag);
2328
0
      }
2329
0
#line 2330 "libyara/grammar.c"
2330
0
    break;
2331
2332
0
  case 25: /* tag_list: "identifier"  */
2333
0
#line 511 "libyara/grammar.y"
2334
0
      {
2335
0
        int result = yr_arena_write_string(
2336
0
            yyget_extra(yyscanner)->arena, YR_SZ_POOL, (yyvsp[0].c_string), &(yyval.tag));
2337
2338
0
        yr_free((yyvsp[0].c_string));
2339
2340
0
        fail_if_error(result);
2341
0
      }
2342
0
#line 2343 "libyara/grammar.c"
2343
0
    break;
2344
2345
0
  case 26: /* tag_list: tag_list "identifier"  */
2346
0
#line 520 "libyara/grammar.y"
2347
0
      {
2348
0
        YR_ARENA_REF ref;
2349
2350
        // Write the new tag identifier.
2351
0
        int result = yr_arena_write_string(
2352
0
            yyget_extra(yyscanner)->arena, YR_SZ_POOL, (yyvsp[0].c_string), &ref);
2353
2354
0
        yr_free((yyvsp[0].c_string));
2355
2356
0
        fail_if_error(result);
2357
2358
        // Get the address for the tag identifier just written.
2359
0
        char* new_tag = (char*) yr_arena_ref_to_ptr(
2360
0
            compiler->arena, &ref);
2361
2362
        // Take the address of first tag's identifier in the list.
2363
0
        char* tag = (char*) yr_arena_ref_to_ptr(
2364
0
            compiler->arena, &(yyval.tag));
2365
2366
        // Search for duplicated tags. Tags are written one after
2367
        // the other, with zeroes in between (i.e: tag1/0tag2/0tag3)
2368
        // that's why can use tag < new_tag as the condition for the
2369
        // loop.
2370
0
        while (tag < new_tag)
2371
0
        {
2372
0
          if (strcmp(tag, new_tag) == 0)
2373
0
          {
2374
0
            yr_compiler_set_error_extra_info(compiler, tag);
2375
0
            fail_with_error(ERROR_DUPLICATED_TAG_IDENTIFIER);
2376
0
          }
2377
2378
0
          tag += strlen(tag) + 1;
2379
0
        }
2380
2381
0
        (yyval.tag) = (yyvsp[-1].tag);
2382
0
      }
2383
0
#line 2384 "libyara/grammar.c"
2384
0
    break;
2385
2386
0
  case 27: /* meta_declarations: meta_declaration  */
2387
0
#line 561 "libyara/grammar.y"
2388
0
                                          {  (yyval.meta) = (yyvsp[0].meta); }
2389
0
#line 2390 "libyara/grammar.c"
2390
0
    break;
2391
2392
0
  case 28: /* meta_declarations: meta_declarations meta_declaration  */
2393
0
#line 562 "libyara/grammar.y"
2394
0
                                          {  (yyval.meta) = (yyvsp[-1].meta); }
2395
0
#line 2396 "libyara/grammar.c"
2396
0
    break;
2397
2398
0
  case 29: /* meta_declaration: "identifier" '=' "text string"  */
2399
0
#line 568 "libyara/grammar.y"
2400
0
      {
2401
0
        SIZED_STRING* sized_string = (yyvsp[0].sized_string);
2402
2403
0
        int result = yr_parser_reduce_meta_declaration(
2404
0
            yyscanner,
2405
0
            META_TYPE_STRING,
2406
0
            (yyvsp[-2].c_string),
2407
0
            sized_string->c_string,
2408
0
            0,
2409
0
            &(yyval.meta));
2410
2411
0
        yr_free((yyvsp[-2].c_string));
2412
0
        yr_free((yyvsp[0].sized_string));
2413
2414
0
        fail_if_error(result);
2415
0
      }
2416
0
#line 2417 "libyara/grammar.c"
2417
0
    break;
2418
2419
0
  case 30: /* meta_declaration: "identifier" '=' "integer number"  */
2420
0
#line 585 "libyara/grammar.y"
2421
0
      {
2422
0
        int result = yr_parser_reduce_meta_declaration(
2423
0
            yyscanner,
2424
0
            META_TYPE_INTEGER,
2425
0
            (yyvsp[-2].c_string),
2426
0
            NULL,
2427
0
            (yyvsp[0].integer),
2428
0
            &(yyval.meta));
2429
2430
0
        yr_free((yyvsp[-2].c_string));
2431
2432
0
        fail_if_error(result);
2433
0
      }
2434
0
#line 2435 "libyara/grammar.c"
2435
0
    break;
2436
2437
0
  case 31: /* meta_declaration: "identifier" '=' '-' "integer number"  */
2438
0
#line 599 "libyara/grammar.y"
2439
0
      {
2440
0
        int result = yr_parser_reduce_meta_declaration(
2441
0
            yyscanner,
2442
0
            META_TYPE_INTEGER,
2443
0
            (yyvsp[-3].c_string),
2444
0
            NULL,
2445
0
            -(yyvsp[0].integer),
2446
0
            &(yyval.meta));
2447
2448
0
        yr_free((yyvsp[-3].c_string));
2449
2450
0
        fail_if_error(result);
2451
0
      }
2452
0
#line 2453 "libyara/grammar.c"
2453
0
    break;
2454
2455
0
  case 32: /* meta_declaration: "identifier" '=' "<true>"  */
2456
0
#line 613 "libyara/grammar.y"
2457
0
      {
2458
0
        int result = yr_parser_reduce_meta_declaration(
2459
0
            yyscanner,
2460
0
            META_TYPE_BOOLEAN,
2461
0
            (yyvsp[-2].c_string),
2462
0
            NULL,
2463
0
            true,
2464
0
            &(yyval.meta));
2465
2466
0
        yr_free((yyvsp[-2].c_string));
2467
2468
0
        fail_if_error(result);
2469
0
      }
2470
0
#line 2471 "libyara/grammar.c"
2471
0
    break;
2472
2473
0
  case 33: /* meta_declaration: "identifier" '=' "<false>"  */
2474
0
#line 627 "libyara/grammar.y"
2475
0
      {
2476
0
        int result = yr_parser_reduce_meta_declaration(
2477
0
            yyscanner,
2478
0
            META_TYPE_BOOLEAN,
2479
0
            (yyvsp[-2].c_string),
2480
0
            NULL,
2481
0
            false,
2482
0
            &(yyval.meta));
2483
2484
0
        yr_free((yyvsp[-2].c_string));
2485
2486
0
        fail_if_error(result);
2487
0
      }
2488
0
#line 2489 "libyara/grammar.c"
2489
0
    break;
2490
2491
0
  case 34: /* string_declarations: string_declaration  */
2492
0
#line 644 "libyara/grammar.y"
2493
0
                                              { (yyval.string) = (yyvsp[0].string); }
2494
0
#line 2495 "libyara/grammar.c"
2495
0
    break;
2496
2497
0
  case 35: /* string_declarations: string_declarations string_declaration  */
2498
0
#line 645 "libyara/grammar.y"
2499
0
                                              { (yyval.string) = (yyvsp[-1].string); }
2500
0
#line 2501 "libyara/grammar.c"
2501
0
    break;
2502
2503
0
  case 36: /* $@3: %empty  */
2504
0
#line 651 "libyara/grammar.y"
2505
0
      {
2506
0
        compiler->current_line = yyget_lineno(yyscanner);
2507
0
      }
2508
0
#line 2509 "libyara/grammar.c"
2509
0
    break;
2510
2511
0
  case 37: /* string_declaration: "string identifier" '=' $@3 "text string" string_modifiers  */
2512
0
#line 655 "libyara/grammar.y"
2513
0
      {
2514
0
        int result = yr_parser_reduce_string_declaration(
2515
0
            yyscanner, (yyvsp[0].modifier), (yyvsp[-4].c_string), (yyvsp[-1].sized_string), &(yyval.string));
2516
2517
0
        yr_free((yyvsp[-4].c_string));
2518
0
        yr_free((yyvsp[-1].sized_string));
2519
0
        yr_free((yyvsp[0].modifier).alphabet);
2520
2521
0
        fail_if_error(result);
2522
0
        compiler->current_line = 0;
2523
0
      }
2524
0
#line 2525 "libyara/grammar.c"
2525
0
    break;
2526
2527
0
  case 38: /* $@4: %empty  */
2528
0
#line 667 "libyara/grammar.y"
2529
0
      {
2530
0
        compiler->current_line = yyget_lineno(yyscanner);
2531
0
      }
2532
0
#line 2533 "libyara/grammar.c"
2533
0
    break;
2534
2535
0
  case 39: /* string_declaration: "string identifier" '=' $@4 "regular expression" regexp_modifiers  */
2536
0
#line 671 "libyara/grammar.y"
2537
0
      {
2538
0
        int result;
2539
2540
0
        (yyvsp[0].modifier).flags |= STRING_FLAGS_REGEXP;
2541
2542
0
        result = yr_parser_reduce_string_declaration(
2543
0
            yyscanner, (yyvsp[0].modifier), (yyvsp[-4].c_string), (yyvsp[-1].sized_string), &(yyval.string));
2544
2545
0
        yr_free((yyvsp[-4].c_string));
2546
0
        yr_free((yyvsp[-1].sized_string));
2547
2548
0
        fail_if_error(result);
2549
2550
0
        compiler->current_line = 0;
2551
0
      }
2552
0
#line 2553 "libyara/grammar.c"
2553
0
    break;
2554
2555
0
  case 40: /* $@5: %empty  */
2556
0
#line 687 "libyara/grammar.y"
2557
0
      {
2558
0
        compiler->current_line = yyget_lineno(yyscanner);
2559
0
      }
2560
0
#line 2561 "libyara/grammar.c"
2561
0
    break;
2562
2563
0
  case 41: /* string_declaration: "string identifier" '=' $@5 "hex string" hex_modifiers  */
2564
0
#line 691 "libyara/grammar.y"
2565
0
      {
2566
0
        int result;
2567
2568
0
        (yyvsp[0].modifier).flags |= STRING_FLAGS_HEXADECIMAL;
2569
2570
0
        result = yr_parser_reduce_string_declaration(
2571
0
            yyscanner, (yyvsp[0].modifier), (yyvsp[-4].c_string), (yyvsp[-1].sized_string), &(yyval.string));
2572
2573
0
        yr_free((yyvsp[-4].c_string));
2574
0
        yr_free((yyvsp[-1].sized_string));
2575
2576
0
        fail_if_error(result);
2577
2578
0
        compiler->current_line = 0;
2579
0
      }
2580
0
#line 2581 "libyara/grammar.c"
2581
0
    break;
2582
2583
0
  case 42: /* string_modifiers: %empty  */
2584
0
#line 711 "libyara/grammar.y"
2585
0
      {
2586
0
        (yyval.modifier).flags = 0;
2587
0
        (yyval.modifier).xor_min = 0;
2588
0
        (yyval.modifier).xor_max = 0;
2589
0
        (yyval.modifier).alphabet = NULL;
2590
0
      }
2591
0
#line 2592 "libyara/grammar.c"
2592
0
    break;
2593
2594
0
  case 43: /* string_modifiers: string_modifiers string_modifier  */
2595
0
#line 718 "libyara/grammar.y"
2596
0
      {
2597
0
        (yyval.modifier) = (yyvsp[-1].modifier);
2598
2599
        // Only set the xor minimum and maximum if we are dealing with the
2600
        // xor modifier. If we don't check for this then we can end up with
2601
        // "xor wide" resulting in whatever is on the stack for "wide"
2602
        // overwriting the values for xor.
2603
0
        if ((yyvsp[0].modifier).flags & STRING_FLAGS_XOR)
2604
0
        {
2605
0
          (yyval.modifier).xor_min = (yyvsp[0].modifier).xor_min;
2606
0
          (yyval.modifier).xor_max = (yyvsp[0].modifier).xor_max;
2607
0
        }
2608
2609
        // Only set the base64 alphabet if we are dealing with the base64
2610
        // modifier. If we don't check for this then we can end up with
2611
        // "base64 ascii" resulting in whatever is on the stack for "ascii"
2612
        // overwriting the values for base64.
2613
0
        if (((yyvsp[0].modifier).flags & STRING_FLAGS_BASE64) ||
2614
0
            ((yyvsp[0].modifier).flags & STRING_FLAGS_BASE64_WIDE))
2615
0
        {
2616
0
          if ((yyval.modifier).alphabet != NULL)
2617
0
          {
2618
0
            if (ss_compare((yyval.modifier).alphabet, (yyvsp[0].modifier).alphabet) != 0)
2619
0
            {
2620
0
              yr_compiler_set_error_extra_info(
2621
0
                  compiler, "can not specify multiple alphabets");
2622
2623
0
              yr_free((yyvsp[0].modifier).alphabet);
2624
0
              yr_free((yyval.modifier).alphabet);
2625
2626
0
              fail_with_error(ERROR_INVALID_MODIFIER);
2627
0
            }
2628
0
            else
2629
0
            {
2630
0
              yr_free((yyvsp[0].modifier).alphabet);
2631
0
            }
2632
0
          }
2633
0
          else
2634
0
          {
2635
0
            (yyval.modifier).alphabet = (yyvsp[0].modifier).alphabet;
2636
0
          }
2637
0
        }
2638
2639
0
        if ((yyval.modifier).flags & (yyvsp[0].modifier).flags)
2640
0
        {
2641
0
          if ((yyval.modifier).alphabet != NULL)
2642
0
            yr_free((yyval.modifier).alphabet);
2643
2644
0
          fail_with_error(ERROR_DUPLICATED_MODIFIER);
2645
0
        }
2646
0
        else
2647
0
        {
2648
0
          (yyval.modifier).flags = (yyval.modifier).flags | (yyvsp[0].modifier).flags;
2649
0
        }
2650
0
      }
2651
0
#line 2652 "libyara/grammar.c"
2652
0
    break;
2653
2654
0
  case 44: /* string_modifier: "<wide>"  */
2655
0
#line 777 "libyara/grammar.y"
2656
0
                    { (yyval.modifier).flags = STRING_FLAGS_WIDE; }
2657
0
#line 2658 "libyara/grammar.c"
2658
0
    break;
2659
2660
0
  case 45: /* string_modifier: "<ascii>"  */
2661
0
#line 778 "libyara/grammar.y"
2662
0
                    { (yyval.modifier).flags = STRING_FLAGS_ASCII; }
2663
0
#line 2664 "libyara/grammar.c"
2664
0
    break;
2665
2666
0
  case 46: /* string_modifier: "<nocase>"  */
2667
0
#line 779 "libyara/grammar.y"
2668
0
                    { (yyval.modifier).flags = STRING_FLAGS_NO_CASE; }
2669
0
#line 2670 "libyara/grammar.c"
2670
0
    break;
2671
2672
0
  case 47: /* string_modifier: "<fullword>"  */
2673
0
#line 780 "libyara/grammar.y"
2674
0
                    { (yyval.modifier).flags = STRING_FLAGS_FULL_WORD; }
2675
0
#line 2676 "libyara/grammar.c"
2676
0
    break;
2677
2678
0
  case 48: /* string_modifier: "<private>"  */
2679
0
#line 781 "libyara/grammar.y"
2680
0
                    { (yyval.modifier).flags = STRING_FLAGS_PRIVATE; }
2681
0
#line 2682 "libyara/grammar.c"
2682
0
    break;
2683
2684
0
  case 49: /* string_modifier: "<xor>"  */
2685
0
#line 783 "libyara/grammar.y"
2686
0
      {
2687
0
        (yyval.modifier).flags = STRING_FLAGS_XOR;
2688
0
        (yyval.modifier).xor_min = 0;
2689
0
        (yyval.modifier).xor_max = 255;
2690
0
      }
2691
0
#line 2692 "libyara/grammar.c"
2692
0
    break;
2693
2694
0
  case 50: /* string_modifier: "<xor>" '(' "integer number" ')'  */
2695
0
#line 789 "libyara/grammar.y"
2696
0
      {
2697
0
        int result = ERROR_SUCCESS;
2698
2699
0
        if ((yyvsp[-1].integer) < 0 || (yyvsp[-1].integer) > 255)
2700
0
        {
2701
0
          yr_compiler_set_error_extra_info(compiler, "invalid xor range");
2702
0
          result = ERROR_INVALID_MODIFIER;
2703
0
        }
2704
2705
0
        fail_if_error(result);
2706
2707
0
        (yyval.modifier).flags = STRING_FLAGS_XOR;
2708
0
        (yyval.modifier).xor_min = (uint8_t) (yyvsp[-1].integer);
2709
0
        (yyval.modifier).xor_max = (uint8_t) (yyvsp[-1].integer);
2710
0
      }
2711
0
#line 2712 "libyara/grammar.c"
2712
0
    break;
2713
2714
0
  case 51: /* string_modifier: "<xor>" '(' "integer number" '-' "integer number" ')'  */
2715
0
#line 810 "libyara/grammar.y"
2716
0
      {
2717
0
        int result = ERROR_SUCCESS;
2718
2719
0
        if ((yyvsp[-3].integer) < 0)
2720
0
        {
2721
0
          yr_compiler_set_error_extra_info(
2722
0
              compiler, "lower bound for xor range exceeded (min: 0)");
2723
0
          result = ERROR_INVALID_MODIFIER;
2724
0
        }
2725
2726
0
        if ((yyvsp[-1].integer) > 255)
2727
0
        {
2728
0
          yr_compiler_set_error_extra_info(
2729
0
              compiler, "upper bound for xor range exceeded (max: 255)");
2730
0
          result = ERROR_INVALID_MODIFIER;
2731
0
        }
2732
2733
0
        if ((yyvsp[-3].integer) > (yyvsp[-1].integer))
2734
0
        {
2735
0
          yr_compiler_set_error_extra_info(
2736
0
              compiler, "xor lower bound exceeds upper bound");
2737
0
          result = ERROR_INVALID_MODIFIER;
2738
0
        }
2739
2740
0
        fail_if_error(result);
2741
2742
0
        (yyval.modifier).flags = STRING_FLAGS_XOR;
2743
0
        (yyval.modifier).xor_min = (uint8_t) (yyvsp[-3].integer);
2744
0
        (yyval.modifier).xor_max = (uint8_t) (yyvsp[-1].integer);
2745
0
      }
2746
0
#line 2747 "libyara/grammar.c"
2747
0
    break;
2748
2749
0
  case 52: /* string_modifier: "<base64>"  */
2750
0
#line 841 "libyara/grammar.y"
2751
0
      {
2752
0
        (yyval.modifier).flags = STRING_FLAGS_BASE64;
2753
0
        (yyval.modifier).alphabet = ss_new(DEFAULT_BASE64_ALPHABET);
2754
0
      }
2755
0
#line 2756 "libyara/grammar.c"
2756
0
    break;
2757
2758
0
  case 53: /* string_modifier: "<base64>" '(' "text string" ')'  */
2759
0
#line 846 "libyara/grammar.y"
2760
0
      {
2761
0
        int result = ERROR_SUCCESS;
2762
2763
0
        if ((yyvsp[-1].sized_string)->length != 64)
2764
0
        {
2765
0
          yr_free((yyvsp[-1].sized_string));
2766
0
          yr_compiler_set_error_extra_info(
2767
0
              compiler, "length of base64 alphabet must be 64");
2768
0
          result = ERROR_INVALID_MODIFIER;
2769
0
        }
2770
2771
0
        fail_if_error(result);
2772
2773
0
        (yyval.modifier).flags = STRING_FLAGS_BASE64;
2774
0
        (yyval.modifier).alphabet = (yyvsp[-1].sized_string);
2775
0
      }
2776
0
#line 2777 "libyara/grammar.c"
2777
0
    break;
2778
2779
0
  case 54: /* string_modifier: "<base64wide>"  */
2780
0
#line 863 "libyara/grammar.y"
2781
0
      {
2782
0
        (yyval.modifier).flags = STRING_FLAGS_BASE64_WIDE;
2783
0
        (yyval.modifier).alphabet = ss_new(DEFAULT_BASE64_ALPHABET);
2784
0
      }
2785
0
#line 2786 "libyara/grammar.c"
2786
0
    break;
2787
2788
0
  case 55: /* string_modifier: "<base64wide>" '(' "text string" ')'  */
2789
0
#line 868 "libyara/grammar.y"
2790
0
      {
2791
0
        int result = ERROR_SUCCESS;
2792
2793
0
        if ((yyvsp[-1].sized_string)->length != 64)
2794
0
        {
2795
0
          yr_free((yyvsp[-1].sized_string));
2796
0
          yr_compiler_set_error_extra_info(
2797
0
              compiler, "length of base64 alphabet must be 64");
2798
0
          result = ERROR_INVALID_MODIFIER;
2799
0
        }
2800
2801
0
        fail_if_error(result);
2802
2803
0
        (yyval.modifier).flags = STRING_FLAGS_BASE64_WIDE;
2804
0
        (yyval.modifier).alphabet = (yyvsp[-1].sized_string);
2805
0
      }
2806
0
#line 2807 "libyara/grammar.c"
2807
0
    break;
2808
2809
0
  case 56: /* regexp_modifiers: %empty  */
2810
0
#line 887 "libyara/grammar.y"
2811
0
                                          { (yyval.modifier).flags = 0; }
2812
0
#line 2813 "libyara/grammar.c"
2813
0
    break;
2814
2815
0
  case 57: /* regexp_modifiers: regexp_modifiers regexp_modifier  */
2816
0
#line 889 "libyara/grammar.y"
2817
0
      {
2818
0
        if ((yyvsp[-1].modifier).flags & (yyvsp[0].modifier).flags)
2819
0
        {
2820
0
          fail_with_error(ERROR_DUPLICATED_MODIFIER);
2821
0
        }
2822
0
        else
2823
0
        {
2824
0
          (yyval.modifier).flags = (yyvsp[-1].modifier).flags | (yyvsp[0].modifier).flags;
2825
0
        }
2826
0
      }
2827
0
#line 2828 "libyara/grammar.c"
2828
0
    break;
2829
2830
0
  case 58: /* regexp_modifier: "<wide>"  */
2831
0
#line 902 "libyara/grammar.y"
2832
0
                    { (yyval.modifier).flags = STRING_FLAGS_WIDE; }
2833
0
#line 2834 "libyara/grammar.c"
2834
0
    break;
2835
2836
0
  case 59: /* regexp_modifier: "<ascii>"  */
2837
0
#line 903 "libyara/grammar.y"
2838
0
                    { (yyval.modifier).flags = STRING_FLAGS_ASCII; }
2839
0
#line 2840 "libyara/grammar.c"
2840
0
    break;
2841
2842
0
  case 60: /* regexp_modifier: "<nocase>"  */
2843
0
#line 904 "libyara/grammar.y"
2844
0
                    { (yyval.modifier).flags = STRING_FLAGS_NO_CASE; }
2845
0
#line 2846 "libyara/grammar.c"
2846
0
    break;
2847
2848
0
  case 61: /* regexp_modifier: "<fullword>"  */
2849
0
#line 905 "libyara/grammar.y"
2850
0
                    { (yyval.modifier).flags = STRING_FLAGS_FULL_WORD; }
2851
0
#line 2852 "libyara/grammar.c"
2852
0
    break;
2853
2854
0
  case 62: /* regexp_modifier: "<private>"  */
2855
0
#line 906 "libyara/grammar.y"
2856
0
                    { (yyval.modifier).flags = STRING_FLAGS_PRIVATE; }
2857
0
#line 2858 "libyara/grammar.c"
2858
0
    break;
2859
2860
0
  case 63: /* hex_modifiers: %empty  */
2861
0
#line 910 "libyara/grammar.y"
2862
0
                                          { (yyval.modifier).flags = 0; }
2863
0
#line 2864 "libyara/grammar.c"
2864
0
    break;
2865
2866
0
  case 64: /* hex_modifiers: hex_modifiers hex_modifier  */
2867
0
#line 912 "libyara/grammar.y"
2868
0
      {
2869
0
        if ((yyvsp[-1].modifier).flags & (yyvsp[0].modifier).flags)
2870
0
        {
2871
0
          fail_with_error(ERROR_DUPLICATED_MODIFIER);
2872
0
        }
2873
0
        else
2874
0
        {
2875
0
          (yyval.modifier).flags = (yyvsp[-1].modifier).flags | (yyvsp[0].modifier).flags;
2876
0
        }
2877
0
      }
2878
0
#line 2879 "libyara/grammar.c"
2879
0
    break;
2880
2881
0
  case 65: /* hex_modifier: "<private>"  */
2882
0
#line 925 "libyara/grammar.y"
2883
0
                    { (yyval.modifier).flags = STRING_FLAGS_PRIVATE; }
2884
0
#line 2885 "libyara/grammar.c"
2885
0
    break;
2886
2887
0
  case 66: /* identifier: "identifier"  */
2888
0
#line 930 "libyara/grammar.y"
2889
0
      {
2890
0
        YR_EXPRESSION expr;
2891
2892
0
        int result = ERROR_SUCCESS;
2893
0
        int var_index = yr_parser_lookup_loop_variable(yyscanner, (yyvsp[0].c_string), &expr);
2894
2895
0
        if (var_index >= 0)
2896
0
        {
2897
          // The identifier corresponds to a loop variable.
2898
0
          result = yr_parser_emit_with_arg(
2899
0
              yyscanner,
2900
0
              OP_PUSH_M,
2901
0
              var_index,
2902
0
              NULL,
2903
0
              NULL);
2904
2905
          // The expression associated to this identifier is the same one
2906
          // associated to the loop variable.
2907
0
          (yyval.expression) = expr;
2908
0
        }
2909
0
        else
2910
0
        {
2911
          // Search for identifier within the global namespace, where the
2912
          // externals variables reside.
2913
2914
0
          YR_OBJECT* object = (YR_OBJECT*) yr_hash_table_lookup(
2915
0
              compiler->objects_table, (yyvsp[0].c_string), NULL);
2916
2917
0
          YR_NAMESPACE* ns = (YR_NAMESPACE*) yr_arena_get_ptr(
2918
0
              compiler->arena,
2919
0
              YR_NAMESPACES_TABLE,
2920
0
              compiler->current_namespace_idx * sizeof(struct YR_NAMESPACE));
2921
2922
0
          if (object == NULL)
2923
0
          {
2924
            // If not found, search within the current namespace.
2925
0
            object = (YR_OBJECT*) yr_hash_table_lookup(
2926
0
                compiler->objects_table, (yyvsp[0].c_string), ns->name);
2927
0
          }
2928
2929
0
          if (object != NULL)
2930
0
          {
2931
0
            YR_ARENA_REF ref;
2932
2933
0
            result = _yr_compiler_store_string(
2934
0
                compiler, (yyvsp[0].c_string), &ref);
2935
2936
0
            if (result == ERROR_SUCCESS)
2937
0
              result = yr_parser_emit_with_arg_reloc(
2938
0
                  yyscanner,
2939
0
                  OP_OBJ_LOAD,
2940
0
                  yr_arena_ref_to_ptr(compiler->arena, &ref),
2941
0
                  NULL,
2942
0
                  NULL);
2943
2944
0
            (yyval.expression).type = EXPRESSION_TYPE_OBJECT;
2945
0
            (yyval.expression).value.object = object;
2946
0
            (yyval.expression).identifier.ptr = NULL;
2947
0
            (yyval.expression).identifier.ref = ref;
2948
0
          }
2949
0
          else
2950
0
          {
2951
0
            uint32_t rule_idx = yr_hash_table_lookup_uint32(
2952
0
                compiler->rules_table, (yyvsp[0].c_string), ns->name);
2953
2954
0
            if (rule_idx != UINT32_MAX)
2955
0
            {
2956
0
              result = yr_parser_emit_with_arg(
2957
0
                  yyscanner,
2958
0
                  OP_PUSH_RULE,
2959
0
                  rule_idx,
2960
0
                  NULL,
2961
0
                  NULL);
2962
2963
0
              YR_RULE* rule = _yr_compiler_get_rule_by_idx(compiler, rule_idx);
2964
2965
0
              yr_arena_ptr_to_ref(compiler->arena, rule->identifier, &(yyval.expression).identifier.ref);
2966
2967
0
              (yyval.expression).type = EXPRESSION_TYPE_BOOLEAN;
2968
0
              (yyval.expression).value.integer = YR_UNDEFINED;
2969
0
              (yyval.expression).identifier.ptr = NULL;
2970
0
              (yyval.expression).required_strings.count = 0;
2971
0
            }
2972
0
            else
2973
0
            {
2974
0
              yr_compiler_set_error_extra_info(compiler, (yyvsp[0].c_string));
2975
0
              result = ERROR_UNDEFINED_IDENTIFIER;
2976
0
            }
2977
0
          }
2978
0
        }
2979
2980
0
        yr_free((yyvsp[0].c_string));
2981
2982
0
        fail_if_error(result);
2983
0
      }
2984
0
#line 2985 "libyara/grammar.c"
2985
0
    break;
2986
2987
0
  case 67: /* identifier: identifier '.' "identifier"  */
2988
0
#line 1026 "libyara/grammar.y"
2989
0
      {
2990
0
        int result = ERROR_SUCCESS;
2991
0
        YR_OBJECT* field = NULL;
2992
2993
0
        if ((yyvsp[-2].expression).type == EXPRESSION_TYPE_OBJECT &&
2994
0
            (yyvsp[-2].expression).value.object->type == OBJECT_TYPE_STRUCTURE)
2995
0
        {
2996
0
          field = yr_object_lookup_field((yyvsp[-2].expression).value.object, (yyvsp[0].c_string));
2997
2998
0
          if (field != NULL)
2999
0
          {
3000
0
            YR_ARENA_REF ref;
3001
3002
0
            result = _yr_compiler_store_string(
3003
0
                compiler, (yyvsp[0].c_string), &ref);
3004
3005
0
            if (result == ERROR_SUCCESS)
3006
0
              result = yr_parser_emit_with_arg_reloc(
3007
0
                  yyscanner,
3008
0
                  OP_OBJ_FIELD,
3009
0
                  yr_arena_ref_to_ptr(compiler->arena, &ref),
3010
0
                  NULL,
3011
0
                  NULL);
3012
3013
0
            (yyval.expression).type = EXPRESSION_TYPE_OBJECT;
3014
0
            (yyval.expression).value.object = field;
3015
0
            (yyval.expression).identifier.ref = ref;
3016
0
            (yyval.expression).identifier.ptr = NULL;
3017
0
          }
3018
0
          else
3019
0
          {
3020
0
            yr_compiler_set_error_extra_info(compiler, (yyvsp[0].c_string));
3021
0
            result = ERROR_INVALID_FIELD_NAME;
3022
0
          }
3023
0
        }
3024
0
        else
3025
0
        {
3026
0
          yr_compiler_set_error_extra_info(
3027
0
             compiler, expression_identifier((yyvsp[-2].expression)));
3028
3029
0
          result = ERROR_NOT_A_STRUCTURE;
3030
0
        }
3031
3032
0
        yr_free((yyvsp[0].c_string));
3033
3034
0
        fail_if_error(result);
3035
0
      }
3036
0
#line 3037 "libyara/grammar.c"
3037
0
    break;
3038
3039
0
  case 68: /* identifier: identifier '[' primary_expression ']'  */
3040
0
#line 1074 "libyara/grammar.y"
3041
0
      {
3042
0
        int result = ERROR_SUCCESS;
3043
0
        YR_OBJECT_ARRAY* array;
3044
0
        YR_OBJECT_DICTIONARY* dict;
3045
3046
0
        if ((yyvsp[-3].expression).type == EXPRESSION_TYPE_OBJECT &&
3047
0
            (yyvsp[-3].expression).value.object->type == OBJECT_TYPE_ARRAY)
3048
0
        {
3049
0
          if ((yyvsp[-1].expression).type != EXPRESSION_TYPE_INTEGER)
3050
0
          {
3051
0
            yr_compiler_set_error_extra_info(
3052
0
                compiler, "array indexes must be of integer type");
3053
0
            result = ERROR_WRONG_TYPE;
3054
0
          }
3055
3056
0
          fail_if_error(result);
3057
3058
0
          result = yr_parser_emit(
3059
0
              yyscanner, OP_INDEX_ARRAY, NULL);
3060
3061
0
          array = object_as_array((yyvsp[-3].expression).value.object);
3062
3063
0
          (yyval.expression).type = EXPRESSION_TYPE_OBJECT;
3064
0
          (yyval.expression).value.object = array->prototype_item;
3065
0
          (yyval.expression).identifier.ptr = array->identifier;
3066
0
          (yyval.expression).identifier.ref = YR_ARENA_NULL_REF;
3067
0
        }
3068
0
        else if ((yyvsp[-3].expression).type == EXPRESSION_TYPE_OBJECT &&
3069
0
                 (yyvsp[-3].expression).value.object->type == OBJECT_TYPE_DICTIONARY)
3070
0
        {
3071
0
          if ((yyvsp[-1].expression).type != EXPRESSION_TYPE_STRING)
3072
0
          {
3073
0
            yr_compiler_set_error_extra_info(
3074
0
                compiler, "dictionary keys must be of string type");
3075
0
            result = ERROR_WRONG_TYPE;
3076
0
          }
3077
3078
0
          fail_if_error(result);
3079
3080
0
          result = yr_parser_emit(
3081
0
              yyscanner, OP_LOOKUP_DICT, NULL);
3082
3083
0
          dict = object_as_dictionary((yyvsp[-3].expression).value.object);
3084
3085
0
          (yyval.expression).type = EXPRESSION_TYPE_OBJECT;
3086
0
          (yyval.expression).value.object = dict->prototype_item;
3087
0
          (yyval.expression).identifier.ptr = dict->identifier;
3088
0
          (yyval.expression).identifier.ref = YR_ARENA_NULL_REF;
3089
0
        }
3090
0
        else
3091
0
        {
3092
0
          yr_compiler_set_error_extra_info(
3093
0
              compiler, expression_identifier((yyvsp[-3].expression)));
3094
3095
0
          result = ERROR_NOT_INDEXABLE;
3096
0
        }
3097
3098
0
        fail_if_error(result);
3099
0
      }
3100
0
#line 3101 "libyara/grammar.c"
3101
0
    break;
3102
3103
0
  case 69: /* identifier: identifier '(' arguments ')'  */
3104
0
#line 1135 "libyara/grammar.y"
3105
0
      {
3106
0
        YR_ARENA_REF ref = YR_ARENA_NULL_REF;
3107
0
        int result = ERROR_SUCCESS;
3108
3109
0
        if ((yyvsp[-3].expression).type == EXPRESSION_TYPE_OBJECT &&
3110
0
            (yyvsp[-3].expression).value.object->type == OBJECT_TYPE_FUNCTION)
3111
0
        {
3112
0
          YR_OBJECT_FUNCTION* function = object_as_function((yyvsp[-3].expression).value.object);
3113
3114
0
          result = yr_parser_check_types(compiler, function, (yyvsp[-1].c_string));
3115
3116
0
          if (result == ERROR_SUCCESS)
3117
0
            result = _yr_compiler_store_string(
3118
0
                compiler, (yyvsp[-1].c_string), &ref);
3119
3120
0
          if (result == ERROR_SUCCESS)
3121
0
            result = yr_parser_emit_with_arg_reloc(
3122
0
                yyscanner,
3123
0
                OP_CALL,
3124
0
                yr_arena_ref_to_ptr(compiler->arena, &ref),
3125
0
                NULL,
3126
0
                NULL);
3127
3128
0
          (yyval.expression).type = EXPRESSION_TYPE_OBJECT;
3129
0
          (yyval.expression).value.object = function->return_obj;
3130
0
          (yyval.expression).identifier.ref = ref;
3131
0
          (yyval.expression).identifier.ptr = NULL;
3132
0
        }
3133
0
        else
3134
0
        {
3135
0
          yr_compiler_set_error_extra_info(
3136
0
              compiler, expression_identifier((yyvsp[-3].expression)));
3137
3138
0
          result = ERROR_NOT_A_FUNCTION;
3139
0
        }
3140
3141
0
        yr_free((yyvsp[-1].c_string));
3142
3143
0
        fail_if_error(result);
3144
0
      }
3145
0
#line 3146 "libyara/grammar.c"
3146
0
    break;
3147
3148
0
  case 70: /* arguments: %empty  */
3149
0
#line 1179 "libyara/grammar.y"
3150
0
                      { (yyval.c_string) = yr_strdup(""); }
3151
0
#line 3152 "libyara/grammar.c"
3152
0
    break;
3153
3154
0
  case 71: /* arguments: arguments_list  */
3155
0
#line 1180 "libyara/grammar.y"
3156
0
                      { (yyval.c_string) = (yyvsp[0].c_string); }
3157
0
#line 3158 "libyara/grammar.c"
3158
0
    break;
3159
3160
0
  case 72: /* arguments_list: expression  */
3161
0
#line 1185 "libyara/grammar.y"
3162
0
      {
3163
0
        (yyval.c_string) = (char*) yr_malloc(YR_MAX_FUNCTION_ARGS + 1);
3164
3165
0
        if ((yyval.c_string) == NULL)
3166
0
          fail_with_error(ERROR_INSUFFICIENT_MEMORY);
3167
3168
0
        switch((yyvsp[0].expression).type)
3169
0
        {
3170
0
          case EXPRESSION_TYPE_INTEGER:
3171
0
            strlcpy((yyval.c_string), "i", YR_MAX_FUNCTION_ARGS);
3172
0
            break;
3173
0
          case EXPRESSION_TYPE_FLOAT:
3174
0
            strlcpy((yyval.c_string), "f", YR_MAX_FUNCTION_ARGS);
3175
0
            break;
3176
0
          case EXPRESSION_TYPE_BOOLEAN:
3177
0
            strlcpy((yyval.c_string), "b", YR_MAX_FUNCTION_ARGS);
3178
0
            break;
3179
0
          case EXPRESSION_TYPE_STRING:
3180
0
            strlcpy((yyval.c_string), "s", YR_MAX_FUNCTION_ARGS);
3181
0
            break;
3182
0
          case EXPRESSION_TYPE_REGEXP:
3183
0
            strlcpy((yyval.c_string), "r", YR_MAX_FUNCTION_ARGS);
3184
0
            break;
3185
0
          case EXPRESSION_TYPE_UNKNOWN:
3186
0
            yr_free((yyval.c_string));
3187
0
            yr_compiler_set_error_extra_info(
3188
0
                compiler, "unknown type for argument 1 in function call");
3189
0
            fail_with_error(ERROR_WRONG_TYPE);
3190
0
            break;
3191
0
          default:
3192
            // An unknown expression type is OK iff an error ocurred.
3193
0
            assert(compiler->last_error != ERROR_SUCCESS);
3194
0
        }
3195
0
      }
3196
0
#line 3197 "libyara/grammar.c"
3197
0
    break;
3198
3199
0
  case 73: /* arguments_list: arguments_list ',' expression  */
3200
0
#line 1220 "libyara/grammar.y"
3201
0
      {
3202
0
        int result = ERROR_SUCCESS;
3203
3204
0
        if (strlen((yyvsp[-2].c_string)) == YR_MAX_FUNCTION_ARGS)
3205
0
        {
3206
0
          result = ERROR_TOO_MANY_ARGUMENTS;
3207
0
        }
3208
0
        else
3209
0
        {
3210
0
          switch((yyvsp[0].expression).type)
3211
0
          {
3212
0
            case EXPRESSION_TYPE_INTEGER:
3213
0
              strlcat((yyvsp[-2].c_string), "i", YR_MAX_FUNCTION_ARGS);
3214
0
              break;
3215
0
            case EXPRESSION_TYPE_FLOAT:
3216
0
              strlcat((yyvsp[-2].c_string), "f", YR_MAX_FUNCTION_ARGS);
3217
0
              break;
3218
0
            case EXPRESSION_TYPE_BOOLEAN:
3219
0
              strlcat((yyvsp[-2].c_string), "b", YR_MAX_FUNCTION_ARGS);
3220
0
              break;
3221
0
            case EXPRESSION_TYPE_STRING:
3222
0
              strlcat((yyvsp[-2].c_string), "s", YR_MAX_FUNCTION_ARGS);
3223
0
              break;
3224
0
            case EXPRESSION_TYPE_REGEXP:
3225
0
              strlcat((yyvsp[-2].c_string), "r", YR_MAX_FUNCTION_ARGS);
3226
0
              break;
3227
0
            case EXPRESSION_TYPE_UNKNOWN:
3228
0
              result = ERROR_WRONG_TYPE;
3229
0
              yr_compiler_set_error_extra_info_fmt(
3230
0
                  compiler, "unknown type for argument %zu in function call",
3231
                  // As we add one character per argument, the length of $1 is
3232
                  // the number of arguments parsed so far, and the argument
3233
                  // represented by <expression> is length of $1 plus one.
3234
0
                  strlen((yyvsp[-2].c_string)) + 1);
3235
0
              break;
3236
0
            default:
3237
              // An unknown expression type is OK iff an error ocurred.
3238
0
              assert(compiler->last_error != ERROR_SUCCESS);
3239
0
          }
3240
0
        }
3241
3242
0
        if (result != ERROR_SUCCESS)
3243
0
          yr_free((yyvsp[-2].c_string));
3244
3245
0
        fail_if_error(result);
3246
3247
0
        (yyval.c_string) = (yyvsp[-2].c_string);
3248
0
      }
3249
0
#line 3250 "libyara/grammar.c"
3250
0
    break;
3251
3252
0
  case 74: /* regexp: "regular expression"  */
3253
0
#line 1273 "libyara/grammar.y"
3254
0
      {
3255
0
        YR_ARENA_REF re_ref;
3256
0
        RE_ERROR error;
3257
3258
0
        int result = ERROR_SUCCESS;
3259
0
        int re_flags = 0;
3260
0
        int parser_flags = RE_PARSER_FLAG_NONE;
3261
3262
0
        if ((yyvsp[0].sized_string)->flags & SIZED_STRING_FLAGS_NO_CASE)
3263
0
          re_flags |= RE_FLAGS_NO_CASE;
3264
3265
0
        if ((yyvsp[0].sized_string)->flags & SIZED_STRING_FLAGS_DOT_ALL)
3266
0
          re_flags |= RE_FLAGS_DOT_ALL;
3267
3268
0
        if (compiler->strict_escape)
3269
0
          parser_flags |= RE_PARSER_FLAG_ENABLE_STRICT_ESCAPE_SEQUENCES;
3270
3271
0
        result = yr_re_compile(
3272
0
            (yyvsp[0].sized_string)->c_string,
3273
0
            re_flags,
3274
0
            parser_flags,
3275
0
            compiler->arena,
3276
0
            &re_ref,
3277
0
            &error);
3278
3279
0
        yr_free((yyvsp[0].sized_string));
3280
3281
0
        if (result == ERROR_INVALID_REGULAR_EXPRESSION)
3282
0
          yr_compiler_set_error_extra_info(compiler, error.message);
3283
3284
0
        if (result == ERROR_SUCCESS || result == ERROR_UNKNOWN_ESCAPE_SEQUENCE)
3285
0
        {
3286
0
          if (result == ERROR_UNKNOWN_ESCAPE_SEQUENCE)
3287
0
          {
3288
0
              yywarning(
3289
0
                yyscanner,
3290
0
                "unknown escape sequence");
3291
0
          }
3292
0
          result = yr_parser_emit_with_arg_reloc(
3293
0
              yyscanner,
3294
0
              OP_PUSH,
3295
0
              yr_arena_ref_to_ptr(compiler->arena, &re_ref),
3296
0
              NULL,
3297
0
              NULL);
3298
0
        }
3299
3300
0
        fail_if_error(result);
3301
3302
0
        (yyval.expression).type = EXPRESSION_TYPE_REGEXP;
3303
0
      }
3304
0
#line 3305 "libyara/grammar.c"
3305
0
    break;
3306
3307
0
  case 75: /* boolean_expression: expression  */
3308
0
#line 1328 "libyara/grammar.y"
3309
0
      {
3310
0
        if ((yyvsp[0].expression).type == EXPRESSION_TYPE_STRING)
3311
0
        {
3312
0
          if (!YR_ARENA_IS_NULL_REF((yyvsp[0].expression).value.sized_string_ref))
3313
0
          {
3314
0
            SIZED_STRING* sized_string = yr_arena_ref_to_ptr(
3315
0
                compiler->arena, &(yyvsp[0].expression).value.sized_string_ref);
3316
3317
0
            yywarning(yyscanner,
3318
0
                "using literal string \"%s\" in a boolean operation.",
3319
0
                sized_string->c_string);
3320
0
          }
3321
3322
0
          fail_if_error(yr_parser_emit(
3323
0
              yyscanner, OP_STR_TO_BOOL, NULL));
3324
0
        }
3325
0
        if ((yyvsp[0].expression).type != EXPRESSION_TYPE_BOOLEAN)
3326
0
        {
3327
0
          (yyval.expression).required_strings.count = 0;
3328
0
        }
3329
0
        else
3330
0
        {
3331
0
          (yyval.expression).required_strings.count = (yyvsp[0].expression).required_strings.count;
3332
0
        }
3333
3334
0
        (yyval.expression).type = EXPRESSION_TYPE_BOOLEAN;
3335
0
      }
3336
0
#line 3337 "libyara/grammar.c"
3337
0
    break;
3338
3339
0
  case 76: /* expression: "<true>"  */
3340
0
#line 1359 "libyara/grammar.y"
3341
0
      {
3342
0
        fail_if_error(yr_parser_emit_push_const(yyscanner, 1));
3343
3344
0
        (yyval.expression).type = EXPRESSION_TYPE_BOOLEAN;
3345
0
        (yyval.expression).required_strings.count = 0;
3346
0
      }
3347
0
#line 3348 "libyara/grammar.c"
3348
0
    break;
3349
3350
0
  case 77: /* expression: "<false>"  */
3351
0
#line 1366 "libyara/grammar.y"
3352
0
      {
3353
0
        fail_if_error(yr_parser_emit_push_const(yyscanner, 0));
3354
3355
0
        (yyval.expression).type = EXPRESSION_TYPE_BOOLEAN;
3356
0
        (yyval.expression).required_strings.count = 0;
3357
0
      }
3358
0
#line 3359 "libyara/grammar.c"
3359
0
    break;
3360
3361
0
  case 78: /* expression: primary_expression "<matches>" regexp  */
3362
0
#line 1373 "libyara/grammar.y"
3363
0
      {
3364
0
        check_type((yyvsp[-2].expression), EXPRESSION_TYPE_STRING, "matches");
3365
0
        check_type((yyvsp[0].expression), EXPRESSION_TYPE_REGEXP, "matches");
3366
3367
0
        fail_if_error(yr_parser_emit(
3368
0
            yyscanner,
3369
0
            OP_MATCHES,
3370
0
            NULL));
3371
3372
0
        (yyval.expression).type = EXPRESSION_TYPE_BOOLEAN;
3373
0
        (yyval.expression).required_strings.count = 0;
3374
0
      }
3375
0
#line 3376 "libyara/grammar.c"
3376
0
    break;
3377
3378
0
  case 79: /* expression: primary_expression "<contains>" primary_expression  */
3379
0
#line 1386 "libyara/grammar.y"
3380
0
      {
3381
0
        check_type((yyvsp[-2].expression), EXPRESSION_TYPE_STRING, "contains");
3382
0
        check_type((yyvsp[0].expression), EXPRESSION_TYPE_STRING, "contains");
3383
3384
0
        fail_if_error(yr_parser_emit(
3385
0
            yyscanner, OP_CONTAINS, NULL));
3386
3387
0
        (yyval.expression).type = EXPRESSION_TYPE_BOOLEAN;
3388
0
        (yyval.expression).required_strings.count = 0;
3389
0
      }
3390
0
#line 3391 "libyara/grammar.c"
3391
0
    break;
3392
3393
0
  case 80: /* expression: primary_expression "<icontains>" primary_expression  */
3394
0
#line 1397 "libyara/grammar.y"
3395
0
      {
3396
0
        check_type((yyvsp[-2].expression), EXPRESSION_TYPE_STRING, "icontains");
3397
0
        check_type((yyvsp[0].expression), EXPRESSION_TYPE_STRING, "icontains");
3398
3399
0
        fail_if_error(yr_parser_emit(
3400
0
            yyscanner, OP_ICONTAINS, NULL));
3401
3402
0
        (yyval.expression).type = EXPRESSION_TYPE_BOOLEAN;
3403
0
        (yyval.expression).required_strings.count = 0;
3404
0
      }
3405
0
#line 3406 "libyara/grammar.c"
3406
0
    break;
3407
3408
0
  case 81: /* expression: primary_expression "<startswith>" primary_expression  */
3409
0
#line 1408 "libyara/grammar.y"
3410
0
      {
3411
0
        check_type((yyvsp[-2].expression), EXPRESSION_TYPE_STRING, "startswith");
3412
0
        check_type((yyvsp[0].expression), EXPRESSION_TYPE_STRING, "startswith");
3413
3414
0
        fail_if_error(yr_parser_emit(
3415
0
            yyscanner, OP_STARTSWITH, NULL));
3416
3417
0
        (yyval.expression).type = EXPRESSION_TYPE_BOOLEAN;
3418
0
        (yyval.expression).required_strings.count = 0;
3419
0
      }
3420
0
#line 3421 "libyara/grammar.c"
3421
0
    break;
3422
3423
0
  case 82: /* expression: primary_expression "<istartswith>" primary_expression  */
3424
0
#line 1419 "libyara/grammar.y"
3425
0
      {
3426
0
        check_type((yyvsp[-2].expression), EXPRESSION_TYPE_STRING, "istartswith");
3427
0
        check_type((yyvsp[0].expression), EXPRESSION_TYPE_STRING, "istartswith");
3428
3429
0
        fail_if_error(yr_parser_emit(
3430
0
            yyscanner, OP_ISTARTSWITH, NULL));
3431
3432
0
        (yyval.expression).type = EXPRESSION_TYPE_BOOLEAN;
3433
0
        (yyval.expression).required_strings.count = 0;
3434
0
      }
3435
0
#line 3436 "libyara/grammar.c"
3436
0
    break;
3437
3438
0
  case 83: /* expression: primary_expression "<endswith>" primary_expression  */
3439
0
#line 1430 "libyara/grammar.y"
3440
0
      {
3441
0
        check_type((yyvsp[-2].expression), EXPRESSION_TYPE_STRING, "endswith");
3442
0
        check_type((yyvsp[0].expression), EXPRESSION_TYPE_STRING, "endswith");
3443
3444
0
        fail_if_error(yr_parser_emit(
3445
0
            yyscanner, OP_ENDSWITH, NULL));
3446
3447
0
        (yyval.expression).type = EXPRESSION_TYPE_BOOLEAN;
3448
0
        (yyval.expression).required_strings.count = 0;
3449
0
      }
3450
0
#line 3451 "libyara/grammar.c"
3451
0
    break;
3452
3453
0
  case 84: /* expression: primary_expression "<iendswith>" primary_expression  */
3454
0
#line 1441 "libyara/grammar.y"
3455
0
      {
3456
0
        check_type((yyvsp[-2].expression), EXPRESSION_TYPE_STRING, "iendswith");
3457
0
        check_type((yyvsp[0].expression), EXPRESSION_TYPE_STRING, "iendswith");
3458
3459
0
        fail_if_error(yr_parser_emit(
3460
0
            yyscanner, OP_IENDSWITH, NULL));
3461
3462
0
        (yyval.expression).type = EXPRESSION_TYPE_BOOLEAN;
3463
0
        (yyval.expression).required_strings.count = 0;
3464
0
      }
3465
0
#line 3466 "libyara/grammar.c"
3466
0
    break;
3467
3468
0
  case 85: /* expression: primary_expression "<iequals>" primary_expression  */
3469
0
#line 1452 "libyara/grammar.y"
3470
0
      {
3471
0
        check_type((yyvsp[-2].expression), EXPRESSION_TYPE_STRING, "iequals");
3472
0
        check_type((yyvsp[0].expression), EXPRESSION_TYPE_STRING, "iequals");
3473
3474
0
        fail_if_error(yr_parser_emit(
3475
0
            yyscanner, OP_IEQUALS, NULL));
3476
3477
0
        (yyval.expression).type = EXPRESSION_TYPE_BOOLEAN;
3478
0
        (yyval.expression).required_strings.count = 0;
3479
0
      }
3480
0
#line 3481 "libyara/grammar.c"
3481
0
    break;
3482
3483
0
  case 86: /* expression: "string identifier"  */
3484
0
#line 1463 "libyara/grammar.y"
3485
0
      {
3486
0
        int result = yr_parser_reduce_string_identifier(
3487
0
            yyscanner,
3488
0
            (yyvsp[0].c_string),
3489
0
            OP_FOUND,
3490
0
            YR_UNDEFINED);
3491
3492
0
        yr_free((yyvsp[0].c_string));
3493
3494
0
        fail_if_error(result);
3495
3496
0
        (yyval.expression).type = EXPRESSION_TYPE_BOOLEAN;
3497
0
        (yyval.expression).required_strings.count = 1;
3498
0
      }
3499
0
#line 3500 "libyara/grammar.c"
3500
0
    break;
3501
3502
0
  case 87: /* expression: "string identifier" "<at>" primary_expression  */
3503
0
#line 1478 "libyara/grammar.y"
3504
0
      {
3505
0
        int result;
3506
3507
0
        check_type_with_cleanup((yyvsp[0].expression), EXPRESSION_TYPE_INTEGER, "at", yr_free((yyvsp[-2].c_string)));
3508
3509
0
        result = yr_parser_reduce_string_identifier(
3510
0
            yyscanner, (yyvsp[-2].c_string), OP_FOUND_AT, (yyvsp[0].expression).value.integer);
3511
3512
0
        yr_free((yyvsp[-2].c_string));
3513
3514
0
        fail_if_error(result);
3515
3516
0
        (yyval.expression).required_strings.count = 1;
3517
0
        (yyval.expression).type = EXPRESSION_TYPE_BOOLEAN;
3518
0
      }
3519
0
#line 3520 "libyara/grammar.c"
3520
0
    break;
3521
3522
0
  case 88: /* expression: "string identifier" "<in>" range  */
3523
0
#line 1494 "libyara/grammar.y"
3524
0
      {
3525
0
        int result = yr_parser_reduce_string_identifier(
3526
0
            yyscanner, (yyvsp[-2].c_string), OP_FOUND_IN, YR_UNDEFINED);
3527
3528
0
        yr_free((yyvsp[-2].c_string));
3529
3530
0
        fail_if_error(result);
3531
3532
0
        (yyval.expression).required_strings.count = 1;
3533
0
        (yyval.expression).type = EXPRESSION_TYPE_BOOLEAN;
3534
0
      }
3535
0
#line 3536 "libyara/grammar.c"
3536
0
    break;
3537
3538
0
  case 89: /* expression: "<for>" for_expression error  */
3539
0
#line 1506 "libyara/grammar.y"
3540
0
      {
3541
        // Free all the loop variable identifiers, including the variables for
3542
        // the current loop (represented by loop_index), and set loop_index to
3543
        // -1. This is OK even if we have nested loops. If an error occurs while
3544
        // parsing the inner loop, it will be propagated to the outer loop
3545
        // anyways, so it's safe to do this cleanup while processing the error
3546
        // for the inner loop.
3547
3548
0
        for (int i = 0; i <= compiler->loop_index; i++)
3549
0
        {
3550
0
          loop_vars_cleanup(i);
3551
0
        }
3552
3553
0
        compiler->loop_index = -1;
3554
0
        YYERROR;
3555
0
      }
3556
0
#line 3557 "libyara/grammar.c"
3557
0
    break;
3558
3559
0
  case 90: /* $@6: %empty  */
3560
0
#line 1580 "libyara/grammar.y"
3561
0
      {
3562
        // var_frame is used for accessing local variables used in this loop.
3563
        // All local variables are accessed using var_frame as a reference,
3564
        // like var_frame + 0, var_frame + 1, etc. Here we initialize var_frame
3565
        // with the correct value, which depends on the number of variables
3566
        // defined by any outer loops.
3567
3568
0
        int var_frame;
3569
0
        int result = ERROR_SUCCESS;
3570
3571
0
        if (compiler->loop_index + 1 == YR_MAX_LOOP_NESTING)
3572
0
          result = ERROR_LOOP_NESTING_LIMIT_EXCEEDED;
3573
3574
0
        fail_if_error(result);
3575
3576
0
        compiler->loop_index++;
3577
3578
        // This loop uses internal variables besides the ones explicitly
3579
        // defined by the user.
3580
0
        compiler->loop[compiler->loop_index].vars_internal_count = \
3581
0
            YR_INTERNAL_LOOP_VARS;
3582
3583
        // Initialize the number of variables, this number will be incremented
3584
        // as variable declaration are processed by for_variables.
3585
0
        compiler->loop[compiler->loop_index].vars_count = 0;
3586
3587
0
        var_frame = _yr_compiler_get_var_frame(compiler);
3588
3589
0
        fail_if_error(yr_parser_emit_with_arg(
3590
0
            yyscanner, OP_CLEAR_M, var_frame + 0, NULL, NULL));
3591
3592
0
        fail_if_error(yr_parser_emit_with_arg(
3593
0
            yyscanner, OP_CLEAR_M, var_frame + 1, NULL, NULL));
3594
3595
0
        fail_if_error(yr_parser_emit_with_arg(
3596
0
            yyscanner, OP_POP_M, var_frame + 2, NULL, NULL));
3597
0
      }
3598
0
#line 3599 "libyara/grammar.c"
3599
0
    break;
3600
3601
0
  case 91: /* $@7: %empty  */
3602
0
#line 1618 "libyara/grammar.y"
3603
0
      {
3604
0
        YR_LOOP_CONTEXT* loop_ctx = &compiler->loop[compiler->loop_index];
3605
0
        YR_FIXUP* fixup;
3606
3607
0
        YR_ARENA_REF loop_start_ref;
3608
0
        YR_ARENA_REF jmp_offset_ref;
3609
3610
0
        int var_frame = _yr_compiler_get_var_frame(compiler);
3611
3612
0
        fail_if_error(yr_parser_emit(
3613
0
            yyscanner, OP_ITER_NEXT, &loop_start_ref));
3614
3615
        // For each variable generate an instruction that pops the value from
3616
        // the stack and store it into one memory slot starting at var_frame +
3617
        // YR_INTERNAL_LOOP_VARS because the first YR_INTERNAL_LOOP_VARS slots
3618
        // in the frame are for the internal variables.
3619
3620
0
        for (int i = 0; i < loop_ctx->vars_count; i++)
3621
0
        {
3622
0
          fail_if_error(yr_parser_emit_with_arg(
3623
0
              yyscanner,
3624
0
              OP_POP_M,
3625
0
              var_frame + YR_INTERNAL_LOOP_VARS + i,
3626
0
              NULL,
3627
0
              NULL));
3628
0
        }
3629
3630
0
        fail_if_error(yr_parser_emit_with_arg_int32(
3631
0
            yyscanner,
3632
0
            OP_JTRUE_P,
3633
0
            0,              // still don't know the jump offset, use 0 for now.
3634
0
            NULL,
3635
0
            &jmp_offset_ref));
3636
3637
        // We still don't know the jump's target, so we push a fixup entry
3638
        // in the stack, so that the jump's offset can be set once we know it.
3639
3640
0
        fixup = (YR_FIXUP*) yr_malloc(sizeof(YR_FIXUP));
3641
3642
0
        if (fixup == NULL)
3643
0
          fail_with_error(ERROR_INSUFFICIENT_MEMORY);
3644
3645
0
        fixup->ref = jmp_offset_ref;
3646
0
        fixup->next = compiler->fixup_stack_head;
3647
0
        compiler->fixup_stack_head = fixup;
3648
3649
0
        loop_ctx->start_ref = loop_start_ref;
3650
0
      }
3651
0
#line 3652 "libyara/grammar.c"
3652
0
    break;
3653
3654
0
  case 92: /* expression: "<for>" for_expression $@6 for_iteration ':' $@7 '(' boolean_expression ')'  */
3655
0
#line 1667 "libyara/grammar.y"
3656
0
      {
3657
0
        int32_t jmp_offset;
3658
0
        YR_FIXUP* fixup;
3659
0
        YR_ARENA_REF pop_ref;
3660
3661
0
        int var_frame = _yr_compiler_get_var_frame(compiler);
3662
3663
0
        if ((yyvsp[-5].integer) == FOR_ITERATION_STRING_SET)
3664
0
        {
3665
0
          compiler->loop_for_of_var_index = -1;
3666
0
        }
3667
3668
0
        fail_if_error(yr_parser_emit_with_arg(
3669
0
            yyscanner, OP_INCR_M, var_frame + 1, NULL, NULL));
3670
3671
0
        fail_if_error(yr_parser_emit_with_arg(
3672
0
            yyscanner, OP_PUSH_M, var_frame + 0, NULL, NULL));
3673
3674
0
        fail_if_error(yr_parser_emit_with_arg(
3675
0
            yyscanner, OP_PUSH_M, var_frame + 2, NULL, NULL));
3676
3677
0
        fail_if_error(yr_parser_emit(yyscanner, OP_ITER_CONDITION, NULL));
3678
3679
0
        fail_if_error(yr_parser_emit_with_arg(
3680
0
            yyscanner, OP_ADD_M, var_frame + 0, NULL, NULL));
3681
3682
0
        jmp_offset = \
3683
0
            compiler->loop[compiler->loop_index].start_ref.offset -
3684
0
            yr_arena_get_current_offset(compiler->arena, YR_CODE_SECTION);
3685
3686
0
        fail_if_error(yr_parser_emit_with_arg_int32(
3687
0
            yyscanner,
3688
0
            OP_JTRUE_P,
3689
0
            jmp_offset,
3690
0
            NULL,
3691
0
            NULL));
3692
3693
0
        fail_if_error(yr_parser_emit(
3694
0
            yyscanner, OP_POP, &pop_ref));
3695
3696
        // Pop from the stack the fixup entry containing the reference to
3697
        // the jump offset that needs to be fixed.
3698
3699
0
        fixup = compiler->fixup_stack_head;
3700
0
        compiler->fixup_stack_head = fixup->next;
3701
3702
        // The fixup entry has a reference to the jump offset that need
3703
        // to be fixed, convert the address into a pointer.
3704
0
        int32_t* jmp_offset_addr = (int32_t*) yr_arena_ref_to_ptr(
3705
0
            compiler->arena, &fixup->ref);
3706
3707
        // The reference in the fixup entry points to the jump's offset
3708
        // but the jump instruction is one byte before, that's why we add
3709
        // one to the offset.
3710
0
        jmp_offset = pop_ref.offset - fixup->ref.offset + 1;
3711
3712
        // Fix the jump's offset.
3713
0
        memcpy(jmp_offset_addr, &jmp_offset, sizeof(jmp_offset));
3714
3715
0
        yr_free(fixup);
3716
3717
0
        fail_if_error(yr_parser_emit_with_arg(
3718
0
            yyscanner, OP_PUSH_M, var_frame + 1, NULL, NULL));
3719
3720
0
        fail_if_error(yr_parser_emit_with_arg(
3721
0
            yyscanner, OP_PUSH_M, var_frame + 0, NULL, NULL));
3722
3723
0
        fail_if_error(yr_parser_emit_with_arg(
3724
0
            yyscanner, OP_PUSH_M, var_frame + 2, NULL, NULL));
3725
3726
0
        fail_if_error(yr_parser_emit(
3727
0
            yyscanner, OP_ITER_END, NULL));
3728
3729
0
        loop_vars_cleanup(compiler->loop_index);
3730
3731
0
        compiler->loop_index--;
3732
3733
0
        (yyval.expression).type = EXPRESSION_TYPE_BOOLEAN;
3734
0
        (yyval.expression).required_strings.count = 0;
3735
0
      }
3736
0
#line 3737 "libyara/grammar.c"
3737
0
    break;
3738
3739
0
  case 93: /* expression: for_expression "<of>" string_set  */
3740
0
#line 1748 "libyara/grammar.y"
3741
0
      {
3742
0
        if ((yyvsp[-2].expression).type == EXPRESSION_TYPE_INTEGER && (yyvsp[-2].expression).value.integer > (yyvsp[0].string_set).count)
3743
0
        {
3744
0
          yywarning(yyscanner,
3745
0
            "expression always false - requesting %" PRId64 " of %" PRId64 ".", (yyvsp[-2].expression).value.integer, (yyvsp[0].string_set).count);
3746
0
        }
3747
3748
0
        if (((yyvsp[-2].expression).type == EXPRESSION_TYPE_INTEGER && (yyvsp[-2].expression).value.integer > 0) ||
3749
0
              ((yyvsp[-2].expression).type == EXPRESSION_TYPE_QUANTIFIER &&
3750
0
                  ((yyvsp[-2].expression).value.integer == FOR_EXPRESSION_ALL || (yyvsp[-2].expression).value.integer == FOR_EXPRESSION_ANY)))
3751
0
        {
3752
0
          (yyval.expression).required_strings.count = 1;
3753
0
        }
3754
0
        else
3755
0
        {
3756
0
          (yyval.expression).required_strings.count = 0;
3757
0
        }
3758
3759
0
        yr_parser_emit_with_arg(yyscanner, OP_OF, OF_STRING_SET, NULL, NULL);
3760
3761
0
        yr_string_set_destroy((yyvsp[0].string_set));
3762
0
        (yyval.expression).type = EXPRESSION_TYPE_BOOLEAN;
3763
0
      }
3764
0
#line 3765 "libyara/grammar.c"
3765
0
    break;
3766
3767
0
  case 94: /* expression: for_expression "<of>" rule_set  */
3768
0
#line 1772 "libyara/grammar.y"
3769
0
      {
3770
0
        if ((yyvsp[-2].expression).type == EXPRESSION_TYPE_INTEGER && (yyvsp[-2].expression).value.integer > (yyvsp[0].integer))
3771
0
        {
3772
0
          yywarning(yyscanner,
3773
0
            "expression always false - requesting %" PRId64 " of %" PRId64 ".", (yyvsp[-2].expression).value.integer, (yyvsp[0].integer));
3774
0
        }
3775
0
        yr_parser_emit_with_arg(yyscanner, OP_OF, OF_RULE_SET, NULL, NULL);
3776
3777
0
        (yyval.expression).type = EXPRESSION_TYPE_BOOLEAN;
3778
0
        (yyval.expression).required_strings.count = 0;
3779
0
      }
3780
0
#line 3781 "libyara/grammar.c"
3781
0
    break;
3782
3783
0
  case 95: /* expression: primary_expression '%' "<of>" string_set  */
3784
0
#line 1784 "libyara/grammar.y"
3785
0
      {
3786
0
        check_type_with_cleanup((yyvsp[-3].expression), EXPRESSION_TYPE_INTEGER, "%", yr_string_set_destroy((yyvsp[0].string_set)));
3787
3788
        // The value of primary_expression can be undefined because
3789
        // it could be a variable for which don't know the value during
3790
        // compiling time. However, if the value is defined it should be
3791
        // in the range [1,100].
3792
0
        if (!IS_UNDEFINED((yyvsp[-3].expression).value.integer) &&
3793
0
            ((yyvsp[-3].expression).value.integer < 1 || (yyvsp[-3].expression).value.integer > 100))
3794
0
        {
3795
0
          yr_compiler_set_error_extra_info(
3796
0
              compiler, "percentage must be between 1 and 100 (inclusive)");
3797
3798
0
          yr_string_set_destroy((yyvsp[0].string_set));
3799
0
          fail_with_error(ERROR_INVALID_PERCENTAGE);
3800
0
        }
3801
3802
0
        if (!IS_UNDEFINED((yyvsp[-3].expression).value.integer))
3803
0
        {
3804
0
          (yyval.expression).required_strings.count = 1;
3805
0
        }
3806
0
        else
3807
0
        {
3808
0
          (yyval.expression).required_strings.count = 0;
3809
0
        }
3810
3811
0
        yr_string_set_destroy((yyvsp[0].string_set));
3812
0
        yr_parser_emit_with_arg(yyscanner, OP_OF_PERCENT, OF_STRING_SET, NULL, NULL);
3813
0
      }
3814
0
#line 3815 "libyara/grammar.c"
3815
0
    break;
3816
3817
0
  case 96: /* expression: primary_expression '%' "<of>" rule_set  */
3818
0
#line 1814 "libyara/grammar.y"
3819
0
      {
3820
0
        check_type((yyvsp[-3].expression), EXPRESSION_TYPE_INTEGER, "%");
3821
3822
        // The value of primary_expression can be undefined because
3823
        // it could be a variable for which don't know the value during
3824
        // compiling time. However, if the value is defined it should be
3825
        // in the range [1,100].
3826
0
        if (!IS_UNDEFINED((yyvsp[-3].expression).value.integer) &&
3827
0
            ((yyvsp[-3].expression).value.integer < 1 || (yyvsp[-3].expression).value.integer > 100))
3828
0
        {
3829
0
          yr_compiler_set_error_extra_info(
3830
0
              compiler, "percentage must be between 1 and 100 (inclusive)");
3831
3832
0
          fail_with_error(ERROR_INVALID_PERCENTAGE);
3833
0
        }
3834
3835
0
        yr_parser_emit_with_arg(yyscanner, OP_OF_PERCENT, OF_RULE_SET, NULL, NULL);
3836
0
      }
3837
0
#line 3838 "libyara/grammar.c"
3838
0
    break;
3839
3840
0
  case 97: /* expression: for_expression "<of>" string_set "<in>" range  */
3841
0
#line 1833 "libyara/grammar.y"
3842
0
      {
3843
0
        if ((yyvsp[-4].expression).type == EXPRESSION_TYPE_INTEGER && (yyvsp[-4].expression).value.integer > (yyvsp[-2].string_set).count)
3844
0
        {
3845
0
          yywarning(yyscanner,
3846
0
            "expression always false - requesting %" PRId64 " of %" PRId64 ".", (yyvsp[-4].expression).value.integer, (yyvsp[-2].string_set).count);
3847
0
        }
3848
3849
0
        if (((yyvsp[-4].expression).type == EXPRESSION_TYPE_INTEGER && (yyvsp[-4].expression).value.integer > 0) ||
3850
0
              ((yyvsp[-4].expression).type == EXPRESSION_TYPE_QUANTIFIER &&
3851
0
                  ((yyvsp[-4].expression).value.integer == FOR_EXPRESSION_ALL || (yyvsp[-4].expression).value.integer == FOR_EXPRESSION_ANY)))
3852
0
        {
3853
0
          (yyval.expression).required_strings.count = 1;
3854
0
        }
3855
0
        else
3856
0
        {
3857
0
          (yyval.expression).required_strings.count = 0;
3858
0
        }
3859
3860
0
        yr_parser_emit(yyscanner, OP_OF_FOUND_IN, NULL);
3861
3862
        // Mark strings as non-fast strings (since we need to check all matches whether they are in range)
3863
0
        yr_parser_mark_nonfast(yyscanner, (yyvsp[-2].string_set));
3864
3865
0
        yr_string_set_destroy((yyvsp[-2].string_set));
3866
0
        (yyval.expression).type = EXPRESSION_TYPE_BOOLEAN;
3867
0
      }
3868
0
#line 3869 "libyara/grammar.c"
3869
0
    break;
3870
3871
0
  case 98: /* expression: for_expression "<of>" string_set "<at>" primary_expression  */
3872
0
#line 1860 "libyara/grammar.y"
3873
0
      {
3874
0
        if ((yyvsp[0].expression).type != EXPRESSION_TYPE_INTEGER)
3875
0
        {
3876
0
          yr_compiler_set_error_extra_info(compiler,
3877
0
              "at expression must be an integer");
3878
3879
0
          yr_string_set_destroy((yyvsp[-2].string_set));
3880
0
          fail_with_error(ERROR_INVALID_VALUE);
3881
0
        }
3882
3883
0
        if ((yyvsp[-4].expression).type == EXPRESSION_TYPE_INTEGER && (yyvsp[-4].expression).value.integer > (yyvsp[-2].string_set).count)
3884
0
        {
3885
0
          yywarning(yyscanner,
3886
0
            "expression always false - requesting %" PRId64 " of %" PRId64 ".", (yyvsp[-4].expression).value.integer, (yyvsp[-2].string_set).count);
3887
0
        }
3888
3889
        // Both of these are warnings:
3890
        //
3891
        // "N of them at 0" where N > 1
3892
        //
3893
        //"all of them at 0" where there is more than 1 in "them".
3894
        //
3895
        // This means you can do "all of them at 0" if you only have one string
3896
        // defined in the set.
3897
0
        if (((yyvsp[-4].expression).type == EXPRESSION_TYPE_INTEGER &&
3898
0
              !IS_UNDEFINED((yyvsp[-4].expression).value.integer) && (yyvsp[-4].expression).value.integer > 1) ||
3899
0
              ((yyvsp[-4].expression).type == EXPRESSION_TYPE_QUANTIFIER &&
3900
0
              (yyvsp[-4].expression).value.integer == FOR_EXPRESSION_ALL && (yyvsp[-2].string_set).count > 1))
3901
0
        {
3902
0
          yywarning(yyscanner,
3903
0
            "multiple strings at an offset is usually false.");
3904
0
        }
3905
3906
0
        if (((yyvsp[-4].expression).type == EXPRESSION_TYPE_INTEGER && (yyvsp[-4].expression).value.integer > 0) ||
3907
0
              ((yyvsp[-4].expression).type == EXPRESSION_TYPE_QUANTIFIER &&
3908
0
                  ((yyvsp[-4].expression).value.integer == FOR_EXPRESSION_ALL || (yyvsp[-4].expression).value.integer == FOR_EXPRESSION_ANY)))
3909
0
        {
3910
0
          (yyval.expression).required_strings.count = 1;
3911
0
        }
3912
0
        else
3913
0
        {
3914
0
          (yyval.expression).required_strings.count = 0;
3915
0
        }
3916
3917
0
        yr_parser_emit(yyscanner, OP_OF_FOUND_AT, NULL);
3918
3919
        // Mark strings as non-fast strings (since we need to check all matches whether they are at location)
3920
0
        yr_parser_mark_nonfast(yyscanner, (yyvsp[-2].string_set));
3921
3922
0
        yr_string_set_destroy((yyvsp[-2].string_set));
3923
0
        (yyval.expression).type = EXPRESSION_TYPE_BOOLEAN;
3924
0
      }
3925
0
#line 3926 "libyara/grammar.c"
3926
0
    break;
3927
3928
0
  case 99: /* expression: "<not>" boolean_expression  */
3929
0
#line 1913 "libyara/grammar.y"
3930
0
      {
3931
0
        yr_parser_emit(yyscanner, OP_NOT, NULL);
3932
3933
0
        (yyval.expression).type = EXPRESSION_TYPE_BOOLEAN;
3934
0
        (yyval.expression).required_strings.count = 0;
3935
0
      }
3936
0
#line 3937 "libyara/grammar.c"
3937
0
    break;
3938
3939
0
  case 100: /* expression: "<defined>" boolean_expression  */
3940
0
#line 1920 "libyara/grammar.y"
3941
0
      {
3942
0
        yr_parser_emit(yyscanner, OP_DEFINED, NULL);
3943
0
        (yyval.expression).type = EXPRESSION_TYPE_BOOLEAN;
3944
0
        (yyval.expression).required_strings.count = 0;
3945
0
      }
3946
0
#line 3947 "libyara/grammar.c"
3947
0
    break;
3948
3949
0
  case 101: /* $@8: %empty  */
3950
0
#line 1926 "libyara/grammar.y"
3951
0
      {
3952
0
        YR_FIXUP* fixup;
3953
0
        YR_ARENA_REF jmp_offset_ref;
3954
3955
0
        fail_if_error(yr_parser_emit_with_arg_int32(
3956
0
            yyscanner,
3957
0
            OP_JFALSE,
3958
0
            0,          // still don't know the jump offset, use 0 for now.
3959
0
            NULL,
3960
0
            &jmp_offset_ref));
3961
3962
        // Create a fixup entry for the jump and push it in the stack.
3963
0
        fixup = (YR_FIXUP*) yr_malloc(sizeof(YR_FIXUP));
3964
3965
0
        if (fixup == NULL)
3966
0
          fail_with_error(ERROR_INSUFFICIENT_MEMORY);
3967
3968
0
        fixup->ref = jmp_offset_ref;
3969
0
        fixup->next = compiler->fixup_stack_head;
3970
0
        compiler->fixup_stack_head = fixup;
3971
0
      }
3972
0
#line 3973 "libyara/grammar.c"
3973
0
    break;
3974
3975
0
  case 102: /* expression: boolean_expression "<and>" $@8 boolean_expression  */
3976
0
#line 1948 "libyara/grammar.y"
3977
0
      {
3978
0
        YR_FIXUP* fixup;
3979
3980
0
        fail_if_error(yr_parser_emit(yyscanner, OP_AND, NULL));
3981
3982
0
        fixup = compiler->fixup_stack_head;
3983
3984
0
        int32_t* jmp_offset_addr = (int32_t*) yr_arena_ref_to_ptr(
3985
0
            compiler->arena, &fixup->ref);
3986
3987
0
        int32_t jmp_offset = \
3988
0
            yr_arena_get_current_offset(compiler->arena, YR_CODE_SECTION) -
3989
0
            fixup->ref.offset + 1;
3990
3991
0
        memcpy(jmp_offset_addr, &jmp_offset, sizeof(jmp_offset));
3992
3993
        // Remove fixup from the stack.
3994
0
        compiler->fixup_stack_head = fixup->next;
3995
0
        yr_free(fixup);
3996
3997
0
        (yyval.expression).type = EXPRESSION_TYPE_BOOLEAN;
3998
0
        (yyval.expression).required_strings.count = (yyvsp[0].expression).required_strings.count + (yyvsp[-3].expression).required_strings.count;
3999
0
      }
4000
0
#line 4001 "libyara/grammar.c"
4001
0
    break;
4002
4003
0
  case 103: /* $@9: %empty  */
4004
0
#line 1972 "libyara/grammar.y"
4005
0
      {
4006
0
        YR_FIXUP* fixup;
4007
0
        YR_ARENA_REF jmp_offset_ref;
4008
4009
0
        fail_if_error(yr_parser_emit_with_arg_int32(
4010
0
            yyscanner,
4011
0
            OP_JTRUE,
4012
0
            0,         // still don't know the jump destination, use 0 for now.
4013
0
            NULL,
4014
0
            &jmp_offset_ref));
4015
4016
0
        fixup = (YR_FIXUP*) yr_malloc(sizeof(YR_FIXUP));
4017
4018
0
        if (fixup == NULL)
4019
0
          fail_with_error(ERROR_INSUFFICIENT_MEMORY);
4020
4021
0
        fixup->ref = jmp_offset_ref;
4022
0
        fixup->next = compiler->fixup_stack_head;
4023
0
        compiler->fixup_stack_head = fixup;
4024
0
      }
4025
0
#line 4026 "libyara/grammar.c"
4026
0
    break;
4027
4028
0
  case 104: /* expression: boolean_expression "<or>" $@9 boolean_expression  */
4029
0
#line 1993 "libyara/grammar.y"
4030
0
      {
4031
0
        YR_FIXUP* fixup;
4032
4033
0
        fail_if_error(yr_parser_emit(yyscanner, OP_OR, NULL));
4034
4035
0
        fixup = compiler->fixup_stack_head;
4036
4037
0
        int32_t jmp_offset = \
4038
0
            yr_arena_get_current_offset(compiler->arena, YR_CODE_SECTION) -
4039
0
            fixup->ref.offset + 1;
4040
4041
0
        int32_t* jmp_offset_addr = (int32_t*) yr_arena_ref_to_ptr(
4042
0
            compiler->arena, &fixup->ref);
4043
4044
0
        memcpy(jmp_offset_addr, &jmp_offset, sizeof(jmp_offset));
4045
4046
        // Remove fixup from the stack.
4047
0
        compiler->fixup_stack_head = fixup->next;
4048
0
        yr_free(fixup);
4049
4050
0
        (yyval.expression).type = EXPRESSION_TYPE_BOOLEAN;
4051
4052
        // Set required string count to minimum from both parts
4053
0
        if ((yyvsp[-3].expression).required_strings.count > (yyvsp[0].expression).required_strings.count) {
4054
0
          (yyval.expression).required_strings.count = (yyvsp[0].expression).required_strings.count;
4055
0
        } else {
4056
0
          (yyval.expression).required_strings.count = (yyvsp[-3].expression).required_strings.count;
4057
0
        }
4058
0
      }
4059
0
#line 4060 "libyara/grammar.c"
4060
0
    break;
4061
4062
0
  case 105: /* expression: primary_expression "<" primary_expression  */
4063
0
#line 2023 "libyara/grammar.y"
4064
0
      {
4065
0
        fail_if_error(yr_parser_reduce_operation(
4066
0
            yyscanner, "<", (yyvsp[-2].expression), (yyvsp[0].expression)));
4067
4068
0
        (yyval.expression).type = EXPRESSION_TYPE_BOOLEAN;
4069
0
        (yyval.expression).required_strings.count = 0;
4070
0
      }
4071
0
#line 4072 "libyara/grammar.c"
4072
0
    break;
4073
4074
0
  case 106: /* expression: primary_expression ">" primary_expression  */
4075
0
#line 2031 "libyara/grammar.y"
4076
0
      {
4077
0
        fail_if_error(yr_parser_reduce_operation(
4078
0
            yyscanner, ">", (yyvsp[-2].expression), (yyvsp[0].expression)));
4079
4080
0
        (yyval.expression).type = EXPRESSION_TYPE_BOOLEAN;
4081
0
        (yyval.expression).required_strings.count = 0;
4082
0
      }
4083
0
#line 4084 "libyara/grammar.c"
4084
0
    break;
4085
4086
0
  case 107: /* expression: primary_expression "<=" primary_expression  */
4087
0
#line 2039 "libyara/grammar.y"
4088
0
      {
4089
0
        fail_if_error(yr_parser_reduce_operation(
4090
0
            yyscanner, "<=", (yyvsp[-2].expression), (yyvsp[0].expression)));
4091
4092
0
        (yyval.expression).type = EXPRESSION_TYPE_BOOLEAN;
4093
0
        (yyval.expression).required_strings.count = 0;
4094
0
      }
4095
0
#line 4096 "libyara/grammar.c"
4096
0
    break;
4097
4098
0
  case 108: /* expression: primary_expression ">=" primary_expression  */
4099
0
#line 2047 "libyara/grammar.y"
4100
0
      {
4101
0
        fail_if_error(yr_parser_reduce_operation(
4102
0
            yyscanner, ">=", (yyvsp[-2].expression), (yyvsp[0].expression)));
4103
4104
0
        (yyval.expression).type = EXPRESSION_TYPE_BOOLEAN;
4105
0
        (yyval.expression).required_strings.count = 0;
4106
0
      }
4107
0
#line 4108 "libyara/grammar.c"
4108
0
    break;
4109
4110
0
  case 109: /* expression: primary_expression "==" primary_expression  */
4111
0
#line 2055 "libyara/grammar.y"
4112
0
      {
4113
0
        fail_if_error(yr_parser_reduce_operation(
4114
0
            yyscanner, "==", (yyvsp[-2].expression), (yyvsp[0].expression)));
4115
4116
0
        (yyval.expression).type = EXPRESSION_TYPE_BOOLEAN;
4117
0
        (yyval.expression).required_strings.count = 0;
4118
0
      }
4119
0
#line 4120 "libyara/grammar.c"
4120
0
    break;
4121
4122
0
  case 110: /* expression: primary_expression "!=" primary_expression  */
4123
0
#line 2063 "libyara/grammar.y"
4124
0
      {
4125
0
        fail_if_error(yr_parser_reduce_operation(
4126
0
            yyscanner, "!=", (yyvsp[-2].expression), (yyvsp[0].expression)));
4127
4128
0
        (yyval.expression).type = EXPRESSION_TYPE_BOOLEAN;
4129
0
        (yyval.expression).required_strings.count = 0;
4130
0
      }
4131
0
#line 4132 "libyara/grammar.c"
4132
0
    break;
4133
4134
0
  case 111: /* expression: primary_expression  */
4135
0
#line 2071 "libyara/grammar.y"
4136
0
      {
4137
0
        (yyval.expression) = (yyvsp[0].expression);
4138
0
      }
4139
0
#line 4140 "libyara/grammar.c"
4140
0
    break;
4141
4142
0
  case 112: /* expression: '(' expression ')'  */
4143
0
#line 2075 "libyara/grammar.y"
4144
0
      {
4145
0
        (yyval.expression) = (yyvsp[-1].expression);
4146
0
      }
4147
0
#line 4148 "libyara/grammar.c"
4148
0
    break;
4149
4150
0
  case 113: /* for_iteration: for_variables "<in>" iterator  */
4151
0
#line 2082 "libyara/grammar.y"
4152
0
                                  { (yyval.integer) = FOR_ITERATION_ITERATOR; }
4153
0
#line 4154 "libyara/grammar.c"
4154
0
    break;
4155
4156
0
  case 114: /* for_iteration: "<of>" string_iterator  */
4157
0
#line 2084 "libyara/grammar.y"
4158
0
      {
4159
0
        int var_frame;
4160
0
        int result = ERROR_SUCCESS;
4161
4162
0
        if (compiler->loop_for_of_var_index != -1)
4163
0
          result = ERROR_NESTED_FOR_OF_LOOP;
4164
4165
0
        fail_if_error(result);
4166
4167
        // Simulate that we have 1 variable with string loops
4168
0
        compiler->loop[compiler->loop_index].vars_count = 1;
4169
4170
        // Set where we can find our string in case $ is in
4171
        // the body of the loop
4172
0
        var_frame = _yr_compiler_get_var_frame(compiler);
4173
0
        compiler->loop_for_of_var_index = var_frame +
4174
0
            compiler->loop[compiler->loop_index].vars_internal_count;
4175
4176
0
        (yyval.integer) = FOR_ITERATION_STRING_SET;
4177
0
      }
4178
0
#line 4179 "libyara/grammar.c"
4179
0
    break;
4180
4181
0
  case 115: /* for_variables: "identifier"  */
4182
0
#line 2109 "libyara/grammar.y"
4183
0
      {
4184
0
        int result = ERROR_SUCCESS;
4185
4186
0
        YR_LOOP_CONTEXT* loop_ctx = &compiler->loop[compiler->loop_index];
4187
4188
0
        if (yr_parser_lookup_loop_variable(yyscanner, (yyvsp[0].c_string), NULL) >= 0)
4189
0
        {
4190
0
          yr_compiler_set_error_extra_info(compiler, (yyvsp[0].c_string));
4191
0
          yr_free((yyvsp[0].c_string));
4192
4193
0
          result = ERROR_DUPLICATED_LOOP_IDENTIFIER;
4194
0
        }
4195
4196
0
        fail_if_error(result);
4197
4198
0
        loop_ctx->vars[loop_ctx->vars_count++].identifier.ptr = (yyvsp[0].c_string);
4199
4200
0
        assert(loop_ctx->vars_count <= YR_MAX_LOOP_VARS);
4201
0
      }
4202
0
#line 4203 "libyara/grammar.c"
4203
0
    break;
4204
4205
0
  case 116: /* for_variables: for_variables ',' "identifier"  */
4206
0
#line 2129 "libyara/grammar.y"
4207
0
      {
4208
0
        int result = ERROR_SUCCESS;
4209
4210
0
        YR_LOOP_CONTEXT* loop_ctx = &compiler->loop[compiler->loop_index];
4211
4212
0
        if (loop_ctx->vars_count == YR_MAX_LOOP_VARS)
4213
0
        {
4214
0
          yr_compiler_set_error_extra_info(compiler, "too many loop variables");
4215
0
          yr_free((yyvsp[0].c_string));
4216
4217
0
          result = ERROR_SYNTAX_ERROR;
4218
0
        }
4219
0
        else if (yr_parser_lookup_loop_variable(yyscanner, (yyvsp[0].c_string), NULL) >= 0)
4220
0
        {
4221
0
          yr_compiler_set_error_extra_info(compiler, (yyvsp[0].c_string));
4222
0
          yr_free((yyvsp[0].c_string));
4223
4224
0
          result = ERROR_DUPLICATED_LOOP_IDENTIFIER;
4225
0
        }
4226
4227
0
        fail_if_error(result);
4228
4229
0
        loop_ctx->vars[loop_ctx->vars_count++].identifier.ptr = (yyvsp[0].c_string);
4230
0
      }
4231
0
#line 4232 "libyara/grammar.c"
4232
0
    break;
4233
4234
0
  case 117: /* iterator: identifier  */
4235
0
#line 2157 "libyara/grammar.y"
4236
0
      {
4237
0
        YR_LOOP_CONTEXT* loop_ctx = &compiler->loop[compiler->loop_index];
4238
4239
        // Initially we assume that the identifier is from a non-iterable type,
4240
        // this will change later if it's iterable.
4241
0
        int result = ERROR_WRONG_TYPE;
4242
4243
0
        if ((yyvsp[0].expression).type == EXPRESSION_TYPE_OBJECT)
4244
0
        {
4245
0
          switch((yyvsp[0].expression).value.object->type)
4246
0
          {
4247
0
            case OBJECT_TYPE_ARRAY:
4248
              // If iterating an array the loop must define a single variable
4249
              // that will hold the current item. If a different number of
4250
              // variables were defined that's an error.
4251
0
              if (loop_ctx->vars_count == 1)
4252
0
              {
4253
0
                loop_ctx->vars[0].type = EXPRESSION_TYPE_OBJECT;
4254
0
                loop_ctx->vars[0].value.object = \
4255
0
                    object_as_array((yyvsp[0].expression).value.object)->prototype_item;
4256
4257
0
                result = yr_parser_emit(yyscanner, OP_ITER_START_ARRAY, NULL);
4258
0
              }
4259
0
              else
4260
0
              {
4261
0
                yr_compiler_set_error_extra_info_fmt(
4262
0
                    compiler,
4263
0
                    "iterator for \"%s\" yields a single item on each iteration"
4264
0
                    ", but the loop expects %d",
4265
0
                    expression_identifier((yyvsp[0].expression)),
4266
0
                    loop_ctx->vars_count);
4267
4268
0
                result = ERROR_SYNTAX_ERROR;
4269
0
              }
4270
0
              break;
4271
4272
0
            case OBJECT_TYPE_DICTIONARY:
4273
              // If iterating a dictionary the loop must define exactly two
4274
              // variables, one for the key and another for the value . If a
4275
              // different number of variables were defined that's an error.
4276
0
              if (loop_ctx->vars_count == 2)
4277
0
              {
4278
0
                loop_ctx->vars[0].type = EXPRESSION_TYPE_STRING;
4279
0
                loop_ctx->vars[0].value.sized_string_ref = YR_ARENA_NULL_REF;
4280
0
                loop_ctx->vars[1].type = EXPRESSION_TYPE_OBJECT;
4281
0
                loop_ctx->vars[1].value.object = \
4282
0
                    object_as_array((yyvsp[0].expression).value.object)->prototype_item;
4283
4284
0
                result = yr_parser_emit(yyscanner, OP_ITER_START_DICT, NULL);
4285
0
              }
4286
0
              else
4287
0
              {
4288
0
                yr_compiler_set_error_extra_info_fmt(
4289
0
                    compiler,
4290
0
                    "iterator for \"%s\" yields a key,value pair item on each iteration",
4291
0
                    expression_identifier((yyvsp[0].expression)));
4292
4293
0
                result = ERROR_SYNTAX_ERROR;
4294
0
              }
4295
0
              break;
4296
0
          }
4297
0
        }
4298
4299
0
        if (result == ERROR_WRONG_TYPE)
4300
0
        {
4301
0
          yr_compiler_set_error_extra_info_fmt(
4302
0
              compiler,
4303
0
              "identifier \"%s\" is not iterable",
4304
0
              expression_identifier((yyvsp[0].expression)));
4305
0
        }
4306
4307
0
        fail_if_error(result);
4308
0
      }
4309
0
#line 4310 "libyara/grammar.c"
4310
0
    break;
4311
4312
0
  case 118: /* iterator: set  */
4313
0
#line 2231 "libyara/grammar.y"
4314
0
      {
4315
0
        int result = ERROR_SUCCESS;
4316
4317
0
        YR_LOOP_CONTEXT* loop_ctx = &compiler->loop[compiler->loop_index];
4318
4319
0
        if (loop_ctx->vars_count == 1)
4320
0
        {
4321
0
          loop_ctx->vars[0].type = (yyvsp[0].enumeration).type;
4322
4323
0
          if ((yyvsp[0].enumeration).type == EXPRESSION_TYPE_STRING)
4324
0
            loop_ctx->vars[0].value.sized_string_ref = YR_ARENA_NULL_REF;
4325
0
          else
4326
0
            loop_ctx->vars[0].value.integer = YR_UNDEFINED;
4327
0
        }
4328
0
        else
4329
0
        {
4330
0
          yr_compiler_set_error_extra_info_fmt(
4331
0
              compiler,
4332
0
              "iterator yields one value on each iteration "
4333
0
              ", but the loop expects %d",
4334
0
              loop_ctx->vars_count);
4335
4336
0
          result = ERROR_SYNTAX_ERROR;
4337
0
        }
4338
4339
0
        fail_if_error(result);
4340
0
      }
4341
0
#line 4342 "libyara/grammar.c"
4342
0
    break;
4343
4344
0
  case 119: /* set: '(' enumeration ')'  */
4345
0
#line 2263 "libyara/grammar.y"
4346
0
      {
4347
        // $2.count contains the number of items in the enumeration
4348
0
        fail_if_error(yr_parser_emit_push_const(yyscanner, (yyvsp[-1].enumeration).count));
4349
4350
0
        if ((yyvsp[-1].enumeration).type == EXPRESSION_TYPE_INTEGER)
4351
0
        {
4352
0
          fail_if_error(yr_parser_emit(
4353
0
              yyscanner, OP_ITER_START_INT_ENUM, NULL));
4354
0
        }
4355
0
        else
4356
0
        {
4357
0
          fail_if_error(yr_parser_emit(
4358
0
              yyscanner, OP_ITER_START_TEXT_STRING_SET, NULL));
4359
0
        }
4360
4361
0
        (yyval.enumeration).type = (yyvsp[-1].enumeration).type;
4362
0
      }
4363
0
#line 4364 "libyara/grammar.c"
4364
0
    break;
4365
4366
0
  case 120: /* set: range  */
4367
0
#line 2281 "libyara/grammar.y"
4368
0
      {
4369
0
        fail_if_error(yr_parser_emit(
4370
0
            yyscanner, OP_ITER_START_INT_RANGE, NULL));
4371
4372
0
        (yyval.enumeration).type = EXPRESSION_TYPE_INTEGER;
4373
0
      }
4374
0
#line 4375 "libyara/grammar.c"
4375
0
    break;
4376
4377
0
  case 121: /* range: '(' primary_expression ".." primary_expression ')'  */
4378
0
#line 2292 "libyara/grammar.y"
4379
0
      {
4380
0
        int result = ERROR_SUCCESS;
4381
4382
0
        if ((yyvsp[-3].expression).type != EXPRESSION_TYPE_INTEGER)
4383
0
        {
4384
0
          yr_compiler_set_error_extra_info(
4385
0
              compiler, "wrong type for range's lower bound");
4386
0
          result = ERROR_WRONG_TYPE;
4387
0
        }
4388
4389
0
        if ((yyvsp[-1].expression).type != EXPRESSION_TYPE_INTEGER)
4390
0
        {
4391
0
          yr_compiler_set_error_extra_info(
4392
0
              compiler, "wrong type for range's upper bound");
4393
0
          result = ERROR_WRONG_TYPE;
4394
0
        }
4395
4396
        // If we can statically determine lower and upper bounds, ensure
4397
        // lower < upper. Check for upper bound here because some things (like
4398
        // string count) are EXPRESSION_TYPE_INTEGER.
4399
0
        if ((yyvsp[-3].expression).value.integer != YR_UNDEFINED && (yyvsp[-1].expression).value.integer != YR_UNDEFINED)
4400
0
        {
4401
0
          if ((yyvsp[-3].expression).value.integer > (yyvsp[-1].expression).value.integer)
4402
0
          {
4403
0
            yr_compiler_set_error_extra_info(
4404
0
                compiler, "range lower bound must be less than upper bound");
4405
0
            result = ERROR_INVALID_VALUE;
4406
0
          }
4407
0
          else if ((yyvsp[-3].expression).value.integer < 0)
4408
0
          {
4409
0
            yr_compiler_set_error_extra_info(
4410
0
                compiler, "range lower bound can not be negative");
4411
0
            result = ERROR_INVALID_VALUE;
4412
0
          }
4413
0
        }
4414
4415
0
        fail_if_error(result);
4416
0
      }
4417
0
#line 4418 "libyara/grammar.c"
4418
0
    break;
4419
4420
0
  case 122: /* enumeration: primary_expression  */
4421
0
#line 2335 "libyara/grammar.y"
4422
0
      {
4423
0
        int result = ERROR_SUCCESS;
4424
4425
0
        if ((yyvsp[0].expression).type != EXPRESSION_TYPE_INTEGER && (yyvsp[0].expression).type != EXPRESSION_TYPE_STRING)
4426
0
        {
4427
0
          yr_compiler_set_error_extra_info(
4428
0
              compiler, "wrong type for enumeration item");
4429
0
          result = ERROR_WRONG_TYPE;
4430
0
        }
4431
4432
0
        fail_if_error(result);
4433
4434
0
        (yyval.enumeration).type = (yyvsp[0].expression).type;
4435
0
        (yyval.enumeration).count = 1;
4436
0
      }
4437
0
#line 4438 "libyara/grammar.c"
4438
0
    break;
4439
4440
0
  case 123: /* enumeration: enumeration ',' primary_expression  */
4441
0
#line 2351 "libyara/grammar.y"
4442
0
      {
4443
0
        int result = ERROR_SUCCESS;
4444
4445
0
        if ((yyvsp[0].expression).type != (yyvsp[-2].enumeration).type)
4446
0
        {
4447
0
          yr_compiler_set_error_extra_info(
4448
0
              compiler, "enumerations must be all the same type");
4449
0
          result = ERROR_WRONG_TYPE;
4450
0
        }
4451
4452
0
        fail_if_error(result);
4453
4454
0
        (yyval.enumeration).type = (yyvsp[-2].enumeration).type;
4455
0
        (yyval.enumeration).count = (yyvsp[-2].enumeration).count + 1;
4456
0
      }
4457
0
#line 4458 "libyara/grammar.c"
4458
0
    break;
4459
4460
0
  case 124: /* string_iterator: string_set  */
4461
0
#line 2371 "libyara/grammar.y"
4462
0
      {
4463
0
        fail_if_error(yr_parser_emit_push_const(yyscanner, (yyvsp[0].string_set).count));
4464
0
        fail_if_error(yr_parser_emit(yyscanner, OP_ITER_START_STRING_SET,
4465
0
            NULL));
4466
0
        fail_if_error(yr_string_set_destroy((yyvsp[0].string_set)));
4467
0
      }
4468
0
#line 4469 "libyara/grammar.c"
4469
0
    break;
4470
4471
0
  case 125: /* $@10: %empty  */
4472
0
#line 2381 "libyara/grammar.y"
4473
0
      {
4474
        // Push end-of-list marker
4475
0
        yr_parser_emit_push_const(yyscanner, YR_UNDEFINED);
4476
0
      }
4477
0
#line 4478 "libyara/grammar.c"
4478
0
    break;
4479
4480
0
  case 126: /* string_set: '(' $@10 string_enumeration ')'  */
4481
0
#line 2386 "libyara/grammar.y"
4482
0
      {
4483
0
        (yyval.string_set) = (yyvsp[-1].string_set);
4484
0
      }
4485
0
#line 4486 "libyara/grammar.c"
4486
0
    break;
4487
4488
0
  case 127: /* string_set: "<them>"  */
4489
0
#line 2390 "libyara/grammar.y"
4490
0
      {
4491
0
        fail_if_error(yr_parser_emit_push_const(yyscanner, YR_UNDEFINED));
4492
4493
0
        YR_STRING_SET strings;
4494
0
        fail_if_error(yr_parser_emit_pushes_for_strings(
4495
0
            yyscanner, "$*", &strings));
4496
4497
0
        (yyval.string_set) = strings;
4498
0
      }
4499
0
#line 4500 "libyara/grammar.c"
4500
0
    break;
4501
4502
0
  case 128: /* string_enumeration: string_enumeration_item  */
4503
0
#line 2403 "libyara/grammar.y"
4504
0
                              { (yyval.string_set) = (yyvsp[0].string_set); }
4505
0
#line 4506 "libyara/grammar.c"
4506
0
    break;
4507
4508
0
  case 129: /* string_enumeration: string_enumeration ',' string_enumeration_item  */
4509
0
#line 2405 "libyara/grammar.y"
4510
0
    {
4511
0
      YR_STRING_SET_ELEMENT* tail = (yyvsp[-2].string_set).head;
4512
0
      while (tail->next != NULL) {
4513
0
        tail = tail->next;
4514
0
      }
4515
      // Combine the linked lists by linking the tail of $1 to the head of $3
4516
0
      tail->next = (yyvsp[0].string_set).head;
4517
0
      (yyvsp[-2].string_set).count += (yyvsp[0].string_set).count;
4518
0
      (yyval.string_set) = (yyvsp[-2].string_set);
4519
0
    }
4520
0
#line 4521 "libyara/grammar.c"
4521
0
    break;
4522
4523
0
  case 130: /* string_enumeration_item: "string identifier"  */
4524
0
#line 2420 "libyara/grammar.y"
4525
0
      {
4526
0
        YR_STRING_SET strings;
4527
0
        int result = yr_parser_emit_pushes_for_strings(yyscanner, (yyvsp[0].c_string), &strings);
4528
0
        yr_free((yyvsp[0].c_string));
4529
4530
0
        fail_if_error(result);
4531
4532
0
        (yyval.string_set) = strings;
4533
0
      }
4534
0
#line 4535 "libyara/grammar.c"
4535
0
    break;
4536
4537
0
  case 131: /* string_enumeration_item: "string identifier with wildcard"  */
4538
0
#line 2430 "libyara/grammar.y"
4539
0
      {
4540
0
        YR_STRING_SET strings;
4541
0
        int result = yr_parser_emit_pushes_for_strings(yyscanner, (yyvsp[0].c_string), &strings);
4542
0
        yr_free((yyvsp[0].c_string));
4543
4544
0
        fail_if_error(result);
4545
4546
0
        (yyval.string_set) = strings;
4547
0
      }
4548
0
#line 4549 "libyara/grammar.c"
4549
0
    break;
4550
4551
0
  case 132: /* $@11: %empty  */
4552
0
#line 2444 "libyara/grammar.y"
4553
0
      {
4554
        // Push end-of-list marker
4555
0
        yr_parser_emit_push_const(yyscanner, YR_UNDEFINED);
4556
0
      }
4557
0
#line 4558 "libyara/grammar.c"
4558
0
    break;
4559
4560
0
  case 133: /* rule_set: '(' $@11 rule_enumeration ')'  */
4561
0
#line 2449 "libyara/grammar.y"
4562
0
      {
4563
0
        (yyval.integer) = (yyvsp[-1].integer);
4564
0
      }
4565
0
#line 4566 "libyara/grammar.c"
4566
0
    break;
4567
4568
0
  case 134: /* rule_enumeration: rule_enumeration_item  */
4569
0
#line 2456 "libyara/grammar.y"
4570
0
                            { (yyval.integer) = (yyvsp[0].integer); }
4571
0
#line 4572 "libyara/grammar.c"
4572
0
    break;
4573
4574
0
  case 135: /* rule_enumeration: rule_enumeration ',' rule_enumeration_item  */
4575
0
#line 2457 "libyara/grammar.y"
4576
0
                                                 { (yyval.integer) = (yyvsp[-2].integer) + (yyvsp[0].integer); }
4577
0
#line 4578 "libyara/grammar.c"
4578
0
    break;
4579
4580
0
  case 136: /* rule_enumeration_item: "identifier"  */
4581
0
#line 2463 "libyara/grammar.y"
4582
0
      {
4583
0
        int result = ERROR_SUCCESS;
4584
4585
0
        YR_NAMESPACE* ns = (YR_NAMESPACE*) yr_arena_get_ptr(
4586
0
            compiler->arena,
4587
0
            YR_NAMESPACES_TABLE,
4588
0
            compiler->current_namespace_idx * sizeof(struct YR_NAMESPACE));
4589
4590
0
        uint32_t rule_idx = yr_hash_table_lookup_uint32(
4591
0
            compiler->rules_table, (yyvsp[0].c_string), ns->name);
4592
4593
0
        if (rule_idx != UINT32_MAX)
4594
0
        {
4595
0
          result = yr_parser_emit_with_arg(
4596
0
              yyscanner,
4597
0
              OP_PUSH_RULE,
4598
0
              rule_idx,
4599
0
              NULL,
4600
0
              NULL);
4601
0
        }
4602
0
        else
4603
0
        {
4604
0
          yr_compiler_set_error_extra_info(compiler, (yyvsp[0].c_string));
4605
0
          result = ERROR_UNDEFINED_IDENTIFIER;
4606
0
        }
4607
4608
0
        yr_free((yyvsp[0].c_string));
4609
4610
0
        fail_if_error(result);
4611
4612
0
        (yyval.integer) = 1;
4613
0
      }
4614
0
#line 4615 "libyara/grammar.c"
4615
0
    break;
4616
4617
0
  case 137: /* rule_enumeration_item: "identifier" '*'  */
4618
0
#line 2496 "libyara/grammar.y"
4619
0
      {
4620
0
        int count = 0;
4621
0
        YR_NAMESPACE* ns = (YR_NAMESPACE*) yr_arena_get_ptr(
4622
0
            compiler->arena,
4623
0
            YR_NAMESPACES_TABLE,
4624
0
            compiler->current_namespace_idx * sizeof(struct YR_NAMESPACE));
4625
4626
0
        yr_hash_table_add_uint32(
4627
0
            compiler->wildcard_identifiers_table,
4628
0
            (yyvsp[-1].c_string),
4629
0
            ns->name,
4630
0
            1);
4631
4632
0
        int result = yr_parser_emit_pushes_for_rules(yyscanner, (yyvsp[-1].c_string), &count);
4633
0
        yr_free((yyvsp[-1].c_string));
4634
4635
0
        fail_if_error(result);
4636
4637
0
        (yyval.integer) = count;
4638
0
      }
4639
0
#line 4640 "libyara/grammar.c"
4640
0
    break;
4641
4642
0
  case 138: /* for_expression: primary_expression  */
4643
0
#line 2521 "libyara/grammar.y"
4644
0
      {
4645
0
        if ((yyvsp[0].expression).type == EXPRESSION_TYPE_INTEGER && !IS_UNDEFINED((yyvsp[0].expression).value.integer))
4646
0
        {
4647
0
          if ((yyvsp[0].expression).value.integer == 0)
4648
0
          {
4649
0
            yywarning(yyscanner,
4650
0
                "consider using \"none\" keyword, it is less ambiguous.");
4651
0
          }
4652
4653
0
          if ((yyvsp[0].expression).value.integer < 0)
4654
0
          {
4655
0
            yr_compiler_set_error_extra_info_fmt(compiler,
4656
0
                "%" PRId64, (yyvsp[0].expression).value.integer);
4657
4658
0
            fail_with_error(ERROR_INVALID_VALUE);
4659
0
          }
4660
0
        }
4661
4662
0
        if ((yyvsp[0].expression).type == EXPRESSION_TYPE_FLOAT)
4663
0
        {
4664
0
          yr_compiler_set_error_extra_info_fmt(compiler,
4665
0
              "%a", (yyvsp[0].expression).value.double_);
4666
4667
0
          fail_with_error(ERROR_INVALID_VALUE);
4668
0
        }
4669
4670
0
        if ((yyvsp[0].expression).type == EXPRESSION_TYPE_STRING)
4671
0
        {
4672
0
          SIZED_STRING* ss = yr_arena_ref_to_ptr(compiler->arena,
4673
0
              &(yyvsp[0].expression).value.sized_string_ref);
4674
          // If the expression is an external string variable we need to get
4675
          // it some other way.
4676
0
          if (ss != NULL)
4677
0
          {
4678
0
            yr_compiler_set_error_extra_info_fmt(compiler, "%s", ss->c_string);
4679
0
          }
4680
0
          else
4681
0
          {
4682
0
            yr_compiler_set_error_extra_info(compiler,
4683
0
                "string in for_expression is invalid");
4684
0
          }
4685
4686
0
          fail_with_error(ERROR_INVALID_VALUE);
4687
0
        }
4688
4689
0
        if ((yyvsp[0].expression).type == EXPRESSION_TYPE_REGEXP)
4690
0
        {
4691
0
          yr_compiler_set_error_extra_info(compiler,
4692
0
              "regexp in for_expression is invalid");
4693
4694
0
          fail_with_error(ERROR_INVALID_VALUE);
4695
0
        }
4696
4697
0
        (yyval.expression).value.integer = (yyvsp[0].expression).value.integer;
4698
0
      }
4699
0
#line 4700 "libyara/grammar.c"
4700
0
    break;
4701
4702
0
  case 139: /* for_expression: for_quantifier  */
4703
0
#line 2577 "libyara/grammar.y"
4704
0
      {
4705
0
        (yyval.expression).value.integer = (yyvsp[0].expression).value.integer;
4706
0
      }
4707
0
#line 4708 "libyara/grammar.c"
4708
0
    break;
4709
4710
0
  case 140: /* for_quantifier: "<all>"  */
4711
0
#line 2584 "libyara/grammar.y"
4712
0
      {
4713
0
        yr_parser_emit_push_const(yyscanner, YR_UNDEFINED);
4714
0
        (yyval.expression).type = EXPRESSION_TYPE_QUANTIFIER;
4715
0
        (yyval.expression).value.integer = FOR_EXPRESSION_ALL;
4716
0
     }
4717
0
#line 4718 "libyara/grammar.c"
4718
0
    break;
4719
4720
0
  case 141: /* for_quantifier: "<any>"  */
4721
0
#line 2590 "libyara/grammar.y"
4722
0
      {
4723
0
        yr_parser_emit_push_const(yyscanner, 1);
4724
0
        (yyval.expression).type = EXPRESSION_TYPE_QUANTIFIER;
4725
0
        (yyval.expression).value.integer = FOR_EXPRESSION_ANY;
4726
0
      }
4727
0
#line 4728 "libyara/grammar.c"
4728
0
    break;
4729
4730
0
  case 142: /* for_quantifier: "<none>"  */
4731
0
#line 2596 "libyara/grammar.y"
4732
0
      {
4733
0
        yr_parser_emit_push_const(yyscanner, 0);
4734
0
        (yyval.expression).type = EXPRESSION_TYPE_QUANTIFIER;
4735
0
        (yyval.expression).value.integer = FOR_EXPRESSION_NONE;
4736
0
      }
4737
0
#line 4738 "libyara/grammar.c"
4738
0
    break;
4739
4740
0
  case 143: /* primary_expression: '(' primary_expression ')'  */
4741
0
#line 2606 "libyara/grammar.y"
4742
0
      {
4743
0
        (yyval.expression) = (yyvsp[-1].expression);
4744
0
      }
4745
0
#line 4746 "libyara/grammar.c"
4746
0
    break;
4747
4748
0
  case 144: /* primary_expression: "<filesize>"  */
4749
0
#line 2610 "libyara/grammar.y"
4750
0
      {
4751
0
        fail_if_error(yr_parser_emit(
4752
0
            yyscanner, OP_FILESIZE, NULL));
4753
4754
0
        (yyval.expression).type = EXPRESSION_TYPE_INTEGER;
4755
0
        (yyval.expression).value.integer = YR_UNDEFINED;
4756
0
      }
4757
0
#line 4758 "libyara/grammar.c"
4758
0
    break;
4759
4760
0
  case 145: /* primary_expression: "<entrypoint>"  */
4761
0
#line 2618 "libyara/grammar.y"
4762
0
      {
4763
0
        yywarning(yyscanner,
4764
0
            "using deprecated \"entrypoint\" keyword. Use the \"entry_point\" "
4765
0
            "function from PE module instead.");
4766
4767
0
        fail_if_error(yr_parser_emit(
4768
0
            yyscanner, OP_ENTRYPOINT, NULL));
4769
4770
0
        (yyval.expression).type = EXPRESSION_TYPE_INTEGER;
4771
0
        (yyval.expression).value.integer = YR_UNDEFINED;
4772
0
      }
4773
0
#line 4774 "libyara/grammar.c"
4774
0
    break;
4775
4776
0
  case 146: /* primary_expression: "integer function" '(' primary_expression ')'  */
4777
0
#line 2630 "libyara/grammar.y"
4778
0
      {
4779
0
        check_type((yyvsp[-1].expression), EXPRESSION_TYPE_INTEGER, "intXXXX or uintXXXX");
4780
4781
        // _INTEGER_FUNCTION_ could be any of int8, int16, int32, uint8,
4782
        // uint32, etc. $1 contains an index that added to OP_READ_INT results
4783
        // in the proper OP_INTXX opcode.
4784
4785
0
        fail_if_error(yr_parser_emit(
4786
0
            yyscanner, (uint8_t) (OP_READ_INT + (yyvsp[-3].integer)), NULL));
4787
4788
0
        (yyval.expression).type = EXPRESSION_TYPE_INTEGER;
4789
0
        (yyval.expression).value.integer = YR_UNDEFINED;
4790
0
      }
4791
0
#line 4792 "libyara/grammar.c"
4792
0
    break;
4793
4794
0
  case 147: /* primary_expression: "integer number"  */
4795
0
#line 2644 "libyara/grammar.y"
4796
0
      {
4797
0
        fail_if_error(yr_parser_emit_push_const(yyscanner, (yyvsp[0].integer)));
4798
4799
0
        (yyval.expression).type = EXPRESSION_TYPE_INTEGER;
4800
0
        (yyval.expression).value.integer = (yyvsp[0].integer);
4801
0
      }
4802
0
#line 4803 "libyara/grammar.c"
4803
0
    break;
4804
4805
0
  case 148: /* primary_expression: "floating point number"  */
4806
0
#line 2651 "libyara/grammar.y"
4807
0
      {
4808
0
        fail_if_error(yr_parser_emit_with_arg_double(
4809
0
            yyscanner, OP_PUSH, (yyvsp[0].double_), NULL, NULL));
4810
4811
0
        (yyval.expression).type = EXPRESSION_TYPE_FLOAT;
4812
0
      }
4813
0
#line 4814 "libyara/grammar.c"
4814
0
    break;
4815
4816
0
  case 149: /* primary_expression: "text string"  */
4817
0
#line 2658 "libyara/grammar.y"
4818
0
      {
4819
0
        YR_ARENA_REF ref;
4820
4821
0
        int result = _yr_compiler_store_data(
4822
0
            compiler,
4823
0
            (yyvsp[0].sized_string),
4824
0
            (yyvsp[0].sized_string)->length + sizeof(SIZED_STRING),
4825
0
            &ref);
4826
4827
0
        yr_free((yyvsp[0].sized_string));
4828
4829
0
        if (result == ERROR_SUCCESS)
4830
0
          result = yr_parser_emit_with_arg_reloc(
4831
0
              yyscanner,
4832
0
              OP_PUSH,
4833
0
              yr_arena_ref_to_ptr(compiler->arena, &ref),
4834
0
              NULL,
4835
0
              NULL);
4836
4837
0
        fail_if_error(result);
4838
4839
0
        (yyval.expression).type = EXPRESSION_TYPE_STRING;
4840
0
        (yyval.expression).value.sized_string_ref = ref;
4841
0
      }
4842
0
#line 4843 "libyara/grammar.c"
4843
0
    break;
4844
4845
0
  case 150: /* primary_expression: "string count" "<in>" range  */
4846
0
#line 2683 "libyara/grammar.y"
4847
0
      {
4848
0
        int result = yr_parser_reduce_string_identifier(
4849
0
            yyscanner, (yyvsp[-2].c_string), OP_COUNT_IN, YR_UNDEFINED);
4850
4851
0
        yr_free((yyvsp[-2].c_string));
4852
4853
0
        fail_if_error(result);
4854
4855
0
        (yyval.expression).type = EXPRESSION_TYPE_INTEGER;
4856
0
        (yyval.expression).value.integer = YR_UNDEFINED;
4857
0
      }
4858
0
#line 4859 "libyara/grammar.c"
4859
0
    break;
4860
4861
0
  case 151: /* primary_expression: "string count"  */
4862
0
#line 2695 "libyara/grammar.y"
4863
0
      {
4864
0
        int result = yr_parser_reduce_string_identifier(
4865
0
            yyscanner, (yyvsp[0].c_string), OP_COUNT, YR_UNDEFINED);
4866
4867
0
        yr_free((yyvsp[0].c_string));
4868
4869
0
        fail_if_error(result);
4870
4871
0
        (yyval.expression).type = EXPRESSION_TYPE_INTEGER;
4872
0
        (yyval.expression).value.integer = YR_UNDEFINED;
4873
0
      }
4874
0
#line 4875 "libyara/grammar.c"
4875
0
    break;
4876
4877
0
  case 152: /* primary_expression: "string offset" '[' primary_expression ']'  */
4878
0
#line 2707 "libyara/grammar.y"
4879
0
      {
4880
0
        int result = yr_parser_reduce_string_identifier(
4881
0
            yyscanner, (yyvsp[-3].c_string), OP_OFFSET, YR_UNDEFINED);
4882
4883
0
        yr_free((yyvsp[-3].c_string));
4884
4885
0
        fail_if_error(result);
4886
4887
0
        (yyval.expression).type = EXPRESSION_TYPE_INTEGER;
4888
0
        (yyval.expression).value.integer = YR_UNDEFINED;
4889
0
      }
4890
0
#line 4891 "libyara/grammar.c"
4891
0
    break;
4892
4893
0
  case 153: /* primary_expression: "string offset"  */
4894
0
#line 2719 "libyara/grammar.y"
4895
0
      {
4896
0
        int result = yr_parser_emit_push_const(yyscanner, 1);
4897
4898
0
        if (result == ERROR_SUCCESS)
4899
0
          result = yr_parser_reduce_string_identifier(
4900
0
              yyscanner, (yyvsp[0].c_string), OP_OFFSET, YR_UNDEFINED);
4901
4902
0
        yr_free((yyvsp[0].c_string));
4903
4904
0
        fail_if_error(result);
4905
4906
0
        (yyval.expression).type = EXPRESSION_TYPE_INTEGER;
4907
0
        (yyval.expression).value.integer = YR_UNDEFINED;
4908
0
      }
4909
0
#line 4910 "libyara/grammar.c"
4910
0
    break;
4911
4912
0
  case 154: /* primary_expression: "string length" '[' primary_expression ']'  */
4913
0
#line 2734 "libyara/grammar.y"
4914
0
      {
4915
0
        int result = yr_parser_reduce_string_identifier(
4916
0
            yyscanner, (yyvsp[-3].c_string), OP_LENGTH, YR_UNDEFINED);
4917
4918
0
        yr_free((yyvsp[-3].c_string));
4919
4920
0
        fail_if_error(result);
4921
4922
0
        (yyval.expression).type = EXPRESSION_TYPE_INTEGER;
4923
0
        (yyval.expression).value.integer = YR_UNDEFINED;
4924
0
      }
4925
0
#line 4926 "libyara/grammar.c"
4926
0
    break;
4927
4928
0
  case 155: /* primary_expression: "string length"  */
4929
0
#line 2746 "libyara/grammar.y"
4930
0
      {
4931
0
        int result = yr_parser_emit_push_const(yyscanner, 1);
4932
4933
0
        if (result == ERROR_SUCCESS)
4934
0
          result = yr_parser_reduce_string_identifier(
4935
0
              yyscanner, (yyvsp[0].c_string), OP_LENGTH, YR_UNDEFINED);
4936
4937
0
        yr_free((yyvsp[0].c_string));
4938
4939
0
        fail_if_error(result);
4940
4941
0
        (yyval.expression).type = EXPRESSION_TYPE_INTEGER;
4942
0
        (yyval.expression).value.integer = YR_UNDEFINED;
4943
0
      }
4944
0
#line 4945 "libyara/grammar.c"
4945
0
    break;
4946
4947
0
  case 156: /* primary_expression: identifier  */
4948
0
#line 2761 "libyara/grammar.y"
4949
0
      {
4950
0
        int result = ERROR_SUCCESS;
4951
4952
0
        if ((yyvsp[0].expression).type == EXPRESSION_TYPE_OBJECT)
4953
0
        {
4954
0
          result = yr_parser_emit(
4955
0
              yyscanner, OP_OBJ_VALUE, NULL);
4956
4957
0
          switch((yyvsp[0].expression).value.object->type)
4958
0
          {
4959
0
            case OBJECT_TYPE_INTEGER:
4960
0
              (yyval.expression).type = EXPRESSION_TYPE_INTEGER;
4961
0
              (yyval.expression).value.integer = (yyvsp[0].expression).value.object->value.i;
4962
0
              break;
4963
0
            case OBJECT_TYPE_FLOAT:
4964
0
              (yyval.expression).type = EXPRESSION_TYPE_FLOAT;
4965
0
              break;
4966
0
            case OBJECT_TYPE_STRING:
4967
0
              (yyval.expression).type = EXPRESSION_TYPE_STRING;
4968
0
              (yyval.expression).value.sized_string_ref = YR_ARENA_NULL_REF;
4969
0
              break;
4970
0
            default:
4971
              // In a primary expression any identifier that corresponds to an
4972
              // object must be of type integer, float or string. If "foobar" is
4973
              // either a function, structure, dictionary or array you can not
4974
              // use it as:
4975
              //   condition: foobar
4976
0
              yr_compiler_set_error_extra_info_fmt(
4977
0
                  compiler,
4978
0
                  "wrong usage of identifier \"%s\"",
4979
0
                  expression_identifier((yyvsp[0].expression)));
4980
4981
0
              result = ERROR_WRONG_TYPE;
4982
0
          }
4983
0
        }
4984
0
        else
4985
0
        {
4986
0
          (yyval.expression) = (yyvsp[0].expression);
4987
0
        }
4988
4989
0
        fail_if_error(result);
4990
0
      }
4991
0
#line 4992 "libyara/grammar.c"
4992
0
    break;
4993
4994
0
  case 157: /* primary_expression: '-' primary_expression  */
4995
0
#line 2804 "libyara/grammar.y"
4996
0
      {
4997
0
        int result = ERROR_SUCCESS;
4998
4999
0
        check_type((yyvsp[0].expression), EXPRESSION_TYPE_INTEGER | EXPRESSION_TYPE_FLOAT, "-");
5000
5001
0
        if ((yyvsp[0].expression).type == EXPRESSION_TYPE_INTEGER)
5002
0
        {
5003
0
          (yyval.expression).type = EXPRESSION_TYPE_INTEGER;
5004
0
          (yyval.expression).value.integer = ((yyvsp[0].expression).value.integer == YR_UNDEFINED) ?
5005
0
              YR_UNDEFINED : -((yyvsp[0].expression).value.integer);
5006
0
          result = yr_parser_emit(yyscanner, OP_INT_MINUS, NULL);
5007
0
        }
5008
0
        else if ((yyvsp[0].expression).type == EXPRESSION_TYPE_FLOAT)
5009
0
        {
5010
0
          (yyval.expression).type = EXPRESSION_TYPE_FLOAT;
5011
0
          result = yr_parser_emit(yyscanner, OP_DBL_MINUS, NULL);
5012
0
        }
5013
5014
0
        fail_if_error(result);
5015
0
      }
5016
0
#line 5017 "libyara/grammar.c"
5017
0
    break;
5018
5019
0
  case 158: /* primary_expression: primary_expression '+' primary_expression  */
5020
0
#line 2825 "libyara/grammar.y"
5021
0
      {
5022
0
        int result = yr_parser_reduce_operation(
5023
0
            yyscanner, "+", (yyvsp[-2].expression), (yyvsp[0].expression));
5024
5025
0
        if ((yyvsp[-2].expression).type == EXPRESSION_TYPE_INTEGER &&
5026
0
            (yyvsp[0].expression).type == EXPRESSION_TYPE_INTEGER)
5027
0
        {
5028
0
          int64_t i1 = (yyvsp[-2].expression).value.integer;
5029
0
          int64_t i2 = (yyvsp[0].expression).value.integer;
5030
5031
0
          if (!IS_UNDEFINED(i1) && !IS_UNDEFINED(i2) &&
5032
0
              (
5033
0
                (i2 > 0 && i1 > INT64_MAX - i2) ||
5034
0
                (i2 < 0 && i1 < INT64_MIN - i2)
5035
0
              ))
5036
0
          {
5037
0
            yr_compiler_set_error_extra_info_fmt(
5038
0
                compiler, "%" PRId64 " + %" PRId64, i1, i2);
5039
5040
0
            result = ERROR_INTEGER_OVERFLOW;
5041
0
          }
5042
0
          else
5043
0
          {
5044
0
            (yyval.expression).value.integer = OPERATION(+, i1, i2);
5045
0
            (yyval.expression).type = EXPRESSION_TYPE_INTEGER;
5046
0
          }
5047
0
        }
5048
0
        else
5049
0
        {
5050
0
          (yyval.expression).type = EXPRESSION_TYPE_FLOAT;
5051
0
        }
5052
5053
0
        fail_if_error(result);
5054
0
      }
5055
0
#line 5056 "libyara/grammar.c"
5056
0
    break;
5057
5058
0
  case 159: /* primary_expression: primary_expression '-' primary_expression  */
5059
0
#line 2860 "libyara/grammar.y"
5060
0
      {
5061
0
        int result = yr_parser_reduce_operation(
5062
0
            yyscanner, "-", (yyvsp[-2].expression), (yyvsp[0].expression));
5063
5064
0
        if ((yyvsp[-2].expression).type == EXPRESSION_TYPE_INTEGER &&
5065
0
            (yyvsp[0].expression).type == EXPRESSION_TYPE_INTEGER)
5066
0
        {
5067
0
          int64_t i1 = (yyvsp[-2].expression).value.integer;
5068
0
          int64_t i2 = (yyvsp[0].expression).value.integer;
5069
5070
0
          if (!IS_UNDEFINED(i1) && !IS_UNDEFINED(i2) &&
5071
0
              (
5072
0
                (i2 < 0 && i1 > INT64_MAX + i2) ||
5073
0
                (i2 > 0 && i1 < INT64_MIN + i2)
5074
0
              ))
5075
0
          {
5076
0
            yr_compiler_set_error_extra_info_fmt(
5077
0
                compiler, "%" PRId64 " - %" PRId64, i1, i2);
5078
5079
0
            result = ERROR_INTEGER_OVERFLOW;
5080
0
          }
5081
0
          else
5082
0
          {
5083
0
            (yyval.expression).value.integer = OPERATION(-, i1, i2);
5084
0
            (yyval.expression).type = EXPRESSION_TYPE_INTEGER;
5085
0
          }
5086
0
        }
5087
0
        else
5088
0
        {
5089
0
          (yyval.expression).type = EXPRESSION_TYPE_FLOAT;
5090
0
        }
5091
5092
0
        fail_if_error(result);
5093
0
      }
5094
0
#line 5095 "libyara/grammar.c"
5095
0
    break;
5096
5097
0
  case 160: /* primary_expression: primary_expression '*' primary_expression  */
5098
0
#line 2895 "libyara/grammar.y"
5099
0
      {
5100
0
        int result = yr_parser_reduce_operation(
5101
0
            yyscanner, "*", (yyvsp[-2].expression), (yyvsp[0].expression));
5102
5103
0
        if ((yyvsp[-2].expression).type == EXPRESSION_TYPE_INTEGER &&
5104
0
            (yyvsp[0].expression).type == EXPRESSION_TYPE_INTEGER)
5105
0
        {
5106
0
          int64_t i1 = (yyvsp[-2].expression).value.integer;
5107
0
          int64_t i2 = (yyvsp[0].expression).value.integer;
5108
5109
0
          if (!IS_UNDEFINED(i1) && !IS_UNDEFINED(i2) &&
5110
0
              (
5111
0
                i2 != 0 && llabs(i1) > INT64_MAX / llabs(i2)
5112
0
              ))
5113
0
          {
5114
0
            yr_compiler_set_error_extra_info_fmt(
5115
0
                compiler, "%" PRId64 " * %" PRId64, i1, i2);
5116
5117
0
            result = ERROR_INTEGER_OVERFLOW;
5118
0
          }
5119
0
          else
5120
0
          {
5121
0
            (yyval.expression).value.integer = OPERATION(*, i1, i2);
5122
0
            (yyval.expression).type = EXPRESSION_TYPE_INTEGER;
5123
0
          }
5124
0
        }
5125
0
        else
5126
0
        {
5127
0
          (yyval.expression).type = EXPRESSION_TYPE_FLOAT;
5128
0
        }
5129
5130
0
        fail_if_error(result);
5131
0
      }
5132
0
#line 5133 "libyara/grammar.c"
5133
0
    break;
5134
5135
0
  case 161: /* primary_expression: primary_expression '\\' primary_expression  */
5136
0
#line 2929 "libyara/grammar.y"
5137
0
      {
5138
0
        int result = yr_parser_reduce_operation(
5139
0
            yyscanner, "\\", (yyvsp[-2].expression), (yyvsp[0].expression));
5140
5141
0
        if ((yyvsp[-2].expression).type == EXPRESSION_TYPE_INTEGER &&
5142
0
            (yyvsp[0].expression).type == EXPRESSION_TYPE_INTEGER)
5143
0
        {
5144
0
          if ((yyvsp[0].expression).value.integer != 0)
5145
0
          {
5146
0
            (yyval.expression).value.integer = OPERATION(/, (yyvsp[-2].expression).value.integer, (yyvsp[0].expression).value.integer);
5147
0
            (yyval.expression).type = EXPRESSION_TYPE_INTEGER;
5148
0
          }
5149
0
          else
5150
0
          {
5151
0
            result = ERROR_DIVISION_BY_ZERO;
5152
0
          }
5153
0
        }
5154
0
        else
5155
0
        {
5156
0
          (yyval.expression).type = EXPRESSION_TYPE_FLOAT;
5157
0
        }
5158
5159
0
        fail_if_error(result);
5160
0
      }
5161
0
#line 5162 "libyara/grammar.c"
5162
0
    break;
5163
5164
0
  case 162: /* primary_expression: primary_expression '%' primary_expression  */
5165
0
#line 2954 "libyara/grammar.y"
5166
0
      {
5167
0
        check_type((yyvsp[-2].expression), EXPRESSION_TYPE_INTEGER, "%");
5168
0
        check_type((yyvsp[0].expression), EXPRESSION_TYPE_INTEGER, "%");
5169
5170
0
        fail_if_error(yr_parser_emit(yyscanner, OP_MOD, NULL));
5171
5172
0
        if ((yyvsp[0].expression).value.integer != 0)
5173
0
        {
5174
0
          (yyval.expression).value.integer = OPERATION(%, (yyvsp[-2].expression).value.integer, (yyvsp[0].expression).value.integer);
5175
0
          (yyval.expression).type = EXPRESSION_TYPE_INTEGER;
5176
0
        }
5177
0
        else
5178
0
        {
5179
0
          fail_if_error(ERROR_DIVISION_BY_ZERO);
5180
0
        }
5181
0
      }
5182
0
#line 5183 "libyara/grammar.c"
5183
0
    break;
5184
5185
0
  case 163: /* primary_expression: primary_expression '^' primary_expression  */
5186
0
#line 2971 "libyara/grammar.y"
5187
0
      {
5188
0
        check_type((yyvsp[-2].expression), EXPRESSION_TYPE_INTEGER, "^");
5189
0
        check_type((yyvsp[0].expression), EXPRESSION_TYPE_INTEGER, "^");
5190
5191
0
        fail_if_error(yr_parser_emit(yyscanner, OP_BITWISE_XOR, NULL));
5192
5193
0
        (yyval.expression).type = EXPRESSION_TYPE_INTEGER;
5194
0
        (yyval.expression).value.integer = OPERATION(^, (yyvsp[-2].expression).value.integer, (yyvsp[0].expression).value.integer);
5195
0
      }
5196
0
#line 5197 "libyara/grammar.c"
5197
0
    break;
5198
5199
0
  case 164: /* primary_expression: primary_expression '&' primary_expression  */
5200
0
#line 2981 "libyara/grammar.y"
5201
0
      {
5202
0
        check_type((yyvsp[-2].expression), EXPRESSION_TYPE_INTEGER, "^");
5203
0
        check_type((yyvsp[0].expression), EXPRESSION_TYPE_INTEGER, "^");
5204
5205
0
        fail_if_error(yr_parser_emit(yyscanner, OP_BITWISE_AND, NULL));
5206
5207
0
        (yyval.expression).type = EXPRESSION_TYPE_INTEGER;
5208
0
        (yyval.expression).value.integer = OPERATION(&, (yyvsp[-2].expression).value.integer, (yyvsp[0].expression).value.integer);
5209
0
      }
5210
0
#line 5211 "libyara/grammar.c"
5211
0
    break;
5212
5213
0
  case 165: /* primary_expression: primary_expression '|' primary_expression  */
5214
0
#line 2991 "libyara/grammar.y"
5215
0
      {
5216
0
        check_type((yyvsp[-2].expression), EXPRESSION_TYPE_INTEGER, "|");
5217
0
        check_type((yyvsp[0].expression), EXPRESSION_TYPE_INTEGER, "|");
5218
5219
0
        fail_if_error(yr_parser_emit(yyscanner, OP_BITWISE_OR, NULL));
5220
5221
0
        (yyval.expression).type = EXPRESSION_TYPE_INTEGER;
5222
0
        (yyval.expression).value.integer = OPERATION(|, (yyvsp[-2].expression).value.integer, (yyvsp[0].expression).value.integer);
5223
0
      }
5224
0
#line 5225 "libyara/grammar.c"
5225
0
    break;
5226
5227
0
  case 166: /* primary_expression: '~' primary_expression  */
5228
0
#line 3001 "libyara/grammar.y"
5229
0
      {
5230
0
        check_type((yyvsp[0].expression), EXPRESSION_TYPE_INTEGER, "~");
5231
5232
0
        fail_if_error(yr_parser_emit(yyscanner, OP_BITWISE_NOT, NULL));
5233
5234
0
        (yyval.expression).type = EXPRESSION_TYPE_INTEGER;
5235
0
        (yyval.expression).value.integer = ((yyvsp[0].expression).value.integer == YR_UNDEFINED) ?
5236
0
            YR_UNDEFINED : ~((yyvsp[0].expression).value.integer);
5237
0
      }
5238
0
#line 5239 "libyara/grammar.c"
5239
0
    break;
5240
5241
0
  case 167: /* primary_expression: primary_expression "<<" primary_expression  */
5242
0
#line 3011 "libyara/grammar.y"
5243
0
      {
5244
0
        int result;
5245
5246
0
        check_type((yyvsp[-2].expression), EXPRESSION_TYPE_INTEGER, "<<");
5247
0
        check_type((yyvsp[0].expression), EXPRESSION_TYPE_INTEGER, "<<");
5248
5249
0
        result = yr_parser_emit(yyscanner, OP_SHL, NULL);
5250
5251
0
        if (!IS_UNDEFINED((yyvsp[0].expression).value.integer) && (yyvsp[0].expression).value.integer < 0)
5252
0
          result = ERROR_INVALID_OPERAND;
5253
0
        else if (!IS_UNDEFINED((yyvsp[0].expression).value.integer) && (yyvsp[0].expression).value.integer >= 64)
5254
0
          (yyval.expression).value.integer = 0;
5255
0
        else
5256
0
          (yyval.expression).value.integer = OPERATION(<<, (yyvsp[-2].expression).value.integer, (yyvsp[0].expression).value.integer);
5257
5258
0
        (yyval.expression).type = EXPRESSION_TYPE_INTEGER;
5259
5260
0
        fail_if_error(result);
5261
0
      }
5262
0
#line 5263 "libyara/grammar.c"
5263
0
    break;
5264
5265
0
  case 168: /* primary_expression: primary_expression ">>" primary_expression  */
5266
0
#line 3031 "libyara/grammar.y"
5267
0
      {
5268
0
        int result;
5269
5270
0
        check_type((yyvsp[-2].expression), EXPRESSION_TYPE_INTEGER, ">>");
5271
0
        check_type((yyvsp[0].expression), EXPRESSION_TYPE_INTEGER, ">>");
5272
5273
0
        result = yr_parser_emit(yyscanner, OP_SHR, NULL);
5274
5275
0
        if (!IS_UNDEFINED((yyvsp[0].expression).value.integer) && (yyvsp[0].expression).value.integer < 0)
5276
0
          result = ERROR_INVALID_OPERAND;
5277
0
        else if (!IS_UNDEFINED((yyvsp[0].expression).value.integer) && (yyvsp[0].expression).value.integer >= 64)
5278
0
          (yyval.expression).value.integer = 0;
5279
0
        else
5280
0
          (yyval.expression).value.integer = OPERATION(<<, (yyvsp[-2].expression).value.integer, (yyvsp[0].expression).value.integer);
5281
5282
0
        (yyval.expression).type = EXPRESSION_TYPE_INTEGER;
5283
5284
0
        fail_if_error(result);
5285
0
      }
5286
0
#line 5287 "libyara/grammar.c"
5287
0
    break;
5288
5289
0
  case 169: /* primary_expression: regexp  */
5290
0
#line 3051 "libyara/grammar.y"
5291
0
      {
5292
0
        (yyval.expression) = (yyvsp[0].expression);
5293
0
      }
5294
0
#line 5295 "libyara/grammar.c"
5295
0
    break;
5296
5297
5298
0
#line 5299 "libyara/grammar.c"
5299
5300
4
      default: break;
5301
6
    }
5302
  /* User semantic actions sometimes alter yychar, and that requires
5303
     that yytoken be updated with the new translation.  We take the
5304
     approach of translating immediately before every use of yytoken.
5305
     One alternative is translating here after every semantic action,
5306
     but that translation would be missed if the semantic action invokes
5307
     YYABORT, YYACCEPT, or YYERROR immediately after altering yychar or
5308
     if it invokes YYBACKUP.  In the case of YYABORT or YYACCEPT, an
5309
     incorrect destructor might then be invoked immediately.  In the
5310
     case of YYERROR or YYBACKUP, subsequent parser actions might lead
5311
     to an incorrect destructor call or verbose syntax error message
5312
     before the lookahead is translated.  */
5313
6
  YY_SYMBOL_PRINT ("-> $$ =", YY_CAST (yysymbol_kind_t, yyr1[yyn]), &yyval, &yyloc);
5314
5315
6
  YYPOPSTACK (yylen);
5316
6
  yylen = 0;
5317
5318
6
  *++yyvsp = yyval;
5319
5320
  /* Now 'shift' the result of the reduction.  Determine what state
5321
     that goes to, based on the state we popped back to and the rule
5322
     number reduced by.  */
5323
6
  {
5324
6
    const int yylhs = yyr1[yyn] - YYNTOKENS;
5325
6
    const int yyi = yypgoto[yylhs] + *yyssp;
5326
6
    yystate = (0 <= yyi && yyi <= YYLAST && yycheck[yyi] == *yyssp
5327
6
               ? yytable[yyi]
5328
6
               : yydefgoto[yylhs]);
5329
6
  }
5330
5331
6
  goto yynewstate;
5332
5333
5334
/*--------------------------------------.
5335
| yyerrlab -- here on detecting error.  |
5336
`--------------------------------------*/
5337
0
yyerrlab:
5338
  /* Make sure we have latest lookahead translation.  See comments at
5339
     user semantic actions for why this is necessary.  */
5340
0
  yytoken = yychar == YYEMPTY ? YYSYMBOL_YYEMPTY : YYTRANSLATE (yychar);
5341
  /* If not already recovering from an error, report this error.  */
5342
0
  if (!yyerrstatus)
5343
0
    {
5344
0
      ++yynerrs;
5345
0
      {
5346
0
        yypcontext_t yyctx
5347
0
          = {yyssp, yytoken};
5348
0
        char const *yymsgp = YY_("syntax error");
5349
0
        int yysyntax_error_status;
5350
0
        yysyntax_error_status = yysyntax_error (&yymsg_alloc, &yymsg, &yyctx);
5351
0
        if (yysyntax_error_status == 0)
5352
0
          yymsgp = yymsg;
5353
0
        else if (yysyntax_error_status == -1)
5354
0
          {
5355
0
            if (yymsg != yymsgbuf)
5356
0
              YYSTACK_FREE (yymsg);
5357
0
            yymsg = YY_CAST (char *,
5358
0
                             YYSTACK_ALLOC (YY_CAST (YYSIZE_T, yymsg_alloc)));
5359
0
            if (yymsg)
5360
0
              {
5361
0
                yysyntax_error_status
5362
0
                  = yysyntax_error (&yymsg_alloc, &yymsg, &yyctx);
5363
0
                yymsgp = yymsg;
5364
0
              }
5365
0
            else
5366
0
              {
5367
0
                yymsg = yymsgbuf;
5368
0
                yymsg_alloc = sizeof yymsgbuf;
5369
0
                yysyntax_error_status = YYENOMEM;
5370
0
              }
5371
0
          }
5372
0
        yyerror (yyscanner, compiler, yymsgp);
5373
0
        if (yysyntax_error_status == YYENOMEM)
5374
0
          YYNOMEM;
5375
0
      }
5376
0
    }
5377
5378
0
  if (yyerrstatus == 3)
5379
0
    {
5380
      /* If just tried and failed to reuse lookahead token after an
5381
         error, discard it.  */
5382
5383
0
      if (yychar <= _END_OF_FILE_)
5384
0
        {
5385
          /* Return failure if at end of input.  */
5386
0
          if (yychar == _END_OF_FILE_)
5387
0
            YYABORT;
5388
0
        }
5389
0
      else
5390
0
        {
5391
0
          yydestruct ("Error: discarding",
5392
0
                      yytoken, &yylval, yyscanner, compiler);
5393
0
          yychar = YYEMPTY;
5394
0
        }
5395
0
    }
5396
5397
  /* Else will try to reuse lookahead token after shifting the error
5398
     token.  */
5399
0
  goto yyerrlab1;
5400
5401
5402
/*---------------------------------------------------.
5403
| yyerrorlab -- error raised explicitly by YYERROR.  |
5404
`---------------------------------------------------*/
5405
0
yyerrorlab:
5406
  /* Pacify compilers when the user code never invokes YYERROR and the
5407
     label yyerrorlab therefore never appears in user code.  */
5408
0
  if (0)
5409
0
    YYERROR;
5410
0
  ++yynerrs;
5411
5412
  /* Do not reclaim the symbols of the rule whose action triggered
5413
     this YYERROR.  */
5414
0
  YYPOPSTACK (yylen);
5415
0
  yylen = 0;
5416
0
  YY_STACK_PRINT (yyss, yyssp);
5417
0
  yystate = *yyssp;
5418
0
  goto yyerrlab1;
5419
5420
5421
/*-------------------------------------------------------------.
5422
| yyerrlab1 -- common code for both syntax error and YYERROR.  |
5423
`-------------------------------------------------------------*/
5424
0
yyerrlab1:
5425
0
  yyerrstatus = 3;      /* Each real token shifted decrements this.  */
5426
5427
  /* Pop stack until we find a state that shifts the error token.  */
5428
0
  for (;;)
5429
0
    {
5430
0
      yyn = yypact[yystate];
5431
0
      if (!yypact_value_is_default (yyn))
5432
0
        {
5433
0
          yyn += YYSYMBOL_YYerror;
5434
0
          if (0 <= yyn && yyn <= YYLAST && yycheck[yyn] == YYSYMBOL_YYerror)
5435
0
            {
5436
0
              yyn = yytable[yyn];
5437
0
              if (0 < yyn)
5438
0
                break;
5439
0
            }
5440
0
        }
5441
5442
      /* Pop the current state because it cannot handle the error token.  */
5443
0
      if (yyssp == yyss)
5444
0
        YYABORT;
5445
5446
5447
0
      yydestruct ("Error: popping",
5448
0
                  YY_ACCESSING_SYMBOL (yystate), yyvsp, yyscanner, compiler);
5449
0
      YYPOPSTACK (1);
5450
0
      yystate = *yyssp;
5451
0
      YY_STACK_PRINT (yyss, yyssp);
5452
0
    }
5453
5454
0
  YY_IGNORE_MAYBE_UNINITIALIZED_BEGIN
5455
0
  *++yyvsp = yylval;
5456
0
  YY_IGNORE_MAYBE_UNINITIALIZED_END
5457
5458
5459
  /* Shift the error token.  */
5460
0
  YY_SYMBOL_PRINT ("Shifting", YY_ACCESSING_SYMBOL (yyn), yyvsp, yylsp);
5461
5462
0
  yystate = yyn;
5463
0
  goto yynewstate;
5464
5465
5466
/*-------------------------------------.
5467
| yyacceptlab -- YYACCEPT comes here.  |
5468
`-------------------------------------*/
5469
2
yyacceptlab:
5470
2
  yyresult = 0;
5471
2
  goto yyreturnlab;
5472
5473
5474
/*-----------------------------------.
5475
| yyabortlab -- YYABORT comes here.  |
5476
`-----------------------------------*/
5477
0
yyabortlab:
5478
0
  yyresult = 1;
5479
0
  goto yyreturnlab;
5480
5481
5482
/*-----------------------------------------------------------.
5483
| yyexhaustedlab -- YYNOMEM (memory exhaustion) comes here.  |
5484
`-----------------------------------------------------------*/
5485
0
yyexhaustedlab:
5486
0
  yyerror (yyscanner, compiler, YY_("memory exhausted"));
5487
0
  yyresult = 2;
5488
0
  goto yyreturnlab;
5489
5490
5491
/*----------------------------------------------------------.
5492
| yyreturnlab -- parsing is finished, clean up and return.  |
5493
`----------------------------------------------------------*/
5494
2
yyreturnlab:
5495
2
  if (yychar != YYEMPTY)
5496
0
    {
5497
      /* Make sure we have latest lookahead translation.  See comments at
5498
         user semantic actions for why this is necessary.  */
5499
0
      yytoken = YYTRANSLATE (yychar);
5500
0
      yydestruct ("Cleanup: discarding lookahead",
5501
0
                  yytoken, &yylval, yyscanner, compiler);
5502
0
    }
5503
  /* Do not reclaim the symbols of the rule whose action triggered
5504
     this YYABORT or YYACCEPT.  */
5505
2
  YYPOPSTACK (yylen);
5506
2
  YY_STACK_PRINT (yyss, yyssp);
5507
6
  while (yyssp != yyss)
5508
4
    {
5509
4
      yydestruct ("Cleanup: popping",
5510
4
                  YY_ACCESSING_SYMBOL (+*yyssp), yyvsp, yyscanner, compiler);
5511
4
      YYPOPSTACK (1);
5512
4
    }
5513
2
#ifndef yyoverflow
5514
2
  if (yyss != yyssa)
5515
0
    YYSTACK_FREE (yyss);
5516
2
#endif
5517
2
  if (yymsg != yymsgbuf)
5518
0
    YYSTACK_FREE (yymsg);
5519
2
  return yyresult;
5520
0
}
5521
5522
#line 3056 "libyara/grammar.y"
5523