Ejemplo n.º 1
0
VectorOf<Chars> PresentationParser::parseGeneratorList( Chars& errMesg )
{
  VectorOf<Chars> result;

  if ( curToken == INIT ) getToken();

  while ( curToken == GENERATOR ) {

	 Chars name(tokenName);

    // Check for duplication and presence of inverses.
	 if ( result.indexOf(name) >= 0 ) {
		parseError("Duplicate generator");
		errMesg = parseErrorMessage;
		return result;
	 } else {
		invertName(tokenName);
		if ( result.indexOf(Chars(tokenName)) >= 0 ) {
		  parseError("Duplicate generator: formal inverse");
		  errMesg = parseErrorMessage;
		  return result;
		}
	 }

	 result.append(name); // Ok, it's inefficient, but time is $$

	 getToken();

	 if ( curToken == COMMA ) {
	   getToken();
	   if ( curToken == DOT ) {
	     if (!getGeneratorRange(name,result,errMesg))
	       return result;
	   } else {
	     if ( curToken != GENERATOR ) {
	       parseError("Expected a generator here");
	       errMesg = parseErrorMessage;
	       return result;
	     }
	   }
	 }
  }

  return result;
}
Ejemplo n.º 2
0
Subgroup& Subgroup::deleteGenerator( const Word& w ) {
  VectorOf<Word> theGenerators = look()->theGenerators;
  int i = theGenerators.indexOf(w);
  if ( i == -1 )
	 error("attempt to delete nonexistent word in Subgroup::deleteGenerator");
  else {
	 int len = theGenerators.length();
	 VectorOf<Word> temp(len - 1);
	 int k = 0;
	 for( int j = 0; j < len; ++j )
		if ( j != i ) temp[k++] = theGenerators[j];
	 change()->theGenerators = temp;
	 
	 enhance()->theOrder = -1;
	 // @stc not yet correct: the order does not necessarily become unknown
	 return *this;
  }
}
Ejemplo n.º 3
0
bool PresentationParser::getGeneratorRange( const Chars& name,
					    VectorOf<Chars>& result,
					    Chars& errMesg )
{
  if ( curToken != DOT ) 
    error("bool PresentationParser::getGeneratorRange() "
	  "can't read the range");
  // Make sure, that we have 3 dots in a row
  for (int i = 0;i<2;i++){
    getToken();
    if ( curToken != DOT ) {
      parseError("Expected '.' here");
      errMesg = parseErrorMessage;
      return false;
    }   
  }
  getToken();
  
   // Supose to be ','
  if ( curToken != COMMA ) {
    parseError("Expected ',' here");
    errMesg = parseErrorMessage;
    return false;
  }    

  getToken();
  
  // Supose to be a generator
  if ( curToken != GENERATOR ) {
    parseError("Expected a generator here");
    errMesg = parseErrorMessage;
    return false;
  }    
  Chars name1;
  int beginRange;
  
  // Generators must be in the form: <name><index>, where
  // index is the first and the last generator index in a range.
  // 
  Chars rangeErrMsg = "When defining a set of generators using a range of "
    "subscripts, both the smallest subscript and the largest subscript"
    " must be given and the smallest subscript mast be less then the "
    "largest one";

  if ( !getRangeOf(name,name1,beginRange)) {
    parseError(rangeErrMsg);
    errMesg = parseErrorMessage;
    return false;    
  }
  Chars name2;
  int endRange;  
  if ( !getRangeOf(tokenName,name2,endRange)) {
    parseError(rangeErrMsg);
    errMesg = parseErrorMessage;
    return false;    
  }

  // The last index must be greater than the first one
  if ( endRange <= beginRange) {
    parseError(rangeErrMsg);
    errMesg = parseErrorMessage;
    return false;    
  }
 
  // Names gave to be equal
  if ( name2 != name1) {
    parseError(rangeErrMsg);
    errMesg = parseErrorMessage;
    return false;    
  }

  // Generate generators of type: name1<index>, where
  // beginRange < index < endRange
  int numberOfGens = endRange - beginRange - 1;
  if (numberOfGens > 0){
    VectorOf<Chars> gens(numberOfGens);
    
    for(int i = 0;i<numberOfGens;i++){
      gens[i] = name1+Chars(beginRange + 1 + i);
      // Check for duplication and presence of inverses.
      if ( result.indexOf(gens[i]) >= 0 ) {
	parseError("Duplicate generator");
	errMesg = parseErrorMessage;
	return false;
      } else {
	char str[100];
	strcpy(str,gens[i]);
	invertName(str);
	if ( result.indexOf(Chars(str)) >= 0 ) {
	  parseError("Duplicate generator: formal inverse");
	  errMesg = parseErrorMessage;
	  return false;
	}
      }
    }
    result = concatenate(result, gens);
  }
  return true;
}