10 void yyerror (char const *);
12 int regex_cmp(char* s, char* r);
25 %left EQ NEQ GE LE GT LT RE NRE
36 | boo '\n' { printf("%s\n",$1?"true":"false"); }
37 | error '\n' { yyerrok; }
40 boo: CONST EQ CONST { $$ = ! strcmp($1, $3); }
41 | CONST NEQ CONST { $$ = !! strcmp($1, $3); }
42 | CONST RE REGEX { $$ = regex_cmp($1,$3) >= 0 }
43 | CONST NRE REGEX { $$ = regex_cmp($1,$3) < 0 }
44 | NUM EQ NUM { $$ = $1 == $3 }
45 | NUM NEQ NUM { $$ = $1 != $3 }
46 | NUM GE NUM { $$ = $1 >= $3 }
47 | NUM LE NUM { $$ = $1 <= $3 }
48 | NUM GT NUM { $$ = $1 > $3 }
49 | NUM LT NUM { $$ = $1 < $3 }
50 | boo '|' boo { $$ = $1 || $3 }
51 | boo '&' boo { $$ = $1 && $3 }
52 | boo '^' boo { $$ = ($1 || $3) && !($1 && $3) }
53 | '!' boo { $$ = ! $2 }
65 regex_cmp(char* s, char* r)
70 int ovector[OVECCOUNT];
72 brum=pcre_compile(r,0,&error,&erroroffset,NULL);
76 int res=pcre_exec(brum,NULL,s,strlen(s),0,0,ovector,OVECCOUNT);
84 get_string_out(char delim)
91 if (!(s = malloc(BUFSIZE))){
96 while ((c = getchar()) != delim || last == '\\'){
97 if (last=='\\' && c != delim)
118 while ((c = getchar ()) == ' ' || c == '\t');
122 yylval.str = get_string_out('"');
128 yylval.str = get_string_out('\'');
134 yylval.str = get_string_out('/');
140 scanf("%d",&yylval.n);
145 if ((c = getchar ()) == '=')
154 if ((c = getchar ()) == '=')
163 if ((c = getchar ()) == '=')
172 if ((c = getchar ()) == '=')
179 if ((c = getchar ()) == '~')
192 yyerror (char const *s)
194 fprintf (stderr, "%s\n", s);