Support var

This commit is contained in:
2026-01-19 22:07:25 +08:00
parent 57def6137b
commit 0833a2229b
6 changed files with 93 additions and 55 deletions

View File

@@ -2,8 +2,8 @@
// This demonstrates the Person class from the specification
class Person {
number age;
string name;
var age : number;
var name : string;
func sayHi() -> string {
print(name, "says: I'm", age, "years old");
@@ -18,7 +18,7 @@ class Person {
}
// Create an instance
Person p;
var p : Person;
p.age = 10;
p.name = "Peter";
@@ -29,12 +29,12 @@ p.sayHi();
// Test lists (0-indexed)
print("\n=== List Demo ===");
list numbers = [1, 2, 3, 4, 5];
var numbers = [1, 2, 3, 4, 5];
print("List:", numbers);
print("First element (index 0):", numbers[0]);
print("测试 element (index 2):", numbers[2]);
for(number i = 0; i < len(numbers); i = i + 1) {
for(var i = 0; i < len(numbers); i = i + 1) {
print("List element", numbers[i]);
}
@@ -44,7 +44,7 @@ while(true) {
}
// Test maps
print("\n=== Map Demo ===");
map config = {"host": "localhost", "port": "8080"};
var config = {"host": "localhost", "port": "8080"};
print("Config:", config);
print("Host:", config["host"]);