0% found this document useful (0 votes)
3 views

Compiler Lab Experiment 5 Program

The document outlines a simple language acceptance program using YACC and Lex. It defines a grammar that accepts strings consisting of 'a' followed by 'b', and implements error handling for invalid inputs. The program demonstrates its functionality with example inputs and outputs indicating acceptance or rejection of the strings.

Uploaded by

abhishek21032004
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
3 views

Compiler Lab Experiment 5 Program

The document outlines a simple language acceptance program using YACC and Lex. It defines a grammar that accepts strings consisting of 'a' followed by 'b', and implements error handling for invalid inputs. The program demonstrates its functionality with example inputs and outputs indicating acceptance or rejection of the strings.

Uploaded by

abhishek21032004
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 1

Language Acceptance Using YACC -1

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

You might also like