C++Talk.NET Forum Index C++Talk.NET
C++ language newsgroups
 
Archives   FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Help Badly needed- replacing rules & strings

 
Post new topic   Reply to topic    C++Talk.NET Forum Index -> C++ language (comp.lang.c++)
View previous topic :: View next topic  
Author Message
Willing 2 Learn
Guest





PostPosted: Tue Feb 28, 2006 4:06 am    Post subject: Help Badly needed- replacing rules & strings Reply with quote



I'm working on this program below but im stuck. after it finds a match
b/ween sentence & non_terminal it will output where these are found in
both strings. I need it to spit out the rules with a matching LHS
related to that non_terminal; i want to allow the user to select a rule
(from # key)they want to use. When the user selects a specified rule;
i need to replace the rule in that present address by expanding the
non_terminal. I was trying to do this by finding the length of string &
length of senetnce then from left to right move over to make space for
length of string that is being inserted. After doing this couple
times, it will ask the user to enter a dummy value; this will tell it
to go to the next address & do same by outputting rules related to next
address; then repating steps from user. It should do this till entire
string is replaced then output the new string.

#include <iostream.h>
#include <string.h>

int main()
{
char sentence[81]= "E+ND+T";
char terminal[] = "0123456789+-()";
char non_terminal[]="ETND";
char* sptr;
char* nptr;
char s, n;
int rule,length;

//Output the sentence
cout<<(int)&sentence<<endl; //convert string address to int

sptr = &sentence[0];


while(*sptr !='\0')
{

s = *sptr;
cout<<"s="<<s<<endl;
sptr++;

nptr = &non_terminal[0];

while(*nptr !='\0')
{
n = *nptr;
cout<<"n="<< n;


//Output the non-terminals and their position n the sentence and in
the non-terminals

if (s == n)
{
cout<<"Found "<<s<<" at "<<(int)sptr<<" in "<<sentence<<endl;
cout<<"Found "<<n<<" at "<<(int)nptr<<" in "<<non_terminal<<endl;


//output rule relating to non-terminal
if(n =='E')
{
cout<<"Rule: E= E+T (Enter 1)"<<endl;
cout<<"Rule: E= E-T (Enter 2)"<<endl;
cout<<"Rule: E= T (Enter 3)"<<endl;
}

if(n =='T')
{
cout<<"Rule: T = N (Enter 4)"<<endl;
cout<<"Rule: T = (E) (Enter 5)"<<endl;

}
if(n =='N')
{
cout<<"Rule: N= ND (Enter 6)"<<endl;
cout<<"Rule: N = D (Enter 7)"<<endl;

}
if(n =='D')
{
cout<<"Rule: D = 0 (Enter Cool"<<endl;
cout<<"Rule: D = 1 (Enter 9)"<<endl;
cout<<"Rule: D = 2 (Enter 10)"<<endl;
cout<<"Rule: D = 3 (Enter 11)"<<endl;
cout<<"Rule: D = 4 (Enter 12)"<<endl;
cout<<"Rule: D = 5 (Enter 13)"<<endl;
cout<<"Rule: D = 6 (Enter 14)"<<endl;
cout<<"Rule: D = 7 (Enter 15)"<<endl;
cout<<"Rule: D = 8 (Enter 16)"<<endl;
cout<<"Rule: D = 9 (Enter 17)"<<endl;


}



break;

}
nptr++;
}
}

//Ask user to enter # for rule
cout<<"Please enter # for rule selected ";
cin>>rule;

//for(int i=0; i>1; i++)
//{
//length= n.length();
//cout<<length<<endl;
//}




/*switch(rule)
{
case '1': E + T;
case '2': E - T;
case '3': E = T
case '4': T = N;
case '5': T = (E);
case '6': N = ND;
case '7': N = D;
case '8': D = 0;
case '9': D = 1;
case '10': D = 2;
case '11': D = 3;
case '12': D = 4;
case '13': D = 5;
case '14': D = 6;
case '15': D = 7;
case '16': D = 8;
case '17': D = 9;
}*/


return 0;
}
Back to top
Display posts from previous:   
Post new topic   Reply to topic    C++Talk.NET Forum Index -> C++ language (comp.lang.c++) All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2006 phpBB Group
SEO toolkit © 2004-2006 webmedic.