/* For each production, get its first set. */ void calc_first_table() { CC_Class *firstset; CC_Class copy; PT_Symbol symbol; PT_Symbols symbols; PT_Production prod; ATbool changed = ATtrue; int ip; while(changed) { changed = ATfalse; for(ip = MIN_PROD_NUM; ip < PGEN_getMaxProductionNumber(); ip++) { prod = PGEN_getProductionOfProductionNumber(ip); assert(PT_isValidProduction(prod)); symbols = PT_getProductionLhs(prod); symbol = PT_getProductionRhs(prod); firstset = get_first_set(symbol, ATfalse); if(firstset) { CC_copy(firstset, ©); first(firstset, symbols); CC_union(firstset, ©, firstset); changed |= !CC_isEqual(©, firstset); } else { firstset = get_first_set(symbol, ATtrue); first(firstset, symbols); changed = ATtrue; } } } }
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; }