Пример #1
0
off_t test_open(char **buf)
{
	assert(buf);
	char file[512];
	snprintf(file, sizeof(file), "%s%s", TEST_INPUT_DIR, cur.i.in);
	return test_open_file(file, buf);
}
Пример #2
0
int main()
{
	int fd;

	decoder = bert_decoder_create();
	fd = test_open_file("files/big_int.bert");
	bert_decoder_stream(decoder,fd);

	test_read();

	bert_decoder_destroy(decoder);
	close(fd);
	return 0;
}
Пример #3
0
int main(int argc, char **argv)
{
	int ret = EXIT_FAILURE;
	struct prog_settings settings = {
		.letter_file = "grammar/letters.in",
		.token_file = "grammar/tokens.in",
		.keyword_file = "grammar/keywords.in",
		.grammar_file = "grammar/grammar.in",
		.input_file = "test.file",
		.k = 1,
	};
	if (get_settings(argc, argv, &settings))
		return EXIT_FAILURE;

	if (sh_lexer_init(&lexer))
		return EXIT_FAILURE;
	if (test_init_lexer(&lexer, &settings))
		goto exit_cleanup_lexer;

#if DO_LEX
	/* the code below tests functionality of the lexer alone */
	test_print_tokens(&lexer, DO_LEX_DETAILED);
#endif

	if (sh_parser_init(&parser))
		goto exit_cleanup_lexer;

#if DO_PARSE
	sh_parser_ambiguity_resolution(&parser, SH_PARSER_ACCEPT_SHIFT);
	if (test_init_parser(&parser, &lexer, &settings, SH_PARSER_LRK))
		goto exit_cleanup_parser;

	/* give parser callbacks */
	sh_parser_set_action_routine(&parser, "@init", init);
	sh_parser_set_action_routine(&parser, "@print_result", print_result);
	sh_parser_set_action_routine(&parser, "@push_variable_in_stack_possibly_new", push_variable_in_stack_possibly_new);
	sh_parser_set_action_routine(&parser, "@store_in_variable", store_in_variable);
	sh_parser_set_action_routine(&parser, "@push_op_in_stack", push_op_in_stack);
	sh_parser_set_action_routine(&parser, "@compute", compute);
	sh_parser_set_action_routine(&parser, "@push_variable_in_stack", push_variable_in_stack);
	sh_parser_set_action_routine(&parser, "@push_number_in_stack", push_number_in_stack);
	sh_parser_set_action_routine(&parser, "@negate", negate);
	sh_parser_set_action_routine(&parser, "@possibly_ignore_if", possibly_ignore_if);
	sh_parser_set_action_routine(&parser, "@possibly_ignore_else", possibly_ignore_else);
	sh_parser_set_action_routine(&parser, "@if_part_over", if_part_over);
	sh_parser_set_action_routine(&parser, "@else_part_over", else_part_over);
	sh_parser_set_action_routine(&parser, "@if_finished", if_finished);

	if (semantics_init(&parser))
	{
		fprintf(stderr, "error: out of memory\n");
		goto exit_cleanup_parser;
	}

	/* do the actual parsing */
	if (test_open_file(&lexer, &settings) == 0)
		test_parse_file(&parser);

	semantics_free(&parser);
#endif

	ret = 0;
exit_cleanup_parser:
	sh_parser_free(&parser);
exit_cleanup_lexer:
	sh_lexer_free(&lexer);

	return ret;
}
Пример #4
0
int main(int argc, char **argv)
{
	int ret = EXIT_FAILURE;
	struct prog_settings settings = {
		.letter_file = "grammar/letters.in",
		.token_file = "grammar/tokens.in",
		.keyword_file = "grammar/keywords.in",
		.grammar_file = "grammar/grammar.in",
		.input_file = "test.file",
		.k = 1,
	};
	if (get_settings(argc, argv, &settings))
		return EXIT_FAILURE;

	if (sh_lexer_init(&lexer))
		return EXIT_FAILURE;
	if (test_init_lexer(&lexer, &settings))
		goto exit_cleanup_lexer;
	/* redo read file to make sure proper cleanup is done */
	if (sh_lexer_file(&lexer, settings.input_file) == SH_LEXER_NO_FILE)
	{
		fprintf(stderr, "error: could not open file\n");
		goto exit_cleanup_lexer;
	}

#if DO_LEX
	/* the code below tests functionality of the lexer alone */
	test_print_tokens(&lexer, DO_LEX_DETAILED);
#endif

	if (sh_parser_init(&parser))
		goto exit_cleanup_lexer;

#ifdef DO_PARSE
	if (test_init_parser(&parser, &lexer, &settings, SH_PARSER_LLK))
		goto exit_cleanup_parser;

	/* give parser callbacks */
	sh_parser_set_action_routine(&parser, "@init", init);
	sh_parser_set_action_routine(&parser, "@print_result", print_result);
	sh_parser_set_action_routine(&parser, "@push_op_in_stack", push_op_in_stack);
	sh_parser_set_action_routine(&parser, "@compute", compute);
	sh_parser_set_action_routine(&parser, "@push_number_in_stack", push_number_in_stack);
	sh_parser_set_action_routine(&parser, "@negate", negate);

	if (semantics_init(&parser))
	{
		fprintf(stderr, "error: out of memory\n");
		goto exit_cleanup_parser;
	}

	/* do the actual parsing */
	if (test_open_file(&lexer, &settings) == 0)
		test_parse_file(&parser);

	/* continue the parse from stdin, to make sure it switches over and everything is ok */
	if (sh_lexer_interactive(&lexer, NULL, "stdin", NULL) != SH_LEXER_SUCCESS)
		fprintf(stderr, "error: failed to initialize lexer in interactive mode\n");
	else
		test_parse_file(&parser);

	semantics_free(&parser);
#endif

	ret = 0;
exit_cleanup_parser:
	sh_parser_free(&parser);
exit_cleanup_lexer:
	sh_lexer_free(&lexer);

	return ret;
}