Esempio n. 1
0
  static void readGrammar(ifstream& infile, map<string, Definition>& grammar)
  {   
    // Keep parsing until EOF is reached.
    while(infile.good())
    { 
      // Ignore all chars until '{' is reached.
      infile.ignore(numeric_limits<streamsize>::max(), '{');

      // Ignore all chars until '\n' is reached.
      infile.ignore(numeric_limits<streamsize>::max(), '<');

      if(infile.good()) 
      {
        // Beginning of a definition; parse into program.
        Definition myDefinition = Definition(infile);
        
        // Fill map.
        string myNonTerminal = myDefinition.getNonterminal();
        pair<string, Definition> myPair(myNonTerminal, myDefinition);
        grammar.insert(myPair);
      }
    }

    infile.close();
}
static void readGrammar(ifstream& infile, map<string, Definition>& grammar)
{
 
  string currentLine;
   
  while (!infile.eof()) {

    getline(infile,currentLine);
      
    char lastChar = currentLine.back();

    if (lastChar == '{') {
    
      Definition definition (infile);

      // Now put Definition in grammar map

      grammar.insert ( pair<string, Definition>(definition.getNonterminal(),definition) );
    }
  }
  infile.close();
}