forked from KPGPMC/furlang
feat(furc): add compound statement
This one: { [statement]... }
This commit is contained in:
@@ -60,6 +60,12 @@ void ir_generator::visit_if_statement_node(const ast::if_statement_node& node) {
|
||||
push_block();
|
||||
}
|
||||
|
||||
void ir_generator::visit_compound_statement_node(const ast::compound_statement_node& node) {
|
||||
for (const auto& stmt : node.body()->statements) {
|
||||
stmt->accept(*this);
|
||||
}
|
||||
}
|
||||
|
||||
void ir_generator::visit_string_literal_node(const ast::string_literal_node& node) {
|
||||
m_currentBlock->emplace<furlang::ir::assign_instruction>(ir::operand::new_string(std::string(*node.value())),
|
||||
ir::operand::new_reg(m_registerCounter++));
|
||||
|
||||
@@ -89,6 +89,7 @@ ast::declaration_node_h parser::parse_declaration() {
|
||||
ast::statement_node_h parser::parse_statement() {
|
||||
const auto& tok = peek_token();
|
||||
if (tok.has_error()) return tok;
|
||||
auto location = tok.location();
|
||||
switch (tok->type) {
|
||||
case token_t::Keyword: {
|
||||
switch (tok->value.keyword) {
|
||||
@@ -121,20 +122,21 @@ ast::statement_node_h parser::parse_statement() {
|
||||
peek_token()->value.keyword == keyword_token::Else) {
|
||||
next_token();
|
||||
|
||||
return ast::if_statement_node_h{ tok.location(),
|
||||
return ast::if_statement_node_h{ location,
|
||||
m_arena,
|
||||
std::move(cond),
|
||||
std::move(then),
|
||||
std::move(parse_statement()) };
|
||||
}
|
||||
|
||||
return ast::if_statement_node_h{ tok.location(), m_arena, std::move(cond), std::move(then) };
|
||||
return ast::if_statement_node_h{ location, m_arena, std::move(cond), std::move(then) };
|
||||
}
|
||||
case keyword_token::None:
|
||||
case keyword_token::Func:
|
||||
default: break;
|
||||
}
|
||||
}
|
||||
case token_t::Lbrace: return ast::compound_statement_node_h{ location, m_arena, parse_body() };
|
||||
default: break;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user