From 50b415b85379c3dc9a23f79b5abc37c19ef64421 Mon Sep 17 00:00:00 2001 From: Pranav Verma Date: Mon, 14 Oct 2024 14:09:15 +0530 Subject: [PATCH] Added String Comparison --- code/Normal/file-16.td | 17 +++++++++++++++++ code/Normal/file-17.td | 29 +++++++++++++++++++++++++++++ code/Normal/file-18.td | 1 + src/interpreter.rs | 5 +++++ 4 files changed, 52 insertions(+) create mode 100644 code/Normal/file-16.td create mode 100644 code/Normal/file-17.td create mode 100644 code/Normal/file-18.td diff --git a/code/Normal/file-16.td b/code/Normal/file-16.td new file mode 100644 index 0000000..77d2e51 --- /dev/null +++ b/code/Normal/file-16.td @@ -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")); */ \ No newline at end of file diff --git a/code/Normal/file-17.td b/code/Normal/file-17.td new file mode 100644 index 0000000..d3aa4f8 --- /dev/null +++ b/code/Normal/file-17.td @@ -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); \ No newline at end of file diff --git a/code/Normal/file-18.td b/code/Normal/file-18.td new file mode 100644 index 0000000..79298de --- /dev/null +++ b/code/Normal/file-18.td @@ -0,0 +1 @@ +print("3" < "2"); \ No newline at end of file diff --git a/src/interpreter.rs b/src/interpreter.rs index 0fafb2b..76f01ea 100755 --- a/src/interpreter.rs +++ b/src/interpreter.rs @@ -165,9 +165,14 @@ fn interpret_node(node: &ASTNode, symbol_table: &mut HashMap 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))),