Coverage Report

Created: 2025-07-11 06:08

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