You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
@@ -6,34 +6,162 @@ A simple programing language based on basic
6
6
* Still working on it
7
7
* Now is a simpile interpreter which support basic arithmetic operations
8
8
9
-
## 1. Quick start
9
+
## 1. Try ZeroLang in terminal
10
10
11
11
python3 shell.py
12
12
13
13
14
-
## 2. functions
15
-
* Support basic operations
16
-
* Support variable definition
17
-
* Support comparison operations
18
-
* Support if statement
19
-
* Support while and for
20
-
* Support defined function and call function
21
-
```
22
-
#for loop:
23
-
var res=0
24
-
for i=0 to 6 then var res=res+i
25
-
26
-
#while loop:
27
-
var res=0
28
-
while res<10000 then var res=res+1
29
-
30
-
#func
31
-
func add(a,b)-> a+b
32
-
add(a+b)
33
-
var sum=add(a+b)
34
-
14
+
## 🔤 Basic Elements
15
+
16
+
### Variable Declaration
17
+
18
+
Use the `var` keyword to declare a variable:
19
+
20
+
```plaintext
21
+
var x = 10
22
+
```
23
+
24
+
---
25
+
26
+
### Number Types
27
+
28
+
Supports both integers and floats:
29
+
30
+
```plaintext
31
+
x = 5
32
+
y = 3.14
33
+
```
34
+
35
+
---
36
+
37
+
### Operators
38
+
39
+
#### Arithmetic Operators
40
+
41
+
| Operator | Meaning | Example |
42
+
| --- | --- | --- |
43
+
|`+`| Addition |`2 + 3`|
44
+
|`-`| Subtraction |`5 - 1`|
45
+
|`*`| Multiplication |`4 * 2`|
46
+
|`/`| Division |`10 / 2`|
47
+
|`%`| Modulo |`7 % 3`|
48
+
|`^`| Power |`2 ^ 3`|
49
+
50
+
#### Comparison Operators
51
+
52
+
| Operator | Meaning | Example |
53
+
| --- | --- | --- |
54
+
|`==`| Equals |`x == 5`|
55
+
|`!=`| Not equals |`x != 0`|
56
+
|`<`| Less than |`x < 10`|
57
+
|`>`| Greater than |`x > 3`|
58
+
|`<=`| Less than or equal |`x <= 5`|
59
+
|`>=`| Greater or equal |`x >= 2`|
60
+
61
+
#### Logical Operators
62
+
63
+
| Keyword | Meaning | Example |
64
+
| --- | --- | --- |
65
+
|`and`| Logical AND |`x > 0 and y < 10`|
66
+
|`or`| Logical OR |`x == 0 or y == 5`|
67
+
|`not`| Logical NOT |`not x == 0`|
68
+
69
+
---
70
+
71
+
### Strings
72
+
73
+
Defined using double quotes, with support for escape characters:
74
+
75
+
```plaintext
76
+
msg = "Hello\nWorld"
77
+
```
78
+
79
+
---
80
+
81
+
### Lists
82
+
83
+
Lists are enclosed in square brackets:
84
+
85
+
```plaintext
86
+
arr = [1, 2, 3]
87
+
```
88
+
89
+
- Access element: `arr / 1` → returns element at index 1
90
+
- Remove element: `arr - 0` → removes element at index 0
91
+
92
+
---
93
+
94
+
## 🔁 Control Flow
95
+
96
+
### If Expression
97
+
98
+
```plaintext
99
+
if x > 0 then "positive"
100
+
elif x == 0 then "zero"
101
+
else "negative"
102
+
```
103
+
104
+
---
105
+
106
+
### For Loop
107
+
108
+
```plaintext
109
+
for i = 1 to 5 then i * 2
110
+
```
111
+
112
+
With optional step:
113
+
114
+
```plaintext
115
+
for i = 1 to 10 step 2 then i
35
116
```
36
117
118
+
---
119
+
120
+
### While Loop
121
+
122
+
```plaintext
123
+
while x < 5 then x = x + 1
124
+
```
125
+
126
+
---
127
+
128
+
## 🧩 Functions
129
+
130
+
### Define a Function
131
+
132
+
```plaintext
133
+
func add(a, b) -> a + b
134
+
```
135
+
136
+
### Anonymous Function
137
+
138
+
```plaintext
139
+
var square = func(x) -> x * x
140
+
```
141
+
142
+
### Function Call
143
+
144
+
```plaintext
145
+
add(2, 3) # Returns 5
146
+
```
147
+
148
+
---
149
+
150
+
## 🔍 Example Program
151
+
152
+
```plaintext
153
+
var square = func(x) -> x * x
154
+
square(4)
155
+
```
156
+
157
+
---
158
+
159
+
## ⚠️ Error Handling
160
+
161
+
Lexical and syntax errors are handled by classes like `IllegalCharError`, `InvalidSyntaxError`, and `RTError`. They provide clear messages with line numbers and context arrows.
0 commit comments