Lex and Yacc program that accepts bits(0 and 1)

LEX file:

%{
#include "y.tab.c"
extern int yylval;
%}

%%
[0] {yylval=atoi(yytext); return zero;}
[1] {yylval=atoi(yytext); return one;}
%%

Yacc file:

%{
#include<stdio.h>
#include<string.h>
%}

%token zero one

%%
s : e {printf("String acepted");}
   ;
e : e t
   | t
   ;
t  : zero
   | one
   ;
%%
 main()
{
yyparse();
}
yyerror(char * arg)
{
printf("Invalid expression");
}

Comments