Skip to content

Commit

Permalink
Added String Comparison
Browse files Browse the repository at this point in the history
  • Loading branch information
PranavVerma-droid committed Oct 14, 2024
1 parent 2264715 commit 50b415b
Show file tree
Hide file tree
Showing 4 changed files with 52 additions and 0 deletions.
17 changes: 17 additions & 0 deletions code/Normal/file-16.td
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
print("Error Testing File, Check Source Code");

/* Try to Uncomment Each of These: */

/* break; */
/* continue; */

/* var test = 0 */

/* a = 10; */

/* var a = 10;
var a = 20; */

/* print("hi" + 10); */

/* print(int("hi")); */
29 changes: 29 additions & 0 deletions code/Normal/file-17.td
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
var arr = [3, 1, 2];
print(arr);
arr.sort();
print(arr);
arr.reverse();
print(arr);
arr.insert(1, 4);
print(arr);
print(arr.count());
arr.clear();
print(arr);
print(arr.count());

var arr2 = arr.copy();

var str = " Hello World ";
print(str);
str = str.strip();
print(str);
str = str.upper();
print(str);
str = str.lower();
print(str);

var arr3 = ["heloo", "hi"];
var arr4 = ["Helo"];
arr3.insert(arr4);
arr3.insert([123, 123, 43]);
print(arr3);
1 change: 1 addition & 0 deletions code/Normal/file-18.td
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
print("3" < "2");
5 changes: 5 additions & 0 deletions src/interpreter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -165,9 +165,14 @@ fn interpret_node(node: &ASTNode, symbol_table: &mut HashMap<String, (Value, boo
}
Token::Equal => Ok(Value::Boolean(s == t)),
Token::NotEqual => Ok(Value::Boolean(s != t)),
Token::Greater => Ok(Value::Boolean(s > t)),
Token::Less => Ok(Value::Boolean(s < t)),
Token::GreaterEqual => Ok(Value::Boolean(s >= t)),
Token::LessEqual => Ok(Value::Boolean(s <= t)),
_ => Err(Error::UnsupportedOperation(format!("Unsupported operator for strings"))),
}
}

(Value::String(s), Value::Number(n)) => {
match op {
Token::Multiply => Ok(Value::String(s.repeat(n as usize))),
Expand Down

0 comments on commit 50b415b

Please sign in to comment.