Exemplo n.º 1
0
void interface::refreshLabels()                 //for updating our label names
{                                               //with the current term #
    nL->setText(genLabel("n"));
    mL->setText(genLabel("m"));
    rL->setText(genLabel("r"));
    aL->setText(genLabel("a"));
}
Exemplo n.º 2
0
TNode *StringConstNode::translate( Codegen *g ){
	string lab=genLabel();

	g->i_data( 0,lab );
	g->s_data( value );
	const_strings.push_back( lab );

	return mem( global(lab) );
}
Exemplo n.º 3
0
SymTabESP sym_make_label(void)
{
	SymTabESP e;
	e = NULL;
	ENTRY(SymTabES, e);
	e->name = genLabel();
	e->label = e->name; 
	e->val = -1;
	e->lineno = -1;
	e->level = LEVEL;
	e->posi = -1;
	e->obj = Label_Obj_t;
	e->type = Nop_Type_t;
	e->stp = NULL;
	return e;
}
Exemplo n.º 4
0
itk::Image<unsigned char, 3>::Pointer pdp::EMClassification::classify(itk::Image<float, 3>::Pointer img, itk::Image<unsigned char, 3>::Pointer mask)
{
	typedef itk::Vector< double, 1 > MeasurementVectorType;
	typedef itk::Image<unsigned char, 3> MaskType;
	typedef itk::Image<float, 3> ImageType;

	typedef itk::ImageRegionConstIterator< ImageType > ImageIteratorType;
	ImageIteratorType imgIt(img, img->GetLargestPossibleRegion());

	typedef itk::ImageRegionConstIterator< MaskType> MaskIteratorType;
	MaskIteratorType maskIt( mask, mask->GetLargestPossibleRegion());

	MaskType::Pointer correctImage = MaskType::New();
	correctImage->CopyInformation(mask);
	MaskType::RegionType outputRegion = mask->GetLargestPossibleRegion();
	correctImage->SetRegions( outputRegion );
	correctImage->Allocate();
	typedef itk::ImageRegionIterator<MaskType> IteratorType;
	IteratorType outputIt( correctImage, outputRegion);

	MeasurementVectorType mv;
	for ( imgIt.GoToBegin(), maskIt.GoToBegin(), outputIt.GoToBegin(); !maskIt.IsAtEnd(); ++maskIt, ++imgIt, ++outputIt)
	{

		if (maskIt.Get() == 255)
		{
			mv[0] = imgIt.Get();
			if (genLabel(mv) == 3)
			{
				outputIt.Set(255);
			}
		}
	}

	return correctImage;
}
Exemplo n.º 5
0
TNode *StringConstNode::translate( Codegen *g ){
	string lab=genLabel();
	g->s_data( value,lab );
	return call( "__bbStrConst",global( lab ) );
}
Exemplo n.º 6
0
void processStatement(SymbolTable *table, Node *ptr)
{
    Node *p;
    char label1[LABEL_SIZE]={0}, label2[LABEL_SIZE]={0};

    switch(ptr->token.tokenNumber) {
        case COMPOUND_ST:
            p = ptr->son->next;
            p = p->son;
            while (p) {
                processStatement(table, p);
                p = p->next;
            }
            break;

        case EXP_ST:
            if (ptr->son != NULL) {
                processOperator(table, ptr->son);
            }
            break;

        case RETURN_ST:
            if (ptr->son != NULL) {
                p = ptr->son;
                if (p->noderep == NONTERM) {
                    processOperator(table, p);
                } else {
                    rv_emit(table, p);
                }
                emit0("retv");
            } else
                emit0("ret");
            flag_returned=1;
            break;

        case IF_ST:
            genLabel(label1);
            processCondition(table, ptr->son);
            emitJump("fjp", label1);
            processStatement(table, ptr->son->next);
            emitLabel(label1);
        	break;

        case IF_ELSE_ST:
            genLabel(label1);
            genLabel(label2);
            processCondition(table, ptr->son);
            emitJump("fjp", label1);
            processStatement(table, ptr->son->next);
            emitJump("ujp", label2);
            emitLabel(label1);
            processStatement(table, ptr->son->next->next);
            emitLabel(label2);
        	break;

        case WHILE_ST:
            genLabel(label1);
            genLabel(label2);
            emitLabel(label1);
            processCondition(table, ptr->son);
            emitJump("fjp", label2);

            processStatement(table, ptr->son->next);

            emitJump("ujp", label1);
            emitLabel(label2);
	        break;

        default:
            fprintf(file, "not yet implemented.\n");
            break;
    }
}
Exemplo n.º 7
0
Arquivo: parser.c Projeto: bieber/pm0
void statement(){
  int l;
  int m;
  symTableEntry* symbol;
  int tempLabels[2];
 
  if(currentToken == identsym){
    symbol = findSymbol(symTable, VAR, tokenVal.string, scope);
    if(!findVar(tokenVal.string, scope, &l, &m)){
      if(findConst(tokenVal.string, scope, &m))
        throwError(CANNOT_ASSIGN_TO_CONST_OR_PROC);
      else
        throwError(UNDEC_ID);
    }
    
    readToken();
    
    if(currentToken != becomessym)
      throwError(ASSIGN_EXPEC);
    
    readToken();
    
    expression();
 
    genCode(STO, l, m);
  }
  else if(currentToken == syawsym){
    readToken();
    
    if(currentToken != identsym)
      throwError(ID_FOLLOW_SYAW);

    if(!findFunc(tokenVal.string, scope, &l, &m))
      throwError(UNDEC_ID);

    genCode(CAL, l, m);
    
    readToken();
  }
  else if(currentToken == sngaisym){ // 'beginsym'
    readToken();
    
    statement();
    
    while(currentToken == semicolonsym){
      readToken();
      
      statement();
    }
      
    if(currentToken != fpesym && 
        (currentToken != identsym && currentToken != sngaisym
        && currentToken != txosym && currentToken != tengkrrsym)) // 'endsym'
      //throwError(WRONG_SYM_AFTER_STATE);
      throwError(SEMICOL_OR_RBRACK_EXPEC);
    else if(currentToken == identsym || currentToken == sngaisym
        || currentToken == txosym || currentToken == tengkrrsym)
      throwError(SEMICOL_BW_STATE_MISS);
    
    readToken();
  }
  else if(currentToken == txosym){ // 'ifsym'
    tempLabels[1] = 0;

    readToken();
    
    condition();
    
    tempLabels[0] = reserveCode(); //Conditional jump will go here
 
    if(currentToken != tsakrrsym) // 'thensym'
      throwError(TSAKRR_EXPEC);
    
    readToken();
    
    statement();

    if(currentToken == txokefyawsym){
      tempLabels[1] = reserveCode();
      readToken();
    }
 
    backPatch(tempLabels[0], JPC, 0, genLabel());
    
    if(tempLabels[1]){
      statement();
      backPatch(tempLabels[1], JMP, 0, genLabel());
    }

  }
  else if(currentToken == tengkrrsym){ // 'whilesym'
 
    readToken();
    
    tempLabels[0] = genLabel(); //Jump back up to here at the end of the loop
 
    condition();
 
    tempLabels[1] = reserveCode(); //Stick the conditional jump here
 
    if(currentToken != sisym) // 'dosym'
      throwError(SI_EXPEC);
    
    readToken();
      
    statement();
    
    genCode(JMP, 0, tempLabels[0]);
    backPatch(tempLabels[1], JPC, 0, genLabel());
  }
  else if(currentToken == misym){ // Input
    genCode(SIO, 0, 2);
    
    readToken();
    
    if(currentToken == identsym){
      if(findVar(tokenVal.string, scope, &l, &m))
        genCode(STO, l, m);
      else if(findConst(tokenVal.string, scope, &m)
              || findFunc(tokenVal.string, scope, &l, &m))
        throwError(CANNOT_STORE_IN_CONST_OR_PROC);
      else
        throwError(UNDEC_ID);
      
      readToken();
    }
  }
  else if(currentToken == wrrpasym){ // Output
    readToken();
    
    if(currentToken == identsym){
      if(findVar(tokenVal.string, scope, &l, &m))
        genCode(LOD, l, m);
      else if(findConst(tokenVal.string, scope, &m))
        genCode(LIT, 0, m);
      else
        throwError(UNDEC_ID);
      
      readToken();
    }
    
    genCode(SOI, 0, 1);
  }
  else if(currentToken == fpesym){
    return;
  }
  else{
    if(currentToken == periodsym)
      throwError(RBRACK_EXPEC_AT_END);
    else
      throwError(STATEMENT_EXPEC);
  }
  
  return;
}
Exemplo n.º 8
0
Arquivo: parser.c Projeto: bieber/pm0
void block(){

  int jmpLoc = reserveCode();

  int thisScope;
  int numVars = 0;
  char tempSymbol[MAX_IDENT_LENGTH + 1];
 
  if(currentToken == constsym){
    /***************************************************************/
    /* const-declaration ::= [ "const" ident "=" number            */
    /*                               {"," ident "=" number} ";"]   */
    /***************************************************************/
    do{
      readToken();
      
      if(currentToken != identsym){
        throwError(ID_FOLLOW_CONST_VAR_PROC);
      }else{
        strcpy(tempSymbol, tokenVal.string);
      }
 
      readToken();
      
      if(currentToken != eqsym){
        if(currentToken == becomessym)
          throwError(EQ_NOT_BECOMES);
        else
          throwError(EQ_FOLLOW_ID);
      }
      
      readToken();
    
      if(currentToken != numbersym){
        throwError(NUM_FOLLOW_EQ);
      }else{
        insertSymbol(symTable, newSymbol(CONST, tempSymbol, scope, 0,
                                         tokenVal.numeric));
      }
    
      readToken();
    }while(currentToken == commasym);
    
    if(currentToken != semicolonsym)
      throwError(SEMICOL_COMMA_MISS);
 
    readToken();
  }
  
  if(currentToken == intsym){
    /*******************************************************/
    /* var-declaration ::= ["int" ident {"," ident} ";"] */
    /*******************************************************/
    do{
      readToken();
      
      if(currentToken != identsym){
        throwError(ID_FOLLOW_CONST_VAR_PROC);
      }else{
        insertSymbol(symTable, newSymbol(VAR, tokenVal.string,
                                         scope, BASE_OFFSET + numVars++, 0));
      }
        
      readToken();
    }while(currentToken == commasym);
    
    if(currentToken != semicolonsym)
      throwError(SEMICOL_COMMA_MISS);
      
    readToken();
  }
  
  //Saving the scope before moving into procedure declarations
  thisScope = scope;

  while(currentToken == procsym){
    /**********************************************************************/
    /* proc-declaration ::= {"procedure" ident ";" block ";"} statement   */
    /**********************************************************************/

    readToken();
    
    if(currentToken != identsym)
      throwError(ID_FOLLOW_CONST_VAR_PROC);

    //Storing the function name in the symbol table
    insertSymbol(symTable, newSymbol(FUNC, tokenVal.string, thisScope, 
                                     genLabel(), 0));

    
    readToken();
    
    if(currentToken != semicolonsym)
      throwError(SEMICOL_COMMA_MISS);
      
    readToken();

    //Incrementing the scope for our new function and saving its parent
    //in the disjoint set
    scope++;
    scopeParent[scope] = thisScope;

    block();
    
    if(currentToken != semicolonsym)
      throwError(WRONG_SYM_AFTER_PROC);
    
    readToken();
  }

  //Restoring the scope
  scope = thisScope;

  backPatch(jmpLoc, JMP, 0, genLabel());
  genCode(INC, 0, BASE_OFFSET + numVars);
 
  statement();
  
  genCode(OPR, 0, RET);
 
  return;
}