11. Program in YACC to recognize the language (a^n b , n>=10). (output to say input is valid or not)

 

Program in YACC to recognize the language (a^n b , n>=10). (output to say input is valid or not)


File Name : pr12.y
/* program to check whether the given string is  a part of the language a^n b or not */
/* Shows nothing if string is a part of language */
/* shows a message if string is not a part of language */
%{
 #include<stdio.h>
 int yylex(void);
 int yyerror(char *);
 
%}

%token A B   //tokens : the alphabets of language 'a' and 'b' 

%%
//production rules for grammar
expr: s B         
  ;
s : s A 
| A   

;

%%

int main()
{
 
 printf("Enter the string \n");
 yyparse(); 
 return 0;
}

int yyerror(char *s)
{
 printf("Invalid: Not a part of the language - a^n b \n");
}

File Name : pr12.l
%{
 #include "y.tab.h"
 extern int yylval;
%}
A [a]
B [b]
%%

{A} {yylval=yytext[0];return A;}
{B} {yylval=yytext[1];return B;}
\n {return 0;}
. {return yytext[0];}

%%

// Output of the Above Program.
Program in YACC to recognize the language (a^n b , n>=10). (output to say input is valid or not)
Program in YACC to recognize the language (a^n b , n>=10). (output to say input is valid or not)

Comments

  1. Last-minute coursework can be stressful, particularly when students have several deadlines approaching together. In such situations, last minute assignment help can provide timely academic guidance and help students organise their workload. Support with research, structure, proofreading, and difficult concepts can make urgent tasks more manageable. Students should still review the work carefully and understand the subject matter. Planning ahead is always preferable, but appropriate guidance can help reduce pressure when unexpected deadlines or busy schedules arise.

    ReplyDelete

Post a Comment

Popular posts from this blog

Compiler Design

7. Lex specification program that generates a C program which takes a string “abcd” and prints the pattern

10. Program in YACC to recognize the string „abbb^n, „ab^n „a^n of the langauge (a^n b^n , n>=1)