Exemplo n.º 1
0
void expression_prune(Sentence sent)
{
	int N_deleted;
	X_node * x;
	size_t w;
	Connector *ct[CONTABSZ];
	Connector *dummy_list = NULL;

	zero_connector_table(ct);

	N_deleted = 1;  /* a lie to make it always do at least 2 passes */

	while (1)
	{
		/* Left-to-right pass */
		/* For every word */
		for (w = 0; w < sent->length; w++)
		{
			/* For every expression in word */
			for (x = sent->word[w].x; x != NULL; x = x->next)
			{
DBG(printf("before marking: "); print_expression(x->exp); printf("\n"););
				N_deleted += mark_dead_connectors(ct, x->exp, '-');
DBG(printf(" after marking: "); print_expression(x->exp); printf("\n"););
			}
			for (x = sent->word[w].x; x != NULL; x = x->next)
			{
DBG(printf("before purging: "); print_expression(x->exp); printf("\n"););
				x->exp = purge_Exp(x->exp);
DBG(printf("after purging: "); print_expression(x->exp); printf("\n"););
Exemplo n.º 2
0
void print_alloc_fun(struct funcall *f)
{
  assert(strcmp(f->fun_ident, "allouer") == 0);
  print_expression(f->args.data[0]->e);
  printf(" = malloc(sizeof(*(");
  print_expression(f->args.data[0]->e);
  printf(")));\n");
}
Exemplo n.º 3
0
Arquivo: ast.c Projeto: MatzeB/fluffy
static void print_array_access_expression(const array_access_expression_t *access)
{
	fprintf(out, "(");
	print_expression(access->array_ref);
	fprintf(out, ")[");
	print_expression(access->index);
	fprintf(out, "]");
}
Exemplo n.º 4
0
void print_exprlist(exprlist_t l)
{
  unsigned i = 0;
  for (; i + 1 < l.size; ++i)
  {
    print_expression(l.data[i]);
    printf(", ");
  }
  if (l.size > 0)
    print_expression(list_nth(l, i));
}
Exemplo n.º 5
0
void print_arg(struct arg *arg)
{
  if (arg->global)
  {
    printf("&(");
    print_expression(arg->e);
    printf(")");
  }
  else
    print_expression(arg->e);
}
Exemplo n.º 6
0
static void vertex_printer(NODE *vertex, void *data)
{
    DAA_SET *set = NULL;
    if (data)
    {
        DFA *dfa = data;
        LIST *input = get_from_hash(dfa->inputs, vertex, sizeof(void *));
        set = input->size ? input->items[0] : NULL;
    }
    
    if (tree_is_type(vertex, STMT_ASSIGN))
    {
        EXPRESSION *dest = tree_get_child(vertex, 0);
        print_expression(dest, set);
        printf(" = ");
        EXPRESSION *src = tree_get_child(vertex, 1);
        print_expression(src, set);
    }
    else if (tree_is_type(vertex, STMT_RETURN))
    {
        printf("return ");
        EXPRESSION *expr = tree_get_child(vertex, 0);
        print_expression(expr, set);
    }
    else if (tree_is_type(vertex, STMT_TEST))
    {
        printf("test ");
        EXPRESSION *expr = tree_get_child(vertex, 0);
        print_expression(expr, set);
    }
    else if (tree_is_type(vertex, STMT_PASS))
    {
        printf("pass");
    }
    else if (tree_is_type(vertex, STMT_JOIN))
    {
        printf("join");
    }
    else if (tree_is_type(vertex, STMT_ENTER))
    {
        printf("enter");
    }
    else if (tree_is_type(vertex, STMT_EXIT))
    {
        printf("exit");
    }
    else if (tree_is_type(vertex, DEF_VARIABLE))
    {
        DECLARATION *decl = CAST_TO_DECLARATION(vertex);
        printf("%s", decl->name);
    }
    else
        printf("?%d?", vertex->type);
}
Exemplo n.º 7
0
Arquivo: ast.c Projeto: MatzeB/fluffy
static void print_binary_expression(const binary_expression_t *binexpr)
{
	fprintf(out, "(");
	print_expression(binexpr->left);
	fprintf(out, " ");
	switch (binexpr->base.kind) {
	case EXPR_BINARY_ASSIGN:
		fprintf(out, "<-");
		break;
	case EXPR_BINARY_ADD:
		fprintf(out, "+");
		break;
	case EXPR_BINARY_SUB:
		fprintf(out, "-");
		break;
	case EXPR_BINARY_MUL:
		fprintf(out, "*");
		break;
	case EXPR_BINARY_DIV:
		fprintf(out, "/");
		break;
	case EXPR_BINARY_NOTEQUAL:
		fprintf(out, "/=");
		break;
	case EXPR_BINARY_EQUAL:
		fprintf(out, "=");
		break;
	case EXPR_BINARY_LESS:
		fprintf(out, "<");
		break;
	case EXPR_BINARY_LESSEQUAL:
		fprintf(out, "<=");
		break;
	case EXPR_BINARY_GREATER:
		fprintf(out, ">");
		break;
	case EXPR_BINARY_GREATEREQUAL:
		fprintf(out, ">=");
		break;
	default:
		/* TODO: add missing ops */
		fprintf(out, "op%d", binexpr->base.kind);
		break;
	}
	fprintf(out, " ");
	print_expression(binexpr->right);
	fprintf(out, ")");
}
Exemplo n.º 8
0
Arquivo: type.c Projeto: MatzeB/fluffy
static void print_array_type(const array_type_t *type)
{
	print_type(type->element_type);
	fputs("[", out);
	print_expression(type->size_expression);
	fputs("]", out);
}
Exemplo n.º 9
0
/**
 * print the expression, in prefix-style
 */
void print_expression(Exp * n)
{
	E_list * el;
	int i, icost;

	if (n == NULL)
	{
		printf("NULL expression");
		return;
	}

	icost = (int) (n->cost);
	if (n->type == CONNECTOR_type)
	{
		for (i=0; i<icost; i++) printf("[");
		if (n->multi) printf("@");
		printf("%s%c", n->u.string, n->dir);
		for (i=0; i<icost; i++) printf("]");
		if (icost > 0) printf(" ");
	}
	else
	{
		for (i=0; i<icost; i++) printf("[");
		if (icost == 0) printf("(");
		if (n->type == AND_type) printf("& ");
		if (n->type == OR_type) printf("or ");
		for (el = n->u.l; el != NULL; el = el->next)
		{
			print_expression(el->e);
		}
		for (i=0; i<icost; i++) printf("]");
		if (icost > 0) printf(" ");
		if (icost == 0) printf(") ");
	}
}
Exemplo n.º 10
0
void   print_expression_list(expression_list_t * node, int spaces) {
	print_spaces(spaces);
	fprintf(stderr, "EXPR_LIST:\n");
	for(; node != NULL; node = node->next)
		print_expression(node->expression, spaces + SP_INDENT);
	
}
Exemplo n.º 11
0
/* 
 * list expressions 
 */
void print_expression(expression *e) 
{
	if (!e) return;

	printf("%s, ", e->value);
	if (e->next) print_expression(e->next);
}
Exemplo n.º 12
0
void print_free_fun(struct funcall *f)
{
  assert(strcmp(f->fun_ident, "liberer") == 0);
  printf("free(");
  print_expression(f->args.data[0]->e);
  printf(");\n");
}
Exemplo n.º 13
0
Arquivo: ast.c Projeto: MatzeB/fluffy
static void print_call_expression(const call_expression_t *call)
{
	print_expression(call->function);
	fprintf(out, "(");
	call_argument_t *argument = call->arguments;
	int              first    = 1;
	while (argument != NULL) {
		if (!first) {
			fprintf(out, ", ");
		} else {
			first = 0;
		}
		print_expression(argument->expression);

		argument = argument->next;
	}
	fprintf(out, ")");
}
Exemplo n.º 14
0
static void rprint_dictionary_data(Dict_node * n)
{
	if (n == NULL) return;
	rprint_dictionary_data(n->left);
	printf("%s: ", n->string);
	print_expression(n->exp);
	printf("\n");
	rprint_dictionary_data(n->right);
}
Exemplo n.º 15
0
/**
 * Prints the prefix part of a typeof type.
 *
 * @param type   The typeof type.
 */
static void print_typeof_type_pre(const typeof_type_t *const type)
{
	print_string("typeof(");
	if (type->expression != NULL) {
		print_expression(type->expression);
	} else {
		print_type(type->typeof_type);
	}
	print_char(')');
}
Exemplo n.º 16
0
/* 
 * list rules 
 */
void print_rule(rule *r) 
{
	if (!r) return;
		
	printf("\nNEW RULE:\n");
	printf("\n\tLEFT: ");
	if (r->left) print_expression(r->left);  else printf("ALL");
	if (r->left_exceptions) {
		printf("\n\tLEFT EXCEPTIONS: ");
		print_expression(r->left_exceptions);
	}
	printf("\n\tRIGHT: ");
	if (r->right) print_expression(r->right);  else printf("ALL");
	if (r->right_exceptions) {
		printf("\n\tRIGHT EXCEPTIONS: ");
		print_expression(r->right_exceptions);
	}
	printf("\n");
	if (r->next) print_rule(r->next);
}
Exemplo n.º 17
0
Arquivo: ast.c Projeto: MatzeB/fluffy
static void print_select_expression(const select_expression_t *select)
{
	fprintf(out, "(");
	print_expression(select->compound);
	fprintf(out, ").");

	if (select->compound_entry != NULL) {
		fputs(select->compound_entry->symbol->string, out);
	} else {
		fprintf(out, "?%s", select->symbol->string);
	}
}
Exemplo n.º 18
0
Arquivo: type.c Projeto: MatzeB/fluffy
void print_type(const type_t *type)
{
	if (type == NULL) {
		fputs("nil type", out);
		return;
	}

	switch (type->kind) {
	case TYPE_INVALID:
		fputs("invalid", out);
		return;
	case TYPE_TYPEOF: {
		const typeof_type_t *typeof_type = (const typeof_type_t*) type;
		fputs("typeof(", out);
		print_expression(typeof_type->expression);
		fputs(")", out);
		return;
	}
	case TYPE_ERROR:
		fputs("error", out);
		return;
	case TYPE_VOID:
		fputs("void", out);
		return;
	case TYPE_ATOMIC:
		print_atomic_type(&type->atomic);
		return;
	case TYPE_COMPOUND_UNION:
	case TYPE_COMPOUND_STRUCT:
		print_compound_type(&type->compound);
		return;
	case TYPE_FUNCTION:
		print_function_type(&type->function);
		return;
	case TYPE_POINTER:
		print_pointer_type(&type->pointer);
		return;
	case TYPE_ARRAY:
		print_array_type(&type->array);
		return;
	case TYPE_REFERENCE:
		print_type_reference(&type->reference);
		return;
	case TYPE_REFERENCE_TYPE_VARIABLE:
		print_type_reference_variable(&type->reference);
		return;
	case TYPE_BIND_TYPEVARIABLES:
		print_bind_type_variables(&type->bind_typevariables);
		return;
	}
	fputs("unknown", out);
}
Exemplo n.º 19
0
Arquivo: ast.c Projeto: MatzeB/fluffy
static void print_constant(const constant_t *constant)
{
	fprintf(out, "const %s", constant->base.symbol->string);
	if (constant->type != NULL) {
		fprintf(out, " ");
		print_type(constant->type);
	}
	if (constant->expression != NULL) {
		fprintf(out, " <- ");
		print_expression(constant->expression);
	}
	fprintf(out, "\n");
}
Exemplo n.º 20
0
void print_case(struct caseblock *c, int indent)
{
  for(size_t i = 0; i<c->exprlist.size;i++)
  {
    print_indent(indent);
    printf("case ");
    print_expression(c->exprlist.data[i]);
    printf(":\n");
  }
  print_instructions(c->instructions, indent + INDENT_WIDTH);
  print_indent(indent + INDENT_WIDTH);
  printf("break;\n");
}
Exemplo n.º 21
0
void print_expression(struct expr *e)
{
  switch (e->exprtype)
  {
    case valtype:
      print_val(e->val.val);
      break;
    case binopexprtype:
      printf("(");
      print_expression(e->val.binopexpr.e1);
      printf(" %s ", getopstr(e->val.binopexpr.op));
      print_expression(e->val.binopexpr.e2);
      printf(")");
      break;
    case unopexprtype:
      printf("(");
      printf("%s ", getopstr(e->val.unopexpr.op));
      print_expression(e->val.unopexpr.e);
      printf(")");
      break;
    case arrayexprtype:
      print_expression(e->val.arrayexpr.e1);
      for (unsigned i = 0; i < e->val.arrayexpr.indices.size; ++i)
      {
        printf("[");
        print_expression(list_nth(e->val.arrayexpr.indices, i));
        printf(" - 1]");
      }
      break;
    case identtype:
      if (e->argref)
        printf("*(%s)", e->val.ident);
      else
        printf("%s", e->val.ident);
      break;
    case dereftype:
      printf("*");
      print_expression(e->val.deref.e);
      break;
    case funcalltype:
      printf("%s(", e->val.funcall.fun_ident);
      print_arglist(e->val.funcall.args);
      printf(")");
      break;
    case structelttype:
      printf("(");
      print_expression(e->val.structelt.record);
      printf(").%s", e->val.structelt.field);
      break;
    default:
      printf("expr not handled yet in print_expression\n");
  }
}
Exemplo n.º 22
0
Arquivo: ast.c Projeto: MatzeB/fluffy
static void print_if_statement(const if_statement_t *statement)
{
	fprintf(out, "if ");
	print_expression(statement->condition);
	fprintf(out, ":\n");
	if (statement->true_statement != NULL)
		print_statement(statement->true_statement);

	if (statement->false_statement != NULL) {
		print_indent();
		fprintf(out, "else:\n");
		print_statement(statement->false_statement);
	}
}
Exemplo n.º 23
0
/**
 * Prints the postfix part of an array type.
 *
 * @param type   The array type.
 */
static void print_array_type_post(const array_type_t *type)
{
	print_char('[');
	if (type->is_static) {
		print_string("static ");
	}
	print_type_qualifiers(type->base.qualifiers, QUAL_SEP_END);
	if (type->size_expression != NULL
			&& (print_implicit_array_size || !type->has_implicit_size)) {
		print_expression(type->size_expression);
	}
	print_char(']');
	intern_print_type_post(type->element_type);
}
Exemplo n.º 24
0
void print_expression(node_t *root)
{
	if (!root) return;
	printf("%s", "( ");
	print_expression(root->left_child);
	switch (root->type) {
		case OP:
			printf(" %i ", root->value.op);
			break;
		case FIELD:
			printf(" (%s", root->value.field.fieldname);
			break;
		case STRING:
			printf("%s) ", root->value.string_literal);
			break;
		case INT:
			printf(" %llu) ", (long long unsigned) root->value.int_literal);
			break;
		default:
			break;
	}
	print_expression(root->right_child);
	printf("%s", " )");
}
Exemplo n.º 25
0
Arquivo: ast.c Projeto: MatzeB/fluffy
static void print_unary_expression(const unary_expression_t *unexpr)
{
	fprintf(out, "(");
	switch (unexpr->base.kind) {
	case EXPR_UNARY_CAST:
		fprintf(out, "cast<");
		print_type(unexpr->base.type);
		fprintf(out, "> ");
		print_expression(unexpr->value);
		break;
	default:
		fprintf(out, "*unexpr %d*", unexpr->base.kind);
		break;
	}
	fprintf(out, ")");
}
Exemplo n.º 26
0
Arquivo: expprint.c Projeto: 5kg/gdb
void
dump_prefix_expression (struct expression *exp, struct ui_file *stream)
{
  int elt;

  fprintf_filtered (stream, "Dump of expression @ ");
  gdb_print_host_address (exp, stream);
  fputs_filtered (", after conversion to prefix form:\nExpression: `", stream);
  print_expression (exp, stream);
  fprintf_filtered (stream, "'\n\tLanguage %s, %d elements, %ld bytes each.\n",
		    exp->language_defn->la_name, exp->nelts,
		    (long) sizeof (union exp_element));
  fputs_filtered ("\n", stream);

  for (elt = 0; elt < exp->nelts;)
    elt = dump_subexp (exp, stream, elt);
  fputs_filtered ("\n", stream);
}
Exemplo n.º 27
0
static Dict_node * db_lookup_list(Dictionary dict, const char *s)
{
	cbdata bs;
	bs.dict = dict;
	bs.dn = NULL;
	db_lookup_common(dict, s, morph_cb, &bs);
	if (3 < verbosity)
	{
		if (bs.dn)
		{
			printf("Found expression for word %s: ", s);
			print_expression(bs.dn->exp);
		}
		else
		{
			printf("No expression for word %s\n", s);
		}
	}
	return bs.dn;
}
Exemplo n.º 28
0
static void
db_lookup_exp(Dictionary dict, const char *s, cbdata* bs)
{
	sqlite3 *db = dict->db_handle;
	dyn_str *qry;

	/* The token to look up is called the 'morpheme'. */
	qry = dyn_str_new();
	dyn_strcat(qry, "SELECT disjunct, cost FROM Disjuncts WHERE classname = \'");
	dyn_strcat(qry, s);
	dyn_strcat(qry, "\';");

	sqlite3_exec(db, qry->str, exp_cb, bs, NULL);
	dyn_str_delete(qry);

	if (4 < verbosity)
	{
		printf("Found expression for class %s: ", s);
		print_expression(bs->exp);
	}
}
Exemplo n.º 29
0
void print_enum_definition(const enum_t *enume)
{
	print_string("{\n");
	change_indent(1);

	for (const entity_t *entry = enume->first_value;
	     entry != NULL && entry->kind == ENTITY_ENUM_VALUE;
	     entry = entry->base.next) {
		print_indent();
		print_string(entry->base.symbol->string);
		if (entry->enum_value.value != NULL) {
			print_string(" = ");
			print_expression(entry->enum_value.value);
		}
		print_string(",\n");
	}

	change_indent(-1);
	print_indent();
	print_char('}');
}
Exemplo n.º 30
0
void repl(FILE *input, environment_t **env, int interactive) {
  int check = 0;

  do {
  	if (check == 0 && interactive < 2) {
  	  printf("evaluate> ");
  	}

  	expression_t *ptr = read_expression(input);

  	if (ptr != NULL) {
  	  //print_expression(ptr); printf(" = "); print_expression(evaluate_expression(ptr, env)); printf("\n");
	  print_expression(evaluate_expression(ptr, env)); printf("\n");

  	  if (check != 0) {
  		check = 0;
  	  }
  	} else {
  	  check = 1;
  	}
  } while (1);
}