Exemple #1
0
int main(int argc, char **argv)
{  
  //No checks, make sure the parameters are OK, otherwise SEGFAULT!
  if (argc < 6)
    return printf("%s [outfile.dot] [graph name] [reg file] [x86 file] [stack file] [postfix expression]\n", argv[0]), 0;
  
  hashtab h;
  
  hashtab_init(&h, hash_2, 20);
  
  insert(&h, "ln");
  insert(&h, "log");
  insert(&h, "exp");
  insert(&h, "cos");
  insert(&h, "sin");
  insert(&h, "tan");
  insert(&h, "cosh");
  insert(&h, "sinh");
  insert(&h, "acos");
  insert(&h, "asin");
  insert(&h, "cotan");

  tree t = build(argv[6], &h);
  
  printf("Expr : ");
  print_expr(t);
  printf("\n\n");

  printf("Tree :\n");
  print_tree(t);

  //Fictional register machine code generation
  gen_reg_asm_code(argv[3], t);
  
  //x86 machine code generation
  gen_x86_asm_code(argv[4], t);

  //Stack machine code generation
  gen_stack_code(argv[5], t);

  printf("\nParallel sub expressions : \n");
  leaf *l;
  lstack *s = get_par_subtrees(t);

  //Write the AST with some nice colors
  write_tree_dot(argv[1], argv[2], t, s); 
  
  while (lpop(s, &l))
    print_tree(l), printf("\n");

  lstack_free(s);
  hashtab_free(&h);

  return 0;
}
Exemple #2
0
static struct scope* scope_new(struct parser_state *state)
{
	struct scope *parent = state->current;
	struct scope *s = cli_calloc(1, sizeof(*s));
	if(!s)
		return NULL;
	if(hashtab_init(&s->id_map, 10) < 0) {
		free(s);
		return NULL;
	}
	s->parent = parent;
	s->fsm_state = Base;
	s->nxt = state->list;
	state->list = s;
	state->current = s;
	return s;
}
Exemple #3
0
int main(int argc, char *argv[]) {
	FILE *f = fopen("test_kp.txt", "a");
    FILE *dictionary = fopen("text.txt", "r");
    
    int i;
    int size = atoi(argv[1]);
    srand(time(NULL));
    int rand_node = rand() % size;
   
    char *rand_data = malloc(sizeof(char)*100);
    hashtab_init(hashtab);
    
    for (i = 0; i < size; i++) {
		char *ftemp = malloc(sizeof(char)*100);
        fscanf(dictionary, "%s\n", ftemp);
        
		hashtab_add(hashtab, ftemp, i);
      
        if (i == rand_node)
            strcpy(rand_data, ftemp);
    }
    printf("%s\n", rand_data);
    
    listnode *lkt ;
    double t = clock();
    
    lkt = hashtab_lookup(hashtab, rand_data);
    fprintf(f, "kp = %d\t%.8f\n", size, (clock() - t) / CLOCKS_PER_SEC);
    printf("%s %d\n", lkt->key, lkt->value);
    
    sleep(1);
    fclose(f);
    fclose(dictionary);
	 
	return 0;
}