コード例 #1
0
    void
    CapabilityContainer::init( vector<Capability*> const & vecCap, TypeSystem const & typeSystem, EnMatchPolicy enMatchPolicy ) {
      iv_enMatchPolicy = enMatchPolicy;
      vector<Capability*>::const_iterator it;
      assert(iv_mapLang2InputTypesOrFeatures.size() == 0);
      assert(iv_mapLang2OutputTypesOrFeatures.size() == 0);
      for (it = vecCap.begin(); it != vecCap.end(); ++it) {
        assert(EXISTS(*it));
        Capability const & cap = (*(*it));
        initTypeOrFeatures(
          iv_mapLang2InputTypesOrFeatures,
          cap.getCapabilityTypes(Capability::INPUT),
          cap.getSupportedLanguages(),
          typeSystem);
        initTypeOrFeatures(
          iv_mapLang2InputTypesOrFeatures,
          cap.getCapabilityFeatures(Capability::INPUT),
          cap.getSupportedLanguages(),
          typeSystem);
        initTypeOrFeatures(
          iv_mapLang2OutputTypesOrFeatures,
          cap.getCapabilityTypes(Capability::OUTPUT),
          cap.getSupportedLanguages(),
          typeSystem);
        initTypeOrFeatures(
          iv_mapLang2OutputTypesOrFeatures,
          cap.getCapabilityFeatures(Capability::OUTPUT),
          cap.getSupportedLanguages(),
          typeSystem);
      }

      // try to find input tofs for unspecifed language
      assert(iv_psetInputTOFsForUnspecifiedLang == NULL);
      TySetTypeOrFeatures const * pSetInputTOFs =
        findInputTOFs(Language(Language::UNSPECIFIED));
      if (pSetInputTOFs != NULL) {
        iv_psetInputTOFsForUnspecifiedLang = pSetInputTOFs;
      }
      // try to find output tofs for unspecifed language
      assert(iv_psetOutputTOFsForUnspecifiedLang == NULL);
      TySetTypeOrFeatures const * pSetOutputTOFs =
        findOutputTOFs(Language(Language::UNSPECIFIED));
      if (pSetOutputTOFs != NULL) {
        iv_psetOutputTOFsForUnspecifiedLang = pSetOutputTOFs;
      }

      copyEntriesForUnspecifedLanguage();
      if (hasEmptyOutputTypeOrFeatures(Language(Language::UNSPECIFIED))) {
        iv_bHasEmptyOutputTOFsForUnspecifiedLang = true;
      }

      computeClosure(iv_mapLang2OutputTypesOrFeatures, iv_mapLang2OutputTypesOrFeaturesNoTerritory );
      computeClosure(iv_mapLang2InputTypesOrFeatures, iv_mapLang2InputTypesOrFeaturesNoTerritory );
    }
コード例 #2
0
ファイル: AliasingManager.cpp プロジェクト: Apolerag/Cours_M1
void AliasingManager::checkChanges() {
	if (!m_matrixBuilt)
		build();

	if (m_matrixChanged)
		computeClosure();
}
コード例 #3
0
void Grammar::generateStates() {
  verbose(2, _T("Computing FIRST1 sets\n"));
  findFirst1Sets();
  m_stateMap.clear();
  m_unfinishedSet.clear();

  BitSet eoiset(getTerminalCount());
  eoiset.add(0); // EOI
  LR1Item initialItem(true, 0, 0, eoiset);
  LR1State initialState(0);
  initialState.addItem(initialItem);

  computeClosure(initialState, true);
  addState(initialState);
//  dump(initialState);
  verbose(2, _T("Computing LALR(1) states\n"));

  for(int i = 0; i < getStateCount(); i++) {
    verbose(2, _T("state %d\r"), i);
    computeSuccessors(m_states[i]);
  }

/*
  Array<int> length = m_stateHash.length();
  FILE *ff = fopen("c:\\temp\\hlength.dat", "w");
  for(i = 0; i < length.size(); i++) {
    fprintf(ff, "%d %d\n", i, length[i]);
  }
  fclose(ff);
*/
  while(!m_unfinishedSet.isEmpty()) {
    const int unfinishedState = m_unfinishedSet.select();
    m_unfinishedSet.remove(unfinishedState);
    verbose(2, _T("Closing state %d.\r"), unfinishedState);
    computeClosure(m_states[unfinishedState], false);
    computeSuccessors(m_states[unfinishedState]);
  }

  verbose(2, _T("Checking consistensy\n"));

  m_warningCount = m_SRconflicts = m_RRconflicts = 0;
  for(int i = 0; i < getStateCount(); i++) {
    LR1State &state = m_states[i];
    m_result.add(StateResult());
    checkStateIsConsistent(state, m_result.last());
  }
}
コード例 #4
0
void Grammar::computeSuccessors(LR1State &state) {
//dump(state); pause();
  BitSet itemsDone(state.m_items.size()); // this is correct!
  for(UINT i = 0; i < state.m_items.size(); i++) {
    if(itemsDone.contains(i)) {
      continue;
    }
    const LR1Item &origItem = state.m_items[i];
    if(isAcceptItem(origItem)) {
      continue; // No successor, but accept
    }
    const Production &origProduction = getProduction(origItem);
    if(origItem.m_dot < origProduction.getLength()) { // origItem is A -> alfa . X beta [la]
      CompactIntArray successorItems;
      successorItems.add(i);
      int symbolNr = origProduction.m_rightSide[origItem.m_dot];
      LR1State newState(getStateCount());
      const LR1Item newItem(true, origItem.m_prod, origItem.m_dot+1, origItem.m_la); // newItem is A -> alfa X . beta [la] (kernelItem)
      newState.addItem(newItem);
      itemsDone += i;
      for(UINT k = i+1; k < state.m_items.size(); k++) {
        if(itemsDone.contains(k)) {
          continue;
        }
        const LR1Item    &sameSymbolItem = state.m_items[k];
        const Production &sameSymbolProd = getProduction(sameSymbolItem);
        if(sameSymbolItem.m_dot < sameSymbolProd.getLength()
          && sameSymbolProd.m_rightSide[sameSymbolItem.m_dot] == symbolNr) { // sameSymbolItem is C -> gamma . X zeta [la1]
          const LR1Item newItem1(true, sameSymbolItem.m_prod, sameSymbolItem.m_dot+1, sameSymbolItem.m_la); // newItem1 is C -> gamma X . zeta [la1] (kernelItem)
          newState.addItem(newItem1);
          itemsDone += k;
          successorItems.add(k);
        }
      }
      newState.sortItems();
      int succStateIndex = findState(newState);
      if(succStateIndex < 0) {
        computeClosure(newState, true);
        succStateIndex = addState(newState);
      } else {
        if(mergeLookahead(m_states[succStateIndex], newState)) {
          m_unfinishedSet.add(succStateIndex);
//          printf(_T(")%d ", succStateIndex);
        }
      }

      assert(succStateIndex >= 0);

      for(size_t j = 0; j < successorItems.size(); j++) {
        state.m_items[successorItems[j]].m_succ = succStateIndex;
      }
    }
  }
}