Search This Blog

Tuesday, December 11, 2018

string belongs to the given grammar or not

C Program for implementation of  language given below
E-> TE’
 E’-> +TE’ | epsilon
T-> FT’
T’-> *FT’  | epsilon
 F-> (E) | i







#include<stdio.h> #include<conio.h> #include<string.h> #include<process.h> void e(); void e1(); void t(); void t1(); void f(); int ip=0; static char s[10]; void main() { char k; int i; ip=0; clrscr(); printf("enter the string:\n "); scanf("%s",s); printf("the string is : %s\n",s); e(); if(s[ip]=='$') printf("String is accepted "); getch(); } void e() { t(); e1(); return; } void t() { f(); t1(); // return; } void e1() { if(s[ip]=='+') { ip++; t(); e1(); } return; } void t1() { if(s[ip]=='*') { ip++; f(); t1(); } return; } void f() { if(s[ip]=='(') { ip++; e(); if(s[ip]==')') ip++; else printf("error closed paranthesis expected"); } else if(s[ip]=='i') ip++; else printf("id expected "); return; }

No comments:

Computer Programming Lab (23CS51) / A.Y : 2025-2026 /IT / I Sem / A

  PRE-REQUISITE: Mathematics, Basic Computer Terminology COURSE EDUCATIONAL OBJECTIVE (CEO): The course aims to give students hands–on exp...