diff --git a/lox_tests/var.lox b/lox_tests/var.lox index 05f3903..224caaf 100644 --- a/lox_tests/var.lox +++ b/lox_tests/var.lox @@ -1,3 +1,6 @@ var a = 1; var b; -print a; \ No newline at end of file +print a; +var str1 = "hello"; +var str2 = "world"; +print str1 + str2; \ No newline at end of file diff --git a/lox_tests/var/bytecode b/lox_tests/var/bytecode index 4f654a2..5998ba6 100644 --- a/lox_tests/var/bytecode +++ b/lox_tests/var/bytecode @@ -16,5 +16,25 @@ Chunk { "a", ), Print, + String( + "hello", + ), + VarDeclaration( + "str1", + ), + String( + "world", + ), + VarDeclaration( + "str2", + ), + Variable( + "str1", + ), + Variable( + "str2", + ), + Add, + Print, ], } \ No newline at end of file diff --git a/lox_tests/var/execute b/lox_tests/var/execute index 63443fe..36b42a8 100644 --- a/lox_tests/var/execute +++ b/lox_tests/var/execute @@ -36,3 +36,62 @@ stack: [ execute: Print stack: [] +execute: String( + "hello", +) +stack: [ + String( + "hello", + ), +] + +execute: VarDeclaration( + "str1", +) +stack: [] + +execute: String( + "world", +) +stack: [ + String( + "world", + ), +] + +execute: VarDeclaration( + "str2", +) +stack: [] + +execute: Variable( + "str1", +) +stack: [ + String( + "hello", + ), +] + +execute: Variable( + "str2", +) +stack: [ + String( + "hello", + ), + String( + "world", + ), +] + +execute: Add +stack: [ + String( + "helloworld", + ), +] + +execute: Print +stack: [] + diff --git a/lox_tests/var/syntax b/lox_tests/var/syntax index 3c32fc3..539aa95 100644 --- a/lox_tests/var/syntax +++ b/lox_tests/var/syntax @@ -11,3 +11,22 @@ Var { Print { expr: Variable(a), } +Var { + name: "str1", + initializer: Some( + StringLiteral(hello), + ), +} +Var { + name: "str2", + initializer: Some( + StringLiteral(world), + ), +} +Print { + expr: BinaryOp { + left: Variable(str1), + op: Plus, + right: Variable(str2), + }, +} diff --git a/lox_tests/var/token b/lox_tests/var/token index da74724..56e5884 100644 --- a/lox_tests/var/token +++ b/lox_tests/var/token @@ -1,5 +1,5 @@ TokenTree { - source text: "var a = 1;\nvar b;\nprint a;", + source text: "var a = 1;\nvar b;\nprint a;\nvar str1 = \"hello\";\nvar str2 = \"world\";\nprint str1 + str2;", tokens: [ Alphabetic(var), Whitespace(' '), @@ -19,5 +19,32 @@ TokenTree { Whitespace(' '), Alphabetic(a), Semicolon, + Whitespace('\n'), + Alphabetic(var), + Whitespace(' '), + Alphabetic(str1), + Whitespace(' '), + Op(=), + Whitespace(' '), + String(hello), + Semicolon, + Whitespace('\n'), + Alphabetic(var), + Whitespace(' '), + Alphabetic(str2), + Whitespace(' '), + Op(=), + Whitespace(' '), + String(world), + Semicolon, + Whitespace('\n'), + Alphabetic(print), + Whitespace(' '), + Alphabetic(str1), + Whitespace(' '), + Op(+), + Whitespace(' '), + Alphabetic(str2), + Semicolon, ], } \ No newline at end of file