Example #1
0
static int testPT2SDF(void)
{
  ATerm contents;
  PT_ParseTree parseTree;
  PT_Tree tree;
  PT_Production ptProduction;
  SDF_Production sdfProduction;

  contents = ATreadFromNamedFile(TEST_PT2SDF_FILE);
  assert(contents != NULL);

  parseTree = PT_ParseTreeFromTerm(contents);
  tree = PT_getParseTreeTree(parseTree);
  assert(PT_isValidTree(tree));

  assert(PT_isTreeAppl(tree));
  ptProduction = PT_getTreeProd(tree);
  assert(PT_isValidProduction(ptProduction));
  /*ATwarning("ptProduction: %t\n", ptProduction);*/

  sdfProduction = PTProductionToSDFProduction(ptProduction);
  assert(SDF_isValidProduction(sdfProduction));
  /*ATwarning("sdfProduction: %t\n", sdfProduction);*/

  return 0;
}
Example #2
0
static PT_Tree toText(PT_ParseTree parseTree)
{
  PT_Tree tree = addBoxToTextFunction(parseTree);
  PT_Production func = PT_getTreeProd(tree);
  ATerm reduct = innermost(tree);
  PT_Tree result = toasfixNoLayout(reduct);

  if (result == NULL) {
    ERR_managerStoreError(
       "Could not format Box expression (unexpected behavior)",
       ERR_makeSubjectListEmpty());
    return NULL;
  }
  else if (PT_isTreeAppl(result) 
      && PT_isEqualProduction(PT_getTreeProd(result), func)) {
    FILE *fp = NULL;
    ERR_managerStoreLocatedError(
         "Could not format Box expression for unknown reasons", 
	 "Box expression", "./debug.box",1,0,1,0,0,1);
   
    fp = fopen("./debug.box", "wb"); 
    if (fp != NULL) {
      PT_yieldParseTreeToFile(parseTree, fp, ATfalse);
      fclose(fp);
    }
    return NULL;
  }

  return result;

}
Example #3
0
ATbool PT_isTreeVar(PT_Tree tree) 
{
  if (PT_isTreeAppl(tree)) {
    PT_Production prod = PT_getTreeProd(tree);
    return PT_isProductionVariable(prod);
  }
  return ATfalse;
}
Example #4
0
ATbool PT_isTreeApplList(PT_Tree tree)
{
  if (PT_isTreeAppl(tree)) {
    PT_Production prod = PT_getTreeProd(tree);
    return PT_isProductionList(prod);
  }
  return ATfalse;
}
Example #5
0
ATbool PT_isTreeLayout(PT_Tree tree)
{
  if (PT_isTreeAppl(tree)) {
    PT_Production prod = PT_getTreeProd(tree);
    return PT_isOptLayoutProd(prod);
  }

  return ATfalse;
}
Example #6
0
ATbool PT_isTreeBracket(PT_Tree tree)
{
  if (PT_isTreeAppl(tree)) {
    PT_Production prod = PT_getTreeProd(tree);
    if (PT_isProductionDefault(prod)) {
      return PT_hasProductionBracketAttr(prod);
    }
  }
  return ATfalse;
}
Example #7
0
ATbool PT_isTreeLexical(PT_Tree tree)
{
  if (PT_isTreeAppl(tree)) {
    PT_Production prod = PT_getTreeProd(tree);
    PT_Symbol rhs = PT_getProductionRhs(prod);

    return PT_isSymbolLex(rhs);
  }
  return ATfalse;
}
Example #8
0
ATbool PT_isTreeFlatLexical(PT_Tree tree)
{
  static PT_Symbol allCharsSymbol;
  allCharsSymbol = makeSymbolAllChars();

  if (PT_isTreeAppl(tree)) {
    PT_Production listProd = PT_getTreeProd(tree);
    PT_Symbol listSymbol = PT_getProductionRhs(listProd);
    return PT_isEqualSymbol(listSymbol, allCharsSymbol);
  }
  return ATfalse;
}
Example #9
0
static PT_Tree pTree(PT_Tree tree, int *i)
{
  if (PT_isTreeAmb(tree)) {
    return pAmb(tree, i);
  }
  else if (PT_isTreeAppl(tree)) {
    return pAppl(tree, i);
  }
  else {
    return tree;
  }
}
Example #10
0
ATbool PT_isTreeVarListPlus(PT_Tree tree)
{
  if (PT_isTreeAppl(tree)) {
    PT_Production prod = PT_getTreeProd(tree);
    if (PT_isProductionVariable(prod)) {
      PT_Symbol rhssym = PT_getProductionRhs(prod);
      if (PT_isSymbolCf(rhssym) || PT_isSymbolLex(rhssym)) {
        PT_Symbol sym = PT_getSymbolSymbol(rhssym);
        return PT_isSymbolIterPlus(sym) 
               || PT_isSymbolIterPlusSep(sym);
      }
    }
  }
  return ATfalse;
}
Example #11
0
PT_Tree PT_renameInTree(PT_Tree tree,
                     PT_Symbol formalParam,
                     PT_Symbol actualParam)
{
  if (PT_isTreeAppl(tree)) {
    PT_Production prod = PT_getTreeProd(tree);
    PT_Symbol     rhs = PT_getProductionRhs(prod);
    PT_Args       args = PT_getTreeArgs(tree);

  
    PT_Production newProd = renameInProduction(prod, formalParam, actualParam);
    PT_Symbol newRhs  = PT_getProductionRhs(newProd);
    PT_Args       newArgs = renameInArgs(args, formalParam, actualParam);
    PT_Tree       newTree;

    newTree = PT_setTreeArgs(PT_setTreeProd(tree, newProd), newArgs);

    /* Wrap new variable lists in a proper list production */
    if (PT_isTreeVar(newTree) &&
	(PT_isIterSymbol(newRhs) || PT_isIterSepSymbol(newRhs)) && 
	!(PT_isIterSymbol(rhs) || PT_isIterSepSymbol(rhs))) {
      PT_Production listProd = PT_makeProductionList(newRhs);
      PT_Tree listTree = PT_makeTreeAppl(listProd,
					 PT_makeArgsList(newTree,
							 PT_makeArgsEmpty()));
      newTree = listTree;
    }

    return newTree;
  }
  else if (PT_isTreeLit(tree)) {
    if (PT_isSymbolLit(formalParam)) {
      char *localStr = PT_getTreeString(tree);
      char *formalStr = PT_getSymbolString(formalParam);

      if (strcmp(localStr, formalStr) == 0) {
        return PT_setTreeString(tree, PT_getSymbolString(actualParam));
      }
    }
    return tree;
  }
  else {
    return tree;
  }
}
Example #12
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;
}