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