Exemple #1
0
/*
 * write the generated parsing table into the arrays
 * used by the driver code.
 */
void write_parsing_table_arrays() {
  getFinalStates();

  print_parsing_tbl_col(); // yytbltok[]
  print_parsing_tbl();     // yytblact[], yyrowoffset[]

  print_yyr1(); // yyr1[]
  print_yyr2(); // yyr2[]

  fprintf(fp, "\n#ifdef YYDEBUG\n\n");
  fprintf(fp, "typedef struct {char *t_name; int t_val;} yytoktype;\n\n");
  print_yynonterminals(); // yynts[]. nonterminals.

  print_yytoks(); // yytoks[]. tokens.
  print_yyreds(); // yyreds[]. Productions of grammar.
  fprintf(fp, "#endif /* YYDEBUG */\n\n");
}
    void
    WFA::path_summary_via_wpds(WPDS & pds) {
      if (this->getFinalStates().size() == 0u) {
        return;
      }

      sem_elem_t wt = getSomeWeight()->one();
      Key pkey = getKey("__pstate");

      if (getQuery() == INORDER) {
          this->toWpds(pkey, &pds, is_any_transition, true, wali::domains::wrapToReversedSemElem);
      }
      else {
          this->toWpds(pkey, &pds, is_any_transition, true);
      }

#ifdef JAMDEBUG
      std::cerr << "##### FWPDS" << std::endl;
      pds.print(std::cerr);
#endif

      WFA query;
      query.addState(pkey, wt->zero());
      query.setInitialState(pkey);
      Key fin = getKey("__done");
      query.addState(fin, wt->zero());
      query.addFinalState(fin);

      sem_elem_t one = wt->one();
      if (getQuery() == INORDER) {
        one = new domains::ReversedSemElem(one);
      }
      
      for (std::set<Key>::const_iterator fit = getFinalStates().begin();
        fit!=getFinalStates().end(); fit++)
      {
        Key fkey = *fit;
        query.addTrans(pkey, fkey, fin, one);
      }

#ifdef JAMDEBUG
      std::cerr << "##### QUERY2" << std::endl;
      query.print(std::cerr);
#endif

      WFA ans;
      pds.poststar(query, ans);

#ifdef JAMDEBUG
      fstream foo;
      foo.open("regexp_prestar.dot", fstream::out);
      const wali::graph::reg_exp_hash_t& roots = wali::graph::RegExp::getRoots();
      foo << "digraph {\n";
      std::set<long> seen;
      for (wali::graph::reg_exp_hash_t::const_iterator iter = roots.begin();
           iter != roots.end();
           ++iter)
      {
        (iter->second)->toDot(foo, seen, true, true);
      }
      foo << "}\n";
      foo.close();
      
      std::cerr << "##### ANS" << std::endl;
      ans.print(std::cerr);
#endif


      for (state_map_t::const_iterator smit=state_map.begin();
           smit!=state_map.end(); smit++)
      {
        Key stkey = smit->first;

        Key initkey = ans.init_state;
        Key finkey = *ans.getFinalStates().begin();

        State *st = smit->second;
        ITrans *trans = ans.find(initkey, stkey, finkey);
        sem_elem_t weight;
        if (trans != NULL) {
          weight = trans->weight();
        } else {
          weight = wt->zero();
        }

        if (getQuery() == INORDER) {
          domains::ReversedSemElem * rw = dynamic_cast<domains::ReversedSemElem*>(weight.get_ptr());
          assert(rw);
          weight = rw->backingSemElem();
        }

        st->weight() = weight;
      }
    }