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 %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 %{ 21 extern int ematch_lex(void); 22 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 %% 36 input: 37 /* empty */ 38 | expr 39 { ematch_root = $1; } 40 | expr error 41 { 42 ematch_root = $1; 43 YYACCEPT; 44 } 45 ; 46 47 expr: 48 match 49 { $$ = $1; } 50 | match relation expr 51 { 52 $1->relation = $2; 53 $1->next = $3; 54 $$ = $1; 55 } 56 ; 57 58 match: 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 75 args: 76 ATTRIBUTE 77 { $$ = $1; } 78 | ATTRIBUTE args 79 { $1->next = $2; } 80 ; 81 82 relation: 83 AND 84 { $$ = TCF_EM_REL_AND; } 85 | OR 86 { $$ = TCF_EM_REL_OR; } 87 ; 88 89 invert: 90 /* empty */ 91 { $$ = 0; } 92 | NOT 93 { $$ = 1; } 94 ; 95 %% 96 97 void yyerror(char *s) 98 { 99 ematch_err = strdup(s); 100 } 101 102