Esempio n. 1
0
static void
collect_sorts(SDF_Grammar grammar, SDF_SymbolList *sorts)
{
  
  if (SDF_isGrammarSorts(grammar)) {
    SDF_Symbols symbols = SDF_getGrammarSymbols(grammar);
    SDF_SymbolList symbolList = SDF_getSymbolsList(symbols);
    while (!SDF_isSymbolListEmpty(symbolList)) {
      SDF_Symbol symbol = SDF_getSymbolListHead(symbolList);

      if (SDF_isSymbolSort(symbol)) {
        if (SDF_isSymbolListEmpty(*sorts)) {
	  *sorts = SDF_makeSymbolListSingle(symbol);
        }
        else {
	  *sorts = SDF_makeSymbolListMany(symbol, 
                                          SDF_makeLayoutEmpty(),
                                          *sorts);
        }
      }

      if (SDF_isSymbolListSingle(symbolList)) {
	break;
      }
      symbolList = SDF_getSymbolListTail(symbolList);
    }
  }

}
Esempio n. 2
0
static PT_Tree pAppl(PT_Tree tree, int *i)
{
  int indent = *i;
  PT_Args args = PT_getTreeArgs(tree);
  PT_Production prod = PT_getTreeProd(tree);
  SDF_Production sprod = (SDF_Production) ATtableGet(mapping, (ATerm) prod);

  if (sprod != NULL) {
    PT_Args newArgs = PT_makeArgsEmpty();
    SDF_SymbolList slhs = SDF_getSymbolsList(SDF_getProductionSymbols(sprod));
    PT_Symbols lhs = PT_getProductionLhs(prod);
    PT_Tree nextLayout = NULL;

    for (; !PT_isArgsEmpty(args); args = PT_getArgsTail(args), lhs = PT_getSymbolsTail(lhs)) {
      PT_Tree head = PT_getArgsHead(args);
      PT_Symbol sym = PT_getSymbolsHead(lhs);

      // here we put in the layout that's in between the symbols on the lhs
      if (PT_isOptLayoutSymbol(sym)) {
	assert(nextLayout != NULL);
	newArgs = PT_makeArgsList(createLayoutTree(indent, nextLayout), newArgs);
	*i = calcIndentationLevel(indent, nextLayout);
	nextLayout = NULL;
      }
      else {
	SDF_Symbol ssym = SDF_getSymbolListHead(slhs);
	PT_Symbol real = PT_getSymbolSymbol(sym);

	newArgs = PT_makeArgsList(pTreeWithSymbol(head, i, real, ssym), newArgs);

	if (SDF_hasSymbolListTail(slhs)) {
	  nextLayout = (PT_Tree) SDF_getSymbolListWsAfterFirst(slhs);
	  slhs = SDF_getSymbolListTail(slhs);
	}
      }
    }

    tree = PT_setTreeArgs(tree, PT_reverseArgs(newArgs));
  }
  else {
    tree = PT_setTreeArgs(tree, pArgs(args, i));
  }

  return tree;
}
Esempio n. 3
0
static PT_Symbols SDFSymbolsToPtSymbols(SDF_Symbols sdfSymbols)
{
  SDF_SymbolList sdfSymbolList = SDF_getSymbolsList(sdfSymbols);
  PT_Symbols ptSymbols = PT_makeSymbolsEmpty();

  while (SDF_hasSymbolListHead(sdfSymbolList)) {
    SDF_Symbol sdfSymbol = SDF_getSymbolListHead(sdfSymbolList);
    PT_Symbol ptSymbol = SDFSymbolToPtSymbol(sdfSymbol);

    ptSymbols = PT_appendSymbols(ptSymbols, ptSymbol);


    if (SDF_isSymbolListSingle(sdfSymbolList)) {
      break;
    }
    sdfSymbolList = SDF_getSymbolListTail(sdfSymbolList);
  }

  return ptSymbols;
}