I am trying to write a calculator for nor expressions, such as "true nor false". Here is my .l file:
%{
#include <stdlib.h>
#include "y.tab.h"
%}
%%
"true" {yylval=1; return BOOLEAN;}
"false" {yylval=0; return BOOLEAN;}
"nor" {return NOR;}
" " { }
. {return yytext[0];}
%%
int main(void)
{
yyparse();
return 0;
}
int yywrap(void)
{
return 0;
}
int yyerror(void)
{
printf("Error\n");
}
Here is my .y file:
/* Bison declarations. */
%token BOOLEAN
%token NOR
%left NOR
%% /* The grammar follows. */
input:
/* empty */
| input line
;
line:
'\n'
| exp '\n' {printf ("%s",$1); }
;
exp:
BOOLEAN { $$ = $1;}
| exp NOR exp { $$ = !($1 || $3); }
| '(' exp ')' { $$ = $2;}
;
%%
The problem is that when I enter an expression like "true nor false", I don't see any result being printed out. Anyone know what's wrong?
line
. – StoryTeller - Unslander Monica