Ejemplo n.º 1
0
PT_Symbols PT_foreachSymbolInSymbols(PT_Symbols symbols, PT_SymbolVisitor visitor,
                                     PT_SymbolVisitorData data)
{
  ATermList store;
  PT_Symbols newSymbols = PT_makeSymbolsEmpty();

  /* apply func to each element */
  store = ATempty;
  while (PT_hasSymbolsHead(symbols)) {
    store = ATinsert(store,
                     PT_SymbolToTerm(
                     visitor(PT_getSymbolsHead(symbols), data)));
    if (PT_hasSymbolsTail(symbols)) {
      symbols = PT_getSymbolsTail(symbols);
    }
    else {
      break;
    }
  }

  /* create new list */
  for (; !ATisEmpty(store); store = ATgetNext(store)) {
    PT_Symbol newSymbol = PT_SymbolFromTerm(ATgetFirst(store));
    newSymbols = PT_makeSymbolsList(newSymbol,newSymbols);
  }

  return newSymbols;
}
Ejemplo n.º 2
0
static PT_Production normalizeProduction(PT_Production prod)
{
  PT_Symbol layout = PT_makeOptLayoutSymbol();

  if (!PT_isProductionList(prod)) {
    PT_Symbols lhs = PT_getProductionLhs(prod);
    PT_Symbols newLhs = PT_makeSymbolsEmpty();
    PT_Symbol rhs = PT_getProductionRhs(prod);

    for(; !PT_isSymbolsEmpty(lhs); lhs = PT_getSymbolsTail(lhs)) {
      PT_Symbol head = PT_getSymbolsHead(lhs);
      PT_Symbol newHead;

      if (!PT_isSymbolLit(head)) {
	newHead = PT_makeSymbolCf(head);
      }
      else {
	newHead = head;
      }

      newLhs = PT_makeSymbolsList(newHead, newLhs);

      if (PT_hasSymbolsTail(PT_getSymbolsTail(lhs))) {
	newLhs = PT_makeSymbolsList(layout, newLhs);
      }
    }

    prod = PT_setProductionRhs(prod, PT_makeSymbolCf(rhs));
    prod = PT_setProductionLhs(prod, PT_reverseSymbols(newLhs));

    return prod;
  }
  else {
    return prod;
  }
}