feat: Implement basic interpreter and update documentation

This commit is contained in:
Alvin
2025-09-10 12:49:08 +02:00
parent 5ffe814e0e
commit 4cd38de88c
3 changed files with 68 additions and 4 deletions

View File

@@ -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:
```bash
cargo run -- <file_name>.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 "<message>"`
This command prints a message to the console. The message must be enclosed in double quotes.
## Ciao!

3
hello_world.tralla Normal file
View File

@@ -0,0 +1,3 @@
Tralalero Tralala
Matteeeo bambini gusini "Hello, World!"
Bombardiro Crocodilo

View File

@@ -1,3 +1,42 @@
use std::env;
use std::fs;
fn main() {
println!("Hello, world!");
let args: Vec<String> = 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);
}
}
}