From 4cd38de88c1f3dd2516229af4553f44bcfd8b27c Mon Sep 17 00:00:00 2001 From: Alvin <524715@vistacollege.nl> Date: Wed, 10 Sep 2025 12:49:08 +0200 Subject: [PATCH] feat: Implement basic interpreter and update documentation --- README.md | 28 +++++++++++++++++++++++++--- hello_world.tralla | 3 +++ src/main.rs | 41 ++++++++++++++++++++++++++++++++++++++++- 3 files changed, 68 insertions(+), 4 deletions(-) create mode 100644 hello_world.tralla diff --git a/README.md b/README.md index 28210bc..1e249ef 100644 --- a/README.md +++ b/README.md @@ -2,8 +2,30 @@ Benvenuto! Welcome to Trallalelo Lang, the most whimsical and brain-tickling programming language inspired by the finest Italian-flavored brainrot. -## Documentation +## Getting Started -(Coming soon) +To run a Trallalelo program, you need to have Rust installed. Then, you can use the following command: -## Ciao! +```bash +cargo run -- .tralla +``` + +## Syntax + +A Trallalelo program must start with `Tralalero Tralala` and end with `Bombardiro Crocodilo`. + +## Keywords + +### `Tralalero Tralala` + +This is the entry point of the program. It must be the first line of your code. + +### `Bombardiro Crocodilo` + +This is the exit point of the program. It must be the last line of your code. + +### `Matteeeo bambini gusini ""` + +This command prints a message to the console. The message must be enclosed in double quotes. + +## Ciao! \ No newline at end of file diff --git a/hello_world.tralla b/hello_world.tralla new file mode 100644 index 0000000..19eebb6 --- /dev/null +++ b/hello_world.tralla @@ -0,0 +1,3 @@ +Tralalero Tralala +Matteeeo bambini gusini "Hello, World!" +Bombardiro Crocodilo diff --git a/src/main.rs b/src/main.rs index e7a11a9..c793cf2 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,3 +1,42 @@ +use std::env; +use std::fs; + fn main() { - println!("Hello, world!"); + let args: Vec = env::args().collect(); + if args.len() < 2 { + println!("Please provide a file to run"); + return; + } + + let file_path = &args[1]; + let content = fs::read_to_string(file_path).expect("Could not read the file"); + + let lines: Vec<&str> = content.lines().collect(); + + if lines.is_empty() || lines[0] != "Tralalero Tralala" { + println!("The program must start with 'Tralalero Tralala'"); + return; + } + + if lines.last() != Some(&"Bombardiro Crocodilo") { + println!("The program must end with 'Bombardiro Crocodilo'"); + return; + } + + for line in lines.iter().skip(1).rev().skip(1).rev() { + parse_and_execute(line); + } +} + +fn parse_and_execute(line: &str) { + if line.starts_with("Matteeeo bambini gusini") { + let parts: Vec<&str> = line.splitn(2, ' ').collect(); + if parts.len() > 1 { + let string_to_print = parts[1] + .trim_start_matches("bambini gusini") + .trim() + .trim_matches('"'); + println!("{}", string_to_print); + } + } }