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