예제 #1
0
CodeGen hex(AST &ast){
	CodeGen cg;
	cg.generate(ast.get_root());
	cg.back_patch();
	cg.fill();
	// cg.print_hex();
	// cg.print_tables();

	return cg;
}
예제 #2
0
    IfNode * if_node = new IfNode;
    if_node->conditions.push_back(condition);
    
    WhileNode * while_node = new WhileNode;
    if_node->next = while_node;
    
    AssignNode * assign_node = new AssignNode;
    while_node->next = assign_node;
    
    PrintNode * print_node = new PrintNode;
    assign_node->next = print_node;
    
    // create AST set root which will be deleted automatically
    AST ast;
    ast.set_root(if_node);
    Node * root = ast.get_root();
    REQUIRE(root == if_node);
}

void ast_correctness_test_helper(std::string program) {
    RXCompiler compiler(PARSE_WITH_AST);
    compiler.set_source(program);
    REQUIRE_NOTHROW(compiler.compile());
}

TEST_CASE("parser with AST parses correctly") {
    
    SECTION("type inference parse correctly") {
        ast_correctness_test_helper("var x = true; x = false");
        ast_correctness_test_helper("var x = 1 < 2; x = true");
    }