コード例 #1
0
ファイル: functions6.c プロジェクト: holbertonschool/Betty
int test_lexer(test_chain_t *chain)
{
	const char	*line = chain->line;
	t_t	        *t = t_create();
	char		quote = 0;
	int		error = 0;

	while (*line && !error)
	{
		const char	*start = test_skip_space(line);
		test_t		*test = test_find_test(start);
		const char	*end = line;

		if (test->test)
		{
			end = process_test(chain, &t, test, start);
		}
		else
		{
			end = test_skip_any(start, &quote);
			if (end - start > 0)
			{
				if (!t->test &&
					(t->test_type == MACRO_TEST_0 ||
					t->test_type == MACRO_TEST_1 ||
					t->test_type == MACRO_TEST_2 ||
					t->test_type == MACRO_TEST_3))
				{
					t->test = hstrndup(start, end - start);
				}
				else
				{
					ARRAY_ADD(t->v, hstrndup(start, end - start), V_BUFFER_SIZE);
				}
			}
			else if (*end)
			{
				end++;
			}
		}
		line = end;
	}
	if (error)
	{
		hprintf("parsing error @ %s", line);
	}
	ARRAY_ADD(t->v, NULL, V_BUFFER_SIZE);
	ARRAY_ADD(chain->root.tests, t, 2);
	ARRAY_ADD(chain->root.tests, NULL, 1);
	return (!quote);
}
コード例 #2
0
int
main (void)
{
	puts ("\n    Zero Order Hold interpolator :") ;
	simple_test		(SRC_ZERO_ORDER_HOLD, 1, 45.0) ;
	process_test	(SRC_ZERO_ORDER_HOLD, 1, 45.0) ;
	callback_test	(SRC_ZERO_ORDER_HOLD, 1, 45.0) ;
	simple_test		(SRC_ZERO_ORDER_HOLD, 2, 44.0) ;
	process_test	(SRC_ZERO_ORDER_HOLD, 2, 44.0) ;
	callback_test	(SRC_ZERO_ORDER_HOLD, 2, 44.0) ;
	simple_test		(SRC_ZERO_ORDER_HOLD, 3, 44.0) ;
	process_test	(SRC_ZERO_ORDER_HOLD, 3, 44.0) ;
	callback_test	(SRC_ZERO_ORDER_HOLD, 3, 44.0) ;

	puts ("\n    Linear interpolator :") ;
	simple_test		(SRC_LINEAR, 1, 92.0) ;
	process_test	(SRC_LINEAR, 1, 92.0) ;
	callback_test	(SRC_LINEAR, 1, 92.0) ;
	simple_test		(SRC_LINEAR, 2, 90.0) ;
	process_test	(SRC_LINEAR, 2, 90.0) ;
	callback_test	(SRC_LINEAR, 2, 90.0) ;
	simple_test		(SRC_LINEAR, 3, 88.0) ;
	process_test	(SRC_LINEAR, 3, 88.0) ;
	callback_test	(SRC_LINEAR, 3, 88.0) ;

	puts ("\n    Sinc interpolator :") ;
	simple_test		(SRC_SINC_FASTEST, 1, 100.0) ;
	process_test	(SRC_SINC_FASTEST, 1, 100.0) ;
	callback_test	(SRC_SINC_FASTEST, 1, 100.0) ;
	simple_test		(SRC_SINC_FASTEST, 2, 100.0) ;
	process_test	(SRC_SINC_FASTEST, 2, 100.0) ;
	callback_test	(SRC_SINC_FASTEST, 2, 100.0) ;
	simple_test		(SRC_SINC_FASTEST, 3, 100.0) ;
	process_test	(SRC_SINC_FASTEST, 3, 100.0) ;
	callback_test	(SRC_SINC_FASTEST, 3, 100.0) ;

	puts ("") ;

	return 0 ;
} /* main */
コード例 #3
0
// tokenise the input file (or stdin if filename is empty), outputing the appropriate Python code
void process(const std::string &filename, const Options &opt, const std::set<std::string> &restrict_vars)
{
    std::ifstream file_stream;
    
    if (!filename.empty())
    {
        file_stream.open(filename.c_str());
        if (!file_stream) { std::cerr << exec_name << ": cannot open " << filename << '\n'; exit(1); }
    }

    std::istream &infile = (filename.empty() ? std::cin : file_stream);

    std::string line;
    std::vector<Token> tokens;

    // map from demangled (original) variable name to mangled name for variables on lhs of an assignment statement;
    // not used for --assign or --test
    Varmap assigned_vars;

    // set of "seen" variable names (e.g. "a", "a.b", "a.b["); only used for --assign
    Varset variable_hierarchy;
    
    // variables that appear in expressions (other than as arguments to function calls); only used for --test
    // (key = mangled id, value = demangled id)
    Varmap test_vars;

    // with the input to --test is raw python code (vs just being a list of boolean expressions, one per line)
    bool test_is_raw_python = false;
    std::string pending_line;
    int pending_line_num = 0;

    for (int line_num = 1;std::getline(infile, line);++line_num)
    {
        size_t len = line.length();
        if (len != 0 && line[len - 1] == '\\')
        {
            if (pending_line.empty()) { pending_line_num = line_num; }
            pending_line += line.substr(0, len - 1);
            pending_line += ' ';
            continue;
        }

        int actual_line_num = line_num;
        if (!pending_line.empty())
        {
            line = pending_line + line;
            pending_line.clear();
            actual_line_num = pending_line_num;
        }

        tokens.resize(0);
        tokenise(line, filename, line_num, opt, tokens, test_is_raw_python);
        // debug_tokens(tokens);

        if (opt.assign) { process_assign(tokens, line, filename, actual_line_num, variable_hierarchy); }
        else if (opt.test) { process_test(tokens, line, filename, actual_line_num, &test_is_raw_python, test_vars); }
        else { process_command(tokens, assigned_vars, opt, restrict_vars); }
    }

    if (opt.command) { print_assigned_variables(assigned_vars); }
    if (opt.test && !test_is_raw_python) { validate_test_variables(test_vars); }
}