emp_ematch.y revision 311b41454dc445639924c691a949bd15fbfab0cb
1%{
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
10%pure_parser
11%token-table
12%error-verbose
13%name-prefix="ematch_"
14
15%union {
16	unsigned int i;
17	struct bstr *b;
18	struct ematch *e;
19}
20
21%{
22 extern int yylex(YYSTYPE *, YYLTYPE *);
23 extern void yyerror(char *s);
24 extern struct ematch *ematch_root;
25 extern char *ematch_err;
26%}
27
28%token <i> ERROR
29%token <b> ATTRIBUTE
30%token <i> AND OR NOT
31%type <i> invert relation
32%type <e> match expr
33%type <b> args
34%right AND OR
35%start input
36%%
37input:
38	/* empty */
39	| expr
40		{ ematch_root = $1; }
41	| expr error
42		{
43			ematch_root = $1;
44			YYACCEPT;
45		}
46	;
47
48expr:
49	match
50		{ $$ = $1; }
51	| match relation expr
52		{
53			$1->relation = $2;
54			$1->next = $3;
55			$$ = $1;
56		}
57	;
58
59match:
60	invert ATTRIBUTE '(' args ')'
61		{
62			$2->next = $4;
63			$$ = new_ematch($2, $1);
64			if ($$ == NULL)
65				YYABORT;
66		}
67	| invert '(' expr ')'
68		{
69			$$ = new_ematch(NULL, $1);
70			if ($$ == NULL)
71				YYABORT;
72			$$->child = $3;
73		}
74	;
75
76args:
77	ATTRIBUTE
78		{ $$ = $1; }
79	| ATTRIBUTE args
80		{ $1->next = $2; }
81	;
82
83relation:
84	AND
85		{ $$ = TCF_EM_REL_AND; }
86	| OR
87		{ $$ = TCF_EM_REL_OR; }
88	;
89
90invert:
91	/* empty */
92		{ $$ = 0; }
93	| NOT
94		{ $$ = 1; }
95	;
96%%
97
98 void yyerror(char *s)
99 {
100	 ematch_err = strdup(s);
101 }
102
103