Example #1
0
void tryGetForks(int i){
	if(state[i] == HUNGRY && state[left[i]] != EATING && state[right[i]] != EATING){
		state[i] = EATING;
		printStates();
		sem_post(&sem_p[i]);
	}
}
Example #2
0
void initializeStates(){
	int i;
	for(i=0; i<num_philosof; i++){
		state[i] = THINKING;
	}
	printStates();

}
Example #3
0
void take_forks(int i){
	sem_wait(mutex);
	state[i] = HUNGRY;
	printStates();
	tryGetForks(i);
	sem_post(mutex);
	sem_wait(&sem_p[i]);  // block if forks weren't caught
}
Example #4
0
void put_forks(int i){
	sem_wait(mutex);
	state[i] = THINKING;
	printStates();
	tryGetForks(left[i]);  // check if neigh. can eat
	tryGetForks(right[i]);
	sem_post(mutex);       // end of critical region
}
Example #5
0
void printStates(State *s, int depth)
{
  int i;
  static statepVec *log;

  if(depth == 0)
    log = new_statepVec();

  if(s == NULL) {
    for(i = 0; i < depth; i++) printf(" ");  
    printf("NULL\n");
    return;
  }
  
  for(i = 0; i < depth; i++)
    printf(" ");  
  printState(s);

  if(set_add_statepVec(log, s)) {
    // only visit children if parent has not previously been seen
    printStates(s->out1, depth+1);
    printStates(s->out2, depth+1);
  }
}
void LLScriptLSOParse::printData(LLFILE *fp)
{
	


	printNameDesc(fp);

	printRegisters(fp);

	printGlobals(fp);

	printGlobalFunctions(fp);

	printStates(fp);

	printHeap(fp);
}
int intSysMain()
{
	Rule *rule;
	char str[128];
	int key;
	int i;

	if (is.sitChange)
		key = 0;
	else
		key = 1;
	if (is.sitChange)
	{
		is.sitChange = 0;
		rule = findRule(&is);
		printf("%s\n", printStates(&is, str));
		if (!rule)
		{
			is.emf = 0;
			printf("No rule found\n");
			strcpy(ruleDesc, "Suitable response rule not found!");
			roboThought = "Damn it! I don't know what to do!!!";
			return 1;
		}
		else
		{
			printf("Response - %d %s\n", rule->respid, emfName[rule->respid]);
		}
		is.emf = emf[rule->respid];
		*ruleDesc = 0;
		for (i=0; i<rule->numsit; ++i)
		{
			strcat(ruleDesc, rule->sit[i]);
			if (i < rule->numsit-1)
				strcat(ruleDesc, ", ");
		}
		strcat(ruleDesc, " --> ");
		strcat(ruleDesc, emfName[rule->respid]);
		roboThought = rule->respdesc;
	}
	if (is.emf)
		is.emf(key);

	return 1;
}
Example #8
0
void dfsa::printDFSAOutput(){
	cout << "(1) ";
	printStates();
	cout << endl;

	for(int i = 0; i < stateMap.size(); ++i){
		cout << "state " << i << ": {";
		for(set<int>::iterator it = stateMap[i].begin(); it != stateMap[i].end(); ++it){
			cout << *it << " ";
		}
		cout <<"}"<<endl;
	}

	cout << "(2) " ;
	printFinalStates();
	cout << endl;

	cout << "(3) ";
	cout << "transitions: " << endl;

	//For each state
	for(int stateNumber = 0; stateNumber < transitions.size(); ++stateNumber){
		//For each possible symbol
		cout << "state " << stateNumber << ": ";
		bool comma = false;
		for(map<char, int>::iterator it = alphabet.begin(); it != alphabet.end(); ++it){

			int representation = it->second;
			char symbol = it->first;

			//if there are any next states print, else skip
			if(transitions[stateNumber][representation].size() > 0){
				if(comma) cout << ", ";
				else comma = true;
				cout << symbol << " " << transitions[stateNumber][representation][0];
			}
		}
		cout <<endl;
	}
	cout << endl;

}
int initIntSys()
{
	char str[128];

	is.fsize=fsize;
	is.hdPanAngle = is.hdTiltAngle = 90.0f;
	is.ltMotorVal = is.rtMotorVal = 0;
	//is.rule = 0;
	is.sit = 0;
	intruder = getBlobTracker(bbt, 1);
	
	if (!(addState(&is, "roaming_greenhouse")))
	{
		cleanStates(&is);
		return 0;
	}
	writePanTiltServos(is.hdPanAngle, is.hdTiltAngle);
	INIT_SW();
	printStates(&is, str);
	printf("%s\n", str);
	return 1;
}
Example #10
0
//-----------------------------------------------------------------------------
//
//   RBBITableBuilder::build  -  This is the main function for building the DFA state transtion
//                               table from the RBBI rules parse tree.
//
//-----------------------------------------------------------------------------
void  RBBITableBuilder::build() {

    if (U_FAILURE(*fStatus)) {
        return;
    }

    // If there were no rules, just return.  This situation can easily arise
    //   for the reverse rules.
    if (fTree==NULL) {
        return;
    }

    //
    // Walk through the tree, replacing any references to $variables with a copy of the
    //   parse tree for the substition expression.
    //
    fTree = fTree->flattenVariables();
#ifdef RBBI_DEBUG
    if (fRB->fDebugEnv && uprv_strstr(fRB->fDebugEnv, "ftree")) {
        RBBIDebugPuts("Parse tree after flattening variable references.");
        fTree->printTree(TRUE);
    }
#endif

    //
    // If the rules contained any references to {bof} 
    //   add a {bof} <cat> <former root of tree> to the
    //   tree.  Means that all matches must start out with the 
    //   {bof} fake character.
    // 
    if (fRB->fSetBuilder->sawBOF()) {
        RBBINode *bofTop    = new RBBINode(RBBINode::opCat);
        RBBINode *bofLeaf   = new RBBINode(RBBINode::leafChar);
        bofTop->fLeftChild  = bofLeaf;
        bofTop->fRightChild = fTree;
        bofLeaf->fParent    = bofTop;
        bofLeaf->fVal       = 2;      // Reserved value for {bof}.
        fTree               = bofTop;
    }

    //
    // Add a unique right-end marker to the expression.
    //   Appears as a cat-node, left child being the original tree,
    //   right child being the end marker.
    //
    RBBINode *cn = new RBBINode(RBBINode::opCat);
    cn->fLeftChild = fTree;
    fTree->fParent = cn;
    cn->fRightChild = new RBBINode(RBBINode::endMark);
    cn->fRightChild->fParent = cn;
    fTree = cn;

    //
    //  Replace all references to UnicodeSets with the tree for the equivalent
    //      expression.
    //
    fTree->flattenSets();
#ifdef RBBI_DEBUG
    if (fRB->fDebugEnv && uprv_strstr(fRB->fDebugEnv, "stree")) {
        RBBIDebugPuts("Parse tree after flattening Unicode Set references.");
        fTree->printTree(TRUE);
    }
#endif


    //
    // calculate the functions nullable, firstpos, lastpos and followpos on
    // nodes in the parse tree.
    //    See the alogrithm description in Aho.
    //    Understanding how this works by looking at the code alone will be
    //       nearly impossible.
    //
    calcNullable(fTree);
    calcFirstPos(fTree);
    calcLastPos(fTree);
    calcFollowPos(fTree);
    if (fRB->fDebugEnv && uprv_strstr(fRB->fDebugEnv, "pos")) {
        RBBIDebugPuts("\n");
        printPosSets(fTree);
    }

    //
    //  For "chained" rules, modify the followPos sets
    //
    if (fRB->fChainRules) {
        calcChainedFollowPos(fTree);
    }

    //
    //  BOF (start of input) test fixup.
    //
    if (fRB->fSetBuilder->sawBOF()) {
        bofFixup();
    }

    //
    // Build the DFA state transition tables.
    //
    buildStateTable();
    flagAcceptingStates();
    flagLookAheadStates();
    flagTaggedStates();

    //
    // Update the global table of rule status {tag} values
    // The rule builder has a global vector of status values that are common
    //    for all tables.  Merge the ones from this table into the global set.
    //
    mergeRuleStatusVals();

    if (fRB->fDebugEnv && uprv_strstr(fRB->fDebugEnv, "states")) {printStates();};
}