Exemple #1
0
/** 
 * Determines whether the given follow restriction matches the remaining input 
 * string. It is used to determine if the associated reduction should be 
 * performed.
 * 
 * \param inputString the input string.
 * \param restrictions the follow restriction to compare against the input 
 * string.
 * 
 * \return \c true if the restriction does not match the input string; 
 * \c false otherwise.
 */
ATbool IS_checkLookahead(InputString inputString, PTBL_Restrictions restrictions) {
  PTBL_Restriction restriction;
  PT_Symbols charClasses;
  PT_Symbol cc;
  ATbool permitted = ATtrue;
  int index;
  
  for (; permitted && !PTBL_isRestrictionsEmpty(restrictions); restrictions = PTBL_getRestrictionsTail(restrictions)) {
    restriction = PTBL_getRestrictionsHead(restrictions);
    index = inputString->index;
    charClasses = (PT_Symbols)PTBL_getRestrictionCharClasses(restriction);

    while (!PT_isSymbolsEmpty(charClasses)) {
      cc = PT_getSymbolsHead(charClasses);
      charClasses = PT_getSymbolsTail(charClasses);
      index++;

      /* If at end of input no lookahead restrictions apply. */
      if (IS_getLength(inputString) == index) {
        break;
      }

      if (PT_elementOfCharClass(PT_makeTreeChar(getToken(inputString, index)), cc) && PT_isSymbolsEmpty(charClasses)) {
        permitted = ATfalse;
      }
    }
  }

  return permitted;
}
Exemple #2
0
PT_Tree PT_makeTreeLit(const char* string)
{
  int len = strlen(string);
  int i;
  PT_Args args = PT_makeArgsEmpty();
  PT_Symbols symbols = PT_makeSymbolsEmpty();
  PT_Symbol symbol = PT_makeSymbolLit(string);
  PT_Attributes attrs = PT_makeAttributesNoAttrs();
  PT_Production prod;

  for (i = len - 1; i >= 0; i--) {
    PT_Tree arg;
    PT_Symbol symbol;

    arg = PT_makeTreeChar(string[i]);
    args = PT_makeArgsMany(arg, args);

    symbol = PT_makeSymbolCharClass(
	      PT_makeCharRangesSingle(
	        PT_makeCharRangeCharacter(string[i])));
    symbols = PT_makeSymbolsMany(symbol, symbols);
  }

  prod = PT_makeProductionDefault(symbols, symbol, attrs);

  return PT_makeTreeAppl(prod, args);
}
Exemple #3
0
PT_Tree PT_makeTreeFlatLexicalFromString(const char *str)
{
  PT_Args args = PT_makeArgsEmpty();
  int i;

  for (i = strlen(str) - 1; i >= 0; i--) {
    args = PT_makeArgsList(PT_makeTreeChar((int) str[i]), args);
  }

  return PT_makeTreeFlatLexical(args);
}
Exemple #4
0
PT_Tree PT_makeTreeCilit(const char* string)
{
  int len = strlen(string);
  int i;
  PT_Args args = PT_makeArgsEmpty();
  PT_Symbols symbols = PT_makeSymbolsEmpty();
  PT_Symbol symbol = PT_makeSymbolCilit(string);
  PT_Attributes attrs = PT_makeAttributesNoAttrs();
  PT_Production prod;

  for (i = len - 1; i >= 0; i--) {
    PT_Tree arg;
    PT_Symbol symbol;

    arg = PT_makeTreeChar(string[i]);
    args = PT_makeArgsMany(arg, args);

    if (string[i] >= 'A' && string[i] <= 'Z') {
      PT_CharRanges range1 =  PT_makeCharRangesSingle(              
	                         PT_makeCharRangeCharacter(string[i]));
      PT_CharRanges range2 =  PT_makeCharRangesSingle(              
	                         PT_makeCharRangeCharacter(string[i]+
							   ('a' - 'A')));
      symbol = PT_makeSymbolCharClass(PT_concatCharRanges(range1,range2));
    }
    else if (string[i] >= 'a' && string[i] <= 'z') {
      PT_CharRanges range1 =  PT_makeCharRangesSingle(              
	                         PT_makeCharRangeCharacter(string[i]));
      PT_CharRanges range2 =  PT_makeCharRangesSingle(              
	                         PT_makeCharRangeCharacter(string[i]-
							   ('a' - 'A')));
      symbol = PT_makeSymbolCharClass(PT_concatCharRanges(range2,range1));
    }
    else {
      symbol = PT_makeSymbolCharClass(
	         PT_makeCharRangesSingle(
	           PT_makeCharRangeCharacter(string[i])));
    }

    symbols = PT_makeSymbolsMany(symbol, symbols);
  }

  prod = PT_makeProductionDefault(symbols, symbol, attrs);

  return PT_makeTreeAppl(prod, args);
}