Hey guys I have a problem with my program, I am trying to read in a grammar putting multiple right hand rules to a left hand rule using multimapping. The thing is that let’s say the rule is:
a -> al be ze
it maps [a, al] and ignores the rest.
Leaving the key alone, I want to put different attributes to that key.
Was wondering if you guys could spot an error that I cannot seem to find.
Am I using multi-mapping incorrectly?
Thank you.
map<string, string> rule; // global var
void righthandside(){ // get rhs of grammar rule
char c;
skipSpace();
c = getchar();
if(isalpha(c)){
checkforE = false; // rule not epsilon
while(isalnum(c)){
righths += c;
c = getchar();
}
righths += '\0';
rule.insert(pair<string, string>(LHS[lhs], righths));
righths.clear();
righthandside();
}
else if(c == '#'){
if(checkforE == true)
rule.insert(pair<string, string>(LHS[lhs], epsilon)); // rule states NT goes to epsilon
skipSpace();
c = getchar();
if(c == '#'){ //end of file
cout << "end of file \n";
}
else{ // end of rule
ungetc(c, stdin);
lhs++;
readGR();
}
}
else{
errorcode(0);
}
}
If you want a single unique key with multiple values you could use
std::mapwith a container for the values such as:If you want duplicate keys with one value each you could instead use
std::multimaplike this:That would allow
ruleto contain the pairs[a,al],[a,be],[a,ze]