blob: 2e6cf3530ef2cd5a22a09896154cd550c2abc39c [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
Stephen Hemmingeredd39792014-10-09 08:31:10 -070012%name-prefix "ematch_"
shemminger311b4142005-06-23 20:25:16 +000013
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);
Stephen Hemminger5761f042012-01-03 13:55:00 -080022 extern void yyerror(const char *s);
shemminger311b4142005-06-23 20:25:16 +000023 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
Stephen Hemminger5761f042012-01-03 13:55:00 -080097 void yyerror(const char *s)
shemminger311b4142005-06-23 20:25:16 +000098 {
99 ematch_err = strdup(s);
100 }