summary refs log tree commit diff
diff options
context:
space:
mode:
authorBaitinq <manuelpalenzuelamerino@gmail.com>2025-01-18 12:16:00 +0100
committerBaitinq <manuelpalenzuelamerino@gmail.com>2025-01-18 12:16:00 +0100
commit2e0eeeed63308e004e882f74a6077bc0fb3352bc (patch)
treed39fe550b23e2cd82bfe2ff939ff71a59ba6d6f8
parentTokenizer: Fix comment skipping (diff)
downloadinterpreter-2e0eeeed63308e004e882f74a6077bc0fb3352bc.tar.gz
interpreter-2e0eeeed63308e004e882f74a6077bc0fb3352bc.tar.bz2
interpreter-2e0eeeed63308e004e882f74a6077bc0fb3352bc.zip
Examples: Add variable scopes example
-rw-r--r--examples/5.src13
-rw-r--r--examples/6.src8
2 files changed, 17 insertions, 4 deletions
diff --git a/examples/5.src b/examples/5.src
index 573ee6a..d9a8dad 100644
--- a/examples/5.src
+++ b/examples/5.src
@@ -1,8 +1,13 @@
-let print_input = (input) => {
-	print(input);
-	return input;
+let foo = () => {
+	let x = 1;
+	print(x);
+	return x;
 };
 
 let main = () => {
-	return print_input(7);
+	let x = 2;
+	/* As you see, the language supports variable scopes */
+	foo();
+	print(x);
+	return x;
 };
diff --git a/examples/6.src b/examples/6.src
new file mode 100644
index 0000000..573ee6a
--- /dev/null
+++ b/examples/6.src
@@ -0,0 +1,8 @@
+let print_input = (input) => {
+	print(input);
+	return input;
+};
+
+let main = () => {
+	return print_input(7);
+};