Coverage Report

Created: 2025-07-18 06:53

/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
102
#define YYFREE yr_free
107
108
16.8k
#define FOR_EXPRESSION_ALL  1
109
3.79k
#define FOR_EXPRESSION_ANY  2
110
0
#define FOR_EXPRESSION_NONE 3
111
112
737
#define FOR_ITERATION_ITERATOR   1
113
306
#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
8.44k
    { \
121
8.44k
      compiler->last_error = e; \
122
8.44k
      yyerror(yyscanner, compiler, NULL); \
123
8.44k
      switch (e) \
124
8.44k
      { \
125
0
      case ERROR_INSUFFICIENT_MEMORY: \
126
0
        YYABORT; \
127
8.44k
      default: \
128
8.44k
        YYERROR; \
129
8.44k
      } \
130
8.44k
    }
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
287k
    if (e != ERROR_SUCCESS && e != ERROR_UNKNOWN_ESCAPE_SEQUENCE) \
136
287k
    { \
137
8.26k
      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
62.4k
    if (((expression.type) & (expected_type)) == 0) \
146
62.4k
    { \
147
599
      switch(expression.type) \
148
599
      { \
149
100
        case EXPRESSION_TYPE_INTEGER: \
150
100
          yr_compiler_set_error_extra_info( \
151
100
              compiler, "wrong type \"integer\" for " op " operator"); \
152
100
          break; \
153
104
        case EXPRESSION_TYPE_FLOAT: \
154
104
          yr_compiler_set_error_extra_info( \
155
104
              compiler, "wrong type \"float\" for " op " operator"); \
156
104
          break; \
157
114
        case EXPRESSION_TYPE_STRING: \
158
114
          yr_compiler_set_error_extra_info( \
159
114
              compiler, "wrong type \"string\" for " op " operator"); \
160
114
          break; \
161
99
        case EXPRESSION_TYPE_BOOLEAN: \
162
99
          yr_compiler_set_error_extra_info( \
163
99
              compiler, "wrong type \"boolean\" for " op " operator"); \
164
99
          break; \
165
599
      } \
166
599
      cleanup; \
167
599
      compiler->last_error = ERROR_WRONG_TYPE; \
168
599
      yyerror(yyscanner, compiler, NULL); \
169
599
      YYERROR; \
170
599
    }
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
61.6k
    check_type_with_cleanup(expression, expected_type, op, )
176
177
178
#define loop_vars_cleanup(loop_index) \
179
2.00k
    {  \
180
2.00k
      YR_LOOP_CONTEXT* loop_ctx = &compiler->loop[loop_index]; \
181
4.25k
      for (int i = 0; i < loop_ctx->vars_count; i++) \
182
2.24k
      { \
183
2.24k
        yr_free((void*) loop_ctx->vars[i].identifier.ptr); \
184
2.24k
        loop_ctx->vars[i].identifier.ptr = NULL; \
185
2.24k
        loop_ctx->vars[i].identifier.ref = YR_ARENA_NULL_REF; \
186
2.24k
      } \
187
2.00k
      loop_ctx->vars_count = 0; \
188
2.00k
    } \
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.27k
    "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.38M
#   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
2.02M
#define YYEMPTY -2
313
1.33M
#define _END_OF_FILE_ 0
314
1.12M
#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.9k
#  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
612
#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.22k
#  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.59k
# 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.42M
#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
102
#  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
204
# 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
204
    do                                                                  \
847
204
      {                                                                 \
848
204
        YYPTRDIFF_T yynewbytes;                                         \
849
204
        YYCOPY (&yyptr->Stack_alloc, Stack, yysize);                    \
850
204
        Stack = &yyptr->Stack_alloc;                                    \
851
204
        yynewbytes = yystacksize * YYSIZEOF (*Stack) + YYSTACK_GAP_MAXIMUM; \
852
204
        yyptr += yynewbytes / YYSIZEOF (*yyptr);                        \
853
204
      }                                                                 \
854
204
    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
204
      __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.42M
#define YYFINAL  2
880
/* YYLAST -- Last index in YYTABLE.  */
881
3.66M
#define YYLAST   480
882
883
/* YYNTOKENS -- Number of terminals.  */
884
737k
#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.33M
#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.54M
  (0 <= (YYX) && (YYX) <= YYMAXUTOK                     \
900
1.54M
   ? YY_CAST (yysymbol_kind_t, yytranslate[YYX])        \
901
1.54M
   : 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
584k
#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.21M
#define YYPACT_NINF (-170)
1018
1019
#define yypact_value_is_default(Yyn) \
1020
2.21M
  ((Yyn) == YYPACT_NINF)
1021
1022
#define YYTABLE_NINF (-139)
1023
1024
#define yytable_value_is_error(Yyn) \
1025
35.2k
  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
135
#define YYACCEPT        goto yyacceptlab
1312
1.66k
#define YYABORT         goto yyabortlab
1313
10.9k
#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.11M
# 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.79k
# 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
208
# 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.22k
{
1504
  /* Actual size of YYARG. */
1505
6.22k
  int yycount = 0;
1506
6.22k
  int yyn = yypact[+*yyctx->yyssp];
1507
6.22k
  if (!yypact_value_is_default (yyn))
1508
6.22k
    {
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.22k
      int yyxbegin = yyn < 0 ? -yyn : 0;
1513
      /* Stay within bounds of both yycheck and yytname.  */
1514
6.22k
      int yychecklim = YYLAST - yyn + 1;
1515
6.22k
      int yyxend = yychecklim < YYNTOKENS ? yychecklim : YYNTOKENS;
1516
6.22k
      int yyx;
1517
443k
      for (yyx = yyxbegin; yyx < yyxend; ++yyx)
1518
438k
        if (yycheck[yyx + yyn] == yyx && yyx != YYSYMBOL_YYerror
1519
438k
            && !yytable_value_is_error (yytable[yyx + yyn]))
1520
11.8k
          {
1521
11.8k
            if (!yyarg)
1522
0
              ++yycount;
1523
11.8k
            else if (yycount == yyargn)
1524
1.09k
              return 0;
1525
10.7k
            else
1526
10.7k
              yyarg[yycount++] = YY_CAST (yysymbol_kind_t, yyx);
1527
11.8k
          }
1528
6.22k
    }
1529
5.13k
  if (yyarg && yycount == 0 && 0 < yyargn)
1530
0
    yyarg[0] = YYSYMBOL_YYEMPTY;
1531
5.13k
  return yycount;
1532
6.22k
}
1533
1534
1535
1536
1537
#ifndef yystrlen
1538
# if defined __GLIBC__ && defined _STRING_H
1539
8.69k
#  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.46k
#  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.2k
    {
1586
20.2k
      YYPTRDIFF_T yyn = 0;
1587
20.2k
      char const *yyp = yystr;
1588
20.2k
      for (;;)
1589
214k
        switch (*++yyp)
1590
214k
          {
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
194k
          default:
1603
194k
            if (yyres)
1604
97.2k
              yyres[yyn] = *yyp;
1605
194k
            yyn++;
1606
194k
            break;
1607
1608
20.2k
          case '"':
1609
20.2k
            if (yyres)
1610
10.1k
              yyres[yyn] = '\0';
1611
20.2k
            return yyn;
1612
214k
          }
1613
0
    do_not_strip_quotes: ;
1614
0
    }
1615
1616
4.93k
  if (yyres)
1617
2.46k
    return yystpcpy (yyres, yystr) - yyres;
1618
2.46k
  else
1619
2.46k
    return yystrlen (yystr);
1620
4.93k
}
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.22k
{
1628
  /* Actual size of YYARG. */
1629
6.22k
  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.22k
  if (yyctx->yytoken != YYSYMBOL_YYEMPTY)
1654
6.22k
    {
1655
6.22k
      int yyn;
1656
6.22k
      if (yyarg)
1657
6.22k
        yyarg[yycount] = yyctx->yytoken;
1658
6.22k
      ++yycount;
1659
6.22k
      yyn = yypcontext_expected_tokens (yyctx,
1660
6.22k
                                        yyarg ? yyarg + 1 : yyarg, yyargn - 1);
1661
6.22k
      if (yyn == YYENOMEM)
1662
0
        return YYENOMEM;
1663
6.22k
      else
1664
6.22k
        yycount += yyn;
1665
6.22k
    }
1666
6.22k
  return yycount;
1667
6.22k
}
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.22k
{
1681
6.22k
  enum { YYARGS_MAX = 5 };
1682
  /* Internationalized format string. */
1683
6.22k
  const char *yyformat = YY_NULLPTR;
1684
  /* Arguments of yyformat: reported tokens (one for the "unexpected",
1685
     one per "expected"). */
1686
6.22k
  yysymbol_kind_t yyarg[YYARGS_MAX];
1687
  /* Cumulated lengths of YYARG.  */
1688
6.22k
  YYPTRDIFF_T yysize = 0;
1689
1690
  /* Actual size of YYARG. */
1691
6.22k
  int yycount = yy_syntax_error_arguments (yyctx, yyarg, YYARGS_MAX);
1692
6.22k
  if (yycount == YYENOMEM)
1693
0
    return YYENOMEM;
1694
1695
6.22k
  switch (yycount)
1696
6.22k
    {
1697
0
#define YYCASE_(N, S)                       \
1698
6.22k
      case N:                               \
1699
6.22k
        yyformat = S;                       \
1700
6.22k
        break
1701
0
    default: /* Avoid compiler warnings. */
1702
0
      YYCASE_(0, YY_("syntax error"));
1703
1.09k
      YYCASE_(1, YY_("syntax error, unexpected %s"));
1704
4.40k
      YYCASE_(2, YY_("syntax error, unexpected %s, expecting %s"));
1705
245
      YYCASE_(3, YY_("syntax error, unexpected %s, expecting %s or %s"));
1706
486
      YYCASE_(4, YY_("syntax error, unexpected %s, expecting %s or %s or %s"));
1707
6.22k
      YYCASE_(5, YY_("syntax error, unexpected %s, expecting %s or %s or %s or %s"));
1708
6.22k
#undef YYCASE_
1709
6.22k
    }
1710
1711
  /* Compute error message size.  Don't count the "%s"s, but reserve
1712
     room for the terminator.  */
1713
6.22k
  yysize = yystrlen (yyformat) - 2 * yycount + 1;
1714
6.22k
  {
1715
6.22k
    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.22k
  }
1726
1727
6.22k
  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.22k
  {
1740
6.22k
    char *yyp = *yymsg;
1741
6.22k
    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
222k
      else
1749
222k
        {
1750
222k
          ++yyp;
1751
222k
          ++yyformat;
1752
222k
        }
1753
6.22k
  }
1754
6.22k
  return 0;
1755
6.22k
}
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
780k
{
1766
780k
  YY_USE (yyvaluep);
1767
780k
  YY_USE (yyscanner);
1768
780k
  YY_USE (compiler);
1769
780k
  if (!yymsg)
1770
0
    yymsg = "Deleting";
1771
780k
  YY_SYMBOL_PRINT (yymsg, yykind, yyvaluep, yylocationp);
1772
1773
780k
  YY_IGNORE_MAYBE_UNINITIALIZED_BEGIN
1774
780k
  switch (yykind)
1775
780k
    {
1776
51.3k
    case YYSYMBOL__IDENTIFIER_: /* "identifier"  */
1777
51.3k
#line 313 "libyara/grammar.y"
1778
51.3k
            { yr_free(((*yyvaluep).c_string)); ((*yyvaluep).c_string) = NULL; }
1779
51.3k
#line 1780 "libyara/grammar.c"
1780
51.3k
        break;
1781
1782
7.41k
    case YYSYMBOL__STRING_IDENTIFIER_: /* "string identifier"  */
1783
7.41k
#line 317 "libyara/grammar.y"
1784
7.41k
            { yr_free(((*yyvaluep).c_string)); ((*yyvaluep).c_string) = NULL; }
1785
7.41k
#line 1786 "libyara/grammar.c"
1786
7.41k
        break;
1787
1788
792
    case YYSYMBOL__STRING_COUNT_: /* "string count"  */
1789
792
#line 314 "libyara/grammar.y"
1790
792
            { yr_free(((*yyvaluep).c_string)); ((*yyvaluep).c_string) = NULL; }
1791
792
#line 1792 "libyara/grammar.c"
1792
792
        break;
1793
1794
1.06k
    case YYSYMBOL__STRING_OFFSET_: /* "string offset"  */
1795
1.06k
#line 315 "libyara/grammar.y"
1796
1.06k
            { yr_free(((*yyvaluep).c_string)); ((*yyvaluep).c_string) = NULL; }
1797
1.06k
#line 1798 "libyara/grammar.c"
1798
1.06k
        break;
1799
1800
2.31k
    case YYSYMBOL__STRING_LENGTH_: /* "string length"  */
1801
2.31k
#line 316 "libyara/grammar.y"
1802
2.31k
            { yr_free(((*yyvaluep).c_string)); ((*yyvaluep).c_string) = NULL; }
1803
2.31k
#line 1804 "libyara/grammar.c"
1804
2.31k
        break;
1805
1806
226
    case YYSYMBOL__STRING_IDENTIFIER_WITH_WILDCARD_: /* "string identifier with wildcard"  */
1807
226
#line 318 "libyara/grammar.y"
1808
226
            { yr_free(((*yyvaluep).c_string)); ((*yyvaluep).c_string) = NULL; }
1809
226
#line 1810 "libyara/grammar.c"
1810
226
        break;
1811
1812
4.67k
    case YYSYMBOL__TEXT_STRING_: /* "text string"  */
1813
4.67k
#line 319 "libyara/grammar.y"
1814
4.67k
            { yr_free(((*yyvaluep).sized_string)); ((*yyvaluep).sized_string) = NULL; }
1815
4.67k
#line 1816 "libyara/grammar.c"
1816
4.67k
        break;
1817
1818
923
    case YYSYMBOL__HEX_STRING_: /* "hex string"  */
1819
923
#line 320 "libyara/grammar.y"
1820
923
            { yr_free(((*yyvaluep).sized_string)); ((*yyvaluep).sized_string) = NULL; }
1821
923
#line 1822 "libyara/grammar.c"
1822
923
        break;
1823
1824
4.19k
    case YYSYMBOL__REGEXP_: /* "regular expression"  */
1825
4.19k
#line 321 "libyara/grammar.y"
1826
4.19k
            { yr_free(((*yyvaluep).sized_string)); ((*yyvaluep).sized_string) = NULL; }
1827
4.19k
#line 1828 "libyara/grammar.c"
1828
4.19k
        break;
1829
1830
50
    case YYSYMBOL_string_modifiers: /* string_modifiers  */
1831
50
#line 334 "libyara/grammar.y"
1832
50
            {
1833
50
  if (((*yyvaluep).modifier).alphabet != NULL)
1834
12
  {
1835
12
    yr_free(((*yyvaluep).modifier).alphabet);
1836
12
    ((*yyvaluep).modifier).alphabet = NULL;
1837
12
  }
1838
50
}
1839
50
#line 1840 "libyara/grammar.c"
1840
50
        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
137
    case YYSYMBOL_arguments: /* arguments  */
1855
137
#line 323 "libyara/grammar.y"
1856
137
            { yr_free(((*yyvaluep).c_string)); ((*yyvaluep).c_string) = NULL; }
1857
137
#line 1858 "libyara/grammar.c"
1858
137
        break;
1859
1860
1.91k
    case YYSYMBOL_arguments_list: /* arguments_list  */
1861
1.91k
#line 324 "libyara/grammar.y"
1862
1.91k
            { yr_free(((*yyvaluep).c_string)); ((*yyvaluep).c_string) = NULL; }
1863
1.91k
#line 1864 "libyara/grammar.c"
1864
1.91k
        break;
1865
1866
705k
      default:
1867
705k
        break;
1868
780k
    }
1869
780k
  YY_IGNORE_MAYBE_UNINITIALIZED_END
1870
780k
}
1871
1872
1873
1874
1875
1876
1877
/*----------.
1878
| yyparse.  |
1879
`----------*/
1880
1881
int
1882
yyparse (void *yyscanner, YR_COMPILER* compiler)
1883
1.79k
{
1884
/* Lookahead token kind.  */
1885
1.79k
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.79k
YY_INITIAL_VALUE (static YYSTYPE yyval_default;)
1892
1.79k
YYSTYPE yylval YY_INITIAL_VALUE (= yyval_default);
1893
1894
    /* Number of syntax errors so far.  */
1895
1.79k
    int yynerrs = 0;
1896
1897
1.79k
    yy_state_fast_t yystate = 0;
1898
    /* Number of tokens to shift before error messages enabled.  */
1899
1.79k
    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.79k
    YYPTRDIFF_T yystacksize = YYINITDEPTH;
1906
1907
    /* The state stack: array, bottom, top.  */
1908
1.79k
    yy_state_t yyssa[YYINITDEPTH];
1909
1.79k
    yy_state_t *yyss = yyssa;
1910
1.79k
    yy_state_t *yyssp = yyss;
1911
1912
    /* The semantic value stack: array, bottom, top.  */
1913
1.79k
    YYSTYPE yyvsa[YYINITDEPTH];
1914
1.79k
    YYSTYPE *yyvs = yyvsa;
1915
1.79k
    YYSTYPE *yyvsp = yyvs;
1916
1917
1.79k
  int yyn;
1918
  /* The return value of yyparse.  */
1919
1.79k
  int yyresult;
1920
  /* Lookahead symbol kind.  */
1921
1.79k
  yysymbol_kind_t yytoken = YYSYMBOL_YYEMPTY;
1922
  /* The variables used to return semantic value and location from the
1923
     action routines.  */
1924
1.79k
  YYSTYPE yyval;
1925
1926
  /* Buffer for error messages, and its allocated size.  */
1927
1.79k
  char yymsgbuf[128];
1928
1.79k
  char *yymsg = yymsgbuf;
1929
1.79k
  YYPTRDIFF_T yymsg_alloc = sizeof yymsgbuf;
1930
1931
1.32M
#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.79k
  int yylen = 0;
1936
1937
1.79k
  YYDPRINTF ((stderr, "Starting parse\n"));
1938
1939
1.79k
  yychar = YYEMPTY; /* Cause a token to be read.  */
1940
1941
1.79k
  goto yysetstate;
1942
1943
1944
/*------------------------------------------------------------.
1945
| yynewstate -- push a new state, which is found in yystate.  |
1946
`------------------------------------------------------------*/
1947
1.42M
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.42M
  yyssp++;
1951
1952
1953
/*--------------------------------------------------------------------.
1954
| yysetstate -- set current state (the top of the stack) to yystate.  |
1955
`--------------------------------------------------------------------*/
1956
1.42M
yysetstate:
1957
1.42M
  YYDPRINTF ((stderr, "Entering state %d\n", yystate));
1958
1.42M
  YY_ASSERT (0 <= yystate && yystate < YYNSTATES);
1959
1.42M
  YY_IGNORE_USELESS_CAST_BEGIN
1960
1.42M
  *yyssp = YY_CAST (yy_state_t, yystate);
1961
1.42M
  YY_IGNORE_USELESS_CAST_END
1962
1.42M
  YY_STACK_PRINT (yyss, yyssp);
1963
1964
1.42M
  if (yyss + yystacksize - 1 <= yyssp)
1965
#if !defined yyoverflow && !defined YYSTACK_RELOCATE
1966
    YYNOMEM;
1967
#else
1968
103
    {
1969
      /* Get the current used size of the three stacks, in elements.  */
1970
103
      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
103
      if (YYMAXDEPTH <= yystacksize)
1994
1
        YYNOMEM;
1995
102
      yystacksize *= 2;
1996
102
      if (YYMAXDEPTH < yystacksize)
1997
3
        yystacksize = YYMAXDEPTH;
1998
1999
102
      {
2000
102
        yy_state_t *yyss1 = yyss;
2001
102
        union yyalloc *yyptr =
2002
102
          YY_CAST (union yyalloc *,
2003
102
                   YYSTACK_ALLOC (YY_CAST (YYSIZE_T, YYSTACK_BYTES (yystacksize))));
2004
102
        if (! yyptr)
2005
0
          YYNOMEM;
2006
102
        YYSTACK_RELOCATE (yyss_alloc, yyss);
2007
102
        YYSTACK_RELOCATE (yyvs_alloc, yyvs);
2008
102
#  undef YYSTACK_RELOCATE
2009
102
        if (yyss1 != yyssa)
2010
55
          YYSTACK_FREE (yyss1);
2011
102
      }
2012
0
# endif
2013
2014
0
      yyssp = yyss + yysize - 1;
2015
102
      yyvsp = yyvs + yysize - 1;
2016
2017
102
      YY_IGNORE_USELESS_CAST_BEGIN
2018
102
      YYDPRINTF ((stderr, "Stack size increased to %ld\n",
2019
102
                  YY_CAST (long, yystacksize)));
2020
102
      YY_IGNORE_USELESS_CAST_END
2021
2022
102
      if (yyss + yystacksize - 1 <= yyssp)
2023
0
        YYABORT;
2024
102
    }
2025
1.42M
#endif /* !defined yyoverflow && !defined YYSTACK_RELOCATE */
2026
2027
2028
1.42M
  if (yystate == YYFINAL)
2029
135
    YYACCEPT;
2030
2031
1.42M
  goto yybackup;
2032
2033
2034
/*-----------.
2035
| yybackup.  |
2036
`-----------*/
2037
1.42M
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.42M
  yyn = yypact[yystate];
2043
1.42M
  if (yypact_value_is_default (yyn))
2044
292k
    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.13M
  if (yychar == YYEMPTY)
2050
679k
    {
2051
679k
      YYDPRINTF ((stderr, "Reading a token\n"));
2052
679k
      yychar = yylex (&yylval, yyscanner, compiler);
2053
679k
    }
2054
2055
1.13M
  if (yychar <= _END_OF_FILE_)
2056
4.65k
    {
2057
4.65k
      yychar = _END_OF_FILE_;
2058
4.65k
      yytoken = YYSYMBOL_YYEOF;
2059
4.65k
      YYDPRINTF ((stderr, "Now at end of input.\n"));
2060
4.65k
    }
2061
1.12M
  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.12M
  else
2072
1.12M
    {
2073
1.12M
      yytoken = YYTRANSLATE (yychar);
2074
1.12M
      YY_SYMBOL_PRINT ("Next token is", yytoken, &yylval, &yylloc);
2075
1.12M
    }
2076
2077
  /* If the proper action on seeing token YYTOKEN is to reduce or to
2078
     detect an error, take that action.  */
2079
1.13M
  yyn += yytoken;
2080
1.13M
  if (yyn < 0 || YYLAST < yyn || yycheck[yyn] != yytoken)
2081
614k
    goto yydefault;
2082
518k
  yyn = yytable[yyn];
2083
518k
  if (yyn <= 0)
2084
35.2k
    {
2085
35.2k
      if (yytable_value_is_error (yyn))
2086
0
        goto yyerrlab;
2087
35.2k
      yyn = -yyn;
2088
35.2k
      goto yyreduce;
2089
35.2k
    }
2090
2091
  /* Count tokens shifted since error; after three, turn off error
2092
     status.  */
2093
483k
  if (yyerrstatus)
2094
41.6k
    yyerrstatus--;
2095
2096
  /* Shift the lookahead token.  */
2097
483k
  YY_SYMBOL_PRINT ("Shifting", yytoken, &yylval, &yylloc);
2098
483k
  yystate = yyn;
2099
483k
  YY_IGNORE_MAYBE_UNINITIALIZED_BEGIN
2100
483k
  *++yyvsp = yylval;
2101
483k
  YY_IGNORE_MAYBE_UNINITIALIZED_END
2102
2103
  /* Discard the shifted token.  */
2104
483k
  yychar = YYEMPTY;
2105
483k
  goto yynewstate;
2106
2107
2108
/*-----------------------------------------------------------.
2109
| yydefault -- do the default action for the current state.  |
2110
`-----------------------------------------------------------*/
2111
907k
yydefault:
2112
907k
  yyn = yydefact[yystate];
2113
907k
  if (yyn == 0)
2114
206k
    goto yyerrlab;
2115
700k
  goto yyreduce;
2116
2117
2118
/*-----------------------------.
2119
| yyreduce -- do a reduction.  |
2120
`-----------------------------*/
2121
736k
yyreduce:
2122
  /* yyn is the number of a rule to reduce with.  */
2123
736k
  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
736k
  yyval = yyvsp[1-yylen];
2134
2135
2136
736k
  YY_REDUCE_PRINT (yyn);
2137
736k
  switch (yyn)
2138
736k
    {
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.33k
  case 10: /* import: "<import>" "text string"  */
2156
2.33k
#line 381 "libyara/grammar.y"
2157
2.33k
      {
2158
2.33k
        int result = yr_parser_reduce_import(yyscanner, (yyvsp[0].sized_string));
2159
2160
2.33k
        yr_free((yyvsp[0].sized_string));
2161
2162
2.33k
        fail_if_error(result);
2163
1.74k
      }
2164
0
#line 2165 "libyara/grammar.c"
2165
0
    break;
2166
2167
16.2k
  case 11: /* @1: %empty  */
2168
16.2k
#line 393 "libyara/grammar.y"
2169
16.2k
      {
2170
16.2k
        fail_if_error(yr_parser_reduce_rule_declaration_phase_1(
2171
16.2k
            yyscanner, (int32_t) (yyvsp[-2].integer), (yyvsp[0].c_string), &(yyval.rule)));
2172
11.1k
      }
2173
0
#line 2174 "libyara/grammar.c"
2174
0
    break;
2175
2176
6.78k
  case 12: /* $@2: %empty  */
2177
6.78k
#line 398 "libyara/grammar.y"
2178
6.78k
      {
2179
6.78k
        YR_RULE* rule = (YR_RULE*) yr_arena_ref_to_ptr(
2180
6.78k
            compiler->arena, &(yyvsp[-4].rule));
2181
2182
6.78k
        rule->tags = (char*) yr_arena_ref_to_ptr(
2183
6.78k
            compiler->arena, &(yyvsp[-3].tag));
2184
2185
6.78k
        rule->metas = (YR_META*) yr_arena_ref_to_ptr(
2186
6.78k
            compiler->arena, &(yyvsp[-1].meta));
2187
2188
6.78k
        rule->strings = (YR_STRING*) yr_arena_ref_to_ptr(
2189
6.78k
            compiler->arena, &(yyvsp[0].string));
2190
6.78k
      }
2191
6.78k
#line 2192 "libyara/grammar.c"
2192
6.78k
    break;
2193
2194
667
  case 13: /* rule: rule_modifiers "<rule>" "identifier" @1 tags '{' meta strings $@2 condition '}'  */
2195
667
#line 412 "libyara/grammar.y"
2196
667
      {
2197
667
        YR_RULE* rule = (YR_RULE*) yr_arena_ref_to_ptr(
2198
667
            compiler->arena, &(yyvsp[-7].rule));
2199
667
        rule->required_strings = (yyvsp[-1].expression).required_strings.count;
2200
2201
667
        int result = yr_parser_reduce_rule_declaration_phase_2(
2202
667
            yyscanner, &(yyvsp[-7].rule)); // rule created in phase 1
2203
2204
667
        yr_free((yyvsp[-8].c_string));
2205
2206
667
        fail_if_error(result);
2207
650
      }
2208
0
#line 2209 "libyara/grammar.c"
2209
0
    break;
2210
2211
8.16k
  case 14: /* meta: %empty  */
2212
8.16k
#line 429 "libyara/grammar.y"
2213
8.16k
      {
2214
8.16k
        (yyval.meta) = YR_ARENA_NULL_REF;
2215
8.16k
      }
2216
8.16k
#line 2217 "libyara/grammar.c"
2217
8.16k
    break;
2218
2219
19
  case 15: /* meta: "<meta>" ':' meta_declarations  */
2220
19
#line 433 "libyara/grammar.y"
2221
19
      {
2222
19
        YR_META* meta = yr_arena_get_ptr(
2223
19
            compiler->arena,
2224
19
            YR_METAS_TABLE,
2225
19
            (compiler->current_meta_idx - 1) * sizeof(YR_META));
2226
2227
19
        meta->flags |= META_FLAGS_LAST_IN_RULE;
2228
2229
19
        (yyval.meta) = (yyvsp[0].meta);
2230
19
      }
2231
19
#line 2232 "libyara/grammar.c"
2232
19
    break;
2233
2234
5.57k
  case 16: /* strings: %empty  */
2235
5.57k
#line 448 "libyara/grammar.y"
2236
5.57k
      {
2237
5.57k
        (yyval.string) = YR_ARENA_NULL_REF;
2238
5.57k
      }
2239
5.57k
#line 2240 "libyara/grammar.c"
2240
5.57k
    break;
2241
2242
1.21k
  case 17: /* strings: "<strings>" ':' string_declarations  */
2243
1.21k
#line 452 "libyara/grammar.y"
2244
1.21k
      {
2245
1.21k
        YR_STRING* string = (YR_STRING*) yr_arena_get_ptr(
2246
1.21k
            compiler->arena,
2247
1.21k
            YR_STRINGS_TABLE,
2248
1.21k
            (compiler->current_string_idx - 1) * sizeof(YR_STRING));
2249
2250
1.21k
        string->flags |= STRING_FLAGS_LAST_IN_RULE;
2251
2252
1.21k
        (yyval.string) = (yyvsp[0].string);
2253
1.21k
      }
2254
1.21k
#line 2255 "libyara/grammar.c"
2255
1.21k
    break;
2256
2257
1.05k
  case 18: /* condition: "<condition>" ':' boolean_expression  */
2258
1.05k
#line 467 "libyara/grammar.y"
2259
1.05k
      {
2260
1.05k
        (yyval.expression) = (yyvsp[0].expression);
2261
1.05k
      }
2262
1.05k
#line 2263 "libyara/grammar.c"
2263
1.05k
    break;
2264
2265
214k
  case 19: /* rule_modifiers: %empty  */
2266
214k
#line 474 "libyara/grammar.y"
2267
214k
                                       { (yyval.integer) = 0;  }
2268
214k
#line 2269 "libyara/grammar.c"
2269
214k
    break;
2270
2271
796
  case 20: /* rule_modifiers: rule_modifiers rule_modifier  */
2272
796
#line 475 "libyara/grammar.y"
2273
796
                                       { (yyval.integer) = (yyvsp[-1].integer) | (yyvsp[0].integer); }
2274
796
#line 2275 "libyara/grammar.c"
2275
796
    break;
2276
2277
170
  case 21: /* rule_modifier: "<private>"  */
2278
170
#line 480 "libyara/grammar.y"
2279
170
                     { (yyval.integer) = RULE_FLAGS_PRIVATE; }
2280
170
#line 2281 "libyara/grammar.c"
2281
170
    break;
2282
2283
626
  case 22: /* rule_modifier: "<global>"  */
2284
626
#line 481 "libyara/grammar.y"
2285
626
                     { (yyval.integer) = RULE_FLAGS_GLOBAL; }
2286
626
#line 2287 "libyara/grammar.c"
2287
626
    break;
2288
2289
10.3k
  case 23: /* tags: %empty  */
2290
10.3k
#line 487 "libyara/grammar.y"
2291
10.3k
      {
2292
10.3k
        (yyval.tag) = YR_ARENA_NULL_REF;
2293
10.3k
      }
2294
10.3k
#line 2295 "libyara/grammar.c"
2295
10.3k
    break;
2296
2297
347
  case 24: /* tags: ':' tag_list  */
2298
347
#line 491 "libyara/grammar.y"
2299
347
      {
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
347
        fail_if_error(yr_arena_write_string(
2306
347
            yyget_extra(yyscanner)->arena, YR_SZ_POOL, "", NULL));
2307
2308
347
        (yyval.tag) = (yyvsp[0].tag);
2309
347
      }
2310
0
#line 2311 "libyara/grammar.c"
2311
0
    break;
2312
2313
411
  case 25: /* tag_list: "identifier"  */
2314
411
#line 507 "libyara/grammar.y"
2315
411
      {
2316
411
        int result = yr_arena_write_string(
2317
411
            yyget_extra(yyscanner)->arena, YR_SZ_POOL, (yyvsp[0].c_string), &(yyval.tag));
2318
2319
411
        yr_free((yyvsp[0].c_string));
2320
2321
411
        fail_if_error(result);
2322
411
      }
2323
0
#line 2324 "libyara/grammar.c"
2324
0
    break;
2325
2326
698
  case 26: /* tag_list: tag_list "identifier"  */
2327
698
#line 516 "libyara/grammar.y"
2328
698
      {
2329
698
        YR_ARENA_REF ref;
2330
2331
        // Write the new tag identifier.
2332
698
        int result = yr_arena_write_string(
2333
698
            yyget_extra(yyscanner)->arena, YR_SZ_POOL, (yyvsp[0].c_string), &ref);
2334
2335
698
        yr_free((yyvsp[0].c_string));
2336
2337
698
        fail_if_error(result);
2338
2339
        // Get the address for the tag identifier just written.
2340
698
        char* new_tag = (char*) yr_arena_ref_to_ptr(
2341
698
            compiler->arena, &ref);
2342
2343
        // Take the address of first tag's identifier in the list.
2344
698
        char* tag = (char*) yr_arena_ref_to_ptr(
2345
698
            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
2.24k
        while (tag < new_tag)
2352
1.61k
        {
2353
1.61k
          if (strcmp(tag, new_tag) == 0)
2354
64
          {
2355
64
            yr_compiler_set_error_extra_info(compiler, tag);
2356
64
            fail_with_error(ERROR_DUPLICATED_TAG_IDENTIFIER);
2357
0
          }
2358
2359
1.54k
          tag += strlen(tag) + 1;
2360
1.54k
        }
2361
2362
634
        (yyval.tag) = (yyvsp[-1].tag);
2363
634
      }
2364
0
#line 2365 "libyara/grammar.c"
2365
0
    break;
2366
2367
33
  case 27: /* meta_declarations: meta_declaration  */
2368
33
#line 557 "libyara/grammar.y"
2369
33
                                          {  (yyval.meta) = (yyvsp[0].meta); }
2370
33
#line 2371 "libyara/grammar.c"
2371
33
    break;
2372
2373
728
  case 28: /* meta_declarations: meta_declarations meta_declaration  */
2374
728
#line 558 "libyara/grammar.y"
2375
728
                                          {  (yyval.meta) = (yyvsp[-1].meta); }
2376
728
#line 2377 "libyara/grammar.c"
2377
728
    break;
2378
2379
355
  case 29: /* meta_declaration: "identifier" '=' "text string"  */
2380
355
#line 564 "libyara/grammar.y"
2381
355
      {
2382
355
        SIZED_STRING* sized_string = (yyvsp[0].sized_string);
2383
2384
355
        int result = yr_parser_reduce_meta_declaration(
2385
355
            yyscanner,
2386
355
            META_TYPE_STRING,
2387
355
            (yyvsp[-2].c_string),
2388
355
            sized_string->c_string,
2389
355
            0,
2390
355
            &(yyval.meta));
2391
2392
355
        yr_free((yyvsp[-2].c_string));
2393
355
        yr_free((yyvsp[0].sized_string));
2394
2395
355
        fail_if_error(result);
2396
355
      }
2397
0
#line 2398 "libyara/grammar.c"
2398
0
    break;
2399
2400
159
  case 30: /* meta_declaration: "identifier" '=' "integer number"  */
2401
159
#line 581 "libyara/grammar.y"
2402
159
      {
2403
159
        int result = yr_parser_reduce_meta_declaration(
2404
159
            yyscanner,
2405
159
            META_TYPE_INTEGER,
2406
159
            (yyvsp[-2].c_string),
2407
159
            NULL,
2408
159
            (yyvsp[0].integer),
2409
159
            &(yyval.meta));
2410
2411
159
        yr_free((yyvsp[-2].c_string));
2412
2413
159
        fail_if_error(result);
2414
159
      }
2415
0
#line 2416 "libyara/grammar.c"
2416
0
    break;
2417
2418
58
  case 31: /* meta_declaration: "identifier" '=' '-' "integer number"  */
2419
58
#line 595 "libyara/grammar.y"
2420
58
      {
2421
58
        int result = yr_parser_reduce_meta_declaration(
2422
58
            yyscanner,
2423
58
            META_TYPE_INTEGER,
2424
58
            (yyvsp[-3].c_string),
2425
58
            NULL,
2426
58
            -(yyvsp[0].integer),
2427
58
            &(yyval.meta));
2428
2429
58
        yr_free((yyvsp[-3].c_string));
2430
2431
58
        fail_if_error(result);
2432
58
      }
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.33k
  case 34: /* string_declarations: string_declaration  */
2473
1.33k
#line 640 "libyara/grammar.y"
2474
1.33k
                                              { (yyval.string) = (yyvsp[0].string); }
2475
1.33k
#line 2476 "libyara/grammar.c"
2476
1.33k
    break;
2477
2478
27.1k
  case 35: /* string_declarations: string_declarations string_declaration  */
2479
27.1k
#line 641 "libyara/grammar.y"
2480
27.1k
                                              { (yyval.string) = (yyvsp[-1].string); }
2481
27.1k
#line 2482 "libyara/grammar.c"
2482
27.1k
    break;
2483
2484
4.15k
  case 36: /* $@3: %empty  */
2485
4.15k
#line 647 "libyara/grammar.y"
2486
4.15k
      {
2487
4.15k
        compiler->current_line = yyget_lineno(yyscanner);
2488
4.15k
      }
2489
4.15k
#line 2490 "libyara/grammar.c"
2490
4.15k
    break;
2491
2492
3.92k
  case 37: /* string_declaration: "string identifier" '=' $@3 "text string" string_modifiers  */
2493
3.92k
#line 651 "libyara/grammar.y"
2494
3.92k
      {
2495
3.92k
        int result = yr_parser_reduce_string_declaration(
2496
3.92k
            yyscanner, (yyvsp[0].modifier), (yyvsp[-4].c_string), (yyvsp[-1].sized_string), &(yyval.string));
2497
2498
3.92k
        yr_free((yyvsp[-4].c_string));
2499
3.92k
        yr_free((yyvsp[-1].sized_string));
2500
3.92k
        yr_free((yyvsp[0].modifier).alphabet);
2501
2502
3.92k
        fail_if_error(result);
2503
3.89k
        compiler->current_line = 0;
2504
3.89k
      }
2505
0
#line 2506 "libyara/grammar.c"
2506
0
    break;
2507
2508
24.3k
  case 38: /* $@4: %empty  */
2509
24.3k
#line 663 "libyara/grammar.y"
2510
24.3k
      {
2511
24.3k
        compiler->current_line = yyget_lineno(yyscanner);
2512
24.3k
      }
2513
24.3k
#line 2514 "libyara/grammar.c"
2514
24.3k
    break;
2515
2516
24.3k
  case 39: /* string_declaration: "string identifier" '=' $@4 "regular expression" regexp_modifiers  */
2517
24.3k
#line 667 "libyara/grammar.y"
2518
24.3k
      {
2519
24.3k
        int result;
2520
2521
24.3k
        (yyvsp[0].modifier).flags |= STRING_FLAGS_REGEXP;
2522
2523
24.3k
        result = yr_parser_reduce_string_declaration(
2524
24.3k
            yyscanner, (yyvsp[0].modifier), (yyvsp[-4].c_string), (yyvsp[-1].sized_string), &(yyval.string));
2525
2526
24.3k
        yr_free((yyvsp[-4].c_string));
2527
24.3k
        yr_free((yyvsp[-1].sized_string));
2528
2529
24.3k
        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.28k
  case 40: /* $@5: %empty  */
2537
1.28k
#line 683 "libyara/grammar.y"
2538
1.28k
      {
2539
1.28k
        compiler->current_line = yyget_lineno(yyscanner);
2540
1.28k
      }
2541
1.28k
#line 2542 "libyara/grammar.c"
2542
1.28k
    break;
2543
2544
1.27k
  case 41: /* string_declaration: "string identifier" '=' $@5 "hex string" hex_modifiers  */
2545
1.27k
#line 687 "libyara/grammar.y"
2546
1.27k
      {
2547
1.27k
        int result;
2548
2549
1.27k
        (yyvsp[0].modifier).flags |= STRING_FLAGS_HEXADECIMAL;
2550
2551
1.27k
        result = yr_parser_reduce_string_declaration(
2552
1.27k
            yyscanner, (yyvsp[0].modifier), (yyvsp[-4].c_string), (yyvsp[-1].sized_string), &(yyval.string));
2553
2554
1.27k
        yr_free((yyvsp[-4].c_string));
2555
1.27k
        yr_free((yyvsp[-1].sized_string));
2556
2557
1.27k
        fail_if_error(result);
2558
2559
935
        compiler->current_line = 0;
2560
935
      }
2561
0
#line 2562 "libyara/grammar.c"
2562
0
    break;
2563
2564
4.00k
  case 42: /* string_modifiers: %empty  */
2565
4.00k
#line 707 "libyara/grammar.y"
2566
4.00k
      {
2567
4.00k
        (yyval.modifier).flags = 0;
2568
4.00k
        (yyval.modifier).xor_min = 0;
2569
4.00k
        (yyval.modifier).xor_max = 0;
2570
4.00k
        (yyval.modifier).alphabet = NULL;
2571
4.00k
      }
2572
4.00k
#line 2573 "libyara/grammar.c"
2573
4.00k
    break;
2574
2575
5.18k
  case 43: /* string_modifiers: string_modifiers string_modifier  */
2576
5.18k
#line 714 "libyara/grammar.y"
2577
5.18k
      {
2578
5.18k
        (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
5.18k
        if ((yyvsp[0].modifier).flags & STRING_FLAGS_XOR)
2585
884
        {
2586
884
          (yyval.modifier).xor_min = (yyvsp[0].modifier).xor_min;
2587
884
          (yyval.modifier).xor_max = (yyvsp[0].modifier).xor_max;
2588
884
        }
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
5.18k
        if (((yyvsp[0].modifier).flags & STRING_FLAGS_BASE64) ||
2595
5.18k
            ((yyvsp[0].modifier).flags & STRING_FLAGS_BASE64_WIDE))
2596
2.44k
        {
2597
2.44k
          if ((yyval.modifier).alphabet != NULL)
2598
727
          {
2599
727
            if (ss_compare((yyval.modifier).alphabet, (yyvsp[0].modifier).alphabet) != 0)
2600
12
            {
2601
12
              yr_compiler_set_error_extra_info(
2602
12
                  compiler, "can not specify multiple alphabets");
2603
2604
12
              yr_free((yyvsp[0].modifier).alphabet);
2605
12
              yr_free((yyval.modifier).alphabet);
2606
2607
12
              fail_with_error(ERROR_INVALID_MODIFIER);
2608
0
            }
2609
715
            else
2610
715
            {
2611
715
              yr_free((yyvsp[0].modifier).alphabet);
2612
715
            }
2613
727
          }
2614
1.71k
          else
2615
1.71k
          {
2616
1.71k
            (yyval.modifier).alphabet = (yyvsp[0].modifier).alphabet;
2617
1.71k
          }
2618
2.44k
        }
2619
2620
5.16k
        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
5.15k
        else
2628
5.15k
        {
2629
5.15k
          (yyval.modifier).flags = (yyval.modifier).flags | (yyvsp[0].modifier).flags;
2630
5.15k
        }
2631
5.16k
      }
2632
5.15k
#line 2633 "libyara/grammar.c"
2633
5.15k
    break;
2634
2635
5.15k
  case 44: /* string_modifier: "<wide>"  */
2636
879
#line 773 "libyara/grammar.y"
2637
879
                    { (yyval.modifier).flags = STRING_FLAGS_WIDE; }
2638
879
#line 2639 "libyara/grammar.c"
2639
879
    break;
2640
2641
443
  case 45: /* string_modifier: "<ascii>"  */
2642
443
#line 774 "libyara/grammar.y"
2643
443
                    { (yyval.modifier).flags = STRING_FLAGS_ASCII; }
2644
443
#line 2645 "libyara/grammar.c"
2645
443
    break;
2646
2647
277
  case 46: /* string_modifier: "<nocase>"  */
2648
277
#line 775 "libyara/grammar.y"
2649
277
                    { (yyval.modifier).flags = STRING_FLAGS_NO_CASE; }
2650
277
#line 2651 "libyara/grammar.c"
2651
277
    break;
2652
2653
76
  case 47: /* string_modifier: "<fullword>"  */
2654
76
#line 776 "libyara/grammar.y"
2655
76
                    { (yyval.modifier).flags = STRING_FLAGS_FULL_WORD; }
2656
76
#line 2657 "libyara/grammar.c"
2657
76
    break;
2658
2659
176
  case 48: /* string_modifier: "<private>"  */
2660
176
#line 777 "libyara/grammar.y"
2661
176
                    { (yyval.modifier).flags = STRING_FLAGS_PRIVATE; }
2662
176
#line 2663 "libyara/grammar.c"
2663
176
    break;
2664
2665
388
  case 49: /* string_modifier: "<xor>"  */
2666
388
#line 779 "libyara/grammar.y"
2667
388
      {
2668
388
        (yyval.modifier).flags = STRING_FLAGS_XOR;
2669
388
        (yyval.modifier).xor_min = 0;
2670
388
        (yyval.modifier).xor_max = 255;
2671
388
      }
2672
388
#line 2673 "libyara/grammar.c"
2673
388
    break;
2674
2675
287
  case 50: /* string_modifier: "<xor>" '(' "integer number" ')'  */
2676
287
#line 785 "libyara/grammar.y"
2677
287
      {
2678
287
        int result = ERROR_SUCCESS;
2679
2680
287
        if ((yyvsp[-1].integer) < 0 || (yyvsp[-1].integer) > 255)
2681
5
        {
2682
5
          yr_compiler_set_error_extra_info(compiler, "invalid xor range");
2683
5
          result = ERROR_INVALID_MODIFIER;
2684
5
        }
2685
2686
287
        fail_if_error(result);
2687
2688
282
        (yyval.modifier).flags = STRING_FLAGS_XOR;
2689
282
        (yyval.modifier).xor_min = (uint8_t) (yyvsp[-1].integer);
2690
282
        (yyval.modifier).xor_max = (uint8_t) (yyvsp[-1].integer);
2691
282
      }
2692
0
#line 2693 "libyara/grammar.c"
2693
0
    break;
2694
2695
228
  case 51: /* string_modifier: "<xor>" '(' "integer number" '-' "integer number" ')'  */
2696
228
#line 806 "libyara/grammar.y"
2697
228
      {
2698
228
        int result = ERROR_SUCCESS;
2699
2700
228
        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
228
        if ((yyvsp[-1].integer) > 255)
2708
8
        {
2709
8
          yr_compiler_set_error_extra_info(
2710
8
              compiler, "upper bound for xor range exceeded (max: 255)");
2711
8
          result = ERROR_INVALID_MODIFIER;
2712
8
        }
2713
2714
228
        if ((yyvsp[-3].integer) > (yyvsp[-1].integer))
2715
7
        {
2716
7
          yr_compiler_set_error_extra_info(
2717
7
              compiler, "xor lower bound exceeds upper bound");
2718
7
          result = ERROR_INVALID_MODIFIER;
2719
7
        }
2720
2721
228
        fail_if_error(result);
2722
2723
214
        (yyval.modifier).flags = STRING_FLAGS_XOR;
2724
214
        (yyval.modifier).xor_min = (uint8_t) (yyvsp[-3].integer);
2725
214
        (yyval.modifier).xor_max = (uint8_t) (yyvsp[-1].integer);
2726
214
      }
2727
0
#line 2728 "libyara/grammar.c"
2728
0
    break;
2729
2730
947
  case 52: /* string_modifier: "<base64>"  */
2731
947
#line 837 "libyara/grammar.y"
2732
947
      {
2733
947
        (yyval.modifier).flags = STRING_FLAGS_BASE64;
2734
947
        (yyval.modifier).alphabet = ss_new(DEFAULT_BASE64_ALPHABET);
2735
947
      }
2736
947
#line 2737 "libyara/grammar.c"
2737
947
    break;
2738
2739
73
  case 53: /* string_modifier: "<base64>" '(' "text string" ')'  */
2740
73
#line 842 "libyara/grammar.y"
2741
73
      {
2742
73
        int result = ERROR_SUCCESS;
2743
2744
73
        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
73
        fail_if_error(result);
2753
2754
68
        (yyval.modifier).flags = STRING_FLAGS_BASE64;
2755
68
        (yyval.modifier).alphabet = (yyvsp[-1].sized_string);
2756
68
      }
2757
0
#line 2758 "libyara/grammar.c"
2758
0
    break;
2759
2760
1.33k
  case 54: /* string_modifier: "<base64wide>"  */
2761
1.33k
#line 859 "libyara/grammar.y"
2762
1.33k
      {
2763
1.33k
        (yyval.modifier).flags = STRING_FLAGS_BASE64_WIDE;
2764
1.33k
        (yyval.modifier).alphabet = ss_new(DEFAULT_BASE64_ALPHABET);
2765
1.33k
      }
2766
1.33k
#line 2767 "libyara/grammar.c"
2767
1.33k
    break;
2768
2769
113
  case 55: /* string_modifier: "<base64wide>" '(' "text string" ')'  */
2770
113
#line 864 "libyara/grammar.y"
2771
113
      {
2772
113
        int result = ERROR_SUCCESS;
2773
2774
113
        if ((yyvsp[-1].sized_string)->length != 64)
2775
13
        {
2776
13
          yr_free((yyvsp[-1].sized_string));
2777
13
          yr_compiler_set_error_extra_info(
2778
13
              compiler, "length of base64 alphabet must be 64");
2779
13
          result = ERROR_INVALID_MODIFIER;
2780
13
        }
2781
2782
113
        fail_if_error(result);
2783
2784
100
        (yyval.modifier).flags = STRING_FLAGS_BASE64_WIDE;
2785
100
        (yyval.modifier).alphabet = (yyvsp[-1].sized_string);
2786
100
      }
2787
0
#line 2788 "libyara/grammar.c"
2788
0
    break;
2789
2790
24.3k
  case 56: /* regexp_modifiers: %empty  */
2791
24.3k
#line 883 "libyara/grammar.y"
2792
24.3k
                                          { (yyval.modifier).flags = 0; }
2793
24.3k
#line 2794 "libyara/grammar.c"
2794
24.3k
    break;
2795
2796
1.31k
  case 57: /* regexp_modifiers: regexp_modifiers regexp_modifier  */
2797
1.31k
#line 885 "libyara/grammar.y"
2798
1.31k
      {
2799
1.31k
        if ((yyvsp[-1].modifier).flags & (yyvsp[0].modifier).flags)
2800
2
        {
2801
2
          fail_with_error(ERROR_DUPLICATED_MODIFIER);
2802
0
        }
2803
1.31k
        else
2804
1.31k
        {
2805
1.31k
          (yyval.modifier).flags = (yyvsp[-1].modifier).flags | (yyvsp[0].modifier).flags;
2806
1.31k
        }
2807
1.31k
      }
2808
1.31k
#line 2809 "libyara/grammar.c"
2809
1.31k
    break;
2810
2811
1.31k
  case 58: /* regexp_modifier: "<wide>"  */
2812
493
#line 898 "libyara/grammar.y"
2813
493
                    { (yyval.modifier).flags = STRING_FLAGS_WIDE; }
2814
493
#line 2815 "libyara/grammar.c"
2815
493
    break;
2816
2817
375
  case 59: /* regexp_modifier: "<ascii>"  */
2818
375
#line 899 "libyara/grammar.y"
2819
375
                    { (yyval.modifier).flags = STRING_FLAGS_ASCII; }
2820
375
#line 2821 "libyara/grammar.c"
2821
375
    break;
2822
2823
214
  case 60: /* regexp_modifier: "<nocase>"  */
2824
214
#line 900 "libyara/grammar.y"
2825
214
                    { (yyval.modifier).flags = STRING_FLAGS_NO_CASE; }
2826
214
#line 2827 "libyara/grammar.c"
2827
214
    break;
2828
2829
49
  case 61: /* regexp_modifier: "<fullword>"  */
2830
49
#line 901 "libyara/grammar.y"
2831
49
                    { (yyval.modifier).flags = STRING_FLAGS_FULL_WORD; }
2832
49
#line 2833 "libyara/grammar.c"
2833
49
    break;
2834
2835
185
  case 62: /* regexp_modifier: "<private>"  */
2836
185
#line 902 "libyara/grammar.y"
2837
185
                    { (yyval.modifier).flags = STRING_FLAGS_PRIVATE; }
2838
185
#line 2839 "libyara/grammar.c"
2839
185
    break;
2840
2841
1.28k
  case 63: /* hex_modifiers: %empty  */
2842
1.28k
#line 906 "libyara/grammar.y"
2843
1.28k
                                          { (yyval.modifier).flags = 0; }
2844
1.28k
#line 2845 "libyara/grammar.c"
2845
1.28k
    break;
2846
2847
197
  case 64: /* hex_modifiers: hex_modifiers hex_modifier  */
2848
197
#line 908 "libyara/grammar.y"
2849
197
      {
2850
197
        if ((yyvsp[-1].modifier).flags & (yyvsp[0].modifier).flags)
2851
9
        {
2852
9
          fail_with_error(ERROR_DUPLICATED_MODIFIER);
2853
0
        }
2854
188
        else
2855
188
        {
2856
188
          (yyval.modifier).flags = (yyvsp[-1].modifier).flags | (yyvsp[0].modifier).flags;
2857
188
        }
2858
197
      }
2859
188
#line 2860 "libyara/grammar.c"
2860
188
    break;
2861
2862
197
  case 65: /* hex_modifier: "<private>"  */
2863
197
#line 921 "libyara/grammar.y"
2864
197
                    { (yyval.modifier).flags = STRING_FLAGS_PRIVATE; }
2865
197
#line 2866 "libyara/grammar.c"
2866
197
    break;
2867
2868
14.7k
  case 66: /* identifier: "identifier"  */
2869
14.7k
#line 926 "libyara/grammar.y"
2870
14.7k
      {
2871
14.7k
        YR_EXPRESSION expr;
2872
2873
14.7k
        int result = ERROR_SUCCESS;
2874
14.7k
        int var_index = yr_parser_lookup_loop_variable(yyscanner, (yyvsp[0].c_string), &expr);
2875
2876
14.7k
        if (var_index >= 0)
2877
7.53k
        {
2878
          // The identifier corresponds to a loop variable.
2879
7.53k
          result = yr_parser_emit_with_arg(
2880
7.53k
              yyscanner,
2881
7.53k
              OP_PUSH_M,
2882
7.53k
              var_index,
2883
7.53k
              NULL,
2884
7.53k
              NULL);
2885
2886
          // The expression associated to this identifier is the same one
2887
          // associated to the loop variable.
2888
7.53k
          (yyval.expression) = expr;
2889
7.53k
        }
2890
7.21k
        else
2891
7.21k
        {
2892
          // Search for identifier within the global namespace, where the
2893
          // externals variables reside.
2894
2895
7.21k
          YR_OBJECT* object = (YR_OBJECT*) yr_hash_table_lookup(
2896
7.21k
              compiler->objects_table, (yyvsp[0].c_string), NULL);
2897
2898
7.21k
          YR_NAMESPACE* ns = (YR_NAMESPACE*) yr_arena_get_ptr(
2899
7.21k
              compiler->arena,
2900
7.21k
              YR_NAMESPACES_TABLE,
2901
7.21k
              compiler->current_namespace_idx * sizeof(struct YR_NAMESPACE));
2902
2903
7.21k
          if (object == NULL)
2904
7.21k
          {
2905
            // If not found, search within the current namespace.
2906
7.21k
            object = (YR_OBJECT*) yr_hash_table_lookup(
2907
7.21k
                compiler->objects_table, (yyvsp[0].c_string), ns->name);
2908
7.21k
          }
2909
2910
7.21k
          if (object != NULL)
2911
1.50k
          {
2912
1.50k
            YR_ARENA_REF ref;
2913
2914
1.50k
            result = _yr_compiler_store_string(
2915
1.50k
                compiler, (yyvsp[0].c_string), &ref);
2916
2917
1.50k
            if (result == ERROR_SUCCESS)
2918
1.50k
              result = yr_parser_emit_with_arg_reloc(
2919
1.50k
                  yyscanner,
2920
1.50k
                  OP_OBJ_LOAD,
2921
1.50k
                  yr_arena_ref_to_ptr(compiler->arena, &ref),
2922
1.50k
                  NULL,
2923
1.50k
                  NULL);
2924
2925
1.50k
            (yyval.expression).type = EXPRESSION_TYPE_OBJECT;
2926
1.50k
            (yyval.expression).value.object = object;
2927
1.50k
            (yyval.expression).identifier.ptr = NULL;
2928
1.50k
            (yyval.expression).identifier.ref = ref;
2929
1.50k
          }
2930
5.70k
          else
2931
5.70k
          {
2932
5.70k
            uint32_t rule_idx = yr_hash_table_lookup_uint32(
2933
5.70k
                compiler->rules_table, (yyvsp[0].c_string), ns->name);
2934
2935
5.70k
            if (rule_idx != UINT32_MAX)
2936
5.39k
            {
2937
5.39k
              result = yr_parser_emit_with_arg(
2938
5.39k
                  yyscanner,
2939
5.39k
                  OP_PUSH_RULE,
2940
5.39k
                  rule_idx,
2941
5.39k
                  NULL,
2942
5.39k
                  NULL);
2943
2944
5.39k
              YR_RULE* rule = _yr_compiler_get_rule_by_idx(compiler, rule_idx);
2945
2946
5.39k
              yr_arena_ptr_to_ref(compiler->arena, rule->identifier, &(yyval.expression).identifier.ref);
2947
2948
5.39k
              (yyval.expression).type = EXPRESSION_TYPE_BOOLEAN;
2949
5.39k
              (yyval.expression).value.integer = YR_UNDEFINED;
2950
5.39k
              (yyval.expression).identifier.ptr = NULL;
2951
5.39k
              (yyval.expression).required_strings.count = 0;
2952
5.39k
            }
2953
309
            else
2954
309
            {
2955
309
              yr_compiler_set_error_extra_info(compiler, (yyvsp[0].c_string));
2956
309
              result = ERROR_UNDEFINED_IDENTIFIER;
2957
309
            }
2958
5.70k
          }
2959
7.21k
        }
2960
2961
14.7k
        yr_free((yyvsp[0].c_string));
2962
2963
14.7k
        fail_if_error(result);
2964
14.4k
      }
2965
0
#line 2966 "libyara/grammar.c"
2966
0
    break;
2967
2968
1.33k
  case 67: /* identifier: identifier '.' "identifier"  */
2969
1.33k
#line 1022 "libyara/grammar.y"
2970
1.33k
      {
2971
1.33k
        int result = ERROR_SUCCESS;
2972
1.33k
        YR_OBJECT* field = NULL;
2973
2974
1.33k
        if ((yyvsp[-2].expression).type == EXPRESSION_TYPE_OBJECT &&
2975
1.33k
            (yyvsp[-2].expression).value.object->type == OBJECT_TYPE_STRUCTURE)
2976
1.27k
        {
2977
1.27k
          field = yr_object_lookup_field((yyvsp[-2].expression).value.object, (yyvsp[0].c_string));
2978
2979
1.27k
          if (field != NULL)
2980
1.24k
          {
2981
1.24k
            YR_ARENA_REF ref;
2982
2983
1.24k
            result = _yr_compiler_store_string(
2984
1.24k
                compiler, (yyvsp[0].c_string), &ref);
2985
2986
1.24k
            if (result == ERROR_SUCCESS)
2987
1.24k
              result = yr_parser_emit_with_arg_reloc(
2988
1.24k
                  yyscanner,
2989
1.24k
                  OP_OBJ_FIELD,
2990
1.24k
                  yr_arena_ref_to_ptr(compiler->arena, &ref),
2991
1.24k
                  NULL,
2992
1.24k
                  NULL);
2993
2994
1.24k
            (yyval.expression).type = EXPRESSION_TYPE_OBJECT;
2995
1.24k
            (yyval.expression).value.object = field;
2996
1.24k
            (yyval.expression).identifier.ref = ref;
2997
1.24k
            (yyval.expression).identifier.ptr = NULL;
2998
1.24k
          }
2999
35
          else
3000
35
          {
3001
35
            yr_compiler_set_error_extra_info(compiler, (yyvsp[0].c_string));
3002
35
            result = ERROR_INVALID_FIELD_NAME;
3003
35
          }
3004
1.27k
        }
3005
52
        else
3006
52
        {
3007
52
          yr_compiler_set_error_extra_info(
3008
52
             compiler, expression_identifier((yyvsp[-2].expression)));
3009
3010
52
          result = ERROR_NOT_A_STRUCTURE;
3011
52
        }
3012
3013
1.33k
        yr_free((yyvsp[0].c_string));
3014
3015
1.33k
        fail_if_error(result);
3016
1.24k
      }
3017
0
#line 3018 "libyara/grammar.c"
3018
0
    break;
3019
3020
64
  case 68: /* identifier: identifier '[' primary_expression ']'  */
3021
64
#line 1070 "libyara/grammar.y"
3022
64
      {
3023
64
        int result = ERROR_SUCCESS;
3024
64
        YR_OBJECT_ARRAY* array;
3025
64
        YR_OBJECT_DICTIONARY* dict;
3026
3027
64
        if ((yyvsp[-3].expression).type == EXPRESSION_TYPE_OBJECT &&
3028
64
            (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
63
        else if ((yyvsp[-3].expression).type == EXPRESSION_TYPE_OBJECT &&
3050
63
                 (yyvsp[-3].expression).value.object->type == OBJECT_TYPE_DICTIONARY)
3051
29
        {
3052
29
          if ((yyvsp[-1].expression).type != EXPRESSION_TYPE_STRING)
3053
12
          {
3054
12
            yr_compiler_set_error_extra_info(
3055
12
                compiler, "dictionary keys must be of string type");
3056
12
            result = ERROR_WRONG_TYPE;
3057
12
          }
3058
3059
29
          fail_if_error(result);
3060
3061
17
          result = yr_parser_emit(
3062
17
              yyscanner, OP_LOOKUP_DICT, NULL);
3063
3064
17
          dict = object_as_dictionary((yyvsp[-3].expression).value.object);
3065
3066
17
          (yyval.expression).type = EXPRESSION_TYPE_OBJECT;
3067
17
          (yyval.expression).value.object = dict->prototype_item;
3068
17
          (yyval.expression).identifier.ptr = dict->identifier;
3069
17
          (yyval.expression).identifier.ref = YR_ARENA_NULL_REF;
3070
17
        }
3071
34
        else
3072
34
        {
3073
34
          yr_compiler_set_error_extra_info(
3074
34
              compiler, expression_identifier((yyvsp[-3].expression)));
3075
3076
34
          result = ERROR_NOT_INDEXABLE;
3077
34
        }
3078
3079
52
        fail_if_error(result);
3080
18
      }
3081
0
#line 3082 "libyara/grammar.c"
3082
0
    break;
3083
3084
571
  case 69: /* identifier: identifier '(' arguments ')'  */
3085
571
#line 1131 "libyara/grammar.y"
3086
571
      {
3087
571
        YR_ARENA_REF ref = YR_ARENA_NULL_REF;
3088
571
        int result = ERROR_SUCCESS;
3089
3090
571
        if ((yyvsp[-3].expression).type == EXPRESSION_TYPE_OBJECT &&
3091
571
            (yyvsp[-3].expression).value.object->type == OBJECT_TYPE_FUNCTION)
3092
548
        {
3093
548
          YR_OBJECT_FUNCTION* function = object_as_function((yyvsp[-3].expression).value.object);
3094
3095
548
          result = yr_parser_check_types(compiler, function, (yyvsp[-1].c_string));
3096
3097
548
          if (result == ERROR_SUCCESS)
3098
544
            result = _yr_compiler_store_string(
3099
544
                compiler, (yyvsp[-1].c_string), &ref);
3100
3101
548
          if (result == ERROR_SUCCESS)
3102
544
            result = yr_parser_emit_with_arg_reloc(
3103
544
                yyscanner,
3104
544
                OP_CALL,
3105
544
                yr_arena_ref_to_ptr(compiler->arena, &ref),
3106
544
                NULL,
3107
544
                NULL);
3108
3109
548
          (yyval.expression).type = EXPRESSION_TYPE_OBJECT;
3110
548
          (yyval.expression).value.object = function->return_obj;
3111
548
          (yyval.expression).identifier.ref = ref;
3112
548
          (yyval.expression).identifier.ptr = NULL;
3113
548
        }
3114
23
        else
3115
23
        {
3116
23
          yr_compiler_set_error_extra_info(
3117
23
              compiler, expression_identifier((yyvsp[-3].expression)));
3118
3119
23
          result = ERROR_NOT_A_FUNCTION;
3120
23
        }
3121
3122
571
        yr_free((yyvsp[-1].c_string));
3123
3124
571
        fail_if_error(result);
3125
544
      }
3126
0
#line 3127 "libyara/grammar.c"
3127
0
    break;
3128
3129
113
  case 70: /* arguments: %empty  */
3130
113
#line 1175 "libyara/grammar.y"
3131
113
                      { (yyval.c_string) = yr_strdup(""); }
3132
113
#line 3133 "libyara/grammar.c"
3133
113
    break;
3134
3135
595
  case 71: /* arguments: arguments_list  */
3136
595
#line 1176 "libyara/grammar.y"
3137
595
                      { (yyval.c_string) = (yyvsp[0].c_string); }
3138
595
#line 3139 "libyara/grammar.c"
3139
595
    break;
3140
3141
2.52k
  case 72: /* arguments_list: expression  */
3142
2.52k
#line 1181 "libyara/grammar.y"
3143
2.52k
      {
3144
2.52k
        (yyval.c_string) = (char*) yr_malloc(YR_MAX_FUNCTION_ARGS + 1);
3145
3146
2.52k
        if ((yyval.c_string) == NULL)
3147
2.52k
          fail_with_error(ERROR_INSUFFICIENT_MEMORY);
3148
3149
2.52k
        switch((yyvsp[0].expression).type)
3150
2.52k
        {
3151
734
          case EXPRESSION_TYPE_INTEGER:
3152
734
            strlcpy((yyval.c_string), "i", YR_MAX_FUNCTION_ARGS);
3153
734
            break;
3154
488
          case EXPRESSION_TYPE_FLOAT:
3155
488
            strlcpy((yyval.c_string), "f", YR_MAX_FUNCTION_ARGS);
3156
488
            break;
3157
833
          case EXPRESSION_TYPE_BOOLEAN:
3158
833
            strlcpy((yyval.c_string), "b", YR_MAX_FUNCTION_ARGS);
3159
833
            break;
3160
428
          case EXPRESSION_TYPE_STRING:
3161
428
            strlcpy((yyval.c_string), "s", YR_MAX_FUNCTION_ARGS);
3162
428
            break;
3163
35
          case EXPRESSION_TYPE_REGEXP:
3164
35
            strlcpy((yyval.c_string), "r", YR_MAX_FUNCTION_ARGS);
3165
35
            break;
3166
10
          case EXPRESSION_TYPE_UNKNOWN:
3167
10
            yr_free((yyval.c_string));
3168
10
            yr_compiler_set_error_extra_info(
3169
10
                compiler, "unknown type for argument 1 in function call");
3170
10
            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.52k
        }
3176
2.52k
      }
3177
2.51k
#line 3178 "libyara/grammar.c"
3178
2.51k
    break;
3179
3180
18.3k
  case 73: /* arguments_list: arguments_list ',' expression  */
3181
18.3k
#line 1216 "libyara/grammar.y"
3182
18.3k
      {
3183
18.3k
        int result = ERROR_SUCCESS;
3184
3185
18.3k
        if (strlen((yyvsp[-2].c_string)) == YR_MAX_FUNCTION_ARGS)
3186
0
        {
3187
0
          result = ERROR_TOO_MANY_ARGUMENTS;
3188
0
        }
3189
18.3k
        else
3190
18.3k
        {
3191
18.3k
          switch((yyvsp[0].expression).type)
3192
18.3k
          {
3193
1.16k
            case EXPRESSION_TYPE_INTEGER:
3194
1.16k
              strlcat((yyvsp[-2].c_string), "i", YR_MAX_FUNCTION_ARGS);
3195
1.16k
              break;
3196
4.08k
            case EXPRESSION_TYPE_FLOAT:
3197
4.08k
              strlcat((yyvsp[-2].c_string), "f", YR_MAX_FUNCTION_ARGS);
3198
4.08k
              break;
3199
8.81k
            case EXPRESSION_TYPE_BOOLEAN:
3200
8.81k
              strlcat((yyvsp[-2].c_string), "b", YR_MAX_FUNCTION_ARGS);
3201
8.81k
              break;
3202
3.70k
            case EXPRESSION_TYPE_STRING:
3203
3.70k
              strlcat((yyvsp[-2].c_string), "s", YR_MAX_FUNCTION_ARGS);
3204
3.70k
              break;
3205
547
            case EXPRESSION_TYPE_REGEXP:
3206
547
              strlcat((yyvsp[-2].c_string), "r", YR_MAX_FUNCTION_ARGS);
3207
547
              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
18.3k
          }
3221
18.3k
        }
3222
3223
18.3k
        if (result != ERROR_SUCCESS)
3224
7
          yr_free((yyvsp[-2].c_string));
3225
3226
18.3k
        fail_if_error(result);
3227
3228
18.3k
        (yyval.c_string) = (yyvsp[-2].c_string);
3229
18.3k
      }
3230
0
#line 3231 "libyara/grammar.c"
3231
0
    break;
3232
3233
1.50k
  case 74: /* regexp: "regular expression"  */
3234
1.50k
#line 1269 "libyara/grammar.y"
3235
1.50k
      {
3236
1.50k
        YR_ARENA_REF re_ref;
3237
1.50k
        RE_ERROR error;
3238
3239
1.50k
        int result = ERROR_SUCCESS;
3240
1.50k
        int re_flags = 0;
3241
1.50k
        int parser_flags = RE_PARSER_FLAG_NONE;
3242
3243
1.50k
        if ((yyvsp[0].sized_string)->flags & SIZED_STRING_FLAGS_NO_CASE)
3244
28
          re_flags |= RE_FLAGS_NO_CASE;
3245
3246
1.50k
        if ((yyvsp[0].sized_string)->flags & SIZED_STRING_FLAGS_DOT_ALL)
3247
382
          re_flags |= RE_FLAGS_DOT_ALL;
3248
3249
1.50k
        if (compiler->strict_escape)
3250
0
          parser_flags |= RE_PARSER_FLAG_ENABLE_STRICT_ESCAPE_SEQUENCES;
3251
3252
1.50k
        result = yr_re_compile(
3253
1.50k
            (yyvsp[0].sized_string)->c_string,
3254
1.50k
            re_flags,
3255
1.50k
            parser_flags,
3256
1.50k
            compiler->arena,
3257
1.50k
            &re_ref,
3258
1.50k
            &error);
3259
3260
1.50k
        yr_free((yyvsp[0].sized_string));
3261
3262
1.50k
        if (result == ERROR_INVALID_REGULAR_EXPRESSION)
3263
186
          yr_compiler_set_error_extra_info(compiler, error.message);
3264
3265
1.50k
        if (result == ERROR_SUCCESS || result == ERROR_UNKNOWN_ESCAPE_SEQUENCE)
3266
1.27k
        {
3267
1.27k
          if (result == ERROR_UNKNOWN_ESCAPE_SEQUENCE)
3268
0
          {
3269
0
              yywarning(
3270
0
                yyscanner,
3271
0
                "unknown escape sequence");
3272
0
          }
3273
1.27k
          result = yr_parser_emit_with_arg_reloc(
3274
1.27k
              yyscanner,
3275
1.27k
              OP_PUSH,
3276
1.27k
              yr_arena_ref_to_ptr(compiler->arena, &re_ref),
3277
1.27k
              NULL,
3278
1.27k
              NULL);
3279
1.27k
        }
3280
3281
1.50k
        fail_if_error(result);
3282
3283
1.27k
        (yyval.expression).type = EXPRESSION_TYPE_REGEXP;
3284
1.27k
      }
3285
0
#line 3286 "libyara/grammar.c"
3286
0
    break;
3287
3288
21.3k
  case 75: /* boolean_expression: expression  */
3289
21.3k
#line 1324 "libyara/grammar.y"
3290
21.3k
      {
3291
21.3k
        if ((yyvsp[0].expression).type == EXPRESSION_TYPE_STRING)
3292
250
        {
3293
250
          if (!YR_ARENA_IS_NULL_REF((yyvsp[0].expression).value.sized_string_ref))
3294
162
          {
3295
162
            SIZED_STRING* sized_string = yr_arena_ref_to_ptr(
3296
162
                compiler->arena, &(yyvsp[0].expression).value.sized_string_ref);
3297
3298
162
            yywarning(yyscanner,
3299
162
                "using literal string \"%s\" in a boolean operation.",
3300
162
                sized_string->c_string);
3301
162
          }
3302
3303
250
          fail_if_error(yr_parser_emit(
3304
250
              yyscanner, OP_STR_TO_BOOL, NULL));
3305
250
        }
3306
21.3k
        if ((yyvsp[0].expression).type != EXPRESSION_TYPE_BOOLEAN)
3307
1.77k
        {
3308
1.77k
          (yyval.expression).required_strings.count = 0;
3309
1.77k
        }
3310
19.5k
        else
3311
19.5k
        {
3312
19.5k
          (yyval.expression).required_strings.count = (yyvsp[0].expression).required_strings.count;
3313
19.5k
        }
3314
3315
21.3k
        (yyval.expression).type = EXPRESSION_TYPE_BOOLEAN;
3316
21.3k
      }
3317
0
#line 3318 "libyara/grammar.c"
3318
0
    break;
3319
3320
27
  case 76: /* expression: "<true>"  */
3321
27
#line 1355 "libyara/grammar.y"
3322
27
      {
3323
27
        fail_if_error(yr_parser_emit_push_const(yyscanner, 1));
3324
3325
27
        (yyval.expression).type = EXPRESSION_TYPE_BOOLEAN;
3326
27
        (yyval.expression).required_strings.count = 0;
3327
27
      }
3328
0
#line 3329 "libyara/grammar.c"
3329
0
    break;
3330
3331
132
  case 77: /* expression: "<false>"  */
3332
132
#line 1362 "libyara/grammar.y"
3333
132
      {
3334
132
        fail_if_error(yr_parser_emit_push_const(yyscanner, 0));
3335
3336
132
        (yyval.expression).type = EXPRESSION_TYPE_BOOLEAN;
3337
132
        (yyval.expression).required_strings.count = 0;
3338
132
      }
3339
0
#line 3340 "libyara/grammar.c"
3340
0
    break;
3341
3342
24
  case 78: /* expression: primary_expression "<matches>" regexp  */
3343
24
#line 1369 "libyara/grammar.y"
3344
24
      {
3345
24
        check_type((yyvsp[-2].expression), EXPRESSION_TYPE_STRING, "matches");
3346
12
        check_type((yyvsp[0].expression), EXPRESSION_TYPE_REGEXP, "matches");
3347
3348
12
        fail_if_error(yr_parser_emit(
3349
12
            yyscanner,
3350
12
            OP_MATCHES,
3351
12
            NULL));
3352
3353
12
        (yyval.expression).type = EXPRESSION_TYPE_BOOLEAN;
3354
12
        (yyval.expression).required_strings.count = 0;
3355
12
      }
3356
0
#line 3357 "libyara/grammar.c"
3357
0
    break;
3358
3359
232
  case 79: /* expression: primary_expression "<contains>" primary_expression  */
3360
232
#line 1382 "libyara/grammar.y"
3361
232
      {
3362
232
        check_type((yyvsp[-2].expression), EXPRESSION_TYPE_STRING, "contains");
3363
203
        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
264
  case 80: /* expression: primary_expression "<icontains>" primary_expression  */
3375
264
#line 1393 "libyara/grammar.y"
3376
264
      {
3377
264
        check_type((yyvsp[-2].expression), EXPRESSION_TYPE_STRING, "icontains");
3378
226
        check_type((yyvsp[0].expression), EXPRESSION_TYPE_STRING, "icontains");
3379
3380
188
        fail_if_error(yr_parser_emit(
3381
188
            yyscanner, OP_ICONTAINS, NULL));
3382
3383
188
        (yyval.expression).type = EXPRESSION_TYPE_BOOLEAN;
3384
188
        (yyval.expression).required_strings.count = 0;
3385
188
      }
3386
0
#line 3387 "libyara/grammar.c"
3387
0
    break;
3388
3389
215
  case 81: /* expression: primary_expression "<startswith>" primary_expression  */
3390
215
#line 1404 "libyara/grammar.y"
3391
215
      {
3392
215
        check_type((yyvsp[-2].expression), EXPRESSION_TYPE_STRING, "startswith");
3393
195
        check_type((yyvsp[0].expression), EXPRESSION_TYPE_STRING, "startswith");
3394
3395
187
        fail_if_error(yr_parser_emit(
3396
187
            yyscanner, OP_STARTSWITH, NULL));
3397
3398
187
        (yyval.expression).type = EXPRESSION_TYPE_BOOLEAN;
3399
187
        (yyval.expression).required_strings.count = 0;
3400
187
      }
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
68
        check_type((yyvsp[0].expression), EXPRESSION_TYPE_STRING, "istartswith");
3409
3410
59
        fail_if_error(yr_parser_emit(
3411
59
            yyscanner, OP_ISTARTSWITH, NULL));
3412
3413
59
        (yyval.expression).type = EXPRESSION_TYPE_BOOLEAN;
3414
59
        (yyval.expression).required_strings.count = 0;
3415
59
      }
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
91
  case 84: /* expression: primary_expression "<iendswith>" primary_expression  */
3435
91
#line 1437 "libyara/grammar.y"
3436
91
      {
3437
91
        check_type((yyvsp[-2].expression), EXPRESSION_TYPE_STRING, "iendswith");
3438
77
        check_type((yyvsp[0].expression), EXPRESSION_TYPE_STRING, "iendswith");
3439
3440
52
        fail_if_error(yr_parser_emit(
3441
52
            yyscanner, OP_IENDSWITH, NULL));
3442
3443
52
        (yyval.expression).type = EXPRESSION_TYPE_BOOLEAN;
3444
52
        (yyval.expression).required_strings.count = 0;
3445
52
      }
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
464
  case 86: /* expression: "string identifier"  */
3465
464
#line 1459 "libyara/grammar.y"
3466
464
      {
3467
464
        int result = yr_parser_reduce_string_identifier(
3468
464
            yyscanner,
3469
464
            (yyvsp[0].c_string),
3470
464
            OP_FOUND,
3471
464
            YR_UNDEFINED);
3472
3473
464
        yr_free((yyvsp[0].c_string));
3474
3475
464
        fail_if_error(result);
3476
3477
392
        (yyval.expression).type = EXPRESSION_TYPE_BOOLEAN;
3478
392
        (yyval.expression).required_strings.count = 1;
3479
392
      }
3480
0
#line 3481 "libyara/grammar.c"
3481
0
    break;
3482
3483
856
  case 87: /* expression: "string identifier" "<at>" primary_expression  */
3484
856
#line 1474 "libyara/grammar.y"
3485
856
      {
3486
856
        int result;
3487
3488
856
        check_type_with_cleanup((yyvsp[0].expression), EXPRESSION_TYPE_INTEGER, "at", yr_free((yyvsp[-2].c_string)));
3489
3490
850
        result = yr_parser_reduce_string_identifier(
3491
850
            yyscanner, (yyvsp[-2].c_string), OP_FOUND_AT, (yyvsp[0].expression).value.integer);
3492
3493
850
        yr_free((yyvsp[-2].c_string));
3494
3495
850
        fail_if_error(result);
3496
3497
848
        (yyval.expression).required_strings.count = 1;
3498
848
        (yyval.expression).type = EXPRESSION_TYPE_BOOLEAN;
3499
848
      }
3500
0
#line 3501 "libyara/grammar.c"
3501
0
    break;
3502
3503
32
  case 88: /* expression: "string identifier" "<in>" range  */
3504
32
#line 1490 "libyara/grammar.y"
3505
32
      {
3506
32
        int result = yr_parser_reduce_string_identifier(
3507
32
            yyscanner, (yyvsp[-2].c_string), OP_FOUND_IN, YR_UNDEFINED);
3508
3509
32
        yr_free((yyvsp[-2].c_string));
3510
3511
32
        fail_if_error(result);
3512
3513
20
        (yyval.expression).required_strings.count = 1;
3514
20
        (yyval.expression).type = EXPRESSION_TYPE_BOOLEAN;
3515
20
      }
3516
0
#line 3517 "libyara/grammar.c"
3517
0
    break;
3518
3519
1.91k
  case 89: /* expression: "<for>" for_expression error  */
3520
1.91k
#line 1502 "libyara/grammar.y"
3521
1.91k
      {
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.79k
        for (int i = 0; i <= compiler->loop_index; i++)
3530
1.88k
        {
3531
1.88k
          loop_vars_cleanup(i);
3532
1.88k
        }
3533
3534
1.91k
        compiler->loop_index = -1;
3535
1.91k
        YYERROR;
3536
32
      }
3537
0
#line 3538 "libyara/grammar.c"
3538
0
    break;
3539
3540
2.02k
  case 90: /* $@6: %empty  */
3541
2.02k
#line 1576 "libyara/grammar.y"
3542
2.02k
      {
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
2.02k
        int var_frame;
3550
2.02k
        int result = ERROR_SUCCESS;
3551
3552
2.02k
        if (compiler->loop_index + 1 == YR_MAX_LOOP_NESTING)
3553
14
          result = ERROR_LOOP_NESTING_LIMIT_EXCEEDED;
3554
3555
2.02k
        fail_if_error(result);
3556
3557
2.00k
        compiler->loop_index++;
3558
3559
        // This loop uses internal variables besides the ones explicitly
3560
        // defined by the user.
3561
2.00k
        compiler->loop[compiler->loop_index].vars_internal_count = \
3562
2.00k
            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
2.00k
        compiler->loop[compiler->loop_index].vars_count = 0;
3567
3568
2.00k
        var_frame = _yr_compiler_get_var_frame(compiler);
3569
3570
2.00k
        fail_if_error(yr_parser_emit_with_arg(
3571
2.00k
            yyscanner, OP_CLEAR_M, var_frame + 0, NULL, NULL));
3572
3573
2.00k
        fail_if_error(yr_parser_emit_with_arg(
3574
2.00k
            yyscanner, OP_CLEAR_M, var_frame + 1, NULL, NULL));
3575
3576
2.00k
        fail_if_error(yr_parser_emit_with_arg(
3577
2.00k
            yyscanner, OP_POP_M, var_frame + 2, NULL, NULL));
3578
2.00k
      }
3579
0
#line 3580 "libyara/grammar.c"
3580
0
    break;
3581
3582
819
  case 91: /* $@7: %empty  */
3583
819
#line 1614 "libyara/grammar.y"
3584
819
      {
3585
819
        YR_LOOP_CONTEXT* loop_ctx = &compiler->loop[compiler->loop_index];
3586
819
        YR_FIXUP* fixup;
3587
3588
819
        YR_ARENA_REF loop_start_ref;
3589
819
        YR_ARENA_REF jmp_offset_ref;
3590
3591
819
        int var_frame = _yr_compiler_get_var_frame(compiler);
3592
3593
819
        fail_if_error(yr_parser_emit(
3594
819
            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.76k
        for (int i = 0; i < loop_ctx->vars_count; i++)
3602
950
        {
3603
950
          fail_if_error(yr_parser_emit_with_arg(
3604
950
              yyscanner,
3605
950
              OP_POP_M,
3606
950
              var_frame + YR_INTERNAL_LOOP_VARS + i,
3607
950
              NULL,
3608
950
              NULL));
3609
950
        }
3610
3611
819
        fail_if_error(yr_parser_emit_with_arg_int32(
3612
819
            yyscanner,
3613
819
            OP_JTRUE_P,
3614
819
            0,              // still don't know the jump offset, use 0 for now.
3615
819
            NULL,
3616
819
            &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
819
        fixup = (YR_FIXUP*) yr_malloc(sizeof(YR_FIXUP));
3622
3623
819
        if (fixup == NULL)
3624
819
          fail_with_error(ERROR_INSUFFICIENT_MEMORY);
3625
3626
819
        fixup->ref = jmp_offset_ref;
3627
819
        fixup->next = compiler->fixup_stack_head;
3628
819
        compiler->fixup_stack_head = fixup;
3629
3630
819
        loop_ctx->start_ref = loop_start_ref;
3631
819
      }
3632
0
#line 3633 "libyara/grammar.c"
3633
0
    break;
3634
3635
127
  case 92: /* expression: "<for>" for_expression $@6 for_iteration ':' $@7 '(' boolean_expression ')'  */
3636
127
#line 1663 "libyara/grammar.y"
3637
127
      {
3638
127
        int32_t jmp_offset;
3639
127
        YR_FIXUP* fixup;
3640
127
        YR_ARENA_REF pop_ref;
3641
3642
127
        int var_frame = _yr_compiler_get_var_frame(compiler);
3643
3644
127
        if ((yyvsp[-5].integer) == FOR_ITERATION_STRING_SET)
3645
41
        {
3646
41
          compiler->loop_for_of_var_index = -1;
3647
41
        }
3648
3649
127
        fail_if_error(yr_parser_emit_with_arg(
3650
127
            yyscanner, OP_INCR_M, var_frame + 1, NULL, NULL));
3651
3652
127
        fail_if_error(yr_parser_emit_with_arg(
3653
127
            yyscanner, OP_PUSH_M, var_frame + 0, NULL, NULL));
3654
3655
127
        fail_if_error(yr_parser_emit_with_arg(
3656
127
            yyscanner, OP_PUSH_M, var_frame + 2, NULL, NULL));
3657
3658
127
        fail_if_error(yr_parser_emit(yyscanner, OP_ITER_CONDITION, NULL));
3659
3660
127
        fail_if_error(yr_parser_emit_with_arg(
3661
127
            yyscanner, OP_ADD_M, var_frame + 0, NULL, NULL));
3662
3663
127
        jmp_offset = \
3664
127
            compiler->loop[compiler->loop_index].start_ref.offset -
3665
127
            yr_arena_get_current_offset(compiler->arena, YR_CODE_SECTION);
3666
3667
127
        fail_if_error(yr_parser_emit_with_arg_int32(
3668
127
            yyscanner,
3669
127
            OP_JTRUE_P,
3670
127
            jmp_offset,
3671
127
            NULL,
3672
127
            NULL));
3673
3674
127
        fail_if_error(yr_parser_emit(
3675
127
            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
127
        fixup = compiler->fixup_stack_head;
3681
127
        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
127
        int32_t* jmp_offset_addr = (int32_t*) yr_arena_ref_to_ptr(
3686
127
            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
127
        jmp_offset = pop_ref.offset - fixup->ref.offset + 1;
3692
3693
        // Fix the jump's offset.
3694
127
        memcpy(jmp_offset_addr, &jmp_offset, sizeof(jmp_offset));
3695
3696
127
        yr_free(fixup);
3697
3698
127
        fail_if_error(yr_parser_emit_with_arg(
3699
127
            yyscanner, OP_PUSH_M, var_frame + 1, NULL, NULL));
3700
3701
127
        fail_if_error(yr_parser_emit_with_arg(
3702
127
            yyscanner, OP_PUSH_M, var_frame + 0, NULL, NULL));
3703
3704
127
        fail_if_error(yr_parser_emit_with_arg(
3705
127
            yyscanner, OP_PUSH_M, var_frame + 2, NULL, NULL));
3706
3707
127
        fail_if_error(yr_parser_emit(
3708
127
            yyscanner, OP_ITER_END, NULL));
3709
3710
127
        loop_vars_cleanup(compiler->loop_index);
3711
3712
127
        compiler->loop_index--;
3713
3714
127
        (yyval.expression).type = EXPRESSION_TYPE_BOOLEAN;
3715
127
        (yyval.expression).required_strings.count = 0;
3716
127
      }
3717
0
#line 3718 "libyara/grammar.c"
3718
0
    break;
3719
3720
1.45k
  case 93: /* expression: for_expression "<of>" string_set  */
3721
1.45k
#line 1744 "libyara/grammar.y"
3722
1.45k
      {
3723
1.45k
        if ((yyvsp[-2].expression).type == EXPRESSION_TYPE_INTEGER && (yyvsp[-2].expression).value.integer > (yyvsp[0].integer))
3724
735
        {
3725
735
          yywarning(yyscanner,
3726
735
            "expression always false - requesting %" PRId64 " of %" PRId64 ".", (yyvsp[-2].expression).value.integer, (yyvsp[0].integer));
3727
735
        }
3728
3729
1.45k
        if (((yyvsp[-2].expression).type == EXPRESSION_TYPE_INTEGER && (yyvsp[-2].expression).value.integer > 0) ||
3730
1.45k
              ((yyvsp[-2].expression).type == EXPRESSION_TYPE_QUANTIFIER &&
3731
184
                  ((yyvsp[-2].expression).value.integer == FOR_EXPRESSION_ALL || (yyvsp[-2].expression).value.integer == FOR_EXPRESSION_ANY)))
3732
1.40k
        {
3733
1.40k
          (yyval.expression).required_strings.count = 1;
3734
1.40k
        }
3735
53
        else
3736
53
        {
3737
53
          (yyval.expression).required_strings.count = 0;
3738
53
        }
3739
3740
1.45k
        yr_parser_emit_with_arg(yyscanner, OP_OF, OF_STRING_SET, NULL, NULL);
3741
3742
1.45k
        (yyval.expression).type = EXPRESSION_TYPE_BOOLEAN;
3743
1.45k
      }
3744
1.45k
#line 3745 "libyara/grammar.c"
3745
1.45k
    break;
3746
3747
90
  case 94: /* expression: for_expression "<of>" rule_set  */
3748
90
#line 1767 "libyara/grammar.y"
3749
90
      {
3750
90
        if ((yyvsp[-2].expression).type == EXPRESSION_TYPE_INTEGER && (yyvsp[-2].expression).value.integer > (yyvsp[0].integer))
3751
4
        {
3752
4
          yywarning(yyscanner,
3753
4
            "expression always false - requesting %" PRId64 " of %" PRId64 ".", (yyvsp[-2].expression).value.integer, (yyvsp[0].integer));
3754
4
        }
3755
90
        yr_parser_emit_with_arg(yyscanner, OP_OF, OF_RULE_SET, NULL, NULL);
3756
3757
90
        (yyval.expression).type = EXPRESSION_TYPE_BOOLEAN;
3758
90
        (yyval.expression).required_strings.count = 0;
3759
90
      }
3760
90
#line 3761 "libyara/grammar.c"
3761
90
    break;
3762
3763
33
  case 95: /* expression: primary_expression '%' "<of>" string_set  */
3764
33
#line 1779 "libyara/grammar.y"
3765
33
      {
3766
33
        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
22
        if (!IS_UNDEFINED((yyvsp[-3].expression).value.integer) &&
3773
22
            ((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
6
        if (!IS_UNDEFINED((yyvsp[-3].expression).value.integer))
3782
2
        {
3783
2
          (yyval.expression).required_strings.count = 1;
3784
2
        }
3785
4
        else
3786
4
        {
3787
4
          (yyval.expression).required_strings.count = 0;
3788
4
        }
3789
3790
6
        yr_parser_emit_with_arg(yyscanner, OP_OF_PERCENT, OF_STRING_SET, NULL, NULL);
3791
6
      }
3792
0
#line 3793 "libyara/grammar.c"
3793
0
    break;
3794
3795
33
  case 96: /* expression: primary_expression '%' "<of>" rule_set  */
3796
33
#line 1807 "libyara/grammar.y"
3797
33
      {
3798
33
        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
28
        if (!IS_UNDEFINED((yyvsp[-3].expression).value.integer) &&
3805
28
            ((yyvsp[-3].expression).value.integer < 1 || (yyvsp[-3].expression).value.integer > 100))
3806
6
        {
3807
6
          yr_compiler_set_error_extra_info(
3808
6
              compiler, "percentage must be between 1 and 100 (inclusive)");
3809
3810
6
          fail_with_error(ERROR_INVALID_PERCENTAGE);
3811
0
        }
3812
3813
22
        yr_parser_emit_with_arg(yyscanner, OP_OF_PERCENT, OF_RULE_SET, NULL, NULL);
3814
22
      }
3815
0
#line 3816 "libyara/grammar.c"
3816
0
    break;
3817
3818
133
  case 97: /* expression: for_expression "<of>" string_set "<in>" range  */
3819
133
#line 1826 "libyara/grammar.y"
3820
133
      {
3821
133
        if ((yyvsp[-4].expression).type == EXPRESSION_TYPE_INTEGER && (yyvsp[-4].expression).value.integer > (yyvsp[-2].integer))
3822
4
        {
3823
4
          yywarning(yyscanner,
3824
4
            "expression always false - requesting %" PRId64 " of %" PRId64 ".", (yyvsp[-4].expression).value.integer, (yyvsp[-2].integer));
3825
4
        }
3826
3827
133
        if (((yyvsp[-4].expression).type == EXPRESSION_TYPE_INTEGER && (yyvsp[-4].expression).value.integer > 0) ||
3828
133
              ((yyvsp[-4].expression).type == EXPRESSION_TYPE_QUANTIFIER &&
3829
129
                  ((yyvsp[-4].expression).value.integer == FOR_EXPRESSION_ALL || (yyvsp[-4].expression).value.integer == FOR_EXPRESSION_ANY)))
3830
98
        {
3831
98
          (yyval.expression).required_strings.count = 1;
3832
98
        }
3833
35
        else
3834
35
        {
3835
35
          (yyval.expression).required_strings.count = 0;
3836
35
        }
3837
3838
133
        yr_parser_emit(yyscanner, OP_OF_FOUND_IN, NULL);
3839
3840
133
        (yyval.expression).type = EXPRESSION_TYPE_BOOLEAN;
3841
133
      }
3842
133
#line 3843 "libyara/grammar.c"
3843
133
    break;
3844
3845
6.54k
  case 98: /* expression: for_expression "<of>" string_set "<at>" primary_expression  */
3846
6.54k
#line 1849 "libyara/grammar.y"
3847
6.54k
      {
3848
6.54k
        if ((yyvsp[0].expression).type != EXPRESSION_TYPE_INTEGER)
3849
6
        {
3850
6
          yr_compiler_set_error_extra_info(compiler,
3851
6
              "at expression must be an integer");
3852
3853
6
          fail_with_error(ERROR_INVALID_VALUE);
3854
0
        }
3855
3856
6.53k
        if ((yyvsp[-4].expression).type == EXPRESSION_TYPE_INTEGER && (yyvsp[-4].expression).value.integer > (yyvsp[-2].integer))
3857
368
        {
3858
368
          yywarning(yyscanner,
3859
368
            "expression always false - requesting %" PRId64 " of %" PRId64 ".", (yyvsp[-4].expression).value.integer, (yyvsp[-2].integer));
3860
368
        }
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
6.53k
        if (((yyvsp[-4].expression).type == EXPRESSION_TYPE_INTEGER &&
3871
6.53k
              !IS_UNDEFINED((yyvsp[-4].expression).value.integer) && (yyvsp[-4].expression).value.integer > 1) ||
3872
6.53k
              ((yyvsp[-4].expression).type == EXPRESSION_TYPE_QUANTIFIER &&
3873
6.17k
              (yyvsp[-4].expression).value.integer == FOR_EXPRESSION_ALL && (yyvsp[-2].integer) > 1))
3874
875
        {
3875
875
          yywarning(yyscanner,
3876
875
            "multiple strings at an offset is usually false.");
3877
875
        }
3878
3879
6.53k
        if (((yyvsp[-4].expression).type == EXPRESSION_TYPE_INTEGER && (yyvsp[-4].expression).value.integer > 0) ||
3880
6.53k
              ((yyvsp[-4].expression).type == EXPRESSION_TYPE_QUANTIFIER &&
3881
4.23k
                  ((yyvsp[-4].expression).value.integer == FOR_EXPRESSION_ALL || (yyvsp[-4].expression).value.integer == FOR_EXPRESSION_ANY)))
3882
5.15k
        {
3883
5.15k
          (yyval.expression).required_strings.count = 1;
3884
5.15k
        }
3885
1.38k
        else
3886
1.38k
        {
3887
1.38k
          (yyval.expression).required_strings.count = 0;
3888
1.38k
        }
3889
3890
6.53k
        yr_parser_emit(yyscanner, OP_OF_FOUND_AT, NULL);
3891
3892
6.53k
        (yyval.expression).type = EXPRESSION_TYPE_BOOLEAN;
3893
6.53k
      }
3894
0
#line 3895 "libyara/grammar.c"
3895
0
    break;
3896
3897
200
  case 99: /* expression: "<not>" boolean_expression  */
3898
200
#line 1897 "libyara/grammar.y"
3899
200
      {
3900
200
        yr_parser_emit(yyscanner, OP_NOT, NULL);
3901
3902
200
        (yyval.expression).type = EXPRESSION_TYPE_BOOLEAN;
3903
200
        (yyval.expression).required_strings.count = 0;
3904
200
      }
3905
200
#line 3906 "libyara/grammar.c"
3906
200
    break;
3907
3908
1
  case 100: /* expression: "<defined>" boolean_expression  */
3909
1
#line 1904 "libyara/grammar.y"
3910
1
      {
3911
1
        yr_parser_emit(yyscanner, OP_DEFINED, NULL);
3912
1
        (yyval.expression).type = EXPRESSION_TYPE_BOOLEAN;
3913
1
        (yyval.expression).required_strings.count = 0;
3914
1
      }
3915
1
#line 3916 "libyara/grammar.c"
3916
1
    break;
3917
3918
562
  case 101: /* $@8: %empty  */
3919
562
#line 1910 "libyara/grammar.y"
3920
562
      {
3921
562
        YR_FIXUP* fixup;
3922
562
        YR_ARENA_REF jmp_offset_ref;
3923
3924
562
        fail_if_error(yr_parser_emit_with_arg_int32(
3925
562
            yyscanner,
3926
562
            OP_JFALSE,
3927
562
            0,          // still don't know the jump offset, use 0 for now.
3928
562
            NULL,
3929
562
            &jmp_offset_ref));
3930
3931
        // Create a fixup entry for the jump and push it in the stack.
3932
562
        fixup = (YR_FIXUP*) yr_malloc(sizeof(YR_FIXUP));
3933
3934
562
        if (fixup == NULL)
3935
562
          fail_with_error(ERROR_INSUFFICIENT_MEMORY);
3936
3937
562
        fixup->ref = jmp_offset_ref;
3938
562
        fixup->next = compiler->fixup_stack_head;
3939
562
        compiler->fixup_stack_head = fixup;
3940
562
      }
3941
0
#line 3942 "libyara/grammar.c"
3942
0
    break;
3943
3944
560
  case 102: /* expression: boolean_expression "<and>" $@8 boolean_expression  */
3945
560
#line 1932 "libyara/grammar.y"
3946
560
      {
3947
560
        YR_FIXUP* fixup;
3948
3949
560
        fail_if_error(yr_parser_emit(yyscanner, OP_AND, NULL));
3950
3951
560
        fixup = compiler->fixup_stack_head;
3952
3953
560
        int32_t* jmp_offset_addr = (int32_t*) yr_arena_ref_to_ptr(
3954
560
            compiler->arena, &fixup->ref);
3955
3956
560
        int32_t jmp_offset = \
3957
560
            yr_arena_get_current_offset(compiler->arena, YR_CODE_SECTION) -
3958
560
            fixup->ref.offset + 1;
3959
3960
560
        memcpy(jmp_offset_addr, &jmp_offset, sizeof(jmp_offset));
3961
3962
        // Remove fixup from the stack.
3963
560
        compiler->fixup_stack_head = fixup->next;
3964
560
        yr_free(fixup);
3965
3966
560
        (yyval.expression).type = EXPRESSION_TYPE_BOOLEAN;
3967
560
        (yyval.expression).required_strings.count = (yyvsp[0].expression).required_strings.count + (yyvsp[-3].expression).required_strings.count;
3968
560
      }
3969
0
#line 3970 "libyara/grammar.c"
3970
0
    break;
3971
3972
10.0k
  case 103: /* $@9: %empty  */
3973
10.0k
#line 1956 "libyara/grammar.y"
3974
10.0k
      {
3975
10.0k
        YR_FIXUP* fixup;
3976
10.0k
        YR_ARENA_REF jmp_offset_ref;
3977
3978
10.0k
        fail_if_error(yr_parser_emit_with_arg_int32(
3979
10.0k
            yyscanner,
3980
10.0k
            OP_JTRUE,
3981
10.0k
            0,         // still don't know the jump destination, use 0 for now.
3982
10.0k
            NULL,
3983
10.0k
            &jmp_offset_ref));
3984
3985
10.0k
        fixup = (YR_FIXUP*) yr_malloc(sizeof(YR_FIXUP));
3986
3987
10.0k
        if (fixup == NULL)
3988
10.0k
          fail_with_error(ERROR_INSUFFICIENT_MEMORY);
3989
3990
10.0k
        fixup->ref = jmp_offset_ref;
3991
10.0k
        fixup->next = compiler->fixup_stack_head;
3992
10.0k
        compiler->fixup_stack_head = fixup;
3993
10.0k
      }
3994
0
#line 3995 "libyara/grammar.c"
3995
0
    break;
3996
3997
8.69k
  case 104: /* expression: boolean_expression "<or>" $@9 boolean_expression  */
3998
8.69k
#line 1977 "libyara/grammar.y"
3999
8.69k
      {
4000
8.69k
        YR_FIXUP* fixup;
4001
4002
8.69k
        fail_if_error(yr_parser_emit(yyscanner, OP_OR, NULL));
4003
4004
8.69k
        fixup = compiler->fixup_stack_head;
4005
4006
8.69k
        int32_t jmp_offset = \
4007
8.69k
            yr_arena_get_current_offset(compiler->arena, YR_CODE_SECTION) -
4008
8.69k
            fixup->ref.offset + 1;
4009
4010
8.69k
        int32_t* jmp_offset_addr = (int32_t*) yr_arena_ref_to_ptr(
4011
8.69k
            compiler->arena, &fixup->ref);
4012
4013
8.69k
        memcpy(jmp_offset_addr, &jmp_offset, sizeof(jmp_offset));
4014
4015
        // Remove fixup from the stack.
4016
8.69k
        compiler->fixup_stack_head = fixup->next;
4017
8.69k
        yr_free(fixup);
4018
4019
8.69k
        (yyval.expression).type = EXPRESSION_TYPE_BOOLEAN;
4020
4021
        // Set required string count to minimum from both parts
4022
8.69k
        if ((yyvsp[-3].expression).required_strings.count > (yyvsp[0].expression).required_strings.count) {
4023
210
          (yyval.expression).required_strings.count = (yyvsp[0].expression).required_strings.count;
4024
8.48k
        } else {
4025
8.48k
          (yyval.expression).required_strings.count = (yyvsp[-3].expression).required_strings.count;
4026
8.48k
        }
4027
8.69k
      }
4028
0
#line 4029 "libyara/grammar.c"
4029
0
    break;
4030
4031
1.26k
  case 105: /* expression: primary_expression "<" primary_expression  */
4032
1.26k
#line 2007 "libyara/grammar.y"
4033
1.26k
      {
4034
1.26k
        fail_if_error(yr_parser_reduce_operation(
4035
1.26k
            yyscanner, "<", (yyvsp[-2].expression), (yyvsp[0].expression)));
4036
4037
1.26k
        (yyval.expression).type = EXPRESSION_TYPE_BOOLEAN;
4038
1.26k
        (yyval.expression).required_strings.count = 0;
4039
1.26k
      }
4040
0
#line 4041 "libyara/grammar.c"
4041
0
    break;
4042
4043
1.12k
  case 106: /* expression: primary_expression ">" primary_expression  */
4044
1.12k
#line 2015 "libyara/grammar.y"
4045
1.12k
      {
4046
1.12k
        fail_if_error(yr_parser_reduce_operation(
4047
1.12k
            yyscanner, ">", (yyvsp[-2].expression), (yyvsp[0].expression)));
4048
4049
1.08k
        (yyval.expression).type = EXPRESSION_TYPE_BOOLEAN;
4050
1.08k
        (yyval.expression).required_strings.count = 0;
4051
1.08k
      }
4052
0
#line 4053 "libyara/grammar.c"
4053
0
    break;
4054
4055
921
  case 107: /* expression: primary_expression "<=" primary_expression  */
4056
921
#line 2023 "libyara/grammar.y"
4057
921
      {
4058
921
        fail_if_error(yr_parser_reduce_operation(
4059
921
            yyscanner, "<=", (yyvsp[-2].expression), (yyvsp[0].expression)));
4060
4061
921
        (yyval.expression).type = EXPRESSION_TYPE_BOOLEAN;
4062
921
        (yyval.expression).required_strings.count = 0;
4063
921
      }
4064
0
#line 4065 "libyara/grammar.c"
4065
0
    break;
4066
4067
539
  case 108: /* expression: primary_expression ">=" primary_expression  */
4068
539
#line 2031 "libyara/grammar.y"
4069
539
      {
4070
539
        fail_if_error(yr_parser_reduce_operation(
4071
539
            yyscanner, ">=", (yyvsp[-2].expression), (yyvsp[0].expression)));
4072
4073
532
        (yyval.expression).type = EXPRESSION_TYPE_BOOLEAN;
4074
532
        (yyval.expression).required_strings.count = 0;
4075
532
      }
4076
0
#line 4077 "libyara/grammar.c"
4077
0
    break;
4078
4079
1.44k
  case 109: /* expression: primary_expression "==" primary_expression  */
4080
1.44k
#line 2039 "libyara/grammar.y"
4081
1.44k
      {
4082
1.44k
        fail_if_error(yr_parser_reduce_operation(
4083
1.44k
            yyscanner, "==", (yyvsp[-2].expression), (yyvsp[0].expression)));
4084
4085
1.44k
        (yyval.expression).type = EXPRESSION_TYPE_BOOLEAN;
4086
1.44k
        (yyval.expression).required_strings.count = 0;
4087
1.44k
      }
4088
0
#line 4089 "libyara/grammar.c"
4089
0
    break;
4090
4091
750
  case 110: /* expression: primary_expression "!=" primary_expression  */
4092
750
#line 2047 "libyara/grammar.y"
4093
750
      {
4094
750
        fail_if_error(yr_parser_reduce_operation(
4095
750
            yyscanner, "!=", (yyvsp[-2].expression), (yyvsp[0].expression)));
4096
4097
743
        (yyval.expression).type = EXPRESSION_TYPE_BOOLEAN;
4098
743
        (yyval.expression).required_strings.count = 0;
4099
743
      }
4100
0
#line 4101 "libyara/grammar.c"
4101
0
    break;
4102
4103
16.2k
  case 111: /* expression: primary_expression  */
4104
16.2k
#line 2055 "libyara/grammar.y"
4105
16.2k
      {
4106
16.2k
        (yyval.expression) = (yyvsp[0].expression);
4107
16.2k
      }
4108
16.2k
#line 4109 "libyara/grammar.c"
4109
16.2k
    break;
4110
4111
350
  case 112: /* expression: '(' expression ')'  */
4112
350
#line 2059 "libyara/grammar.y"
4113
350
      {
4114
350
        (yyval.expression) = (yyvsp[-1].expression);
4115
350
      }
4116
350
#line 4117 "libyara/grammar.c"
4117
350
    break;
4118
4119
737
  case 113: /* for_iteration: for_variables "<in>" iterator  */
4120
737
#line 2066 "libyara/grammar.y"
4121
737
                                  { (yyval.integer) = FOR_ITERATION_ITERATOR; }
4122
737
#line 4123 "libyara/grammar.c"
4123
737
    break;
4124
4125
212
  case 114: /* for_iteration: "<of>" string_iterator  */
4126
212
#line 2068 "libyara/grammar.y"
4127
212
      {
4128
212
        int var_frame;
4129
212
        int result = ERROR_SUCCESS;
4130
4131
212
        if (compiler->loop_for_of_var_index != -1)
4132
33
          result = ERROR_NESTED_FOR_OF_LOOP;
4133
4134
212
        fail_if_error(result);
4135
4136
        // Simulate that we have 1 variable with string loops
4137
179
        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
179
        var_frame = _yr_compiler_get_var_frame(compiler);
4142
179
        compiler->loop_for_of_var_index = var_frame +
4143
179
            compiler->loop[compiler->loop_index].vars_internal_count;
4144
4145
179
        (yyval.integer) = FOR_ITERATION_STRING_SET;
4146
179
      }
4147
0
#line 4148 "libyara/grammar.c"
4148
0
    break;
4149
4150
1.77k
  case 115: /* for_variables: "identifier"  */
4151
1.77k
#line 2093 "libyara/grammar.y"
4152
1.77k
      {
4153
1.77k
        int result = ERROR_SUCCESS;
4154
4155
1.77k
        YR_LOOP_CONTEXT* loop_ctx = &compiler->loop[compiler->loop_index];
4156
4157
1.77k
        if (yr_parser_lookup_loop_variable(yyscanner, (yyvsp[0].c_string), NULL) >= 0)
4158
18
        {
4159
18
          yr_compiler_set_error_extra_info(compiler, (yyvsp[0].c_string));
4160
18
          yr_free((yyvsp[0].c_string));
4161
4162
18
          result = ERROR_DUPLICATED_LOOP_IDENTIFIER;
4163
18
        }
4164
4165
1.77k
        fail_if_error(result);
4166
4167
1.76k
        loop_ctx->vars[loop_ctx->vars_count++].identifier.ptr = (yyvsp[0].c_string);
4168
4169
1.76k
        assert(loop_ctx->vars_count <= YR_MAX_LOOP_VARS);
4170
1.76k
      }
4171
1.76k
#line 4172 "libyara/grammar.c"
4172
1.76k
    break;
4173
4174
1.76k
  case 116: /* for_variables: for_variables ',' "identifier"  */
4175
318
#line 2113 "libyara/grammar.y"
4176
318
      {
4177
318
        int result = ERROR_SUCCESS;
4178
4179
318
        YR_LOOP_CONTEXT* loop_ctx = &compiler->loop[compiler->loop_index];
4180
4181
318
        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
318
        else if (yr_parser_lookup_loop_variable(yyscanner, (yyvsp[0].c_string), NULL) >= 0)
4189
12
        {
4190
12
          yr_compiler_set_error_extra_info(compiler, (yyvsp[0].c_string));
4191
12
          yr_free((yyvsp[0].c_string));
4192
4193
12
          result = ERROR_DUPLICATED_LOOP_IDENTIFIER;
4194
12
        }
4195
4196
318
        fail_if_error(result);
4197
4198
306
        loop_ctx->vars[loop_ctx->vars_count++].identifier.ptr = (yyvsp[0].c_string);
4199
306
      }
4200
0
#line 4201 "libyara/grammar.c"
4201
0
    break;
4202
4203
187
  case 117: /* iterator: identifier  */
4204
187
#line 2141 "libyara/grammar.y"
4205
187
      {
4206
187
        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
187
        int result = ERROR_WRONG_TYPE;
4211
4212
187
        if ((yyvsp[0].expression).type == EXPRESSION_TYPE_OBJECT)
4213
179
        {
4214
179
          switch((yyvsp[0].expression).value.object->type)
4215
179
          {
4216
14
            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
14
              if (loop_ctx->vars_count == 1)
4221
7
              {
4222
7
                loop_ctx->vars[0].type = EXPRESSION_TYPE_OBJECT;
4223
7
                loop_ctx->vars[0].value.object = \
4224
7
                    object_as_array((yyvsp[0].expression).value.object)->prototype_item;
4225
4226
7
                result = yr_parser_emit(yyscanner, OP_ITER_START_ARRAY, NULL);
4227
7
              }
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
14
              break;
4240
4241
162
            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
162
              if (loop_ctx->vars_count == 2)
4246
162
              {
4247
162
                loop_ctx->vars[0].type = EXPRESSION_TYPE_STRING;
4248
162
                loop_ctx->vars[0].value.sized_string_ref = YR_ARENA_NULL_REF;
4249
162
                loop_ctx->vars[1].type = EXPRESSION_TYPE_OBJECT;
4250
162
                loop_ctx->vars[1].value.object = \
4251
162
                    object_as_array((yyvsp[0].expression).value.object)->prototype_item;
4252
4253
162
                result = yr_parser_emit(yyscanner, OP_ITER_START_DICT, NULL);
4254
162
              }
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
162
              break;
4265
179
          }
4266
179
        }
4267
4268
187
        if (result == ERROR_WRONG_TYPE)
4269
11
        {
4270
11
          yr_compiler_set_error_extra_info_fmt(
4271
11
              compiler,
4272
11
              "identifier \"%s\" is not iterable",
4273
11
              expression_identifier((yyvsp[0].expression)));
4274
11
        }
4275
4276
187
        fail_if_error(result);
4277
169
      }
4278
0
#line 4279 "libyara/grammar.c"
4279
0
    break;
4280
4281
590
  case 118: /* iterator: set  */
4282
590
#line 2215 "libyara/grammar.y"
4283
590
      {
4284
590
        int result = ERROR_SUCCESS;
4285
4286
590
        YR_LOOP_CONTEXT* loop_ctx = &compiler->loop[compiler->loop_index];
4287
4288
590
        if (loop_ctx->vars_count == 1)
4289
568
        {
4290
568
          loop_ctx->vars[0].type = (yyvsp[0].enumeration).type;
4291
4292
568
          if ((yyvsp[0].enumeration).type == EXPRESSION_TYPE_STRING)
4293
14
            loop_ctx->vars[0].value.sized_string_ref = YR_ARENA_NULL_REF;
4294
554
          else
4295
554
            loop_ctx->vars[0].value.integer = YR_UNDEFINED;
4296
568
        }
4297
22
        else
4298
22
        {
4299
22
          yr_compiler_set_error_extra_info_fmt(
4300
22
              compiler,
4301
22
              "iterator yields one value on each iteration "
4302
22
              ", but the loop expects %d",
4303
22
              loop_ctx->vars_count);
4304
4305
22
          result = ERROR_SYNTAX_ERROR;
4306
22
        }
4307
4308
590
        fail_if_error(result);
4309
568
      }
4310
0
#line 4311 "libyara/grammar.c"
4311
0
    break;
4312
4313
564
  case 119: /* set: '(' enumeration ')'  */
4314
564
#line 2247 "libyara/grammar.y"
4315
564
      {
4316
        // $2.count contains the number of items in the enumeration
4317
564
        fail_if_error(yr_parser_emit_push_const(yyscanner, (yyvsp[-1].enumeration).count));
4318
4319
564
        if ((yyvsp[-1].enumeration).type == EXPRESSION_TYPE_INTEGER)
4320
544
        {
4321
544
          fail_if_error(yr_parser_emit(
4322
544
              yyscanner, OP_ITER_START_INT_ENUM, NULL));
4323
544
        }
4324
20
        else
4325
20
        {
4326
20
          fail_if_error(yr_parser_emit(
4327
20
              yyscanner, OP_ITER_START_TEXT_STRING_SET, NULL));
4328
20
        }
4329
4330
564
        (yyval.enumeration).type = (yyvsp[-1].enumeration).type;
4331
564
      }
4332
0
#line 4333 "libyara/grammar.c"
4333
0
    break;
4334
4335
26
  case 120: /* set: range  */
4336
26
#line 2265 "libyara/grammar.y"
4337
26
      {
4338
26
        fail_if_error(yr_parser_emit(
4339
26
            yyscanner, OP_ITER_START_INT_RANGE, NULL));
4340
4341
26
        (yyval.enumeration).type = EXPRESSION_TYPE_INTEGER;
4342
26
      }
4343
0
#line 4344 "libyara/grammar.c"
4344
0
    break;
4345
4346
287
  case 121: /* range: '(' primary_expression ".." primary_expression ')'  */
4347
287
#line 2276 "libyara/grammar.y"
4348
287
      {
4349
287
        int result = ERROR_SUCCESS;
4350
4351
287
        if ((yyvsp[-3].expression).type != EXPRESSION_TYPE_INTEGER)
4352
29
        {
4353
29
          yr_compiler_set_error_extra_info(
4354
29
              compiler, "wrong type for range's lower bound");
4355
29
          result = ERROR_WRONG_TYPE;
4356
29
        }
4357
4358
287
        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
287
        if ((yyvsp[-3].expression).value.integer != YR_UNDEFINED && (yyvsp[-1].expression).value.integer != YR_UNDEFINED)
4369
265
        {
4370
265
          if ((yyvsp[-3].expression).value.integer > (yyvsp[-1].expression).value.integer)
4371
23
          {
4372
23
            yr_compiler_set_error_extra_info(
4373
23
                compiler, "range lower bound must be less than upper bound");
4374
23
            result = ERROR_INVALID_VALUE;
4375
23
          }
4376
242
          else if ((yyvsp[-3].expression).value.integer < 0)
4377
19
          {
4378
19
            yr_compiler_set_error_extra_info(
4379
19
                compiler, "range lower bound can not be negative");
4380
19
            result = ERROR_INVALID_VALUE;
4381
19
          }
4382
265
        }
4383
4384
287
        fail_if_error(result);
4385
233
      }
4386
0
#line 4387 "libyara/grammar.c"
4387
0
    break;
4388
4389
675
  case 122: /* enumeration: primary_expression  */
4390
675
#line 2319 "libyara/grammar.y"
4391
675
      {
4392
675
        int result = ERROR_SUCCESS;
4393
4394
675
        if ((yyvsp[0].expression).type != EXPRESSION_TYPE_INTEGER && (yyvsp[0].expression).type != EXPRESSION_TYPE_STRING)
4395
13
        {
4396
13
          yr_compiler_set_error_extra_info(
4397
13
              compiler, "wrong type for enumeration item");
4398
13
          result = ERROR_WRONG_TYPE;
4399
13
        }
4400
4401
675
        fail_if_error(result);
4402
4403
662
        (yyval.enumeration).type = (yyvsp[0].expression).type;
4404
662
        (yyval.enumeration).count = 1;
4405
662
      }
4406
0
#line 4407 "libyara/grammar.c"
4407
0
    break;
4408
4409
138
  case 123: /* enumeration: enumeration ',' primary_expression  */
4410
138
#line 2335 "libyara/grammar.y"
4411
138
      {
4412
138
        int result = ERROR_SUCCESS;
4413
4414
138
        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
138
        fail_if_error(result);
4422
4423
131
        (yyval.enumeration).type = (yyvsp[-2].enumeration).type;
4424
131
        (yyval.enumeration).count = (yyvsp[-2].enumeration).count + 1;
4425
131
      }
4426
0
#line 4427 "libyara/grammar.c"
4427
0
    break;
4428
4429
212
  case 124: /* string_iterator: string_set  */
4430
212
#line 2355 "libyara/grammar.y"
4431
212
      {
4432
212
        fail_if_error(yr_parser_emit_push_const(yyscanner, (yyvsp[0].integer)));
4433
212
        fail_if_error(yr_parser_emit(yyscanner, OP_ITER_START_STRING_SET,
4434
212
            NULL));
4435
212
      }
4436
0
#line 4437 "libyara/grammar.c"
4437
0
    break;
4438
4439
8.36k
  case 125: /* $@10: %empty  */
4440
8.36k
#line 2364 "libyara/grammar.y"
4441
8.36k
      {
4442
        // Push end-of-list marker
4443
8.36k
        yr_parser_emit_push_const(yyscanner, YR_UNDEFINED);
4444
8.36k
      }
4445
8.36k
#line 4446 "libyara/grammar.c"
4446
8.36k
    break;
4447
4448
8.32k
  case 126: /* string_set: '(' $@10 string_enumeration ')'  */
4449
8.32k
#line 2369 "libyara/grammar.y"
4450
8.32k
      {
4451
8.32k
        (yyval.integer) = (yyvsp[-1].integer);
4452
8.32k
      }
4453
8.32k
#line 4454 "libyara/grammar.c"
4454
8.32k
    break;
4455
4456
73
  case 127: /* string_set: "<them>"  */
4457
73
#line 2373 "libyara/grammar.y"
4458
73
      {
4459
73
        fail_if_error(yr_parser_emit_push_const(yyscanner, YR_UNDEFINED));
4460
4461
73
        int count = 0;
4462
73
        fail_if_error(yr_parser_emit_pushes_for_strings(
4463
73
            yyscanner, "$*", &count));
4464
4465
67
        (yyval.integer) = count;
4466
67
      }
4467
0
#line 4468 "libyara/grammar.c"
4468
0
    break;
4469
4470
8.34k
  case 128: /* string_enumeration: string_enumeration_item  */
4471
8.34k
#line 2386 "libyara/grammar.y"
4472
8.34k
                              { (yyval.integer) = (yyvsp[0].integer); }
4473
8.34k
#line 4474 "libyara/grammar.c"
4474
8.34k
    break;
4475
4476
666
  case 129: /* string_enumeration: string_enumeration ',' string_enumeration_item  */
4477
666
#line 2387 "libyara/grammar.y"
4478
666
                                                     { (yyval.integer) = (yyvsp[-2].integer) + (yyvsp[0].integer); }
4479
666
#line 4480 "libyara/grammar.c"
4480
666
    break;
4481
4482
8.80k
  case 130: /* string_enumeration_item: "string identifier"  */
4483
8.80k
#line 2393 "libyara/grammar.y"
4484
8.80k
      {
4485
8.80k
        int count = 0;
4486
8.80k
        int result = yr_parser_emit_pushes_for_strings(yyscanner, (yyvsp[0].c_string), &count);
4487
8.80k
        yr_free((yyvsp[0].c_string));
4488
4489
8.80k
        fail_if_error(result);
4490
4491
8.79k
        (yyval.integer) = count;
4492
8.79k
      }
4493
0
#line 4494 "libyara/grammar.c"
4494
0
    break;
4495
4496
232
  case 131: /* string_enumeration_item: "string identifier with wildcard"  */
4497
232
#line 2403 "libyara/grammar.y"
4498
232
      {
4499
232
        int count = 0;
4500
232
        int result = yr_parser_emit_pushes_for_strings(yyscanner, (yyvsp[0].c_string), &count);
4501
232
        yr_free((yyvsp[0].c_string));
4502
4503
232
        fail_if_error(result);
4504
4505
221
        (yyval.integer) = count;
4506
221
      }
4507
0
#line 4508 "libyara/grammar.c"
4508
0
    break;
4509
4510
288
  case 132: /* $@11: %empty  */
4511
288
#line 2417 "libyara/grammar.y"
4512
288
      {
4513
        // Push end-of-list marker
4514
288
        yr_parser_emit_push_const(yyscanner, YR_UNDEFINED);
4515
288
      }
4516
288
#line 4517 "libyara/grammar.c"
4517
288
    break;
4518
4519
123
  case 133: /* rule_set: '(' $@11 rule_enumeration ')'  */
4520
123
#line 2422 "libyara/grammar.y"
4521
123
      {
4522
123
        (yyval.integer) = (yyvsp[-1].integer);
4523
123
      }
4524
123
#line 4525 "libyara/grammar.c"
4525
123
    break;
4526
4527
146
  case 134: /* rule_enumeration: rule_enumeration_item  */
4528
146
#line 2429 "libyara/grammar.y"
4529
146
                            { (yyval.integer) = (yyvsp[0].integer); }
4530
146
#line 4531 "libyara/grammar.c"
4531
146
    break;
4532
4533
979
  case 135: /* rule_enumeration: rule_enumeration ',' rule_enumeration_item  */
4534
979
#line 2430 "libyara/grammar.y"
4535
979
                                                 { (yyval.integer) = (yyvsp[-2].integer) + (yyvsp[0].integer); }
4536
979
#line 4537 "libyara/grammar.c"
4537
979
    break;
4538
4539
331
  case 136: /* rule_enumeration_item: "identifier"  */
4540
331
#line 2436 "libyara/grammar.y"
4541
331
      {
4542
331
        int result = ERROR_SUCCESS;
4543
4544
331
        YR_NAMESPACE* ns = (YR_NAMESPACE*) yr_arena_get_ptr(
4545
331
            compiler->arena,
4546
331
            YR_NAMESPACES_TABLE,
4547
331
            compiler->current_namespace_idx * sizeof(struct YR_NAMESPACE));
4548
4549
331
        uint32_t rule_idx = yr_hash_table_lookup_uint32(
4550
331
            compiler->rules_table, (yyvsp[0].c_string), ns->name);
4551
4552
331
        if (rule_idx != UINT32_MAX)
4553
263
        {
4554
263
          result = yr_parser_emit_with_arg(
4555
263
              yyscanner,
4556
263
              OP_PUSH_RULE,
4557
263
              rule_idx,
4558
263
              NULL,
4559
263
              NULL);
4560
263
        }
4561
68
        else
4562
68
        {
4563
68
          yr_compiler_set_error_extra_info(compiler, (yyvsp[0].c_string));
4564
68
          result = ERROR_UNDEFINED_IDENTIFIER;
4565
68
        }
4566
4567
331
        yr_free((yyvsp[0].c_string));
4568
4569
331
        fail_if_error(result);
4570
4571
263
        (yyval.integer) = 1;
4572
263
      }
4573
0
#line 4574 "libyara/grammar.c"
4574
0
    break;
4575
4576
947
  case 137: /* rule_enumeration_item: "identifier" '*'  */
4577
947
#line 2469 "libyara/grammar.y"
4578
947
      {
4579
947
        int count = 0;
4580
947
        YR_NAMESPACE* ns = (YR_NAMESPACE*) yr_arena_get_ptr(
4581
947
            compiler->arena,
4582
947
            YR_NAMESPACES_TABLE,
4583
947
            compiler->current_namespace_idx * sizeof(struct YR_NAMESPACE));
4584
4585
947
        yr_hash_table_add_uint32(
4586
947
            compiler->wildcard_identifiers_table,
4587
947
            (yyvsp[-1].c_string),
4588
947
            ns->name,
4589
947
            1);
4590
4591
947
        int result = yr_parser_emit_pushes_for_rules(yyscanner, (yyvsp[-1].c_string), &count);
4592
947
        yr_free((yyvsp[-1].c_string));
4593
4594
947
        fail_if_error(result);
4595
4596
862
        (yyval.integer) = count;
4597
862
      }
4598
0
#line 4599 "libyara/grammar.c"
4599
0
    break;
4600
4601
6.93k
  case 138: /* for_expression: primary_expression  */
4602
6.93k
#line 2494 "libyara/grammar.y"
4603
6.93k
      {
4604
6.93k
        if ((yyvsp[0].expression).type == EXPRESSION_TYPE_INTEGER && !IS_UNDEFINED((yyvsp[0].expression).value.integer))
4605
6.42k
        {
4606
6.42k
          if ((yyvsp[0].expression).value.integer == 0)
4607
1.63k
          {
4608
1.63k
            yywarning(yyscanner,
4609
1.63k
                "consider using \"none\" keyword, it is less ambiguous.");
4610
1.63k
          }
4611
4612
6.42k
          if ((yyvsp[0].expression).value.integer < 0)
4613
2
          {
4614
2
            yr_compiler_set_error_extra_info_fmt(compiler,
4615
2
                "%" PRId64, (yyvsp[0].expression).value.integer);
4616
4617
2
            fail_with_error(ERROR_INVALID_VALUE);
4618
0
          }
4619
6.42k
        }
4620
4621
6.92k
        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.92k
        if ((yyvsp[0].expression).type == EXPRESSION_TYPE_STRING)
4630
25
        {
4631
25
          SIZED_STRING* ss = yr_arena_ref_to_ptr(compiler->arena,
4632
25
              &(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
25
          if (ss != NULL)
4636
1
          {
4637
1
            yr_compiler_set_error_extra_info_fmt(compiler, "%s", ss->c_string);
4638
1
          }
4639
24
          else
4640
24
          {
4641
24
            yr_compiler_set_error_extra_info(compiler,
4642
24
                "string in for_expression is invalid");
4643
24
          }
4644
4645
25
          fail_with_error(ERROR_INVALID_VALUE);
4646
0
        }
4647
4648
6.90k
        if ((yyvsp[0].expression).type == EXPRESSION_TYPE_REGEXP)
4649
16
        {
4650
16
          yr_compiler_set_error_extra_info(compiler,
4651
16
              "regexp in for_expression is invalid");
4652
4653
16
          fail_with_error(ERROR_INVALID_VALUE);
4654
0
        }
4655
4656
6.88k
        (yyval.expression).value.integer = (yyvsp[0].expression).value.integer;
4657
6.88k
      }
4658
0
#line 4659 "libyara/grammar.c"
4659
0
    break;
4660
4661
3.58k
  case 139: /* for_expression: for_quantifier  */
4662
3.58k
#line 2550 "libyara/grammar.y"
4663
3.58k
      {
4664
3.58k
        (yyval.expression).value.integer = (yyvsp[0].expression).value.integer;
4665
3.58k
      }
4666
3.58k
#line 4667 "libyara/grammar.c"
4667
3.58k
    break;
4668
4669
1.67k
  case 140: /* for_quantifier: "<all>"  */
4670
1.67k
#line 2557 "libyara/grammar.y"
4671
1.67k
      {
4672
1.67k
        yr_parser_emit_push_const(yyscanner, YR_UNDEFINED);
4673
1.67k
        (yyval.expression).type = EXPRESSION_TYPE_QUANTIFIER;
4674
1.67k
        (yyval.expression).value.integer = FOR_EXPRESSION_ALL;
4675
1.67k
     }
4676
1.67k
#line 4677 "libyara/grammar.c"
4677
1.67k
    break;
4678
4679
1.90k
  case 141: /* for_quantifier: "<any>"  */
4680
1.90k
#line 2563 "libyara/grammar.y"
4681
1.90k
      {
4682
1.90k
        yr_parser_emit_push_const(yyscanner, 1);
4683
1.90k
        (yyval.expression).type = EXPRESSION_TYPE_QUANTIFIER;
4684
1.90k
        (yyval.expression).value.integer = FOR_EXPRESSION_ANY;
4685
1.90k
      }
4686
1.90k
#line 4687 "libyara/grammar.c"
4687
1.90k
    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
8.96k
  case 143: /* primary_expression: '(' primary_expression ')'  */
4700
8.96k
#line 2579 "libyara/grammar.y"
4701
8.96k
      {
4702
8.96k
        (yyval.expression) = (yyvsp[-1].expression);
4703
8.96k
      }
4704
8.96k
#line 4705 "libyara/grammar.c"
4705
8.96k
    break;
4706
4707
420
  case 144: /* primary_expression: "<filesize>"  */
4708
420
#line 2583 "libyara/grammar.y"
4709
420
      {
4710
420
        fail_if_error(yr_parser_emit(
4711
420
            yyscanner, OP_FILESIZE, NULL));
4712
4713
420
        (yyval.expression).type = EXPRESSION_TYPE_INTEGER;
4714
420
        (yyval.expression).value.integer = YR_UNDEFINED;
4715
420
      }
4716
0
#line 4717 "libyara/grammar.c"
4717
0
    break;
4718
4719
175
  case 145: /* primary_expression: "<entrypoint>"  */
4720
175
#line 2591 "libyara/grammar.y"
4721
175
      {
4722
175
        yywarning(yyscanner,
4723
175
            "using deprecated \"entrypoint\" keyword. Use the \"entry_point\" "
4724
175
            "function from PE module instead.");
4725
4726
175
        fail_if_error(yr_parser_emit(
4727
175
            yyscanner, OP_ENTRYPOINT, NULL));
4728
4729
175
        (yyval.expression).type = EXPRESSION_TYPE_INTEGER;
4730
175
        (yyval.expression).value.integer = YR_UNDEFINED;
4731
175
      }
4732
0
#line 4733 "libyara/grammar.c"
4733
0
    break;
4734
4735
569
  case 146: /* primary_expression: "integer function" '(' primary_expression ')'  */
4736
569
#line 2603 "libyara/grammar.y"
4737
569
      {
4738
569
        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
550
        fail_if_error(yr_parser_emit(
4745
550
            yyscanner, (uint8_t) (OP_READ_INT + (yyvsp[-3].integer)), NULL));
4746
4747
550
        (yyval.expression).type = EXPRESSION_TYPE_INTEGER;
4748
550
        (yyval.expression).value.integer = YR_UNDEFINED;
4749
550
      }
4750
0
#line 4751 "libyara/grammar.c"
4751
0
    break;
4752
4753
37.1k
  case 147: /* primary_expression: "integer number"  */
4754
37.1k
#line 2617 "libyara/grammar.y"
4755
37.1k
      {
4756
37.1k
        fail_if_error(yr_parser_emit_push_const(yyscanner, (yyvsp[0].integer)));
4757
4758
37.1k
        (yyval.expression).type = EXPRESSION_TYPE_INTEGER;
4759
37.1k
        (yyval.expression).value.integer = (yyvsp[0].integer);
4760
37.1k
      }
4761
0
#line 4762 "libyara/grammar.c"
4762
0
    break;
4763
4764
6.43k
  case 148: /* primary_expression: "floating point number"  */
4765
6.43k
#line 2624 "libyara/grammar.y"
4766
6.43k
      {
4767
6.43k
        fail_if_error(yr_parser_emit_with_arg_double(
4768
6.43k
            yyscanner, OP_PUSH, (yyvsp[0].double_), NULL, NULL));
4769
4770
6.43k
        (yyval.expression).type = EXPRESSION_TYPE_FLOAT;
4771
6.43k
      }
4772
0
#line 4773 "libyara/grammar.c"
4773
0
    break;
4774
4775
7.61k
  case 149: /* primary_expression: "text string"  */
4776
7.61k
#line 2631 "libyara/grammar.y"
4777
7.61k
      {
4778
7.61k
        YR_ARENA_REF ref;
4779
4780
7.61k
        int result = _yr_compiler_store_data(
4781
7.61k
            compiler,
4782
7.61k
            (yyvsp[0].sized_string),
4783
7.61k
            (yyvsp[0].sized_string)->length + sizeof(SIZED_STRING),
4784
7.61k
            &ref);
4785
4786
7.61k
        yr_free((yyvsp[0].sized_string));
4787
4788
7.61k
        if (result == ERROR_SUCCESS)
4789
7.61k
          result = yr_parser_emit_with_arg_reloc(
4790
7.61k
              yyscanner,
4791
7.61k
              OP_PUSH,
4792
7.61k
              yr_arena_ref_to_ptr(compiler->arena, &ref),
4793
7.61k
              NULL,
4794
7.61k
              NULL);
4795
4796
7.61k
        fail_if_error(result);
4797
4798
7.61k
        (yyval.expression).type = EXPRESSION_TYPE_STRING;
4799
7.61k
        (yyval.expression).value.sized_string_ref = ref;
4800
7.61k
      }
4801
0
#line 4802 "libyara/grammar.c"
4802
0
    break;
4803
4804
42
  case 150: /* primary_expression: "string count" "<in>" range  */
4805
42
#line 2656 "libyara/grammar.y"
4806
42
      {
4807
42
        int result = yr_parser_reduce_string_identifier(
4808
42
            yyscanner, (yyvsp[-2].c_string), OP_COUNT_IN, YR_UNDEFINED);
4809
4810
42
        yr_free((yyvsp[-2].c_string));
4811
4812
42
        fail_if_error(result);
4813
4814
8
        (yyval.expression).type = EXPRESSION_TYPE_INTEGER;
4815
8
        (yyval.expression).value.integer = YR_UNDEFINED;
4816
8
      }
4817
0
#line 4818 "libyara/grammar.c"
4818
0
    break;
4819
4820
2.82k
  case 151: /* primary_expression: "string count"  */
4821
2.82k
#line 2668 "libyara/grammar.y"
4822
2.82k
      {
4823
2.82k
        int result = yr_parser_reduce_string_identifier(
4824
2.82k
            yyscanner, (yyvsp[0].c_string), OP_COUNT, YR_UNDEFINED);
4825
4826
2.82k
        yr_free((yyvsp[0].c_string));
4827
4828
2.82k
        fail_if_error(result);
4829
4830
2.81k
        (yyval.expression).type = EXPRESSION_TYPE_INTEGER;
4831
2.81k
        (yyval.expression).value.integer = YR_UNDEFINED;
4832
2.81k
      }
4833
0
#line 4834 "libyara/grammar.c"
4834
0
    break;
4835
4836
394
  case 152: /* primary_expression: "string offset" '[' primary_expression ']'  */
4837
394
#line 2680 "libyara/grammar.y"
4838
394
      {
4839
394
        int result = yr_parser_reduce_string_identifier(
4840
394
            yyscanner, (yyvsp[-3].c_string), OP_OFFSET, YR_UNDEFINED);
4841
4842
394
        yr_free((yyvsp[-3].c_string));
4843
4844
394
        fail_if_error(result);
4845
4846
394
        (yyval.expression).type = EXPRESSION_TYPE_INTEGER;
4847
394
        (yyval.expression).value.integer = YR_UNDEFINED;
4848
394
      }
4849
0
#line 4850 "libyara/grammar.c"
4850
0
    break;
4851
4852
4.03k
  case 153: /* primary_expression: "string offset"  */
4853
4.03k
#line 2692 "libyara/grammar.y"
4854
4.03k
      {
4855
4.03k
        int result = yr_parser_emit_push_const(yyscanner, 1);
4856
4857
4.03k
        if (result == ERROR_SUCCESS)
4858
4.03k
          result = yr_parser_reduce_string_identifier(
4859
4.03k
              yyscanner, (yyvsp[0].c_string), OP_OFFSET, YR_UNDEFINED);
4860
4861
4.03k
        yr_free((yyvsp[0].c_string));
4862
4863
4.03k
        fail_if_error(result);
4864
4865
3.99k
        (yyval.expression).type = EXPRESSION_TYPE_INTEGER;
4866
3.99k
        (yyval.expression).value.integer = YR_UNDEFINED;
4867
3.99k
      }
4868
0
#line 4869 "libyara/grammar.c"
4869
0
    break;
4870
4871
471
  case 154: /* primary_expression: "string length" '[' primary_expression ']'  */
4872
471
#line 2707 "libyara/grammar.y"
4873
471
      {
4874
471
        int result = yr_parser_reduce_string_identifier(
4875
471
            yyscanner, (yyvsp[-3].c_string), OP_LENGTH, YR_UNDEFINED);
4876
4877
471
        yr_free((yyvsp[-3].c_string));
4878
4879
471
        fail_if_error(result);
4880
4881
449
        (yyval.expression).type = EXPRESSION_TYPE_INTEGER;
4882
449
        (yyval.expression).value.integer = YR_UNDEFINED;
4883
449
      }
4884
0
#line 4885 "libyara/grammar.c"
4885
0
    break;
4886
4887
8.72k
  case 155: /* primary_expression: "string length"  */
4888
8.72k
#line 2719 "libyara/grammar.y"
4889
8.72k
      {
4890
8.72k
        int result = yr_parser_emit_push_const(yyscanner, 1);
4891
4892
8.72k
        if (result == ERROR_SUCCESS)
4893
8.72k
          result = yr_parser_reduce_string_identifier(
4894
8.72k
              yyscanner, (yyvsp[0].c_string), OP_LENGTH, YR_UNDEFINED);
4895
4896
8.72k
        yr_free((yyvsp[0].c_string));
4897
4898
8.72k
        fail_if_error(result);
4899
4900
8.72k
        (yyval.expression).type = EXPRESSION_TYPE_INTEGER;
4901
8.72k
        (yyval.expression).value.integer = YR_UNDEFINED;
4902
8.72k
      }
4903
0
#line 4904 "libyara/grammar.c"
4904
0
    break;
4905
4906
10.8k
  case 156: /* primary_expression: identifier  */
4907
10.8k
#line 2734 "libyara/grammar.y"
4908
10.8k
      {
4909
10.8k
        int result = ERROR_SUCCESS;
4910
4911
10.8k
        if ((yyvsp[0].expression).type == EXPRESSION_TYPE_OBJECT)
4912
4.77k
        {
4913
4.77k
          result = yr_parser_emit(
4914
4.77k
              yyscanner, OP_OBJ_VALUE, NULL);
4915
4916
4.77k
          switch((yyvsp[0].expression).value.object->type)
4917
4.77k
          {
4918
503
            case OBJECT_TYPE_INTEGER:
4919
503
              (yyval.expression).type = EXPRESSION_TYPE_INTEGER;
4920
503
              (yyval.expression).value.integer = (yyvsp[0].expression).value.object->value.i;
4921
503
              break;
4922
0
            case OBJECT_TYPE_FLOAT:
4923
0
              (yyval.expression).type = EXPRESSION_TYPE_FLOAT;
4924
0
              break;
4925
4.22k
            case OBJECT_TYPE_STRING:
4926
4.22k
              (yyval.expression).type = EXPRESSION_TYPE_STRING;
4927
4.22k
              (yyval.expression).value.sized_string_ref = YR_ARENA_NULL_REF;
4928
4.22k
              break;
4929
40
            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
40
              yr_compiler_set_error_extra_info_fmt(
4936
40
                  compiler,
4937
40
                  "wrong usage of identifier \"%s\"",
4938
40
                  expression_identifier((yyvsp[0].expression)));
4939
4940
40
              result = ERROR_WRONG_TYPE;
4941
4.77k
          }
4942
4.77k
        }
4943
6.07k
        else
4944
6.07k
        {
4945
6.07k
          (yyval.expression) = (yyvsp[0].expression);
4946
6.07k
        }
4947
4948
10.8k
        fail_if_error(result);
4949
10.8k
      }
4950
0
#line 4951 "libyara/grammar.c"
4951
0
    break;
4952
4953
26.3k
  case 157: /* primary_expression: '-' primary_expression  */
4954
26.3k
#line 2777 "libyara/grammar.y"
4955
26.3k
      {
4956
26.3k
        int result = ERROR_SUCCESS;
4957
4958
26.3k
        check_type((yyvsp[0].expression), EXPRESSION_TYPE_INTEGER | EXPRESSION_TYPE_FLOAT, "-");
4959
4960
26.2k
        if ((yyvsp[0].expression).type == EXPRESSION_TYPE_INTEGER)
4961
24.9k
        {
4962
24.9k
          (yyval.expression).type = EXPRESSION_TYPE_INTEGER;
4963
24.9k
          (yyval.expression).value.integer = ((yyvsp[0].expression).value.integer == YR_UNDEFINED) ?
4964
18.6k
              YR_UNDEFINED : -((yyvsp[0].expression).value.integer);
4965
24.9k
          result = yr_parser_emit(yyscanner, OP_INT_MINUS, NULL);
4966
24.9k
        }
4967
1.36k
        else if ((yyvsp[0].expression).type == EXPRESSION_TYPE_FLOAT)
4968
1.36k
        {
4969
1.36k
          (yyval.expression).type = EXPRESSION_TYPE_FLOAT;
4970
1.36k
          result = yr_parser_emit(yyscanner, OP_DBL_MINUS, NULL);
4971
1.36k
        }
4972
4973
26.2k
        fail_if_error(result);
4974
26.2k
      }
4975
0
#line 4976 "libyara/grammar.c"
4976
0
    break;
4977
4978
5.29k
  case 158: /* primary_expression: primary_expression '+' primary_expression  */
4979
5.29k
#line 2798 "libyara/grammar.y"
4980
5.29k
      {
4981
5.29k
        int result = yr_parser_reduce_operation(
4982
5.29k
            yyscanner, "+", (yyvsp[-2].expression), (yyvsp[0].expression));
4983
4984
5.29k
        if ((yyvsp[-2].expression).type == EXPRESSION_TYPE_INTEGER &&
4985
5.29k
            (yyvsp[0].expression).type == EXPRESSION_TYPE_INTEGER)
4986
3.56k
        {
4987
3.56k
          int64_t i1 = (yyvsp[-2].expression).value.integer;
4988
3.56k
          int64_t i2 = (yyvsp[0].expression).value.integer;
4989
4990
3.56k
          if (!IS_UNDEFINED(i1) && !IS_UNDEFINED(i2) &&
4991
3.56k
              (
4992
2.14k
                (i2 > 0 && i1 > INT64_MAX - i2) ||
4993
2.14k
                (i2 < 0 && i1 < INT64_MIN - i2)
4994
2.14k
              ))
4995
14
          {
4996
14
            yr_compiler_set_error_extra_info_fmt(
4997
14
                compiler, "%" PRId64 " + %" PRId64, i1, i2);
4998
4999
14
            result = ERROR_INTEGER_OVERFLOW;
5000
14
          }
5001
3.55k
          else
5002
3.55k
          {
5003
3.55k
            (yyval.expression).value.integer = OPERATION(+, i1, i2);
5004
3.55k
            (yyval.expression).type = EXPRESSION_TYPE_INTEGER;
5005
3.55k
          }
5006
3.56k
        }
5007
1.73k
        else
5008
1.73k
        {
5009
1.73k
          (yyval.expression).type = EXPRESSION_TYPE_FLOAT;
5010
1.73k
        }
5011
5012
5.29k
        fail_if_error(result);
5013
5.28k
      }
5014
0
#line 5015 "libyara/grammar.c"
5015
0
    break;
5016
5017
8.34k
  case 159: /* primary_expression: primary_expression '-' primary_expression  */
5018
8.34k
#line 2833 "libyara/grammar.y"
5019
8.34k
      {
5020
8.34k
        int result = yr_parser_reduce_operation(
5021
8.34k
            yyscanner, "-", (yyvsp[-2].expression), (yyvsp[0].expression));
5022
5023
8.34k
        if ((yyvsp[-2].expression).type == EXPRESSION_TYPE_INTEGER &&
5024
8.34k
            (yyvsp[0].expression).type == EXPRESSION_TYPE_INTEGER)
5025
7.46k
        {
5026
7.46k
          int64_t i1 = (yyvsp[-2].expression).value.integer;
5027
7.46k
          int64_t i2 = (yyvsp[0].expression).value.integer;
5028
5029
7.46k
          if (!IS_UNDEFINED(i1) && !IS_UNDEFINED(i2) &&
5030
7.46k
              (
5031
2.60k
                (i2 < 0 && i1 > INT64_MAX + i2) ||
5032
2.60k
                (i2 > 0 && i1 < INT64_MIN + i2)
5033
2.60k
              ))
5034
6
          {
5035
6
            yr_compiler_set_error_extra_info_fmt(
5036
6
                compiler, "%" PRId64 " - %" PRId64, i1, i2);
5037
5038
6
            result = ERROR_INTEGER_OVERFLOW;
5039
6
          }
5040
7.46k
          else
5041
7.46k
          {
5042
7.46k
            (yyval.expression).value.integer = OPERATION(-, i1, i2);
5043
7.46k
            (yyval.expression).type = EXPRESSION_TYPE_INTEGER;
5044
7.46k
          }
5045
7.46k
        }
5046
877
        else
5047
877
        {
5048
877
          (yyval.expression).type = EXPRESSION_TYPE_FLOAT;
5049
877
        }
5050
5051
8.34k
        fail_if_error(result);
5052
8.32k
      }
5053
0
#line 5054 "libyara/grammar.c"
5054
0
    break;
5055
5056
2.30k
  case 160: /* primary_expression: primary_expression '*' primary_expression  */
5057
2.30k
#line 2868 "libyara/grammar.y"
5058
2.30k
      {
5059
2.30k
        int result = yr_parser_reduce_operation(
5060
2.30k
            yyscanner, "*", (yyvsp[-2].expression), (yyvsp[0].expression));
5061
5062
2.30k
        if ((yyvsp[-2].expression).type == EXPRESSION_TYPE_INTEGER &&
5063
2.30k
            (yyvsp[0].expression).type == EXPRESSION_TYPE_INTEGER)
5064
1.72k
        {
5065
1.72k
          int64_t i1 = (yyvsp[-2].expression).value.integer;
5066
1.72k
          int64_t i2 = (yyvsp[0].expression).value.integer;
5067
5068
1.72k
          if (!IS_UNDEFINED(i1) && !IS_UNDEFINED(i2) &&
5069
1.72k
              (
5070
1.12k
                i2 != 0 && llabs(i1) > INT64_MAX / llabs(i2)
5071
1.12k
              ))
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
1.72k
          else
5079
1.72k
          {
5080
1.72k
            (yyval.expression).value.integer = OPERATION(*, i1, i2);
5081
1.72k
            (yyval.expression).type = EXPRESSION_TYPE_INTEGER;
5082
1.72k
          }
5083
1.72k
        }
5084
587
        else
5085
587
        {
5086
587
          (yyval.expression).type = EXPRESSION_TYPE_FLOAT;
5087
587
        }
5088
5089
2.30k
        fail_if_error(result);
5090
2.30k
      }
5091
0
#line 5092 "libyara/grammar.c"
5092
0
    break;
5093
5094
1.91k
  case 161: /* primary_expression: primary_expression '\\' primary_expression  */
5095
1.91k
#line 2902 "libyara/grammar.y"
5096
1.91k
      {
5097
1.91k
        int result = yr_parser_reduce_operation(
5098
1.91k
            yyscanner, "\\", (yyvsp[-2].expression), (yyvsp[0].expression));
5099
5100
1.91k
        if ((yyvsp[-2].expression).type == EXPRESSION_TYPE_INTEGER &&
5101
1.91k
            (yyvsp[0].expression).type == EXPRESSION_TYPE_INTEGER)
5102
1.33k
        {
5103
1.33k
          if ((yyvsp[0].expression).value.integer != 0)
5104
1.32k
          {
5105
1.32k
            (yyval.expression).value.integer = OPERATION(/, (yyvsp[-2].expression).value.integer, (yyvsp[0].expression).value.integer);
5106
1.32k
            (yyval.expression).type = EXPRESSION_TYPE_INTEGER;
5107
1.32k
          }
5108
11
          else
5109
11
          {
5110
11
            result = ERROR_DIVISION_BY_ZERO;
5111
11
          }
5112
1.33k
        }
5113
583
        else
5114
583
        {
5115
583
          (yyval.expression).type = EXPRESSION_TYPE_FLOAT;
5116
583
        }
5117
5118
1.91k
        fail_if_error(result);
5119
1.90k
      }
5120
0
#line 5121 "libyara/grammar.c"
5121
0
    break;
5122
5123
1.24k
  case 162: /* primary_expression: primary_expression '%' primary_expression  */
5124
1.24k
#line 2927 "libyara/grammar.y"
5125
1.24k
      {
5126
1.24k
        check_type((yyvsp[-2].expression), EXPRESSION_TYPE_INTEGER, "%");
5127
1.21k
        check_type((yyvsp[0].expression), EXPRESSION_TYPE_INTEGER, "%");
5128
5129
1.20k
        fail_if_error(yr_parser_emit(yyscanner, OP_MOD, NULL));
5130
5131
1.20k
        if ((yyvsp[0].expression).value.integer != 0)
5132
1.19k
        {
5133
1.19k
          (yyval.expression).value.integer = OPERATION(%, (yyvsp[-2].expression).value.integer, (yyvsp[0].expression).value.integer);
5134
1.19k
          (yyval.expression).type = EXPRESSION_TYPE_INTEGER;
5135
1.19k
        }
5136
5
        else
5137
5
        {
5138
5
          fail_if_error(ERROR_DIVISION_BY_ZERO);
5139
0
        }
5140
1.20k
      }
5141
1.19k
#line 5142 "libyara/grammar.c"
5142
1.19k
    break;
5143
5144
2.53k
  case 163: /* primary_expression: primary_expression '^' primary_expression  */
5145
2.53k
#line 2944 "libyara/grammar.y"
5146
2.53k
      {
5147
2.53k
        check_type((yyvsp[-2].expression), EXPRESSION_TYPE_INTEGER, "^");
5148
2.50k
        check_type((yyvsp[0].expression), EXPRESSION_TYPE_INTEGER, "^");
5149
5150
2.49k
        fail_if_error(yr_parser_emit(yyscanner, OP_BITWISE_XOR, NULL));
5151
5152
2.49k
        (yyval.expression).type = EXPRESSION_TYPE_INTEGER;
5153
2.49k
        (yyval.expression).value.integer = OPERATION(^, (yyvsp[-2].expression).value.integer, (yyvsp[0].expression).value.integer);
5154
2.49k
      }
5155
0
#line 5156 "libyara/grammar.c"
5156
0
    break;
5157
5158
1.95k
  case 164: /* primary_expression: primary_expression '&' primary_expression  */
5159
1.95k
#line 2954 "libyara/grammar.y"
5160
1.95k
      {
5161
1.95k
        check_type((yyvsp[-2].expression), EXPRESSION_TYPE_INTEGER, "^");
5162
1.93k
        check_type((yyvsp[0].expression), EXPRESSION_TYPE_INTEGER, "^");
5163
5164
1.93k
        fail_if_error(yr_parser_emit(yyscanner, OP_BITWISE_AND, NULL));
5165
5166
1.93k
        (yyval.expression).type = EXPRESSION_TYPE_INTEGER;
5167
1.93k
        (yyval.expression).value.integer = OPERATION(&, (yyvsp[-2].expression).value.integer, (yyvsp[0].expression).value.integer);
5168
1.93k
      }
5169
0
#line 5170 "libyara/grammar.c"
5170
0
    break;
5171
5172
2.67k
  case 165: /* primary_expression: primary_expression '|' primary_expression  */
5173
2.67k
#line 2964 "libyara/grammar.y"
5174
2.67k
      {
5175
2.67k
        check_type((yyvsp[-2].expression), EXPRESSION_TYPE_INTEGER, "|");
5176
2.66k
        check_type((yyvsp[0].expression), EXPRESSION_TYPE_INTEGER, "|");
5177
5178
2.64k
        fail_if_error(yr_parser_emit(yyscanner, OP_BITWISE_OR, NULL));
5179
5180
2.64k
        (yyval.expression).type = EXPRESSION_TYPE_INTEGER;
5181
2.64k
        (yyval.expression).value.integer = OPERATION(|, (yyvsp[-2].expression).value.integer, (yyvsp[0].expression).value.integer);
5182
2.64k
      }
5183
0
#line 5184 "libyara/grammar.c"
5184
0
    break;
5185
5186
4.90k
  case 166: /* primary_expression: '~' primary_expression  */
5187
4.90k
#line 2974 "libyara/grammar.y"
5188
4.90k
      {
5189
4.90k
        check_type((yyvsp[0].expression), EXPRESSION_TYPE_INTEGER, "~");
5190
5191
4.87k
        fail_if_error(yr_parser_emit(yyscanner, OP_BITWISE_NOT, NULL));
5192
5193
4.87k
        (yyval.expression).type = EXPRESSION_TYPE_INTEGER;
5194
4.87k
        (yyval.expression).value.integer = ((yyvsp[0].expression).value.integer == YR_UNDEFINED) ?
5195
4.84k
            YR_UNDEFINED : ~((yyvsp[0].expression).value.integer);
5196
4.87k
      }
5197
0
#line 5198 "libyara/grammar.c"
5198
0
    break;
5199
5200
3.75k
  case 167: /* primary_expression: primary_expression "<<" primary_expression  */
5201
3.75k
#line 2984 "libyara/grammar.y"
5202
3.75k
      {
5203
3.75k
        int result;
5204
5205
3.75k
        check_type((yyvsp[-2].expression), EXPRESSION_TYPE_INTEGER, "<<");
5206
3.73k
        check_type((yyvsp[0].expression), EXPRESSION_TYPE_INTEGER, "<<");
5207
5208
3.71k
        result = yr_parser_emit(yyscanner, OP_SHL, NULL);
5209
5210
3.71k
        if (!IS_UNDEFINED((yyvsp[0].expression).value.integer) && (yyvsp[0].expression).value.integer < 0)
5211
3
          result = ERROR_INVALID_OPERAND;
5212
3.71k
        else if (!IS_UNDEFINED((yyvsp[0].expression).value.integer) && (yyvsp[0].expression).value.integer >= 64)
5213
688
          (yyval.expression).value.integer = 0;
5214
3.02k
        else
5215
3.02k
          (yyval.expression).value.integer = OPERATION(<<, (yyvsp[-2].expression).value.integer, (yyvsp[0].expression).value.integer);
5216
5217
3.71k
        (yyval.expression).type = EXPRESSION_TYPE_INTEGER;
5218
5219
3.71k
        fail_if_error(result);
5220
3.71k
      }
5221
0
#line 5222 "libyara/grammar.c"
5222
0
    break;
5223
5224
1.84k
  case 168: /* primary_expression: primary_expression ">>" primary_expression  */
5225
1.84k
#line 3004 "libyara/grammar.y"
5226
1.84k
      {
5227
1.84k
        int result;
5228
5229
1.84k
        check_type((yyvsp[-2].expression), EXPRESSION_TYPE_INTEGER, ">>");
5230
1.81k
        check_type((yyvsp[0].expression), EXPRESSION_TYPE_INTEGER, ">>");
5231
5232
1.80k
        result = yr_parser_emit(yyscanner, OP_SHR, NULL);
5233
5234
1.80k
        if (!IS_UNDEFINED((yyvsp[0].expression).value.integer) && (yyvsp[0].expression).value.integer < 0)
5235
0
          result = ERROR_INVALID_OPERAND;
5236
1.80k
        else if (!IS_UNDEFINED((yyvsp[0].expression).value.integer) && (yyvsp[0].expression).value.integer >= 64)
5237
250
          (yyval.expression).value.integer = 0;
5238
1.55k
        else
5239
1.55k
          (yyval.expression).value.integer = OPERATION(<<, (yyvsp[-2].expression).value.integer, (yyvsp[0].expression).value.integer);
5240
5241
1.80k
        (yyval.expression).type = EXPRESSION_TYPE_INTEGER;
5242
5243
1.80k
        fail_if_error(result);
5244
1.80k
      }
5245
0
#line 5246 "libyara/grammar.c"
5246
0
    break;
5247
5248
1.25k
  case 169: /* primary_expression: regexp  */
5249
1.25k
#line 3024 "libyara/grammar.y"
5250
1.25k
      {
5251
1.25k
        (yyval.expression) = (yyvsp[0].expression);
5252
1.25k
      }
5253
1.25k
#line 5254 "libyara/grammar.c"
5254
1.25k
    break;
5255
5256
5257
0
#line 5258 "libyara/grammar.c"
5258
5259
4.18k
      default: break;
5260
736k
    }
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
725k
  YY_SYMBOL_PRINT ("-> $$ =", YY_CAST (yysymbol_kind_t, yyr1[yyn]), &yyval, &yyloc);
5273
5274
725k
  YYPOPSTACK (yylen);
5275
725k
  yylen = 0;
5276
5277
725k
  *++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
725k
  {
5283
725k
    const int yylhs = yyr1[yyn] - YYNTOKENS;
5284
725k
    const int yyi = yypgoto[yylhs] + *yyssp;
5285
725k
    yystate = (0 <= yyi && yyi <= YYLAST && yycheck[yyi] == *yyssp
5286
725k
               ? yytable[yyi]
5287
725k
               : yydefgoto[yylhs]);
5288
725k
  }
5289
5290
725k
  goto yynewstate;
5291
5292
5293
/*--------------------------------------.
5294
| yyerrlab -- here on detecting error.  |
5295
`--------------------------------------*/
5296
206k
yyerrlab:
5297
  /* Make sure we have latest lookahead translation.  See comments at
5298
     user semantic actions for why this is necessary.  */
5299
206k
  yytoken = yychar == YYEMPTY ? YYSYMBOL_YYEMPTY : YYTRANSLATE (yychar);
5300
  /* If not already recovering from an error, report this error.  */
5301
206k
  if (!yyerrstatus)
5302
6.22k
    {
5303
6.22k
      ++yynerrs;
5304
6.22k
      {
5305
6.22k
        yypcontext_t yyctx
5306
6.22k
          = {yyssp, yytoken};
5307
6.22k
        char const *yymsgp = YY_("syntax error");
5308
6.22k
        int yysyntax_error_status;
5309
6.22k
        yysyntax_error_status = yysyntax_error (&yymsg_alloc, &yymsg, &yyctx);
5310
6.22k
        if (yysyntax_error_status == 0)
5311
6.22k
          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.22k
        yyerror (yyscanner, compiler, yymsgp);
5332
6.22k
        if (yysyntax_error_status == YYENOMEM)
5333
0
          YYNOMEM;
5334
6.22k
      }
5335
6.22k
    }
5336
5337
206k
  if (yyerrstatus == 3)
5338
196k
    {
5339
      /* If just tried and failed to reuse lookahead token after an
5340
         error, discard it.  */
5341
5342
196k
      if (yychar <= _END_OF_FILE_)
5343
1.66k
        {
5344
          /* Return failure if at end of input.  */
5345
1.66k
          if (yychar == _END_OF_FILE_)
5346
1.66k
            YYABORT;
5347
1.66k
        }
5348
194k
      else
5349
194k
        {
5350
194k
          yydestruct ("Error: discarding",
5351
194k
                      yytoken, &yylval, yyscanner, compiler);
5352
194k
          yychar = YYEMPTY;
5353
194k
        }
5354
196k
    }
5355
5356
  /* Else will try to reuse lookahead token after shifting the error
5357
     token.  */
5358
204k
  goto yyerrlab1;
5359
5360
5361
/*---------------------------------------------------.
5362
| yyerrorlab -- error raised explicitly by YYERROR.  |
5363
`---------------------------------------------------*/
5364
204k
yyerrorlab:
5365
  /* Pacify compilers when the user code never invokes YYERROR and the
5366
     label yyerrorlab therefore never appears in user code.  */
5367
10.9k
  if (0)
5368
0
    YYERROR;
5369
10.9k
  ++yynerrs;
5370
5371
  /* Do not reclaim the symbols of the rule whose action triggered
5372
     this YYERROR.  */
5373
10.9k
  YYPOPSTACK (yylen);
5374
10.9k
  yylen = 0;
5375
10.9k
  YY_STACK_PRINT (yyss, yyssp);
5376
10.9k
  yystate = *yyssp;
5377
10.9k
  goto yyerrlab1;
5378
5379
5380
/*-------------------------------------------------------------.
5381
| yyerrlab1 -- common code for both syntax error and YYERROR.  |
5382
`-------------------------------------------------------------*/
5383
215k
yyerrlab1:
5384
215k
  yyerrstatus = 3;      /* Each real token shifted decrements this.  */
5385
5386
  /* Pop stack until we find a state that shifts the error token.  */
5387
215k
  for (;;)
5388
784k
    {
5389
784k
      yyn = yypact[yystate];
5390
784k
      if (!yypact_value_is_default (yyn))
5391
760k
        {
5392
760k
          yyn += YYSYMBOL_YYerror;
5393
760k
          if (0 <= yyn && yyn <= YYLAST && yycheck[yyn] == YYSYMBOL_YYerror)
5394
215k
            {
5395
215k
              yyn = yytable[yyn];
5396
215k
              if (0 < yyn)
5397
215k
                break;
5398
215k
            }
5399
760k
        }
5400
5401
      /* Pop the current state because it cannot handle the error token.  */
5402
569k
      if (yyssp == yyss)
5403
0
        YYABORT;
5404
5405
5406
569k
      yydestruct ("Error: popping",
5407
569k
                  YY_ACCESSING_SYMBOL (yystate), yyvsp, yyscanner, compiler);
5408
569k
      YYPOPSTACK (1);
5409
569k
      yystate = *yyssp;
5410
569k
      YY_STACK_PRINT (yyss, yyssp);
5411
569k
    }
5412
5413
215k
  YY_IGNORE_MAYBE_UNINITIALIZED_BEGIN
5414
215k
  *++yyvsp = yylval;
5415
215k
  YY_IGNORE_MAYBE_UNINITIALIZED_END
5416
5417
5418
  /* Shift the error token.  */
5419
215k
  YY_SYMBOL_PRINT ("Shifting", YY_ACCESSING_SYMBOL (yyn), yyvsp, yylsp);
5420
5421
215k
  yystate = yyn;
5422
215k
  goto yynewstate;
5423
5424
5425
/*-------------------------------------.
5426
| yyacceptlab -- YYACCEPT comes here.  |
5427
`-------------------------------------*/
5428
135
yyacceptlab:
5429
135
  yyresult = 0;
5430
135
  goto yyreturnlab;
5431
5432
5433
/*-----------------------------------.
5434
| yyabortlab -- YYABORT comes here.  |
5435
`-----------------------------------*/
5436
1.66k
yyabortlab:
5437
1.66k
  yyresult = 1;
5438
1.66k
  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.79k
yyreturnlab:
5454
1.79k
  if (yychar != YYEMPTY)
5455
1.66k
    {
5456
      /* Make sure we have latest lookahead translation.  See comments at
5457
         user semantic actions for why this is necessary.  */
5458
1.66k
      yytoken = YYTRANSLATE (yychar);
5459
1.66k
      yydestruct ("Cleanup: discarding lookahead",
5460
1.66k
                  yytoken, &yylval, yyscanner, compiler);
5461
1.66k
    }
5462
  /* Do not reclaim the symbols of the rule whose action triggered
5463
     this YYABORT or YYACCEPT.  */
5464
1.79k
  YYPOPSTACK (yylen);
5465
1.79k
  YY_STACK_PRINT (yyss, yyssp);
5466
17.0k
  while (yyssp != yyss)
5467
15.2k
    {
5468
15.2k
      yydestruct ("Cleanup: popping",
5469
15.2k
                  YY_ACCESSING_SYMBOL (+*yyssp), yyvsp, yyscanner, compiler);
5470
15.2k
      YYPOPSTACK (1);
5471
15.2k
    }
5472
1.79k
#ifndef yyoverflow
5473
1.79k
  if (yyss != yyssa)
5474
47
    YYSTACK_FREE (yyss);
5475
1.79k
#endif
5476
1.79k
  if (yymsg != yymsgbuf)
5477
0
    YYSTACK_FREE (yymsg);
5478
1.79k
  return yyresult;
5479
215k
}
5480
5481
#line 3029 "libyara/grammar.y"
5482