Skip to content

Commit 50b415b

Browse files
Added String Comparison
1 parent 2264715 commit 50b415b

File tree

4 files changed

+52
-0
lines changed

4 files changed

+52
-0
lines changed

code/Normal/file-16.td

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
print("Error Testing File, Check Source Code");
2+
3+
/* Try to Uncomment Each of These: */
4+
5+
/* break; */
6+
/* continue; */
7+
8+
/* var test = 0 */
9+
10+
/* a = 10; */
11+
12+
/* var a = 10;
13+
var a = 20; */
14+
15+
/* print("hi" + 10); */
16+
17+
/* print(int("hi")); */

code/Normal/file-17.td

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
var arr = [3, 1, 2];
2+
print(arr);
3+
arr.sort();
4+
print(arr);
5+
arr.reverse();
6+
print(arr);
7+
arr.insert(1, 4);
8+
print(arr);
9+
print(arr.count());
10+
arr.clear();
11+
print(arr);
12+
print(arr.count());
13+
14+
var arr2 = arr.copy();
15+
16+
var str = " Hello World ";
17+
print(str);
18+
str = str.strip();
19+
print(str);
20+
str = str.upper();
21+
print(str);
22+
str = str.lower();
23+
print(str);
24+
25+
var arr3 = ["heloo", "hi"];
26+
var arr4 = ["Helo"];
27+
arr3.insert(arr4);
28+
arr3.insert([123, 123, 43]);
29+
print(arr3);

code/Normal/file-18.td

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
print("3" < "2");

src/interpreter.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -165,9 +165,14 @@ fn interpret_node(node: &ASTNode, symbol_table: &mut HashMap<String, (Value, boo
165165
}
166166
Token::Equal => Ok(Value::Boolean(s == t)),
167167
Token::NotEqual => Ok(Value::Boolean(s != t)),
168+
Token::Greater => Ok(Value::Boolean(s > t)),
169+
Token::Less => Ok(Value::Boolean(s < t)),
170+
Token::GreaterEqual => Ok(Value::Boolean(s >= t)),
171+
Token::LessEqual => Ok(Value::Boolean(s <= t)),
168172
_ => Err(Error::UnsupportedOperation(format!("Unsupported operator for strings"))),
169173
}
170174
}
175+
171176
(Value::String(s), Value::Number(n)) => {
172177
match op {
173178
Token::Multiply => Ok(Value::String(s.repeat(n as usize))),

0 commit comments

Comments
 (0)