Exemple #1
0
Fichier : us.c Projet : gonzus/us
US* us_create(void) {
    US* us = 0;
    MEM_ALLOC_TYPE(us, 1, US);
    LOG(INFO, ("US: created at %p", us));
    us->arena = arena_create();
    us->parser = parser_create(0);
    us->env = make_global_env(us);
    return us;
}
Exemple #2
0
Datum
dregex_init(PG_FUNCTION_ARGS) {
	parser_str *parser = parser_create();
	List *dictoptions = (List *) PG_GETARG_POINTER(0);
	ListCell *l;

	foreach(l, dictoptions){
		DefElem *defel = (DefElem *) lfirst(l);

		if (pg_strcasecmp(defel->defname, "RULES") == 0) {
			parser_read_rules(parser, defGetString(defel));
		} else {
			elog(ERROR,"Unknown option: %s => %s",  defel->defname, defGetString(defel));
		}
	}
Exemple #3
0
int main(int argc, char *argv[]) {
    parser_create();

    if (atexit(exit_hook) != 0) {
        fprintf(stderr, "could not register exit hook\n");
        exit(EXIT_FAILURE);
    }

    int ret = parser_run();

    if (ret == 0) {
        puts("{* input looks ok *}");
        puts("{* symbol table:");
        print_symbol_table();
        puts("*}");
        print_ast_as_prascal(parser_get_root_node());
    }

    return ret;
}
Exemple #4
0
int main(int argc, char *argv[])
{
    if (argc != 2)
    {
        printf("Usage: alic <source>\n");
        return 0;
    }

    if (strcmp(argv[1], "-") != 0)
    {
        /* Open source file */
        if (freopen(argv[1], "rt", stdin) == NULL)
            fatal("Unable to open file \"%s\" for reading.");
    }

    parser_create();
    yyparse();
    create_object_file();
    parser_destroy();

    return 0;
}
Exemple #5
0
/* Top level wrapper around the parser */
int ini_config_parse(struct ini_cfgfile *file_ctx,
                     int error_level,
                     uint32_t collision_flags,
                     uint32_t parse_flags,
                     struct ini_cfgobj *ini_config)
{
    int error = EOK;
    struct parser_obj *po = NULL;
    uint32_t fl1, fl2, fl3;

    TRACE_FLOW_ENTRY();

    if ((!ini_config) || (!(ini_config->cfg))) {
        TRACE_ERROR_NUMBER("Invalid argument", EINVAL);
        return EINVAL;
    }

    if (!file_ctx) {
        TRACE_ERROR_NUMBER("Invalid file context", EINVAL);
        return EINVAL;
    }

    if (!valid_collision_flags(collision_flags)) {
        TRACE_ERROR_NUMBER("Invalid flags.", EINVAL);
        return EINVAL;
    }

    if ((error_level != INI_STOP_ON_ANY) &&
        (error_level != INI_STOP_ON_NONE) &&
        (error_level != INI_STOP_ON_ERROR)) {
        TRACE_ERROR_NUMBER("Invalid argument", EINVAL);
        return EINVAL;
    }

    error = parser_create(ini_config,
                          file_ctx->file,
                          file_ctx->filename,
                          error_level,
                          collision_flags,
                          parse_flags,
                          &po);
    if (error) {
        TRACE_ERROR_NUMBER("Failed to perform an action", error);
        return error;
    }

    error = parser_run(po);
    if (error) {
        fl1 = collision_flags & INI_MS_MASK;
        fl2 = collision_flags & INI_MV1S_MASK;
        fl3 = collision_flags & INI_MV2S_MASK;
        if ((error == EEXIST) &&
            (((fl1 == INI_MS_DETECT) &&
              (fl2 != INI_MV1S_ERROR) &&
              (fl3 != INI_MV2S_ERROR)) ||
             ((fl2 == INI_MV1S_DETECT) &&
              (fl1 != INI_MS_ERROR) &&
              (fl3 != INI_MV2S_ERROR)) ||
             ((fl3 == INI_MV2S_DETECT) &&
              (fl1 != INI_MS_ERROR) &&
              (fl2 != INI_MV1S_ERROR)))) {
            TRACE_ERROR_NUMBER("No error in detect mode", error);
            /* Fall through */
        }
        else {
            TRACE_ERROR_NUMBER("Failed to parse file", error);
            TRACE_ERROR_NUMBER("Mode", collision_flags);
            col_get_collection_count(ini_config->error_list, &(ini_config->count));
            if(ini_config->count) (ini_config->count)--;
            parser_destroy(po);
            return error;
        }
    }

    /* If should be empty anyways */
    col_destroy_collection_with_cb(ini_config->cfg, ini_cleanup_cb, NULL);
    ini_config->cfg = po->top;
    po->top = NULL;

    parser_destroy(po);

    TRACE_FLOW_EXIT();
    return error;
}
Exemple #6
0
void render_set_volume_size(vector3ui volume_size_v, int rebuild)
{
	volume_size = vec3ui_add_c(volume_size_v, 1);
	volume_step = vec3f_div(vec3f(1.0f, 1.0f, 1.0f), vec3ui_to_vec3f(volume_size));
	
	if(rebuild) {

		new_volume = (float*) malloc(sizeof(float) * volume_size.x*volume_size.y*volume_size.z);
		IF_FAILED(new_volume != NULL);

		is_stop_building = 0;

		if(parser_is_stopped())
			parser_resume();

		// проверяем количество потоков и решаем использовать ли многопоточность
		if(num_threads >= 2) {

			// устанавливаем кол-во потоков
			omp_set_num_threads(num_threads);

			int *stop_ptr = &is_stop_building;

			// запускаем паралельно данный участок кода
			#pragma omp parallel firstprivate(volume_size) shared(new_volume, str_function, stop_ptr)
			{
				int i = omp_get_thread_num();

				parser_t tparser;
				parser_create(&tparser);
				parser_clean(&tparser);

				// вычисляем интервал вычислений для данного потока
				vector3ui begin = vec3ui(0, 0, volume_size.z * ((float) (i) / (float) omp_get_num_threads()));
				vector3ui end = vec3ui(volume_size.x, volume_size.y, volume_size.z * ((float) (i+1) / (float) omp_get_num_threads()));

				float_var_value_t float_vars[] =
				{
					{1, 0.0f}, // d
					{2, 0.0f}, // x
					{3, 0.0f}, // y
					{4, 0.0f}, // z
					{0, 0.0f}
				};

				// проходимся по соотвествующему участку массива
				for(unsigned k = begin.z; k < end.z; k++) {
					for(unsigned j = begin.y; j < end.y; j++) {
						for(unsigned i = begin.x; i < end.x; i++) {

							if(*stop_ptr)
								goto exit_loop;

							float_vars[0].value = 0.0f; float_vars[1].value = i;
							float_vars[2].value = j; float_vars[3].value = k;

							if(parser_parse_text(&tparser, str_function, float_vars) == 0) {
								new_volume[i + j*volume_size.x + k*volume_size.x*volume_size.y] = float_vars[0].value;
							}
						}
					}
				}

				exit_loop:

				parser_clean(&tparser);
			}

		} else {
			// проходимся по всему массиву и устанавливаем соотвествующее функции значение
			for(unsigned k = 0; k < volume_size.z; k++) {
				for(unsigned j = 0; j < volume_size.y; j++) {
					for(unsigned i = 0; i < volume_size.x; i++) {

						if(is_stop_building)
							goto exit_loop2;

						new_volume[i + j*volume_size.x + k*volume_size.x*volume_size.y] = volume_func(vec3f(i, j, k));
					}
				}
			}

			exit_loop2: ; // ....

		}


		if(!is_stop_building) {

			is_swap_volumes = 1;
		} else {
			free(new_volume);
			new_volume = NULL;

			is_swap_volumes = 0;
		}

	}

}
Exemple #7
0
int render_init(void)
{
	IF_FAILED0(!init);

	if(!init_opengl) {
		ERROR_MSG("OpenGL not initialised\n");
		return 0;
	}

	log_init();
	
	TRACE_MSG("init base render system\n");
	
	TRACE_MSG("init noise\n");
	noise_init();
	
	glViewport(0, 0, window_width, window_height);
	glClearColor(0.0f, 0.0f, 0.0f, 1.0f);
	glEnable(GL_DEPTH_TEST);
	glClearDepth(1.0f);
	
	glDepthFunc(GL_LESS);
	glEnable(GL_DEPTH_CLAMP);
	
	DEBUG_MSG("OpenGL version: %s\n", glGetString(GL_VERSION));
	DEBUG_MSG("GLSL version: %s\n", (char*) glGetString(GL_SHADING_LANGUAGE_VERSION));
	
	// настраиваем основную камеру
	TRACE_MSG("init main camera\n");
	camera_init(&camera, vec3f(0.0f, 0.0f, 0.5f), vec3f(0.0f, 1.0f, 0.0f), vec3f(0.0f, 0.0f, -1.0f));
	camera_set_limit(&camera, -95.0f, 95.0f, -360.0f, 360.0f);
	camera_set_fov(&camera, camera_fov);
	camera_set_move_velocity(&camera, camera_move_speed);
	camera_set_rotate_velocity(&camera, camera_rotate_speed);
	camera_set_aspect(&camera, (float) window_width / (float) window_height);
	camera_set_zplanes(&camera, 0.001f, 1000.0f);
	camera_update(&camera, 0.0);
	
	isolevel = 30.0f; 
	isolevel_animate = 0;
	
	// устанавливаем функцию по-умолчанию
	parser_create(&parser);
	const char *default_func = "d = y;";
	str_function = (char*) malloc(sizeof(char) * (strlen(default_func) + 1));
	strcpy(str_function, default_func);
	
	// настраиваем и создаем скалярное поле
	render_set_volume_size(vec3ui(128, 128, 128), 1);
	render_set_grid_size(vec3ui(64, 64, 64));
	render_update_volume_tex();
	
	CHECK_GL_ERRORS();
	
	// инициализируем шейдер
	if(!init_shader())
		return 0;
	
	// инициализируем буферы с данными
	init_buffers();
	
	// устанавливаем параметры по-умолчанию
	new_light_position = light_position = vec3f(1.0f, 1.0f, 1.0f);
	rot_axis = vec3f(0.0f, 1.0f, 0.0f);
	num_threads = 1;
	rot_angle = 0.0f;
	light_animate = 0;
	light_rot_angle = 0.0f;
	mat4(rotmat, 1.0f);
	mat4(modelmat, 1.0f);
	material_front_color = vec3f(0.5f, 0.5f, 0.5f);
	material_back_color = vec3f(0.5f, 0.0f, 0.0f);
	light_color = vec3f(1.0f, 1.0f, 1.0f);
	light_spec_color = vec3f(1.0f, 1.0f, 1.0f);
	
	input_set_wheel_limits(20, 150);
	
	init = 1;
	
	// полигонизируем ск. п.
	render_update_mc();
	
	// обновляем рендер
	render_update(0.0f);
	
	return 1;
}
Exemple #8
0
/*
 *  Command-line front end for compiler.
 */
int main(int argc, char **argv)
{
	int action;

	int arg;

	buffer_t *in_buffer;
	buffer_t *out_buffer;

	int is_done;
	parser_t *parser;
	lexer_t *lexer;
	token_t *token;


	/* Set default settings. */
	action = ACT_TRANS;
	in_buffer = buffer_create(stdin);
	out_buffer = buffer_create(stdout);

	/* Parse command-line arguments. */
	for (arg = 1; arg < argc; arg++)
	{
		if ((strcmp(argv[arg], "--help") == 0)
			|| (strcmp(argv[arg], "-h") == 0))
		{
			action = ACT_USAGE;
		}
		else if ((strcmp(argv[arg], "--lex") == 0) && (action <= ACT_LEX))
		{
			action = ACT_LEX;
		}
		else if ((strcmp(argv[arg], "--parse") == 0) && (action <= ACT_PARSE))
		{
			action = ACT_PARSE;
		}
		else if ((strcmp(argv[arg], "--translate") == 0)
			&& (action <= ACT_TRANS))
		{
			action = ACT_TRANS;
		}
		else
		{
			fprintf(stderr, "Invalid argument: %s\n", argv[arg]);
			/* Stop parsing command-line. */
			arg = argc;

			action = ACT_USAGE;
		}
	}

	/* Take action. */
	if (action == ACT_USAGE)
	{
		printf(
			"Usage: compiler [option...]\n"
			"\n"
			"  Options:\n"
			"\n"
			"  -h, --help       Display this help text.\n"
			"      --lex        Run the lexer.\n"
			"      --parse      Run the parser. (Calls the lexer.)\n"
			"      --translate  Run the translator. (Calls the parser.)\n"
		);
	}
	else if (action == ACT_LEX)
	{
		is_done = 0;
		lexer = lexer_create(in_buffer);
		token = token_create();

		while (!is_done)
		{
			lexer_lex(lexer, token);
			token_print(token, stdout);
			printf("\n");
			if (token_get_class(token) == T_EOF)
				is_done = 1;
		}

		token_destroy(token);
		lexer_destroy(lexer);

		return EXIT_SUCCESS;
	}
	else if (action == ACT_PARSE)
	{
		parser = parser_create(in_buffer);

		parser_parse(parser);

		parser_destroy(parser);

		return EXIT_SUCCESS;
	}
	else if (action == ACT_TRANS)
	{
		parser = parser_create(in_buffer);

		parser_parse(parser);
		translator_translate(parser_get_tree(parser));

		parser_destroy(parser);

		return EXIT_SUCCESS;
	}

	return EXIT_SUCCESS;
}