-
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #124 from I-Language-Development/v1.0.0-alpha.5
V1.0.0 alpha.5
- Loading branch information
Showing
13 changed files
with
194 additions
and
57 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
// lexer.rs | ||
|
||
#[derive(Debug, PartialEq)] | ||
enum Token { | ||
Number(i64), | ||
Plus, | ||
Minus, | ||
Multiply, | ||
Divide, | ||
} | ||
|
||
fn lex(input: &str) -> Vec<Token> { | ||
let mut tokens = Vec::new(); | ||
// Implement your lexer logic here | ||
// For simplicity, let's assume input contains only numbers, +, -, *, / | ||
// You'd need to handle whitespace, error cases, and more complex tokens in a real compiler | ||
for token_str in input.split_whitespace() { | ||
match token_str { | ||
"+" => tokens.push(Token::Plus), | ||
"-" => tokens.push(Token::Minus), | ||
"*" => tokens.push(Token::Multiply), | ||
"/" => tokens.push(Token::Divide), | ||
_ => { | ||
if let Ok(num) = token_str.parse::<i64>() { | ||
tokens.push(Token::Number(num)); | ||
} | ||
} | ||
} | ||
} | ||
tokens | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
// parser.rs | ||
|
||
#[derive(Debug)] | ||
enum Expr { | ||
Number(i64), | ||
BinaryOp(Box<Expr>, Token, Box<Expr>), | ||
} | ||
|
||
fn parse(tokens: &[Token]) -> Expr { | ||
// Implement your parser logic here | ||
// For simplicity, assume correct input and only handle + and * operators | ||
// You'd need to handle operator precedence and other expressions in a real compiler | ||
// Recursive descent parsing is a common approach | ||
// Build the AST based on the token stream | ||
// ... | ||
} | ||
|
||
fn main() { | ||
let input = "10 + 5 * 3"; | ||
let tokens = lex(input); | ||
let ast = parse(&tokens); | ||
println!("{:?}", ast); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.