Ejemplo n.º 1
0
ATbool PT_isTreeApplList(PT_Tree tree)
{
  if (PT_isTreeAppl(tree)) {
    PT_Production prod = PT_getTreeProd(tree);
    return PT_isProductionList(prod);
  }
  return ATfalse;
}
Ejemplo n.º 2
0
static PT_Args flattenListAgain(PT_Production prod, PT_Args elems)
{
  PT_Args newElems = PT_makeArgsEmpty();

  for ( ; !PT_isArgsEmpty(elems); elems = PT_getArgsTail(elems)) {
    PT_Tree arg = PT_getArgsHead(elems);

    if (PT_hasTreeProd(arg)) {
      ATbool nested = ATfalse;
      PT_Production argProd = PT_getTreeProd(arg);

      if (PT_isEqualProduction(prod, argProd)) {
	nested = ATtrue;
      }
      else if (PT_isProductionList(argProd)) {
	PT_Symbol rhs = PT_getProductionRhs(prod);
	PT_Symbol rhsArg = PT_getProductionRhs(argProd);

	if (PT_isSymbolCf(rhs) || PT_isSymbolLex(rhs)) {
	  rhs = PT_getSymbolSymbol(rhs);
	}

	if (PT_isSymbolCf(rhsArg) || PT_isSymbolLex(rhsArg)) {
	  rhsArg = PT_getSymbolSymbol(rhsArg);
	}

	if (PT_isSymbolIterStar(rhs) 
	    && PT_isSymbolIterPlus(rhsArg) 
	    && PT_isEqualSymbol(PT_getSymbolSymbol(rhs),
				PT_getSymbolSymbol(rhsArg))) {
	nested = ATtrue;
	}
      }

      if (nested) {	
	PT_Args nestedElems = PT_getTreeArgs(arg);
	newElems = PT_concatArgs(PT_reverseArgs(nestedElems), newElems);
	continue;
      }
    }
    
    newElems = PT_makeArgsMany(arg, newElems);
  }

  return PT_reverseArgs(newElems);
}
Ejemplo n.º 3
0
static int  
lengthOfProd(PT_Production prod)
{
  PT_Symbol rhs = PT_getProductionRhs(prod);

  if (PT_isProductionList(prod)) {
    return lengthOfSymbol(rhs); 
  }
  else {
    PT_Symbols lhs = PT_getProductionLhs(prod);
    PT_Attributes attrs = PT_getProductionAttributes(prod);

    return lengthOfSymbols(lhs) + 4 +
	   lengthOfSymbol(rhs) +
	   lengthOfAttributes(attrs);
  }
}
Ejemplo n.º 4
0
static int 
yieldProd(PT_Production prod, int idx, char *buf, int bufSize)
{
  PT_Symbol rhs = PT_getProductionRhs(prod);

  if (PT_isProductionList(prod)) {
    idx = yieldSymbol(rhs, idx, buf, bufSize);
  }
  else {
    PT_Symbols lhs = PT_getProductionLhs(prod);
    PT_Attributes attrs = PT_getProductionAttributes(prod);

    idx = yieldSymbols(lhs, idx, buf, bufSize);
    buf[idx++] = '-';
    buf[idx++] = '>';
    buf[idx++] = ' ';
    idx = yieldSymbol(rhs, idx, buf, bufSize);
    idx = yieldAttributes(attrs, idx, buf, bufSize);
  }
  return idx;
}
Ejemplo n.º 5
0
static PT_Tree flattenTreeAgain(PT_Tree tree)
{
  if (PT_isTreeAppl(tree)) {
    PT_Production prod = PT_getTreeProd(tree);
    PT_Args args = PT_getTreeArgs(tree);

    args = flattenArgsAgain(args);

    if (PT_isProductionList(prod)) {
      args = flattenListAgain(prod, args);
    }

    return PT_setTreeArgs(tree, args);
  }
  else if (PT_isTreeAmb(tree)) {
    PT_Args ambs = PT_getTreeArgs(tree);
    ambs = flattenArgsAgain(ambs);
    return PT_setTreeArgs(tree, ambs);
  }

  return tree;
}
Ejemplo n.º 6
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;
  }
}