codegen alpha

This commit is contained in:
Leo
2024-04-10 18:32:47 +02:00
parent de2889c5d8
commit e2f87dc818
3 changed files with 29 additions and 22 deletions
+7 -2
View File
@@ -4,6 +4,7 @@ use std::fmt;
#[derive(Clone, Debug, PartialEq, Eq)]
pub enum AstType {
FunctionDeceleration,
VoidFunctionDeceleration,
VariableDeceleration,
MutVariableDeceleration,
Other
@@ -59,12 +60,16 @@ impl Parser {
let token = &self.tokens[index];
match token.token_type {
TokenType::Identifier => {
if self.tokens.len()-index > 2 && self.tokens[index+1].token_type==TokenType::Identifier && self.tokens[index+2].token_type==TokenType::Round && self.tokens[index+3].token_type==TokenType::Curly {
if self.tokens.len()-index > 3 && self.tokens[index+1].token_type==TokenType::Identifier && self.tokens[index+2].token_type==TokenType::Round && self.tokens[index+3].token_type==TokenType::Curly {
ast_res.tokens.push(self.tokens[index].clone());
ast_res.tokens.push(self.tokens[index+1].clone());
ast_res.tokens.push(self.tokens[index+2].clone());
ast_res.tokens.push(self.tokens[index+3].clone());
ast_res.ast_type = AstType::FunctionDeceleration;
if token.value == "void" {
ast_res.ast_type = AstType::VoidFunctionDeceleration;
} else {
ast_res.ast_type = AstType::FunctionDeceleration;
}
self.index += 3;
} else {
loop {