Skip to content

Commit d960e65

Browse files
Update: Implemented a Basic loop.
1 parent 62746bb commit d960e65

File tree

10 files changed

+91
-9
lines changed

10 files changed

+91
-9
lines changed

Cargo.lock

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "Tidal"
3-
version = "1.5.0"
3+
version = "1.6.0"
44

55

66
[dependencies]

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ A Language Made using Rust. <br>
55
Made by Pranav Verma.
66

77
Uses the Extension `.td` and `.br`. <br>
8-
Please Check the [Wiki](https://github.com/PranavVerma-droid/Tidal/wiki) for more Information.
8+
Please Check the [Wiki](https://github.com/PranavVerma-droid/Tidal/wiki) for documentation and syntax.
99

1010
## Download
1111
The Latest Compiled Build Can Be Found in the [Releases](https://github.com/PranavVerma-droid/Blue-Lagoon/releases) (For Windows and Linux)

code/BrainRot/brainrot-4.br

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
rizzler i = 0 no cap
2+
3+
yeet (true) {
4+
skibidi(i) no cap
5+
i = i + 1 no cap
6+
drip (i == 1000) {
7+
aura +69420 no cap
8+
}
9+
}

code/Normal/file-12.td

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
var previousVariable = 1.0;
2+
var currentVariable = 1.0;
3+
var nextVariable;
4+
5+
6+
7+
/* var finalResult = "0 1 1 ";
8+
9+
for(var i = 0; i >= 0; i = i + 1;) {
10+
nextVariable = float(previousVariable + currentVariable);
11+
finalResult = (finalResult + str(nextVariable) + " ");
12+
previousVariable = currentVariable;
13+
currentVariable = nextVariable;
14+
}
15+
16+
print(finalResult); */
17+
18+
print(0);
19+
print(1);
20+
print(1);
21+
22+
for(var i = 0; i <= 1500; i = i + 1;) {
23+
nextVariable = float(previousVariable + currentVariable);
24+
print(nextVariable);
25+
previousVariable = currentVariable;
26+
currentVariable = nextVariable;
27+
}

code/Normal/file-13.td

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
var i = 0;
2+
3+
while (true) {
4+
print(i);
5+
i = i + 1;
6+
if (i == 1000) {
7+
break;
8+
}
9+
}

src/interpreter.rs

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ fn interpret_node(node: &ASTNode, symbol_table: &mut HashMap<String, (Value, boo
4545
_ => panic!("Unsupported operator for numbers"),
4646
}
4747
}
48-
(Value::Float(l), Value::Float(r)) => { // New case for float operations
48+
(Value::Float(l), Value::Float(r)) => {
4949
match op {
5050
Token::Plus => Value::Float(l + r),
5151
Token::Minus => Value::Float(l - r),
@@ -60,7 +60,7 @@ fn interpret_node(node: &ASTNode, symbol_table: &mut HashMap<String, (Value, boo
6060
_ => panic!("Unsupported operator for floats"),
6161
}
6262
}
63-
(Value::Number(l), Value::Float(r)) => { // Mixed number and float operations
63+
(Value::Number(l), Value::Float(r)) => {
6464
let l = l as f64;
6565
match op {
6666
Token::Plus => Value::Float(l + r),
@@ -76,7 +76,7 @@ fn interpret_node(node: &ASTNode, symbol_table: &mut HashMap<String, (Value, boo
7676
_ => panic!("Unsupported operator for mixed number and float"),
7777
}
7878
}
79-
(Value::Float(l), Value::Number(r)) => { // Mixed float and number operations
79+
(Value::Float(l), Value::Number(r)) => {
8080
let r = r as f64;
8181
match op {
8282
Token::Plus => Value::Float(l + r),
@@ -136,6 +136,24 @@ fn interpret_node(node: &ASTNode, symbol_table: &mut HashMap<String, (Value, boo
136136
}
137137
Value::Null
138138
},
139+
ASTNode::While(condition, body) => {
140+
loop {
141+
let cond_value = interpret_node(condition, symbol_table, is_verbose, true);
142+
if let Value::Boolean(false) = cond_value {
143+
break;
144+
}
145+
146+
for stmt in body {
147+
let result = interpret_node(stmt, symbol_table, is_verbose, true);
148+
match result {
149+
Value::Break => return Value::Null,
150+
Value::Continue => break,
151+
_ => {}
152+
}
153+
}
154+
}
155+
Value::Null
156+
},
139157
ASTNode::Var(name, expr, is_mutable) => {
140158
let value = if let Some(expr) = expr {
141159
interpret_node(expr, symbol_table, is_verbose, in_loop)

src/lexer.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ pub enum Token {
3737
RBracket,
3838
Null,
3939
For,
40+
While,
4041
Break,
4142
Continue,
4243
Comma,
@@ -156,6 +157,7 @@ impl<'a> Lexer<'a> {
156157
"true" => Token::Boolean(true),
157158
"false" => Token::Boolean(false),
158159
"for" => Token::For,
160+
"while" => Token::While,
159161
"break" => Token::Break,
160162
"continue" => Token::Continue,
161163
"int" | "str" | "float" | "bool" => {

src/main.rs

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,10 @@ fn main() {
1111
// collect args
1212
let args: Vec<String> = env::args().collect();
1313

14-
// verbose
14+
// verbose mode flag check
1515
let is_verbose = args.contains(&String::from("--verbose")) || args.contains(&String::from("-v"));
1616

17+
// error display lul
1718
if args.len() < 2 || args.contains(&String::from("help")) || args.contains(&String::from("--help")) || args.contains(&String::from("-h")) {
1819
help();
1920
std::process::exit(1);
@@ -39,7 +40,7 @@ fn main() {
3940

4041
// Brain Rot Parser
4142
let processed_contents = if is_brain_rot {
42-
preprocess_brain_rot(&contents)
43+
preprocess_skibidi(&contents)
4344
} else {
4445
contents
4546
};
@@ -66,7 +67,8 @@ fn help() {
6667
println!("");
6768
}
6869

69-
fn preprocess_brain_rot(input: &str) -> String {
70+
//okay, here is where the brainrot starts ☠️☠️
71+
fn preprocess_skibidi(input: &str) -> String {
7072
let replacements: HashMap<&str, &str> = [
7173
("rizzler", "var"),
7274
("sigma", "novar"),
@@ -75,6 +77,7 @@ fn preprocess_brain_rot(input: &str) -> String {
7577
("skibidi", "print"),
7678
("fanum tax", "type"),
7779
("bussin", "for"),
80+
("yeet", "while"),
7881
("sussy", "/*"),
7982
("baka", "*/"),
8083
("aura +69420", "break"),

src/parser.rs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ pub enum ASTNode {
3131
TypeCast(String, Box<ASTNode>),
3232
If(Box<ASTNode>, Vec<ASTNode>, Vec<(ASTNode, Vec<ASTNode>)>, Option<Vec<ASTNode>>),
3333
For(Box<ASTNode>, Box<ASTNode>, Box<ASTNode>, Vec<ASTNode>),
34+
While(Box<ASTNode>, Vec<ASTNode>),
3435
Break,
3536
Continue,
3637
}
@@ -77,6 +78,7 @@ impl<'a> Parser<'a> {
7778
Token::For => self.parse_for_loop(),
7879
Token::Break => self.parse_break(),
7980
Token::Continue => self.parse_continue(),
81+
Token::While => self.parse_while_loop(),
8082
Token::Type => self.parse_type(),
8183
_ => panic!("Unexpected token in statement: {:?}", self.current_token),
8284
}
@@ -91,6 +93,18 @@ impl<'a> Parser<'a> {
9193
ASTNode::Type(Box::new(expr))
9294
}
9395

96+
fn parse_while_loop(&mut self) -> ASTNode {
97+
self.eat(Token::While);
98+
self.eat(Token::LParen);
99+
let condition = self.parse_expr();
100+
self.eat(Token::RParen);
101+
self.eat(Token::LBrace);
102+
let body = self.parse_block();
103+
self.eat(Token::RBrace);
104+
105+
ASTNode::While(Box::new(condition), body)
106+
}
107+
94108
fn parse_if_statement(&mut self) -> ASTNode {
95109
self.eat(Token::If);
96110
self.eat(Token::LParen);

0 commit comments

Comments
 (0)