示例#1
0
void	brainfuck(char *av)
{
	char *tab;
	int	i;

	i = 0;
	tab = (char*)malloc(sizeof(char) * 2049);
	while (i <= 2048)
	{
		tab[i] = 0;
		i++;
	}
	tab[i] = '\0';
	make_operation(tab, av, ft_strlen(str));
}
示例#2
0
void	make_operation(char *tab, char *av, int max)
{
	int	i;
	int j;
	i = 0;
	j = 0;
	while (av[i] != '\0' && i < max)
	{
		if (av[i] == '>')
		{
			tab++;
			i++;
		}
		if (av[i] == '<')
		{
			i++;
			tab--;
		}
		if (av[i] == '+')
		{
			tab[0] = tab[0] + 1;
			i++;
		}
		if (av[i] == '-')
		{
			tab[0] = tab[0] - 1;
			i++;
		}
		if (av[i] == '.')
		{
			write(1, &tab[0], 1);
			i++;
		}
		if (av[i] == '[')
		{
			while (av[i] != ']')
				j++;
			make_operation(tab, &av[i + 1], j);
			j = 0;
		}
		if (av[i] == ']' && tab[0] != 0)
		{
			i = 0;
		}
	}
}
示例#3
0
文件: funcs.c 项目: wazlid/Calculator
double
evaluate_expression(ListElmts *outputList)
{
   if(!outputList || outputList->type !=0)
   {
     print_error("Expression mal formée");
     exit(0); 
   }
   ListElmts *current,
             *stack = NULL,
             rslt
   ;
   current = outputList;
   while(current != NULL)
   {
      if(is_operand(current))
      {
         if(push_stack(&stack, current)!= TRUE)
         {
            print_error("Malloc");
            exit(0);
         }
      }
      else
      {

         if(stack->next == NULL)
         {
            print_error("Expression mal formée");
            exit(0);
         }
         rslt = make_operation(stack->next, stack, current);
         pop_stack(&stack);
         pop_stack(&stack);
         if(push_stack(&stack, &rslt)!=TRUE)
         {
            print_error("Malloc");
            exit(0);
         }
      }
      current = current->next;
   }
   return stack->data;
}