%{
#include <stdio.h>
+#include <string.h>
int yylex (void);
void yyerror (char const *);
%}
-%token CONST
+%union {
+ int b;
+ char* str;
+}
+
+%token <str> CONST
%left EQ
%left '|' '&' '^'
%left '!'
+%type <b> boo
%%
input: /* empty */
;
line: '\n'
- | boo '\n' { printf("%s\n",$1?"true":"false"); }
- | boo EQ boo { $$ = $1 == $2 }
- | boo '|' boo { $$ = $1 || $2 }
- | boo '&' boo { $$ = $1 && $2 }
- | boo '^' boo { $$ = ($1 || $2) && !($1 && $2) }
- | '!' boo { $$ = ! $1 }
+ | boo '\n' { printf("%s\n",$1?"true":"false"); }
+ | error '\n' { yyerrok; }
;
-boo:
+boo: CONST EQ CONST { $$ = ! strcmp($1, $3); }
+ | boo EQ boo { $$ = $1 == $3 }
+ | boo '|' boo { $$ = $1 || $3 }
+ | boo '&' boo { $$ = $1 && $3 }
+ | boo '^' boo { $$ = ($1 || $3) && !($1 && $3) }
+ | '!' boo { $$ = ! $2 }
+;
;
%%
#include <ctype.h>
-#include <string.h>
#define BUFSIZE 4096