From 68bf2f428832629c8fccc80347e298b32996cd11 Mon Sep 17 00:00:00 2001 From: Yann Ahlgrim Date: Thu, 7 May 2026 10:22:48 +0200 Subject: [PATCH] update --- .gitignore | 5 +++++ Cargo.lock | 7 +++++++ Cargo.toml | 6 ++++++ src/lexer/mod.rs | 23 +++++++++++++++++++++++ src/main.rs | 6 ++++++ src/token/mod.rs | 19 +++++++++++++++++++ 6 files changed, 66 insertions(+) create mode 100644 Cargo.lock create mode 100644 Cargo.toml create mode 100644 src/lexer/mod.rs create mode 100644 src/main.rs create mode 100644 src/token/mod.rs diff --git a/.gitignore b/.gitignore index ad67955..0728338 100644 --- a/.gitignore +++ b/.gitignore @@ -19,3 +19,8 @@ target # and can be added to the global gitignore or merged into this file. For a more nuclear # option (not recommended) you can uncomment the following to ignore the entire idea folder. #.idea/ + + +# Added by cargo + +/target diff --git a/Cargo.lock b/Cargo.lock new file mode 100644 index 0000000..1dde1f6 --- /dev/null +++ b/Cargo.lock @@ -0,0 +1,7 @@ +# This file is automatically @generated by Cargo. +# It is not intended for manual editing. +version = 4 + +[[package]] +name = "rust-interpreter" +version = "0.1.0" diff --git a/Cargo.toml b/Cargo.toml new file mode 100644 index 0000000..f53e714 --- /dev/null +++ b/Cargo.toml @@ -0,0 +1,6 @@ +[package] +name = "rust-interpreter" +version = "0.1.0" +edition = "2024" + +[dependencies] diff --git a/src/lexer/mod.rs b/src/lexer/mod.rs new file mode 100644 index 0000000..15fc881 --- /dev/null +++ b/src/lexer/mod.rs @@ -0,0 +1,23 @@ +struct Lexer { + input: String, + position: Option, + read_pos: Option, + ch: Option, +} + +fn new(input_str: String) -> Lexer { + let l: Lexer = Lexer { + input: input_str, + position: None, + read_pos: None, + ch: None, + }; + l +} + +fn read_char(l: Lexer) { + let read_pos = usize::try_from(l.read_pos.unwrap()); + if read_pos >= l.input.len() { + l.ch = 0; + } +} diff --git a/src/main.rs b/src/main.rs new file mode 100644 index 0000000..4021de5 --- /dev/null +++ b/src/main.rs @@ -0,0 +1,6 @@ +mod lexer; +mod token; + +fn main() { + println!("Hello, world!"); +} diff --git a/src/token/mod.rs b/src/token/mod.rs new file mode 100644 index 0000000..bcfd3f4 --- /dev/null +++ b/src/token/mod.rs @@ -0,0 +1,19 @@ +struct Token { + type_: String, + literal: String, +} + +const ILLEGAL: &str = "ILLEGAL"; +const EOF: &str = "EOF"; +const IDENT: &str = "IDENT"; +const INT: &str = "INT"; +const ASSIGN: &str = "="; +const PLUS: &str = "+"; +const COMMA: &str = ","; +const SEMICOLON: &str = ";"; +const LPAREN: &str = "("; +const RPAREN: &str = ")"; +const LBRACE: &str = "{"; +const RBRACE: &str = "}"; +const FUNCTION: &str = "FUNCTION"; +const LET: &str = "LET";