I'd like to know:

1.) On line of code which says: "Production possibleExpansion(infile);", what is the nature of possibleExpansion(infile)? Is it a function? Is it an object of class Production?

2.) On line of code which says: "possibleExpansions.push_back(possibleExpansion);", what is the meaning of it?

#include "definition.h"
#include "random.h"

Definition::Definition(ifstream& infile)
  string uselessText;
  getline(infile, uselessText, '{');
  infile >> nonterminal;
  getline(infile, uselessText); 

  while (infile.peek() != '}') {
    Production possibleExpansion(infile);
  getline(infile, uselessText, '}');

const Production& Definition::getRandomProduction() const
  static RandomGenerator random; 
  int randomIndex = random.getRandomInteger(0, possibleExpansions.size() - 1);
  return possibleExpansions[randomIndex];

Here is the Definition.cpp code:

#ifndef __definition__
#define __definition__

#include "production.h"
#include <vector>
using namespace std;  

class Definition {
  Definition() {}
  Definition(ifstream& infile);
  const string& getNonterminal() const { return nonterminal; }
  const Production& getRandomProduction() const;
  string nonterminal;
  vector<Production> possibleExpansions;

#endif // ! __definition__

1) It is an object of the Production class.
2) It adds the Production object to the end of a collection of Production objects.

Edited 5 Years Ago by Narue: n/a

This article has been dead for over six months. Start a new discussion instead.