This commit is contained in:
YannAhlgrim
2026-05-12 18:39:33 +02:00
parent 7c5005e5da
commit 13d5a20c74
2 changed files with 29 additions and 26 deletions
+2 -26
View File
@@ -1,31 +1,7 @@
mod lexer; mod lexer;
mod repl;
mod token; mod token;
use crate::lexer::LexerTraits;
use lexer::new;
fn main() { fn main() {
let input = "let five = 5; repl::start_repl();
let ten = 10;
let add = fn(x, y) {
x + y;
};
let result = add(five, ten);
!-/*5;
5 < 10 > 5;
if (5 < 10) {
return true;
} else {
return false;
}
10 == 10;
10 != 9;";
let mut l = new(input.to_string());
for (_i, tok) in (0..80).map(|_| l.next_token()).enumerate() {
println!("{}: {:?}", tok.type_, tok.literal);
}
} }
+27
View File
@@ -0,0 +1,27 @@
use crate::lexer::LexerTraits;
use crate::lexer::new;
const PROMPT: &str = ">> ";
pub fn start_repl() {
println!("Welcome to the REPL! Type 'exit' to quit.");
loop {
print!("{}", PROMPT);
let mut input = String::new();
std::io::stdin()
.read_line(&mut input)
.expect("Failed to read line");
let input = input.trim();
if input == "exit" {
break;
}
let mut lexer = new(input.to_string());
loop {
let token = lexer.next_token();
if token.type_ == "EOF" {
break;
}
println!("Token: {:?}, Literal: {:?}", token.type_, token.literal);
}
}
}