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
PT_Symbol     SDFSymbolToPtSymbol(SDF_Symbol sdfSymbol)
{
  PT_Symbol result = NULL;

  if (SDF_isSymbolStart(sdfSymbol)) {
    result = PT_makeSymbolSort("<START>"); 
  }
  else if (SDF_isSymbolFileStart(sdfSymbol)) {
    result = PT_makeSymbolSort("<Start>"); 
  }
  else if (SDF_isSymbolSort(sdfSymbol)) {
    char *str = PT_yieldTreeToString((PT_Tree) SDF_getSymbolSort(sdfSymbol),
				     ATfalse);
    result = PT_makeSymbolSort(str); 
  }
  else if (SDF_isSymbolLit(sdfSymbol)) {
    SDF_StrCon sdfLit = SDF_getSymbolString(sdfSymbol);
    const char *str = SDFStrConToString(sdfLit);
    result = PT_makeSymbolLit(str);
  }
  else if (SDF_isSymbolCiLit(sdfSymbol)) {
    SDF_SingleQuotedStrCon sdfLit = SDF_getSymbolCiString(sdfSymbol);
    const char *str = SDFCiStrConToString(sdfLit);
    result = PT_makeSymbolCilit(str);
  }
  else if (SDF_isSymbolIter(sdfSymbol)) {
    SDF_Symbol sdfIterSymbol = SDF_getSymbolSymbol(sdfSymbol);
    PT_Symbol ptIterSymbol = SDFSymbolToPtSymbol(sdfIterSymbol);
    result = PT_makeSymbolIterPlus(ptIterSymbol);
  }
  else if (SDF_isSymbolIterStar(sdfSymbol)) {
    SDF_Symbol sdfIterSymbol = SDF_getSymbolSymbol(sdfSymbol);
    PT_Symbol ptIterSymbol = SDFSymbolToPtSymbol(sdfIterSymbol);
    result = PT_makeSymbolIterStar(ptIterSymbol);
  }
  else if (SDF_isSymbolIterSep(sdfSymbol)) {
    SDF_Symbol sdfIterSymbol = SDF_getSymbolSymbol(sdfSymbol);
    SDF_Symbol sdfIterSep = SDF_getSymbolSep(sdfSymbol);
    PT_Symbol ptIterSymbol = SDFSymbolToPtSymbol(sdfIterSymbol);
    PT_Symbol ptSepSymbol = SDFSymbolToPtSymbol(sdfIterSep);
    result = PT_makeSymbolIterPlusSep(ptIterSymbol, ptSepSymbol);
  }
  else if (SDF_isSymbolIterStarSep(sdfSymbol)) {
    SDF_Symbol sdfIterSymbol = SDF_getSymbolSymbol(sdfSymbol);
    SDF_Symbol sdfIterSep = SDF_getSymbolSep(sdfSymbol);
    PT_Symbol ptIterSymbol = SDFSymbolToPtSymbol(sdfIterSymbol);
    PT_Symbol ptSepSymbol = SDFSymbolToPtSymbol(sdfIterSep);
    result = PT_makeSymbolIterStarSep(ptIterSymbol, ptSepSymbol);
  } 
  else if (SDF_isSymbolCf(sdfSymbol)) {
    SDF_Symbol sdfSym = SDF_getSymbolSymbol(sdfSymbol);
    PT_Symbol ptSym = SDFSymbolToPtSymbol(sdfSym);
    result = PT_makeSymbolCf(ptSym);
  }
  else if (SDF_isSymbolLex(sdfSymbol)) {
    SDF_Symbol sdfSym = SDF_getSymbolSymbol(sdfSymbol);
    PT_Symbol ptSym = SDFSymbolToPtSymbol(sdfSym);
    result = PT_makeSymbolLex(ptSym);
  }
  else if (SDF_isSymbolVarsym(sdfSymbol)) {
    SDF_Symbol sdfSym = SDF_getSymbolSymbol(sdfSymbol);
    PT_Symbol ptSym = SDFSymbolToPtSymbol(sdfSym);
    result = PT_makeSymbolVarSym(ptSym);
  }
  else if (SDF_isSymbolLayout(sdfSymbol)) {
    result = PT_makeSymbolLayout();
  }
  else if (SDF_isSymbolEmpty(sdfSymbol)) {
    result = PT_makeSymbolEmpty();
  }
  else if (SDF_isSymbolSeq(sdfSymbol)) {
    SDF_Symbol sdfHead = SDF_getSymbolHead(sdfSymbol);
    /* tricky casting of SymbolTail to SymbolList */
    SDF_SymbolList sdfTail = (SDF_SymbolList) SDF_getSymbolTail(sdfSymbol);
    SDF_Symbols sdfSymbols = SDF_makeSymbolsDefault(sdfTail);
    PT_Symbol ptHead = SDFSymbolToPtSymbol(sdfHead);
    PT_Symbols ptTail = SDFSymbolsToPtSymbols(sdfSymbols);
    result = PT_makeSymbolSeq(PT_makeSymbolsMany(ptHead, ptTail));
  }
  else if (SDF_isSymbolOpt(sdfSymbol)) {
    SDF_Symbol sdfSym = SDF_getSymbolSymbol(sdfSymbol);
    PT_Symbol ptSym = SDFSymbolToPtSymbol(sdfSym);
    result = PT_makeSymbolOpt(ptSym);
  }
  else if (SDF_isSymbolTuple(sdfSymbol)) {
    SDF_Symbol sdfHead = SDF_getSymbolHead(sdfSymbol);
    SDF_SymbolRest sdfRest = SDF_getSymbolRest(sdfSymbol);
    PT_Symbol ptHead = SDFSymbolToPtSymbol(sdfHead);
    PT_Symbols ptRest = SDFSymbolRestToPtSymbols(sdfRest);
    result = PT_makeSymbolTuple(ptHead, ptRest);
  }
  else if (SDF_isSymbolFunc(sdfSymbol)) {
    SDF_Symbols sdfArguments = SDF_getSymbolArguments(sdfSymbol);
    SDF_Symbol sdfResult = SDF_getSymbolResults(sdfSymbol);
    PT_Symbols ptArguments = SDFSymbolsToPtSymbols(sdfArguments);
    PT_Symbol ptResult = SDFSymbolToPtSymbol(sdfResult);
    result = PT_makeSymbolFunc(ptArguments,ptResult);
  }
  else if (SDF_isSymbolParameterizedSort(sdfSymbol)) {
    SDF_Sort sdfSort = SDF_getSymbolSort(sdfSymbol);
    SDF_SymbolParameters sdfParameters = SDF_getSymbolParameters(sdfSymbol);
    PT_Symbols ptParameters = SDFSymbolParametersToPtSymbols(sdfParameters);
    char *ptSort = PT_yieldTreeToString((PT_Tree) sdfSort, ATfalse);
    result = PT_makeSymbolParameterizedSort(ptSort, ptParameters);
  }
  else if (SDF_isSymbolAlt(sdfSymbol)) {
    SDF_Symbol sdfLeft = SDF_getSymbolLeft(sdfSymbol);
    SDF_Symbol sdfRight = SDF_getSymbolRight(sdfSymbol);
    PT_Symbol ptLeft = SDFSymbolToPtSymbol(sdfLeft);
    PT_Symbol ptRight = SDFSymbolToPtSymbol(sdfRight);
    result = PT_makeSymbolAlt(ptLeft, ptRight);
  }
  else if (SDF_isSymbolCharClass(sdfSymbol)) {
    SDF_CharClass sdfCC = SDF_getSymbolCharClass(sdfSymbol);
    PT_CharRanges ptCR = SDFCharClassToPtCharRanges(sdfCC);
    result = PT_makeSymbolCharClass(ptCR);
  }
  else if (SDF_isSymbolLabel(sdfSymbol)) {
    SDF_Symbol arg = SDF_getSymbolSymbol(sdfSymbol);
    result = SDFSymbolToPtSymbol(arg);
  }
  else if (SDF_isSymbolStrategy(sdfSymbol)) {
    SDF_Symbol sdfLeft = SDF_getSymbolLeft(sdfSymbol);
    SDF_Symbol sdfRight = SDF_getSymbolRight(sdfSymbol);
    PT_Symbol ptLeft = SDFSymbolToPtSymbol(sdfLeft);
    PT_Symbol ptRight = SDFSymbolToPtSymbol(sdfRight);
    result = PT_makeSymbolStrategy(ptLeft, ptRight);
  }
  else if (SDF_isSymbolBracket(sdfSymbol)) {
    SDF_Symbol sym = SDF_getSymbolSymbol(sdfSymbol);
    result = SDFSymbolToPtSymbol(sym);
  }
  else {
    ATerror("SDFSymbolToPtSymbol: unable to convert symbol %t: %s\n", 
	    sdfSymbol, PT_yieldTreeToString((PT_Tree) sdfSymbol, ATfalse));
    result = NULL;
  }
	    
  return result;
}