Example #1
0
void	resolv(char *base, char *opers, int *i, char **tabexpr, t_list **op, t_list **nb)
{
  char		*expr1;
  char		*operator;
  char		*expr2;
  
  my_put_in_list(op, tabexpr[*i]);
  *i = *i + 1;
  if (is_num(base, opers, tabexpr[*i]) == 1)
    my_put_in_list(nb, tabexpr[*i]);
  if (is_open_parent(opers, tabexpr[*i]) == 1)
    my_put_in_list(nb, parenthesis_mode(base, opers, i, tabexpr));
  if (is_low_op(opers, tabexpr[*i]))
    my_put_in_list(nb, check_sp_low(base, opers, i, tabexpr));
  if ((expr2 = malloc(sizeof(*expr2) * (my_strlen((*nb)->data) + 1))) == 0)
    exit(-1);
  expr2 = (*nb)->data;
  depile(nb);
  operator = malloc(sizeof(*operator) * (my_strlen((*op)->data) + 1));
  operator = (*op)->data;
  depile(op);
  if ((expr1 = malloc(sizeof(*expr1) * (my_strlen((*nb)->data) + 1))) == 0)
    exit(-1);
  expr1 = (*nb)->data;
  depile(nb);
  my_put_in_list(nb, operations(base, opers, expr1, operator, expr2));
}
Example #2
0
void		resolv(int *i, char **tabstring, t_list **op, t_list **nb)
  {
    char	*save;
    int		new_val;
    char	*str;
    my_put_in_list(op, tabstring[*i]);
    *i =*i + 1;
    if  (is_operator(tabstring[*i]) == 0)
      my_put_in_list(nb, tabstring[*i]);
    if (is_operator(tabstring[*i]) == 3) 
      my_put_in_list(nb, parenthesis_mode(i, tabstring));
    //if (is_operator(tabstring[*i]) == 1)
    //{
    //save = malloc(sizeof(*save) * (my_strlen((*nb)->data) + 1));
    //save = (*nb)->data;
    //*i = *i + 1;
    //my_strncat(save,(*nb)->data,my_strlen((*nb)->data));
    // }
    //else 
    //{
	save = malloc(sizeof(*save) * (my_strlen((*nb)->data) + 1));
	save =(*nb)->data;
	//}
    depile(nb);
    if (my_list_size(*(nb)) == 0)
      my_put_in_list(nb, "0");
    new_val = eval(my_getnbr((*nb)->data), *(*op)->data, my_getnbr(save));
    depile(op);
    depile(nb);
    str = malloc(sizeof(*str) * (digit_len(new_val) + 1));
    my_itoa(new_val, str);
    my_put_in_list(nb, str);
    free(save);
  }
Example #3
0
char	*depile_all(char *base, char *operators, t_list *op, t_list *nb)
{
  char	*operator;
  char	*expr1;
  char	*expr2;
 
  if (my_list_size(op) > 0)
    {
      my_rev_list(&op);
      my_rev_list(&nb);
    }
  while (my_list_size(op) > 0)
    {
      operator = op->data;
      depile(&op);
      expr1 = nb->data;
      depile(&nb);
      if (my_list_size(nb) == 0)
	return (special_case_one_expr_only(base, operators, expr1, operator));
      expr2 = nb->data;
      depile(&nb);
      my_put_in_list(&nb, operations(base, operators, expr1, operator, expr2));
  }
  return (nb->data);
}
Example #4
0
/*
** fin empilage, on depile et calcul
 */
int	depile_all(t_list *op, t_list *nb)
{
  char	*operator;
  char	*nb1;
  char	*nb2;
  char	*newval;
  int	inew_val;
  
  if (my_list_size(op) > 0)
    {
      my_rev_list(&op);
      my_rev_list(&nb);
    }
  while (my_list_size(op) > 0)
    {
      nb1 = nb->data;
      depile(&nb);
      nb2=nb->data;
      depile(&nb);
      operator = op->data;
      depile(&op);
      inew_val = eval(my_getnbr(nb1), *operator, my_getnbr(nb2));
      newval = malloc(sizeof(*newval) * (digit_len(inew_val) + 1));
      my_itoa(inew_val, newval);
      my_put_in_list(&nb, newval);
      free(newval);
    }
  return (my_getnbr(nb->data));
}
Example #5
0
void parcours_instr_si(n_instr *n)
{  
  parcours_exp(n->u.si_.test);
  int iRegistre = 0;
  char tmp[250]; 
  char registre[250]; 
  char faux[256];
  char suite[256];

  new_tag(faux);
  new_tag(suite);

  sprintf(registre,"$t%d",iRegistre);
  depile(registre);

  sprintf(tmp,"beq %s $zero %s", registre,faux);
  printMips(tmp);

  parcours_instr(n->u.si_.alors);

  sprintf(tmp,"j %s",suite);
  printMips(tmp);

  sprintf(tmp,"%s:",faux);
  printMips(tmp);

  if(n->u.si_.sinon) {
    parcours_instr(n->u.si_.sinon);
  }

  sprintf(tmp,"%s:",suite);
  printMips(tmp);
}
Example #6
0
void parcours_instr_pour(n_instr *n)                
{                                                  
  parcours_instr(n->u.pour_.init);
  char tmp[250]; 
  char etiquette[256];
  char fin[256];
  char registre[250]; 

  new_tag(etiquette);
  new_tag(fin);

  sprintf(tmp,"%s:",etiquette);
  printMips(tmp);

  parcours_exp(n->u.pour_.test);                    
  
  int iRegistre = 0;
  sprintf(registre,"$t%d",iRegistre);
  depile(registre);
  sprintf(tmp,"beq %s $zero %s", registre, fin);
  printMips(tmp);

  parcours_instr(n->u.pour_.faire);                 
  parcours_instr(n->u.pour_.incr);                  

  sprintf(tmp,"j %s",etiquette);
  printMips(tmp);
  sprintf(tmp,"%s:",fin);
  printMips(tmp);
}                                                  
Example #7
0
int main()
{
  pile p1;
  initialisationPile(p1);
  unsigned int i;
  for (i=0;i<5;i++)
    {
      empile(p1,i);
    }

  pile p2;
  initialisationPile(p2,p1);

  for (i=0;i<5;i++)
    {
      empile(p1,2*i);
    }

  while(!testPileVide(p1))
    {
      std::printf("%d ",sommet(p1));
      depile(p1);
    }
  std::putchar('\n');

  affectationPile(p1,p2);

  while(!testPileVide(p2))
    {
      std::printf("%d ",sommet(p2));
      depile(p2);
    }
  std::putchar('\n');

  while(!testPileVide(p1))
    {
      std::printf("%d ",sommet(p1));
      depile(p1);
    }
  std::putchar('\n');
  testamentPile(p2);
  testamentPile(p1);
  return 0;
}
Example #8
0
void worker(Pile* p){
  TabNombres tn, gauche, droite;
  int pivot;
  depile(p, &tn);
  while(*(tn.tab)){
    partitionner(tn, &pivot);
    if(pivot > 1){
      gauche.tab = tn.tab;
      gauche.lng = pivot;
      empile(p, gauche);
    }if ( tn.lng - (pivot + 1) > 1 ){
      droite.tab = tn.tab + pivot + 1;
      droite.lng = tn.lng - (pivot + 1);
      empile(p, droite);
    }
    depile(p, &tn);
    
  }
  //sleep(2);
  
}
void		get_return_value(struct user *usr, t_graph *graph, t_data *data)
{
  long		rsp;

  if ((data->peektext & 0xff) != 0xc3
      && (data->peektext & 0xff) != 0xc2
      && (data->peektext & 0xff) != 0xca
      && (data->peektext & 0xff) != 0xcb)
    return ;
  rsp = ptrace(PTRACE_PEEKTEXT, data->pid, usr->regs.rsp, 0);
  if (ptrace(PTRACE_PEEKTEXT, data->pid, rsp, 0) != 0 && graph->size > 0)
    depile(graph);
}
Example #10
0
void parcours_instr_affect(n_instr *n)
{
  char var[256];
  char tmp[250]; 
  char registre[250]; 

  parcours_exp(n->u.affecte_.exp);
  parcours_var(n->u.affecte_.var,var);
  

  int iRegistre = 0;
  sprintf(registre,"$t%d",iRegistre);
  depile(registre);
  sprintf(tmp,"sw %s, %s",registre, var);
  printMips(tmp);
}
Example #11
0
/*-------------------------------------------------------------------------*/
void parcours_instr_ecrire(n_instr *n)
{
  parcours_exp(n->u.ecrire_.expression);

  char tmp[250];
  int iRegistre = 0;

  sprintf(tmp,"$t%d",iRegistre);
  depile(tmp);
  sprintf(tmp, "move $a0, $t%d",iRegistre);
  printMips(tmp);
  printMips("li $v0, 1");
  printMips("syscall");
  printMips("li  $a0, '\\n'");
  printMips("li  $v0, 11");
  printMips("syscall");   
}
Example #12
0
/*-------------------------------------------------------------------------*/
void parcours_var_indicee(n_var *n, char * var)
{
  int i = rechercheExecutable(n->nom);
  if( i < 0) {
    printf("Tableau %s non déclaré\n", n->nom);
    affiche_dico();
    exit(1);
  } else if (dico.tab[i].type == T_ENTIER) {
    printf("%s n'est pas un Tableau\n", n->nom);
    affiche_dico();
    exit(1);
  }
  parcours_exp( n->u.indicee_.indice );
  depile ("$t4");
  printMips("add $t4,$t4,$t4");
  printMips("add $t4,$t4,$t4");
  sprintf(var,"$%s($t4)",n->nom);
}
Example #13
0
void parcours_instr_retour(n_instr *n)
{
  char tmp[250];
  char exec[250];
  int returnAdress = 4 *  (nbArg + 1);
  parcours_exp(n->u.retour_.expression);
  int iRegistre = 0;
  sprintf(tmp,"$t%d",iRegistre);
  depile(tmp);
  sprintf(exec,"sw %s %d($fp) #Adresse de retour",tmp , returnAdress);
  printMips(exec);

  sprintf(tmp,"addi $sp, $sp %d # desallocation variables locales",nbvariableLocalFonc * 4);
  printMips(tmp);
  
  finFuncreturn(1);

}
Example #14
0
/* Effectue un tri rapide séquentiel */
void rapide_seq(bloc_t bloc_init) {
    pile p;
    int i, nb_blocs;
    bloc_t bloc;
    bloc_t blocs[2];

    init_pile(&p);
    empile(&p, bloc_init);

    /* Principe du tri rapide séquentiel :
     * tant qu’il y a des blocs à trier, dépile un bloc, le découpe en
     * (au maximum) deux sous-blocs non-encore triés et les empile */
    do {
        bloc = depile(&p);
        nb_blocs = rapide_decoupebloc(bloc, blocs);
        for (i = 0; i < nb_blocs; i++)
            empile(&p, blocs[i]);
    } while (!pile_vide(&p));
}
Example #15
0
void * wrapper(void *arg){
 
    arg_t * arg2 = arg;
    bloc_t bloc;
    bloc_t bret[2];
    int nb_bloc;
    int i;
        while(1){
            //on lock le mutex pour demarrer
            pthread_mutex_lock(&mutex1);
            
            // verif tri terminé, on debloque les threads bloqué + mutex
            if(pile_vide(&ma_pile) && arg2->compteur == 0){
                pthread_cond_broadcast(&cond);
                pthread_mutex_unlock(&mutex1);
                return NULL;
            }

            if(pile_vide(&ma_pile) && arg2->compteur > 0){
                //deverouille le mutex et attends que cond soit signalée
                pthread_cond_wait(&cond,&mutex1);
            }
            //si pile pas vide
            if(!pile_vide(&ma_pile)){
                arg2->compteur++;
                //on depile un bloc
                bloc = depile(&ma_pile);
                if(bloc.fin-bloc.debut > seuil_bloc_long){
                    //on le decoupe
                    nb_bloc = rapide_decoupebloc(bloc,bret);
                    //on empile les sous blocs
                    for(i = 0; i < nb_bloc; i++)
                        empile(&ma_pile,bret[i]);
                }
                else{
                    rapide_seq(bloc);
                }
                arg2->compteur--;
            }
            pthread_mutex_unlock(&mutex1);
        }
}
Example #16
0
/*-------------------------------------------------------------------------*/
void parcours_opExp(n_exp *n) 
{
  char tmp[256];

  int iRegistre = 0;
  int iRegistre2 = 1;
  int iRegistre3 = 2;
  

  if(n->u.opExp_.op == plus) {
    parcours_exp(n->u.opExp_.op1);
    parcours_exp(n->u.opExp_.op2);
    sprintf(tmp, "$t%d", iRegistre3);
    depile(tmp);
    sprintf(tmp, "$t%d", iRegistre2);
    depile(tmp);

    sprintf(tmp,"add $t%d, $t%d, $t%d",iRegistre, iRegistre2, iRegistre3);
    printMips(tmp);
  } else if(n->u.opExp_.op == moins){
    parcours_exp(n->u.opExp_.op1);
    parcours_exp(n->u.opExp_.op2);
    sprintf(tmp, "$t%d", iRegistre3);
    depile(tmp);
    sprintf(tmp, "$t%d", iRegistre2);
    depile(tmp);

    sprintf(tmp,"sub $t%d, $t%d, $t%d",iRegistre, iRegistre2, iRegistre3);
    printMips(tmp);
  } else if(n->u.opExp_.op == fois) {
    parcours_exp(n->u.opExp_.op1);
    parcours_exp(n->u.opExp_.op2);
    sprintf(tmp, "$t%d", iRegistre3);
    depile(tmp);
    sprintf(tmp, "$t%d", iRegistre2);
    depile(tmp);

    sprintf(tmp,"mult  $t%d, $t%d", iRegistre2, iRegistre3);
    printMips(tmp);
    sprintf(tmp,"mflo $t%d",iRegistre);
    printMips(tmp);
  } else if(n->u.opExp_.op == divise) {
    parcours_exp(n->u.opExp_.op1);
    parcours_exp(n->u.opExp_.op2);
    sprintf(tmp, "$t%d", iRegistre3);
    depile(tmp);
    sprintf(tmp, "$t%d", iRegistre2);
    depile(tmp);

    sprintf(tmp,"div  $t%d, $t%d", iRegistre2, iRegistre3);
    printMips(tmp);
    sprintf(tmp,"mflo $t%d",iRegistre);
    printMips(tmp);
  } else if(n->u.opExp_.op == egal){
    parcours_exp(n->u.opExp_.op1);
    parcours_exp(n->u.opExp_.op2);

    sprintf(tmp, "$t%d", iRegistre3);
    depile(tmp);
    sprintf(tmp, "$t%d", iRegistre2);
    depile(tmp);

    char etiquette[256];
    new_tag(etiquette);
    sprintf(tmp,"li $t%d, 1",iRegistre);
    printMips(tmp);
    sprintf(tmp,"beq $t%d, $t%d %s",iRegistre2, iRegistre3, etiquette);
    printMips(tmp);
    sprintf(tmp,"li $t%d, 0",iRegistre);
    printMips(tmp);
    sprintf(tmp,"%s:", etiquette);
    printMips(tmp);
  } else if(n->u.opExp_.op == diff) {
    parcours_exp(n->u.opExp_.op1);
    parcours_exp(n->u.opExp_.op2);
    sprintf(tmp, "$t%d", iRegistre3);
    depile(tmp);
    sprintf(tmp, "$t%d", iRegistre2);
    depile(tmp);

    char etiquette[256];
    new_tag(etiquette);
    sprintf(tmp,"li $t%d, 0",iRegistre);
    printMips(tmp);
    sprintf(tmp,"beq $t%d, $t%d %s",iRegistre2, iRegistre3, etiquette);
    printMips(tmp);
    sprintf(tmp,"li $t%d, 1",iRegistre);
    printMips(tmp);
    sprintf(tmp,"%s:", etiquette);
    printMips(tmp);
  }else if(n->u.opExp_.op == inf){
    parcours_exp(n->u.opExp_.op1);
    parcours_exp(n->u.opExp_.op2);
    sprintf(tmp, "$t%d", iRegistre3);
    depile(tmp);
    sprintf(tmp, "$t%d", iRegistre2);
    depile(tmp);
    char etiquette[256];
    new_tag(etiquette);
    sprintf(tmp,"li $t%d, 1",iRegistre);
    printMips(tmp);
    sprintf(tmp,"blt $t%d, $t%d %s",iRegistre2, iRegistre3, etiquette);
    printMips(tmp);
    sprintf(tmp,"li $t%d, 0",iRegistre);
    printMips(tmp);
    sprintf(tmp,"%s:", etiquette);
    printMips(tmp);
  }else if(n->u.opExp_.op == infeg){  
    parcours_exp(n->u.opExp_.op1);
    parcours_exp(n->u.opExp_.op2);
    sprintf(tmp, "$t%d", iRegistre3);
    depile(tmp);
    sprintf(tmp, "$t%d", iRegistre2);
    depile(tmp);

    char etiquette[256];
    new_tag(etiquette);
    sprintf(tmp,"li $t%d, 1",iRegistre);
    printMips(tmp);
    sprintf(tmp,"ble $t%d, $t%d %s",iRegistre2, iRegistre3, etiquette);
    printMips(tmp);
    sprintf(tmp,"li $t%d, 0",iRegistre);
    printMips(tmp);
    sprintf(tmp,"%s:", etiquette);
    printMips(tmp);
  }else if(n->u.opExp_.op == ou){
    char faux1[256]; 
    char faux2[256]; 
    char vrai[256];
    char empile[256];
    new_tag(faux1);
    new_tag(faux2);
    new_tag(vrai);
    new_tag(empile);
    
    parcours_exp(n->u.opExp_.op1);
    sprintf(tmp, "$t%d", iRegistre2);
    depile(tmp);
    sprintf(tmp,"beq $zero, $t%d, %s",iRegistre2, faux1);
    printMips(tmp);
    sprintf(tmp,"j %s",vrai);
    printMips(tmp);
    sprintf(tmp,"%s :",faux1);
    printMips(tmp);
    
    parcours_exp(n->u.opExp_.op2);
    sprintf(tmp, "$t%d", iRegistre3);
    depile(tmp);
    
    sprintf(tmp,"or $t%d, $zero, $t%d",iRegistre, iRegistre3);
    printMips(tmp);

    sprintf(tmp,"j %s",empile);
    printMips(tmp);
    sprintf(tmp, "%s :", vrai);
    printMips(tmp);
    sprintf(tmp,"move $t%d $t%d",iRegistre, iRegistre2);
    printMips(tmp);

    sprintf(tmp,"%s : ", empile);
    printMips(tmp);
  } else if(n->u.opExp_.op == et) {
    char fin[256];
    char faux[256];
    new_tag(fin);
    new_tag(faux);

    parcours_exp(n->u.opExp_.op1);
    sprintf(tmp, "$t%d", iRegistre2);
    depile(tmp);

    sprintf(tmp,"beq $zero, $t%d, %s",iRegistre2,faux);
    printMips(tmp);

    sprintf(tmp, "$t%d", iRegistre2);
    empile(tmp);

    parcours_exp(n->u.opExp_.op2);
    sprintf(tmp, "$t%d", iRegistre3);
    depile(tmp);

    sprintf(tmp, "$t%d", iRegistre2);
    depile(tmp);

    sprintf(tmp,"beq $zero, $t%d, %s", iRegistre3, faux);
    printMips(tmp);

    
    sprintf(tmp,"and $t%d, $t%d, $t%d",iRegistre, iRegistre2, iRegistre3);
    printMips(tmp);

    sprintf(tmp,"j %s", fin);
    printMips(tmp);

    sprintf(tmp," %s :",faux);
    printMips(tmp);
    sprintf(tmp,"li $t%d 0",iRegistre);
    printMips(tmp);

    sprintf(tmp ," %s :",fin);

    printMips(tmp);

  } else if(n->u.opExp_.op == non) {
    parcours_exp(n->u.opExp_.op1);

    sprintf(tmp, "$t%d", iRegistre3);
    depile(tmp);

    sprintf(tmp,"not $t%d $t%d",iRegistre,iRegistre3);
    printMips(tmp);
  } else if(n->u.opExp_.op == cond) {
    char tmp[256];
    char faux[256];
    char empile[256];
    new_tag(faux);
    new_tag(empile);

    parcours_exp(n->u.opExp_.op1);

    sprintf(tmp, "$t%d", iRegistre2);
    depile(tmp);
    sprintf(tmp,"beq $t%d, $zero %s",iRegistre2, faux);
    printMips(tmp);

    parcours_exp(n->u.opExp_.op2);

    sprintf(tmp, "$t%d", iRegistre);
    depile(tmp);
    sprintf(tmp,"j %s", empile);
    printMips(tmp);

    sprintf(tmp, "%s :", faux);
    printMips(tmp);
    parcours_exp(n->u.opExp_.op3);
    sprintf(tmp, "$t%d", iRegistre);
    depile(tmp);

    sprintf(tmp, "%s :", empile);
    printMips(tmp);
  }  
  sprintf(tmp, "$t%d", iRegistre);
  empile(tmp);
}
Example #17
0
																/*****Programme principal*****/
int main()
{
	file f;
	pile p;

	p = malloc (sizeof(struct e_pile));		//Allocation de mémoire pour la pile
	f = malloc (sizeof(struct e_file));		//Allocation de mémoire pour la file

	init_pile(&p);		//Initialisation de p
	init_file(&f);		//Initialisation de f

															/*Manipulation des file*/
	printf("\nManipulation des files :\n\n");

		/**Insertion dans la file**/

	enfile(&f,5);		//Insertions de la valeur 5
	affiche_file (f);
	enfile(&f,4);		//Insertions de la valeur 4
	affiche_file (f);
	enfile(&f,3);		//Insertions de la valeur 3
	affiche_file (f);
	enfile(&f,2);		//Insertions de la valeur 2
	affiche_file (f);
	enfile(&f,1);		//Insertions de la valeur 1
	affiche_file (f);
	enfile(&f,0);		//Insertions de la valeur 0

		/**Partie suppression**/

	defile(&f);			//Suppressions dans la file
	affiche_file (f);
	defile(&f);			//Suppressions dans la file
	affiche_file (f);
	defile(&f);			//Suppressions dans la file
	affiche_file (f);
	defile(&f);			//Suppressions dans la file
	affiche_file (f);

		/**Réinsertion dans la file**/

	enfile(&f,6);		//Insertions de la valeur 6
	enfile(&f,7);		//Insertions de la valeur 7
	enfile(&f,8);		//Insertions de la valeur 8

	affiche_file (f);

															/*Manipulation des pile*/
	printf("\nManipulation des piles :\n\n");


	empile(&p,1);		//Insertions de la valeur 0
	affiche_pile(p);
	empile(&p,1);		//Insertions de la valeur 1
	affiche_pile(p);
	empile(&p,2);		//Insertions de la valeur 2
	affiche_pile(p);
	empile(&p,3);		//Insertions de la valeur 3
	affiche_pile(p);
	empile(&p,4);		//Insertions de la valeur 4
	affiche_pile(p);
	empile(&p,5);		//Insertions de la valeur 5
	affiche_pile(p);



	depile(&p);			//Suppressions dans la pile
	affiche_pile (p);
	depile(&p);			//Suppressions dans la pile
	affiche_pile (p);
	depile(&p);			//Suppressions dans la pile
	affiche_pile (p);
	depile(&p);			//Suppressions dans la pile
	affiche_pile (p);	



	free (f);			//Libération de mémoire pour la file f
	free (p);			//Libération de mémoire pour la pile p

	return 0;
}