PT_Production SDFProductionToPtProduction(SDF_Production sdfProduction) { SDF_Symbol sdfResult; SDF_Attributes sdfAttributes; PT_Symbols ptSymbols; PT_Symbol ptResult; PT_Attributes ptAttributes; sdfResult = SDF_getProductionResult(sdfProduction); sdfAttributes = SDF_getProductionAttributes(sdfProduction); ptResult = SDFSymbolToPtSymbol(sdfResult); ptAttributes = SDFAttributesToPtAttributes(sdfAttributes); if (SDF_isProductionProd(sdfProduction)) { SDF_Symbols sdfSymbols = SDF_getProductionSymbols(sdfProduction); ptSymbols = SDFSymbolsToPtSymbols(sdfSymbols); } else { ATwarning("SDFProductionToPtProduction: unable to convert %s\n", PT_yieldTreeToString((PT_Tree) sdfProduction, ATfalse)); return NULL; } return PT_makeProductionDefault(ptSymbols, ptResult, ptAttributes); }
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; }