answersLogoWhite

0


Best Answer

#include<stdio.h>

#include<conio.h>

#include<string.h>

void main()

{

char string[50];

int flag,count=o;

clrscr();

printf("The grammar is: S->aS, S->Sb, S->ab\n");

printf("Enter the string to be checked:\n");

gets(string);

if(string[0]=='a')

{

flag=0;

for(count=1;string[count-1]!='\0';count++)

{

if(string[count=='b'])

{

flag=1;

continue;

}

else if((flag==1)&&(string[count]=='a'))

{

printf("The string does not belong to the specified grammar");

break;

}

else if(string[count=='a'])

continue;

else if(flag==1)&&(string[count]='\0'))

{

printf("The string accepted");

break;

}

else

{

printf("String not accepted");

}

getch():

User Avatar

Wiki User

13y ago
This answer is:
User Avatar

Add your answer:

Earn +20 pts
Q: How do you write a program to check the string of a given grammar?
Write your answer...
Submit
Still have questions?
magnify glass
imp
Related questions

Could you write a assembly language program in tasm To check whether a given number present in a sequence of given memory location containing the string to be checked in 8086?

8086 assembly language program to check wether given number is perfect or not


Write a Java Program to find occurences of given word in a text?

Check the documentation of the String class, for a method that searches for a substring.


Write a java program to count the space from the given line?

.... String line = "This is example program with spaces"; String[] tokens = line.split(" "); System.out.println(tokens.length-1); .......


Program to check that given string is palindrome or not in C?

/*To check whether a string is palindrome*/includeincludevoid main () { int i,j,f=0; char a[10]; clrscr (); gets(a); for (i=0;a[i]!='\0';i++) { } i--; for (j=0;a[j]!='\0';j++,i--) { if (a[i]!=a[j]) f=1; } if (f==0) printf("string is palindrome"); else printf("string is not palindrome"); getch (); }


Do I need to write a program to find a substring in a given string in c plus plus?

No.


Program to generate tokens from a given expression string?

a promlem to solve an equation or a assigment


Write a program that stores vowels in an array When you program is given a character it should indicate whether the character is vowel or not?

That's easy to do!This script will get the POST data from an HTML form and check if it is a vowel.


How to write A Java program to print number of digits in a given number?

One way to do this is to convert the number to a String, then use the corresponding String method to find out the length of the String.


A -- AA AA a b what is the parse tree?

The parse tree for the given string would show the structure of the string broken down into tokens and their relationships based on the grammar rules. In this case, based on the example provided, the parse tree would illustrate how the string 'AA AA a b' can be derived from the grammar rules defined for the language.


How do you delete the given string in java programming?

You usually do not need to delete a String, since when the program no longer refers to it, the garbage collector will clean it up.


Write a program to change the case of the given string?

This functionality is already in Java. String.toLowerCase() and String.toUpperCase() will take care of it for you.


How do you write a program to find the no of words in a given string in dot net?

You find a language that can be targeted towards the .NET Framework. What you are suggesting is something related to string manipulation and you can work with delimiters.