void create_quadruple(int opcode, identifier_list a,identifier_list b,identifier_list out)
{
  int i = quad_size;
  //printf("Hello\n");
  quad[i].opcode = opcode;
  //printf("Opcode is : %s\n", tokenName[quad[i].opcode]);
  quad[i].arg1 = create_copy(quad[i].arg1 , a);
  //printf("Hi\n");
  quad[i].arg2 = create_copy(quad[i].arg2 , b);
  quad[i].result = create_copy(quad[i].result , out);
  quad_size ++;
}
예제 #2
0
bank_account* create_account(char* acct_owner, double init_balance, char* acct_num)
{
   bank_account* b = NULL;
   
   if(acct_owner != NULL && strlen(acct_owner) > 0)
   {
      if(acct_num != NULL && is_all_digits(acct_num))
      {
         if(strlen(acct_num) == ACCT_LENGTH)
         {
            if(init_balance >= 0)
            {
               b =  malloc(sizeof(bank_account));
               b -> owner = create_copy(acct_owner);
               b -> balance = init_balance;
               b -> num = create_copy(acct_num);
            }
            else
            {
               printf("The account balance is less than 0.  Please try again with a balance of zero or greater.\n");
               exit(0);
            }
         }
         else 
         {
             printf("Please be sure the account number is 13 digits in length and try again.\n");
             exit(0);
         }
      }
      else 
      {
         printf("Please be sure your account is valid and that the account number contains only digits and try again.\n");
         exit(0);
      }
   }
   else
   {
      printf("Please be sure the account is valid and that there is an owner's name associated with it and try again.\n");
      exit(0);
   }
   return b;
}
예제 #3
0
  ExtendedHeader* ExtendedHeader::replace_lock(STATE, const MemoryFlags h,
      const ExtendedHeader* eh, unsigned int count)
  {
    ExtendedHeader* nh = create_copy(h, eh);

    MemoryLock* lock = new MemoryLock(state->vm()->thread_id(), count);

    for(int i = 0; i < nh->size(); i++) {
      if(nh->words[i].lock_p()) {
        nh->words[i].set_lock(lock);
      }
    }

    return nh;
  }
예제 #4
0
 ComponentPtr create_base_copy() const {
   return create_copy();
 }
void extract_stmt(abstractSyntaxTree temp,symbol_table_ptr st, int scope )
{
  identifier_list id;

  char name[10];
  char temp_name[10];

    //printf("Stmt is : %s\n" ,tokenName[temp->symbol]);

    if(temp->symbol == TK_ASSIGNOP)
    {
      //print_tree(temp);
      //printf("Sup\n");
      //printf("%d\n",temp->childnum);

      if(temp->child[0]->child[0]->symbol == TK_EPSILON)
      {
        //print_tree(temp->child[1]);
        //printf("Child1 : %s\n",tokenName[temp->child[1]->symbol]);
        //printf("Searching for %s\n",temp->child[0]->value);
        id = get_symtable_ptr(" ",temp->child[0]->value, st, scope);
        //printf("Sym  value : %s\n",id->id_name);
        //printf("HI\n");
        create_quadruple(temp->symbol,eval_arithmetic(temp->child[1],st,scope),NULL,id);
      }
      else
      {
        //printf("Searching for %s.%s\n",temp->child[0]->value ,temp->child[0]->child[0]->value);
        id = get_symtable_ptr(temp->child[0]->value,temp->child[0]->child[0]->value, st, scope);
        //printf("Sym table value : %s.%s",id->record_name,id->id_name);

        create_quadruple(temp->symbol,eval_arithmetic(temp->child[1],st,scope),NULL,id);
      }
    }
    //printf("Hi\n");*/

    if(temp->symbol == TK_READ)
    {

      if(temp->child[0]->child[0]->symbol == TK_EPSILON)
      {
        id = get_symtable_ptr(" ",temp->child[0]->value, st, scope);
        //printf("Sym  value : %s\n",id->id_name);
        create_quadruple(temp->symbol,id,NULL,NULL);
      }
      else
      {
        //printf("The record is : %s\n",temp->child[0]->value);
        //printf("The id is : %s\n",temp->child[0]->child[0]->value);
        id = get_symtable_ptr(temp->child[0]->value,temp->child[0]->child[0]->value, st, scope);
        //printf("Sym table value : %s",id->record_name);

        create_quadruple(temp->symbol,id,NULL,NULL);
      }
    }
    else if(temp->symbol == TK_WRITE)
    {

        if(temp->child[0]->symbol == TK_NUM || temp->child[0]->symbol == TK_RNUM )
        {
          //printf("Current expr is: %s\n",temp->value);
          sprintf(name , "%d", num_no);
          strcpy(temp_name,"num");
          strcat(temp_name,name);
          id = create_identifier(3,temp->child[0]->value,temp_name,scope);
          num_no ++;

          create_quadruple(temp->symbol,id,NULL,NULL);
        }


      else if(temp->child[0]->child[0]->symbol == TK_EPSILON)
      {
        id = get_symtable_ptr(" ",temp->child[0]->value, st, scope);
        //printf("Sym  value : %s\n",id->id_name);
        create_quadruple(temp->symbol,id,NULL,NULL);
      }
      else
      {
        //printf("The record is : %s\n",temp->child[0]->value);
        //printf("The id is : %s\n",temp->child[0]->child[0]->value);
        id = get_symtable_ptr(temp->child[0]->value,temp->child[0]->child[0]->value, st, scope);
        //printf("Sym table value : %s",id->record_name);
          create_quadruple(temp->symbol,id,NULL,NULL);
      }
    }

    else if(temp->symbol == TK_IF)
    {
      int jump1,jump2;
      //print_tree(temp->child[0]);
      id = eval_boolean(temp->child[0],st,scope);
      jump1 = quad_size;
      create_quadruple(temp->symbol,id,NULL,NULL);
      extract_stmt(temp->child[1],st,scope);
      extract_individual_stmts(temp->child[2],st,scope);

      if(temp->child[3]->symbol == TK_ENDIF)
      {
        sprintf(name , "%d", quad_size);
        quad[jump1].result = create_copy(quad[jump1].result,create_identifier(0," ",name,scope));
      }
      else if(temp->child[3]->symbol == TK_ELSE)
      {
        jump2 = quad_size;
        extract_stmt(temp->child[3]->child[0],st,scope);
        extract_individual_stmts(temp->child[3]->child[1],st,scope);
        sprintf(name , "%d", quad_size);
        quad[jump1].result = create_copy(quad[jump1].result,create_identifier(0," ",name,scope));
        sprintf(name , "%d", jump2);
        quad[jump1].arg2 = create_copy(quad[jump1].arg2,create_identifier(0," ",name,scope));
      }
    }
    else if(temp->symbol == TK_WHILE)
    {
      int jump;
      create_quadruple(21,NULL,NULL,NULL);
      id = eval_boolean(temp->child[0],st,scope);

      create_quadruple(temp->symbol,id,NULL,NULL);
      jump = quad_size-1;
      extract_stmt(temp->child[1],st,scope);
      extract_individual_stmts(temp->child[2],st,scope);
      sprintf(name , "%d", quad_size);
      quad[jump].result = create_copy(quad[jump].result,create_identifier(0," ",name,scope));
    }
    //printf("Bye");

}