Compiler Design
0
down vote
favorite
Creating email addresses form names
You have given a file containing names of several persons. The file will have exactly one name is each line. You need to create email address ending with @bitmesra.ac.in from those names. the rule for creating email address is defined below: A name will be expressed in the following form: ............
Let F(s) denote the first character of string s. so, email id will be F(string 1)F(string 2)........._lastString@bitmesra.ac.in Some names and their corresponding email id's are listed below as an example
Sachin Ramesh Tendulkar s_r_tendulkar@bitmesra.ac.in Rahul S Dravid r_s_dravid@bitmesra.ac.in
You need to generate a grammer for this.
note: there may multiple spaces b/w names.
my code is here...
#include<cstdio>
#include<cstring>
#include<cctype>
int main()
{
char str1[100],str2[100];
char str3[] = "@bitmesra.ac.in";
while(gets(str1))
{
int index,k=0;
str2[k] = tolower(str1[0]);
for(int i=1;i<strlen(str1);i++)
{
if(str1[i]==' ')
{
index = i;
if(isalpha(str1[i+1]))
{
k++;
str2[k] = '_';
k++;
str2[k] = tolower(str1[i+1]);
}
}
}
index= index + 2;
for(int i=index;str1[i]!='\0';i++)
{
k++;
str2[k] = tolower(str1[i]);
}
str2[++k] = '\0';
strcat(str2,str3);
printf("%s\n",str2);
}
return 0;
}
how to desing CFG for this...