Compiler 3
Compiler 3
Ques:- WAP to check whether the input string is accepted or not by S->
aS|Sb|b code in c.
Code:-
#include <stdio.h>
#include <string.h>
#include <stdbool.h>
int i = 0;
i++;
int b_start = i;
i++;
if (i == len && strchr(str, 'b') != NULL && strrchr(str, 'a') < strchr(str, 'b')) {
return true;
} else {
return false;
}
int main() {
char input[100];
scanf("%s", input);
if (isAccepted(input)) {
} else {
return 0;
Output:-
Program No-6
Code:-
%{
#include <stdio.h>
%}
%%
[aAeEiIoOuU] { vowels++; }
[b-df-hj-np-tv-zB-DF-HJ-NP-TV-Z] { consonants++; }
.|\n ;
%%
int main() {
printf("Enter a string:\n");
yylex();
return 0;
int yywrap() {
return 1;
Output:-
Program No-7
Ques:- Lex program to count the number of vowels and consonants in a given string.
Code:-
%{
#include <stdio.h>
int vowels = 0;
int consonants = 0;
%}
%%
[aAeEiIoOuU] { vowels++; }
[b-df-hj-np-tv-zB-DF-HJ-NP-TV-Z] { consonants++; }
.|\n ;
%%
int main() {
printf("Enter a string:\n");
yylex();
return 0;
int yywrap() {
return 1;
Output:-