Esempio n. 1
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);
}
Esempio n. 2
0
static PT_Attributes SDFAttributesToPtAttributes(SDF_Attributes sdfAttributes) 
{
  PT_Attributes ptAttributes;

  if (SDF_isAttributesNoAttrs(sdfAttributes)) {
    ptAttributes = PT_makeAttributesNoAttrs();
  }
  else {
    SDF_AttributeList sdfAttrList = SDF_getAttributesList(sdfAttributes);
    PT_Attrs ptAttrList = NULL;
 
    if (SDF_isAttributeListEmpty(sdfAttrList)) {
      ptAttributes = PT_makeAttributesNoAttrs();
    }
    else {
      while (SDF_hasAttributeListHead(sdfAttrList)) {
        SDF_Attribute sdfAttr = SDF_getAttributeListHead(sdfAttrList);
        PT_Attr ptAttr = SDFAttributeToPtAttr(sdfAttr);
        
        if (ptAttrList == NULL) {
          ptAttrList = PT_makeAttrsSingle(ptAttr);
        } 
        else {
          ptAttrList = PT_makeAttrsMany(ptAttr, ptAttrList);
        }
  
        if (SDF_isAttributeListSingle(sdfAttrList)) {
          break;
        }
        sdfAttrList = SDF_getAttributeListTail(sdfAttrList);
      }
    }

    if (ptAttrList == NULL) {
      ptAttributes = PT_makeAttributesNoAttrs();
    }
    else {
      ptAttributes = PT_makeAttributesAttrs(
                       PT_reverseAttrs(ptAttrList));
    }
  }

  return ptAttributes;
}
Esempio n. 3
0
PT_Tree PT_makeTreeLexToCf(PT_Symbol sym, PT_Tree tree)
{
  PT_Symbol lexSymbol = PT_makeSymbolLex(sym);
  PT_Symbol cfSymbol = PT_makeSymbolCf(sym);
  PT_Symbols lhs = PT_makeSymbolsSingle(lexSymbol);
  PT_Attributes noattrs = PT_makeAttributesNoAttrs();
  PT_Production prod = PT_makeProductionDefault(lhs, cfSymbol, noattrs);
  PT_Args args = PT_makeArgsSingle(tree);

  return PT_makeTreeAppl(prod, args);
}
Esempio n. 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);
}