System Software Lab 2 | Read Now

System Software VTU Lab

Program 2:- Develop, Implement and execute a program using the YACC tool to recognize all strings ending with b preceded by n a’s using the grammar a b (note: input n value).


Steps in writing LEX Program:

  1. Step – Using gedit create a file with extension .l For example: prg1.l
  2. Step – lex prg1.l
  3. Step – cc lex.yy.c –ll
  4. Step – ./a.out

Steps in writing YACC Program:

  1. Step: Using gedit editor create a file with extension y. For example: gedit prg1.y
  2. Step: YACC –d prg1.y
  3. Step: lex prg1.l
  4. Step: cc y.tab.c lex.yy.c -ll
  5. Step: /a.out
See also  Microprocessor and Microcontroller Lab 12 | Read Now

System Software Lab2 Code [lab2.l]

%{
#include "y.tab.h"
%}
%%
a {return A;}
b {return B;}
[\n] return '\n';
%%

System Software Lab2 Code [lab2.y]

%{
#include<stdio.h>
#include<stdlib.h>
%}
%token A B
%%
input:s'\n' {printf("Successful Grammar\n");exit(0);}
s: A s1 B| B s1: ; | A s1
%%

main()
{
 printf("Enter A String\n"); yyparse();
}

int yyerror()
{
 printf("Error \n"); exit(0);
}

Output

System Software

Leave a Reply

Your email address will not be published. Required fields are marked *

WhatsApp Icon Join For Job Alerts