Compiler Lab Experiment 5 Program
Compiler Lab Experiment 5 Program
vi.filename.l
%{
#include"y.tab.h"
%}
%%
[a] {return A;}
[b] {return B;}
[\n] {return NL;}
%%
vi.filename.y
%{
#include<stdio.h>
#include<stdlib.h>
%}
%token A B NL
%%
Start: S NL {printf("accepted\n");exit (0);}
S: A B | A S B
%%
main()
{
printf("enter the string : ");
yyparse();
}
yyerror()
{
printf("not accepted");
return(0);
}
yywrap()
{
Output
[cs2120@LabServer complier]$ lex filename.l
[cs2120@LabServer complier]$ yacc -d filename.y
[cs2120@LabServer complier]$ cc lex.yy.c y.tab.c -ll
[cs2120@LabServer complier]$ ./a.out
enter the string : ab
accepted
enter the string : abb
not accepted