mirror of
https://github.com/Alvin-Zilverstand/Tralalero_lang.git
synced 2026-03-06 11:17:06 +01:00
feat: Implement basic interpreter and update documentation
This commit is contained in:
28
README.md
28
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.
|
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 -- <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
3
hello_world.tralla
Normal file
@@ -0,0 +1,3 @@
|
|||||||
|
Tralalero Tralala
|
||||||
|
Matteeeo bambini gusini "Hello, World!"
|
||||||
|
Bombardiro Crocodilo
|
||||||
41
src/main.rs
41
src/main.rs
@@ -1,3 +1,42 @@
|
|||||||
|
use std::env;
|
||||||
|
use std::fs;
|
||||||
|
|
||||||
fn main() {
|
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);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user