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:
- Step – Using gedit create a file with extension .l For example: prg1.l
- Step – lex prg1.l
- Step – cc lex.yy.c –ll
- Step – ./a.out
Steps in writing YACC Program:
- Step: Using gedit editor create a file with extension y. For example: gedit prg1.y
- Step: YACC –d prg1.y
- Step: lex prg1.l
- Step: cc y.tab.c lex.yy.c -ll
- Step: /a.out
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