diff --git a/.github/testing.md b/.github/testing.md index ec10ab8..cfe0b1a 100644 --- a/.github/testing.md +++ b/.github/testing.md @@ -63,55 +63,55 @@ SEMICOLON ; 3 VAR var 4 IDENTIFIER("a") a 4 COLON : 4 -TYPE_INT(I4) i4 4 +TypeInt(I4) i4 4 EQUAL = 4 SEMICOLON ; 4 VAR var 5 IDENTIFIER("a") a 5 COLON : 5 -TYPE_INT(I8) i8 5 +TypeInt(I8) i8 5 EQUAL = 5 SEMICOLON ; 5 VAR var 6 IDENTIFIER("a") a 6 COLON : 6 -TYPE_INT(I16) i16 6 +TypeInt(I16) i16 6 EQUAL = 6 SEMICOLON ; 6 VAR var 7 IDENTIFIER("a") a 7 COLON : 7 -TYPE_INT(I32) i32 7 +TypeInt(I32) i32 7 EQUAL = 7 SEMICOLON ; 7 VAR var 8 IDENTIFIER("a") a 8 COLON : 8 -TYPE_INT(I64) i64 8 +TypeInt(I64) i64 8 EQUAL = 8 SEMICOLON ; 8 VAR var 9 IDENTIFIER("a") a 9 COLON : 9 -TYPE_INT(I128) i128 9 +TypeInt(I128) i128 9 EQUAL = 9 SEMICOLON ; 9 VAR var 10 IDENTIFIER("a") a 10 COLON : 10 -TYPE_INT(I512) i512 10 +TypeInt(I512) i512 10 EQUAL = 10 SEMICOLON ; 10 VAR var 11 IDENTIFIER("a") a 11 COLON : 11 -TYPE_INT(I1024) i1024 11 +TypeInt(I1024) i1024 11 EQUAL = 11 SEMICOLON ; 11 VAR var 12 IDENTIFIER("a") a 12 COLON : 12 -TYPE_INT(I2048) i2048 12 +TypeInt(I2048) i2048 12 EQUAL = 12 SEMICOLON ; 12 VAR var 13 @@ -123,18 +123,18 @@ SEMICOLON ; 13 VAR var 14 IDENTIFIER("a") a 14 COLON : 14 -TYPE_INT(I8192) i8192 14 +TypeInt(I8192) i8192 14 EQUAL = 14 SEMICOLON ; 14 IDENTIFIER("a") a 15 COLON : 15 -TYPE_INT(I16384) i16384 15 +TypeInt(I16384) i16384 15 EQUAL = 15 SEMICOLON ; 15 VAR var 16 IDENTIFIER("a") a 16 COLON : 16 -TYPE_INT(I32768) i32768 16 +TypeInt(I32768) i32768 16 EQUAL = 16 SEMICOLON ; 16 VAR var 17 @@ -146,55 +146,55 @@ SEMICOLON ; 17 VAR var 18 IDENTIFIER("b") b 18 COLON : 18 -TYPE_INT(U4) u4 18 +TypeInt(U4) u4 18 EQUAL = 18 SEMICOLON ; 18 VAR var 19 IDENTIFIER("b") b 19 COLON : 19 -TYPE_INT(U8) u8 19 +TypeInt(U8) u8 19 EQUAL = 19 SEMICOLON ; 19 VAR var 20 IDENTIFIER("b") b 20 COLON : 20 -TYPE_INT(U16) u16 20 +TypeInt(U16) u16 20 EQUAL = 20 SEMICOLON ; 20 VAR var 21 IDENTIFIER("b") b 21 COLON : 21 -TYPE_INT(U32) u32 21 +TypeInt(U32) u32 21 EQUAL = 21 SEMICOLON ; 21 VAR var 22 IDENTIFIER("b") b 22 COLON : 22 -TYPE_INT(U64) u64 22 +TypeInt(U64) u64 22 EQUAL = 22 SEMICOLON ; 22 VAR var 23 IDENTIFIER("b") b 23 COLON : 23 -TYPE_INT(U128) u128 23 +TypeInt(U128) u128 23 EQUAL = 23 SEMICOLON ; 23 VAR var 24 IDENTIFIER("b") b 24 COLON : 24 -TYPE_INT(U512) u512 24 +TypeInt(U512) u512 24 EQUAL = 24 SEMICOLON ; 24 VAR var 25 IDENTIFIER("b") b 25 COLON : 25 -TYPE_INT(U1024) u1024 25 +TypeInt(U1024) u1024 25 EQUAL = 25 SEMICOLON ; 25 VAR var 26 IDENTIFIER("b") b 26 COLON : 26 -TYPE_INT(U2048) u2048 26 +TypeInt(U2048) u2048 26 EQUAL = 26 SEMICOLON ; 26 VAR var 27 @@ -206,54 +206,54 @@ SEMICOLON ; 27 VAR var 28 IDENTIFIER("b") b 28 COLON : 28 -TYPE_INT(U8192) u8192 28 +TypeInt(U8192) u8192 28 EQUAL = 28 SEMICOLON ; 28 VAR var 29 IDENTIFIER("b") b 29 COLON : 29 -TYPE_INT(U16384) u16384 29 +TypeInt(U16384) u16384 29 EQUAL = 29 SEMICOLON ; 29 VAR var 30 IDENTIFIER("b") b 30 COLON : 30 -TYPE_INT(U32768) u32768 30 +TypeInt(U32768) u32768 30 EQUAL = 30 SEMICOLON ; 30 VAR var 31 IDENTIFIER("c") c 31 COLON : 31 -TYPE_FLOAT(F32) f32 31 +TypeFloat(F32) f32 31 EQUAL = 31 SEMICOLON ; 31 VAR var 32 IDENTIFIER("c") c 32 COLON : 32 -TYPE_FLOAT(F64) f64 32 +TypeFloat(F64) f64 32 EQUAL = 32 SEMICOLON ; 32 VAR var 33 IDENTIFIER("c") c 33 COLON : 33 -TYPE_FLOAT(F128) f128 33 +TypeFloat(F128) f128 33 EQUAL = 33 SEMICOLON ; 33 IDENTIFIER("c") c 34 COLON : 34 -TYPE_FLOAT(F512) f512 34 +TypeFloat(F512) f512 34 EQUAL = 34 SEMICOLON ; 34 VAR var 35 IDENTIFIER("c") c 35 COLON : 35 -TYPE_FLOAT(F1024) f1024 35 +TypeFloat(F1024) f1024 35 EQUAL = 35 SEMICOLON ; 35 VAR var 36 IDENTIFIER("c") c 36 COLON : 36 -TYPE_FLOAT(F2048) f2048 36 +TypeFloat(F2048) f2048 36 EQUAL = 36 SEMICOLON ; 36 VAR var 37 @@ -265,24 +265,24 @@ SEMICOLON ; 37 VAR var 38 IDENTIFIER("c") c 38 COLON : 38 -TYPE_FLOAT(F8192) f8192 38 +TypeFloat(F8192) f8192 38 EQUAL = 38 SEMICOLON ; 38 VAR var 39 IDENTIFIER("c") c 39 COLON : 39 -TYPE_FLOAT(F16384) f16384 39 +TypeFloat(F16384) f16384 39 EQUAL = 39 SEMICOLON ; 39 VAR var 40 IDENTIFIER("c") c 40 -TYPE_FLOAT(F32768) f32768 40 +TypeFloat(F32768) f32768 40 EQUAL = 40 SEMICOLON ; 40 VAR var 41 IDENTIFIER("d") d 41 COLON : 41 -TYPE_STRING str 41 +TypeString str 41 EQUAL = 41 SEMICOLON ; 41 RBRACE } 42 diff --git a/.gitignore b/.gitignore index 84faa3d..99cd148 100644 --- a/.gitignore +++ b/.gitignore @@ -1,5 +1,11 @@ -zig-cache/ -zig-out/ -build/ -build-*/ -docgen_tmp/ +# Rust Build Output +target/ + +# OS and IDE related files +.DS_Store +.idea/ +.vscode/ + +# Additional files to ignore as needed +*.log +*.tmp \ No newline at end of file diff --git a/src/lexer.rs b/src/lexer.rs index 0b2ae19..05eb9d1 100644 --- a/src/lexer.rs +++ b/src/lexer.rs @@ -103,28 +103,28 @@ pub enum TokenType { INPUT, PRINT, PRINTLN, - LOGICAL_AND, // && - BITWISE_AND, // & - LOGICAL_OR, // || - BITWISE_OR, // | - NOT_EQUAL, // != + LogicalAnd, // && + BitwiseAnd, // & + LogicalOr, // || + BitwiseOr, // | + NotEqual, // != XOR, // ^ XNOR, // ~^ - BITWISE_NOT, // ~ + BitwiseNot, // ~ NAND, // !& NOR, // !| NOT, // ! CONDITION, // ? - NULL_COALESCE, // ?? + NullCoalesce, // ?? CONDITIONAL, // ?: IN, // in IS, // is ROL, ROR, XNAND, - TYPE_INT(IntegerType), - TYPE_FLOAT(FloatType), - TYPE_STRING, + TypeInt(IntegerType), + TypeFloat(FloatType), + TypeString, IDENTIFIER(String), STRING(String), NUMBER(f64), @@ -135,15 +135,15 @@ pub enum TokenType { STAR, // * DIV, // / EQUAL, // = - EQUAL_TWO, // == + EqualTwo, // == COMMA, // , DOT, // . SEMICOLON, // ; COLON, // : LCHEVR, // < - LCHEVR_EQ, // <= + LchevrEq, // <= RCHEVR, // > - RCHEVR_EQ, // >= + RchevrEq, // >= LPAREN, // ( RPAREN, // ) LBRACE, // { @@ -327,7 +327,7 @@ impl<'a> Lexer<'a> { '<' => { if self.match_next('=') { Token { - token_type: TokenType::LCHEVR_EQ, + token_type: TokenType::LchevrEq, lexeme: "<=".to_string(), line: self.line, } @@ -343,7 +343,7 @@ impl<'a> Lexer<'a> { '>' => { if self.match_next('=') { Token { - token_type: TokenType::RCHEVR_EQ, + token_type: TokenType::RchevrEq, lexeme: ">=".to_string(), line: self.line, } @@ -389,7 +389,7 @@ impl<'a> Lexer<'a> { '=' => { if self.match_next('=') { Token { - token_type: TokenType::EQUAL_TWO, + token_type: TokenType::EqualTwo, lexeme: "==".to_string(), line: self.line, } @@ -404,13 +404,13 @@ impl<'a> Lexer<'a> { '&' => { if self.match_next('&') { Token { - token_type: TokenType::LOGICAL_AND, + token_type: TokenType::LogicalAnd, lexeme: "&&".to_string(), line: self.line, } } else { Token { - token_type: TokenType::BITWISE_AND, + token_type: TokenType::BitwiseAnd, lexeme: "&".to_string(), line: self.line, } @@ -419,13 +419,13 @@ impl<'a> Lexer<'a> { '|' => { if self.match_next('|') { Token { - token_type: TokenType::LOGICAL_OR, + token_type: TokenType::LogicalOr, lexeme: "||".to_string(), line: self.line, } } else { Token { - token_type: TokenType::BITWISE_OR, + token_type: TokenType::BitwiseOr, lexeme: "|".to_string(), line: self.line, } @@ -434,7 +434,7 @@ impl<'a> Lexer<'a> { '!' => { if self.match_next('=') { Token { - token_type: TokenType::NOT_EQUAL, + token_type: TokenType::NotEqual, lexeme: "!=".to_string(), line: self.line, } @@ -474,7 +474,7 @@ impl<'a> Lexer<'a> { } } else { Token { - token_type: TokenType::BITWISE_NOT, + token_type: TokenType::BitwiseNot, lexeme: "~".to_string(), line: self.line, } @@ -483,7 +483,7 @@ impl<'a> Lexer<'a> { '?' => { if self.match_next('?') { Token { - token_type: TokenType::NULL_COALESCE, + token_type: TokenType::NullCoalesce, lexeme: "??".to_string(), line: self.line, } @@ -496,22 +496,17 @@ impl<'a> Lexer<'a> { } }, - ':' => Token { - token_type: TokenType::COLON, - lexeme: ":".to_string(), - line: self.line, - }, ',' => Token { token_type: TokenType::COMMA, lexeme: ",".to_string(), line: self.line, }, '"' => { - return Token { + Token { token_type: TokenType::STRING(self.string()), - lexeme: String::new(), // 필요에 따라 설정 + lexeme: String::new(), // Set as needed line: self.line, - }; + } }, 'a'..='z' | 'A'..='Z' => { let identifier = self.identifier(); @@ -607,212 +602,212 @@ impl<'a> Lexer<'a> { line: self.line, }, "isz" => Token { - token_type: TokenType::TYPE_INT(IntegerType::ISZ), + token_type: TokenType::TypeInt(IntegerType::ISZ), lexeme: "isz".to_string(), line: self.line, }, "i4" => Token { - token_type: TokenType::TYPE_INT(IntegerType::I4), + token_type: TokenType::TypeInt(IntegerType::I4), lexeme: "i4".to_string(), line: self.line, }, "i8" => Token { - token_type: TokenType::TYPE_INT(IntegerType::I8), + token_type: TokenType::TypeInt(IntegerType::I8), lexeme: "i8".to_string(), line: self.line, }, "i16" => Token { - token_type: TokenType::TYPE_INT(IntegerType::I16), + token_type: TokenType::TypeInt(IntegerType::I16), lexeme: "i16".to_string(), line: self.line, }, "i32" => Token { - token_type: TokenType::TYPE_INT(IntegerType::I32), + token_type: TokenType::TypeInt(IntegerType::I32), lexeme: "i32".to_string(), line: self.line, }, "i64" => Token { - token_type: TokenType::TYPE_INT(IntegerType::I64), + token_type: TokenType::TypeInt(IntegerType::I64), lexeme: "i64".to_string(), line: self.line, }, "i128" => Token { - token_type: TokenType::TYPE_INT(IntegerType::I128), + token_type: TokenType::TypeInt(IntegerType::I128), lexeme: "i128".to_string(), line: self.line, }, "i256" => Token { - token_type: TokenType::TYPE_INT(IntegerType::I256), + token_type: TokenType::TypeInt(IntegerType::I256), lexeme: "i256".to_string(), line: self.line, }, "i512" => Token { - token_type: TokenType::TYPE_INT(IntegerType::I512), + token_type: TokenType::TypeInt(IntegerType::I512), lexeme: "i512".to_string(), line: self.line, }, "i1024" => Token { - token_type: TokenType::TYPE_INT(IntegerType::I1024), + token_type: TokenType::TypeInt(IntegerType::I1024), lexeme: "i1024".to_string(), line: self.line, }, "i2048" => Token { - token_type: TokenType::TYPE_INT(IntegerType::I2048), + token_type: TokenType::TypeInt(IntegerType::I2048), lexeme: "i2048".to_string(), line: self.line, }, "i4096" => Token { - token_type: TokenType::TYPE_INT(IntegerType::I4096), + token_type: TokenType::TypeInt(IntegerType::I4096), lexeme: "i4096".to_string(), line: self.line, }, "i8192" => Token { - token_type: TokenType::TYPE_INT(IntegerType::I8192), + token_type: TokenType::TypeInt(IntegerType::I8192), lexeme: "i8192".to_string(), line: self.line, }, "i16384" => Token { - token_type: TokenType::TYPE_INT(IntegerType::I16384), + token_type: TokenType::TypeInt(IntegerType::I16384), lexeme: "i16384".to_string(), line: self.line, }, "i32768" => Token { - token_type: TokenType::TYPE_INT(IntegerType::I32768), + token_type: TokenType::TypeInt(IntegerType::I32768), lexeme: "i32768".to_string(), line: self.line, }, "usz" => Token { - token_type: TokenType::TYPE_INT(IntegerType::USZ), + token_type: TokenType::TypeInt(IntegerType::USZ), lexeme: "usz".to_string(), line: self.line, }, "u4" => Token { - token_type: TokenType::TYPE_INT(IntegerType::U4), + token_type: TokenType::TypeInt(IntegerType::U4), lexeme: "u4".to_string(), line: self.line, }, "u8" => Token { - token_type: TokenType::TYPE_INT(IntegerType::U8), + token_type: TokenType::TypeInt(IntegerType::U8), lexeme: "u8".to_string(), line: self.line, }, "u16" => Token { - token_type: TokenType::TYPE_INT(IntegerType::U16), + token_type: TokenType::TypeInt(IntegerType::U16), lexeme: "u16".to_string(), line: self.line, }, "u32" => Token { - token_type: TokenType::TYPE_INT(IntegerType::U32), + token_type: TokenType::TypeInt(IntegerType::U32), lexeme: "u32".to_string(), line: self.line, }, "u64" => Token { - token_type: TokenType::TYPE_INT(IntegerType::U64), + token_type: TokenType::TypeInt(IntegerType::U64), lexeme: "u64".to_string(), line: self.line, }, "u128" => Token { - token_type: TokenType::TYPE_INT(IntegerType::U128), + token_type: TokenType::TypeInt(IntegerType::U128), lexeme: "u128".to_string(), line: self.line, }, "u256" => Token { - token_type: TokenType::TYPE_INT(IntegerType::U256), + token_type: TokenType::TypeInt(IntegerType::U256), lexeme: "u256".to_string(), line: self.line, }, "u512" => Token { - token_type: TokenType::TYPE_INT(IntegerType::U512), + token_type: TokenType::TypeInt(IntegerType::U512), lexeme: "u512".to_string(), line: self.line, }, "u1024" => Token { - token_type: TokenType::TYPE_INT(IntegerType::U1024), + token_type: TokenType::TypeInt(IntegerType::U1024), lexeme: "u1024".to_string(), line: self.line, }, "u2048" => Token { - token_type: TokenType::TYPE_INT(IntegerType::U2048), + token_type: TokenType::TypeInt(IntegerType::U2048), lexeme: "u2048".to_string(), line: self.line, }, "u4096" => Token { - token_type: TokenType::TYPE_INT(IntegerType::U4096), + token_type: TokenType::TypeInt(IntegerType::U4096), lexeme: "u4096".to_string(), line: self.line, }, "u8192" => Token { - token_type: TokenType::TYPE_INT(IntegerType::U8192), + token_type: TokenType::TypeInt(IntegerType::U8192), lexeme: "u8192".to_string(), line: self.line, }, "u16384" => Token { - token_type: TokenType::TYPE_INT(IntegerType::U16384), + token_type: TokenType::TypeInt(IntegerType::U16384), lexeme: "u16384".to_string(), line: self.line, }, "u32768" => Token { - token_type: TokenType::TYPE_INT(IntegerType::U32768), + token_type: TokenType::TypeInt(IntegerType::U32768), lexeme: "u32768".to_string(), line: self.line, }, "f32" => Token { - token_type: TokenType::TYPE_FLOAT(FloatType::F32), + token_type: TokenType::TypeFloat(FloatType::F32), lexeme: "f32".to_string(), line: self.line, }, "f64" => Token { - token_type: TokenType::TYPE_FLOAT(FloatType::F64), + token_type: TokenType::TypeFloat(FloatType::F64), lexeme: "f64".to_string(), line: self.line, }, "f128" => Token { - token_type: TokenType::TYPE_FLOAT(FloatType::F128), + token_type: TokenType::TypeFloat(FloatType::F128), lexeme: "f128".to_string(), line: self.line, }, "f256" => Token { - token_type: TokenType::TYPE_FLOAT(FloatType::F256), + token_type: TokenType::TypeFloat(FloatType::F256), lexeme: "f256".to_string(), line: self.line, }, "f512" => Token { - token_type: TokenType::TYPE_FLOAT(FloatType::F512), + token_type: TokenType::TypeFloat(FloatType::F512), lexeme: "f512".to_string(), line: self.line, }, "f1024" => Token { - token_type: TokenType::TYPE_FLOAT(FloatType::F1024), + token_type: TokenType::TypeFloat(FloatType::F1024), lexeme: "f1024".to_string(), line: self.line, }, "f2048" => Token { - token_type: TokenType::TYPE_FLOAT(FloatType::F2048), + token_type: TokenType::TypeFloat(FloatType::F2048), lexeme: "f2048".to_string(), line: self.line, }, "f4096" => Token { - token_type: TokenType::TYPE_FLOAT(FloatType::F4096), + token_type: TokenType::TypeFloat(FloatType::F4096), lexeme: "f4096".to_string(), line: self.line, }, "f8192" => Token { - token_type: TokenType::TYPE_FLOAT(FloatType::F8192), + token_type: TokenType::TypeFloat(FloatType::F8192), lexeme: "f8192".to_string(), line: self.line, }, "f16384" => Token { - token_type: TokenType::TYPE_FLOAT(FloatType::F16384), + token_type: TokenType::TypeFloat(FloatType::F16384), lexeme: "f16384".to_string(), line: self.line, }, "f32768" => Token { - token_type: TokenType::TYPE_FLOAT(FloatType::F32768), + token_type: TokenType::TypeFloat(FloatType::F32768), lexeme: "f32768".to_string(), line: self.line, }, "str" => Token { - token_type: TokenType::TYPE_STRING, + token_type: TokenType::TypeString, lexeme: "str".to_string(), line: self.line, }, @@ -826,36 +821,36 @@ impl<'a> Lexer<'a> { } }, '0'..='9' => { - let mut num_str = self.number().to_string(); // 숫자를 문자열로 변환 - if self.peek() == '.' { // 다음 문자가 점이면 실수 처리 - num_str.push('.'); // 점을 추가 - self.advance(); // 점을 넘기기 - // 실수 뒤에 올 수 있는 숫자들을 처리 + let mut num_str = self.number().to_string(); // Converting Numbers to Strings + if self.peek() == '.' { // If the following characters are dots, handle mistakes + num_str.push('.'); // Add a dot + self.advance(); // turning over a mole + // deal with numbers that can follow a mistake while self.peek().is_digit(10) { - num_str.push(self.advance()); // 숫자를 계속 추가 + num_str.push(self.advance()); // Keep adding numbers } } - // 실수로 파싱 시 오류를 안전하게 처리 + // Safe handling of errors in accidental parsing let token_type = match num_str.parse::() { Ok(n) => { - // 실수로 파싱될 경우 - if n.fract() == 0.0 { // 정수 부분이 있고 소수 부분이 없다면 - TokenType::NUMBER(n as i64 as f64) // 정수로 처리 + // In case of accidental parsing + if n.fract() == 0.0 { // If there's an integer part and there's no decimal part + TokenType::NUMBER(n as i64 as f64) // Processing with water purification } else { - TokenType::NUMBER(n) // 실수로 처리 + TokenType::NUMBER(n) // Processing with Real number } } Err(_) => { - TokenType::NUMBER(0.0) // 파싱 실패 시 기본값으로 0.0을 사용 + TokenType::NUMBER(0.0) // Use 0.0 as default in case of parsing failure } }; - return Token { + Token { token_type, - lexeme: num_str, // 실수 문자열을 lexeme에 저장 + lexeme: num_str, // Save real string to lexeme line: self.line, - }; + } }, _ => { eprintln!("[eprintln] Unexpected character: {}", c); @@ -867,7 +862,7 @@ impl<'a> Lexer<'a> { // Helper methods to create tokens fn create_int_token(&self, int_type: IntegerType, lexeme: String) -> Token { Token { - token_type: TokenType::TYPE_INT(int_type), + token_type: TokenType::TypeInt(int_type), lexeme, line: self.line, } @@ -875,7 +870,7 @@ impl<'a> Lexer<'a> { fn create_float_token(&self, float_type: FloatType, lexeme: String) -> Token { Token { - token_type: TokenType::TYPE_FLOAT(float_type), + token_type: TokenType::TypeFloat(float_type), lexeme, line: self.line, } @@ -889,7 +884,7 @@ impl<'a> Lexer<'a> { } } - // 문자열 리터럴 처리 함수 추가 + // Add string literal processing function fn string(&mut self) -> String { let mut string_literal = String::new(); diff --git a/src/main.rs b/src/main.rs index ffd328c..ee62d11 100644 --- a/src/main.rs +++ b/src/main.rs @@ -65,7 +65,7 @@ fn main() { asta.add_node(node); - // 형식화된 출력 + // a formalized output println!("Tokens: {}", format_tokens(&tokens)); println!("\nParser: {}", format_parser(&parser)); println!("\nAST: {}", format_ast(&ast)); diff --git a/src/parser.rs b/src/parser.rs index c085561..91a68df 100644 --- a/src/parser.rs +++ b/src/parser.rs @@ -104,7 +104,7 @@ impl<'a> Parser<'a> { self.advance(); let mut body = Vec::new(); - // 함수 본문 처리: 중괄호 안에서 명령문들을 처리 + // Processing the body of a function: processing commands in brackets while self.current_token.token_type != TokenType::RBRACE { eprintln!("Parsing statement in function body: {:?}", self.current_token); match self.current_token.token_type { @@ -120,15 +120,13 @@ impl<'a> Parser<'a> { params, body, }); - - ast; } fn variable(&mut self, ast: &mut AST) { - // `var` 토큰 처리 + // Processing 'var' tokens self.advance(); // `var` - // 변수 이름 처리 + // Processing variable names let var_name = if let TokenType::IDENTIFIER(var_name) = &self.current_token.token_type { var_name.clone() } else { @@ -137,54 +135,54 @@ impl<'a> Parser<'a> { }; self.advance(); - // 변수 타입 처리 + // Processing variable types let var_type = if self.current_token.token_type == TokenType::COLON { self.advance(); match &self.current_token.token_type { - TokenType::TYPE_INT(IntegerType::I4) => "i4".to_string(), - TokenType::TYPE_INT(IntegerType::I8) => "i8".to_string(), - TokenType::TYPE_INT(IntegerType::I16) => "i16".to_string(), - TokenType::TYPE_INT(IntegerType::I32) => "i32".to_string(), - TokenType::TYPE_INT(IntegerType::I64) => "i64".to_string(), - TokenType::TYPE_INT(IntegerType::I128) => "i128".to_string(), - TokenType::TYPE_INT(IntegerType::I256) => "i256".to_string(), - TokenType::TYPE_INT(IntegerType::I512) => "i512".to_string(), - TokenType::TYPE_INT(IntegerType::I1024) => "i1024".to_string(), - TokenType::TYPE_INT(IntegerType::I2048) => "i2048".to_string(), - TokenType::TYPE_INT(IntegerType::I4096) => "i4096".to_string(), - TokenType::TYPE_INT(IntegerType::I8192) => "i8192".to_string(), - TokenType::TYPE_INT(IntegerType::I16384) => "i16384".to_string(), - TokenType::TYPE_INT(IntegerType::I32768) => "i32768".to_string(), - TokenType::TYPE_INT(IntegerType::ISZ) => "isz".to_string(), - - TokenType::TYPE_INT(IntegerType::U4) => "u4".to_string(), - TokenType::TYPE_INT(IntegerType::U8) => "u8".to_string(), - TokenType::TYPE_INT(IntegerType::U16) => "u16".to_string(), - TokenType::TYPE_INT(IntegerType::U32) => "u32".to_string(), - TokenType::TYPE_INT(IntegerType::U64) => "u64".to_string(), - TokenType::TYPE_INT(IntegerType::U8) => "u128".to_string(), - TokenType::TYPE_INT(IntegerType::U256) => "u256".to_string(), - TokenType::TYPE_INT(IntegerType::U512) => "u512".to_string(), - TokenType::TYPE_INT(IntegerType::U1024) => "u1024".to_string(), - TokenType::TYPE_INT(IntegerType::U2048) => "u2048".to_string(), - TokenType::TYPE_INT(IntegerType::U4096) => "u4096".to_string(), - TokenType::TYPE_INT(IntegerType::U8192) => "u8192".to_string(), - TokenType::TYPE_INT(IntegerType::U16384) => "u16384".to_string(), - TokenType::TYPE_INT(IntegerType::U32768) => "u32768".to_string(), - TokenType::TYPE_INT(IntegerType::USZ) => "usz".to_string(), - - TokenType::TYPE_FLOAT(FloatType::F32) => "f32".to_string(), - TokenType::TYPE_FLOAT(FloatType::F64) => "f64".to_string(), - TokenType::TYPE_FLOAT(FloatType::F128) => "f128".to_string(), - TokenType::TYPE_FLOAT(FloatType::F256) => "f256".to_string(), - TokenType::TYPE_FLOAT(FloatType::F512) => "f512".to_string(), - TokenType::TYPE_FLOAT(FloatType::F1024) => "f1024".to_string(), - TokenType::TYPE_FLOAT(FloatType::F2048) => "f2048".to_string(), - TokenType::TYPE_FLOAT(FloatType::F4096) => "f4096".to_string(), - TokenType::TYPE_FLOAT(FloatType::F8192) => "f8192".to_string(), - TokenType::TYPE_FLOAT(FloatType::F16384) => "f16384".to_string(), - TokenType::TYPE_FLOAT(FloatType::F32768) => "f32768".to_string(), - TokenType::TYPE_STRING => "string".to_string(), + TokenType::TypeInt(IntegerType::I4) => "i4".to_string(), + TokenType::TypeInt(IntegerType::I8) => "i8".to_string(), + TokenType::TypeInt(IntegerType::I16) => "i16".to_string(), + TokenType::TypeInt(IntegerType::I32) => "i32".to_string(), + TokenType::TypeInt(IntegerType::I64) => "i64".to_string(), + TokenType::TypeInt(IntegerType::I128) => "i128".to_string(), + TokenType::TypeInt(IntegerType::I256) => "i256".to_string(), + TokenType::TypeInt(IntegerType::I512) => "i512".to_string(), + TokenType::TypeInt(IntegerType::I1024) => "i1024".to_string(), + TokenType::TypeInt(IntegerType::I2048) => "i2048".to_string(), + TokenType::TypeInt(IntegerType::I4096) => "i4096".to_string(), + TokenType::TypeInt(IntegerType::I8192) => "i8192".to_string(), + TokenType::TypeInt(IntegerType::I16384) => "i16384".to_string(), + TokenType::TypeInt(IntegerType::I32768) => "i32768".to_string(), + TokenType::TypeInt(IntegerType::ISZ) => "isz".to_string(), + + TokenType::TypeInt(IntegerType::U4) => "u4".to_string(), + TokenType::TypeInt(IntegerType::U8) => "u8".to_string(), + TokenType::TypeInt(IntegerType::U16) => "u16".to_string(), + TokenType::TypeInt(IntegerType::U32) => "u32".to_string(), + TokenType::TypeInt(IntegerType::U64) => "u64".to_string(), + TokenType::TypeInt(IntegerType::U8) => "u128".to_string(), + TokenType::TypeInt(IntegerType::U256) => "u256".to_string(), + TokenType::TypeInt(IntegerType::U512) => "u512".to_string(), + TokenType::TypeInt(IntegerType::U1024) => "u1024".to_string(), + TokenType::TypeInt(IntegerType::U2048) => "u2048".to_string(), + TokenType::TypeInt(IntegerType::U4096) => "u4096".to_string(), + TokenType::TypeInt(IntegerType::U8192) => "u8192".to_string(), + TokenType::TypeInt(IntegerType::U16384) => "u16384".to_string(), + TokenType::TypeInt(IntegerType::U32768) => "u32768".to_string(), + TokenType::TypeInt(IntegerType::USZ) => "usz".to_string(), + + TokenType::TypeFloat(FloatType::F32) => "f32".to_string(), + TokenType::TypeFloat(FloatType::F64) => "f64".to_string(), + TokenType::TypeFloat(FloatType::F128) => "f128".to_string(), + TokenType::TypeFloat(FloatType::F256) => "f256".to_string(), + TokenType::TypeFloat(FloatType::F512) => "f512".to_string(), + TokenType::TypeFloat(FloatType::F1024) => "f1024".to_string(), + TokenType::TypeFloat(FloatType::F2048) => "f2048".to_string(), + TokenType::TypeFloat(FloatType::F4096) => "f4096".to_string(), + TokenType::TypeFloat(FloatType::F8192) => "f8192".to_string(), + TokenType::TypeFloat(FloatType::F16384) => "f16384".to_string(), + TokenType::TypeFloat(FloatType::F32768) => "f32768".to_string(), + TokenType::TypeString => "string".to_string(), _ => { eprintln!("Error: Expected variable type after ':', but got {:?}", self.current_token.token_type); return; @@ -196,15 +194,15 @@ impl<'a> Parser<'a> { }; self.advance(); - // 변수 값 처리 + // Processing variable values if self.current_token.token_type != TokenType::EQUAL { panic!("Expected '=' after variable type"); } self.advance(); let value = match &self.current_token.token_type { - TokenType::NUMBER(value) => Value::Int(*value as i64), // i64 값을 Value::Int로 감싸줌 - TokenType::STRING(value) => Value::Text(value.clone()), // String 값을 Value::Text로 감싸줌 + TokenType::NUMBER(value) => Value::Int(*value as i64), // Enclosing the i64 value with Value::Int + TokenType::STRING(value) => Value::Text(value.clone()), // Envelopes String value with Value::Text _ => { eprintln!("Error: Expected a balue for the variable, but got {:?}", self.current_token.token_type); return; @@ -212,7 +210,7 @@ impl<'a> Parser<'a> { }; self.advance(); - // 세미콜론 확인 + // Check semicolon if self.current_token.token_type != TokenType::SEMICOLON { eprintln!("Error: Expected ';' at the end of variable declaration, but got {:?}", self.current_token.token_type); return; @@ -221,7 +219,7 @@ impl<'a> Parser<'a> { eprintln!("Adding variable node: {:?} of type {:?} with calue {:?}", var_name, var_type, value); - // AST에 노드 추가 + // Add a Node to AST ast.add_node(ASTNode::Variable { name: var_name, var_type, @@ -254,12 +252,10 @@ impl<'a> Parser<'a> { message, newline: true, }); - - ast; } fn if_statement(&mut self, ast: &mut AST) { - // if 구문 처리 + // if syntax processing self.advance(); // `if` if self.current_token.token_type != TokenType::LPAREN { @@ -309,12 +305,10 @@ impl<'a> Parser<'a> { body: vec![], else_body: None, }); - - ast; } fn while_statement(&mut self, ast: &mut AST) { - // while 구문 처리 + // while syntax processing self.advance(); // `while` if self.current_token.token_type != TokenType::LPAREN { @@ -351,7 +345,7 @@ impl<'a> Parser<'a> { } fn for_statement(&mut self /*, ast: &mut AST */) { - // `for` 구문 처리 + // Syntax 'for' self.advance(); // 'for' if self.current_token.token_type != TokenType::LPAREN { @@ -359,7 +353,7 @@ impl<'a> Parser<'a> { } self.advance(); // '(' - // 초기화 처리 + // Initialization Processing if let TokenType::IDENTIFIER(var_name) = &self.current_token.token_type { println!("Initializing variable: {}", var_name); self.advance(); @@ -384,7 +378,7 @@ impl<'a> Parser<'a> { panic!("Expected variable initialization in 'for' loop"); } - // 조건 처리 + // conditioning if let TokenType::NUMBER(value) = &self.current_token.token_type { println!("Condition value: {}", value); self.advance(); @@ -397,7 +391,7 @@ impl<'a> Parser<'a> { } self.advance(); // ';' - // 증감 처리 + // an increase/decrease process if let TokenType::IDENTIFIER(var_name) = &self.current_token.token_type { println!("Incrementing variable: {}", var_name); self.advance(); @@ -438,7 +432,7 @@ impl<'a> Parser<'a> { } fn import_statement(&mut self, ast: &mut AST) { - // import 구문 처리 + // import parsing self.advance(); // `import` if self.current_token.token_type != TokenType::LPAREN { @@ -447,28 +441,26 @@ impl<'a> Parser<'a> { self.advance(); if let TokenType::STRING(module_name) = &self.current_token.token_type { - println!("Importing module: {}", module_name); // 모듈 이름 출력 + println!("Importing module: {}", module_name); // Module Name Output self.advance(); } else { panic!("Expected a module name string after '('"); } - // ')' 토큰 체크 + // Check ')' token if self.current_token.token_type != TokenType::RPAREN { panic!("Expected ')' after module name"); } - self.advance(); // ')' 건너뜀 + self.advance(); // Skip ')' - // 문장의 끝을 의미하는 `;` 체크 + // a ';' check that means the end of a sentence if self.current_token.token_type != TokenType::SEMICOLON { panic!("Expected ';' at the end of import statement"); } - self.advance(); // `;` 건너뜀 + self.advance(); // `;` Skip ast.add_node(ASTNode::Import { module_name: "".to_string() }); - - ast; } }