Debian Codegraph @

tc/emp_ematch.y

raw
1 %{
2 /* SPDX-License-Identifier: GPL-2.0-or-later */
3 #include <stdio.h>
4 #include <stdlib.h>
5 #include <malloc.h>
6 #include <string.h>
7 #include "m_ematch.h"
8 %}
9
10 %union {
11 unsigned int i;
12 struct bstr *b;
13 struct ematch *e;
14 }
15
16 %{
17 extern int ematch_lex(void);
18 extern void yyerror(const char *s);
19 extern struct ematch *ematch_root;
20 extern char *ematch_err;
21 %}
22
23 %token <i> ERROR
24 %token <b> ATTRIBUTE
25 %token <i> AND OR NOT
26 %type <i> invert relation
27 %type <e> match expr
28 %type <b> args
29 %right AND OR
30 %start input
31 %%
32 input:
33 /* empty */
34 | expr
35 { ematch_root = $1; }
36 | expr error
37 {
38 ematch_root = $1;
39 YYACCEPT;
40 }
41 ;
42
43 expr:
44 match
45 { $$ = $1; }
46 | match relation expr
47 {
48 $1->relation = $2;
49 $1->next = $3;
50 $$ = $1;
51 }
52 ;
53
54 match:
55 invert ATTRIBUTE '(' args ')'
56 {
57 $2->next = $4;
58 $$ = new_ematch($2, $1);
59 if ($$ == NULL)
60 YYABORT;
61 }
62 | invert '(' expr ')'
63 {
64 $$ = new_ematch(NULL, $1);
65 if ($$ == NULL)
66 YYABORT;
67 $$->child = $3;
68 }
69 ;
70
71 args:
72 ATTRIBUTE
73 { $$ = $1; }
74 | ATTRIBUTE args
75 { $1->next = $2; }
76 ;
77
78 relation:
79 AND
80 { $$ = TCF_EM_REL_AND; }
81 | OR
82 { $$ = TCF_EM_REL_OR; }
83 ;
84
85 invert:
86 /* empty */
87 { $$ = 0; }
88 | NOT
89 { $$ = 1; }
90 ;
91 %%
92
93 void yyerror(const char *s)
94 {
95 ematch_err = strdup(s);
96 }