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
@@ -4,11 +4,23 @@ Zhaba script (Russian: ˈʐabə, жаба(frog)) - is a multi-paradigm, high-lev
4
4
5
5
Inspired by JS, Rust, C++, and Python🐍
6
6
7
-
## Docs
7
+

8
+
9
+
# Useful links 🔗
10
+
11
+
## Try it now!
12
+
13
+
I created this web playground, so you can play with examples right now! -> https://wgmlgz.github.io/zhaba/
14
+
15
+
## Docs 📑
8
16
9
17
Here is a zhaba-script docs website with syntax highlighting -> https://wgmlgz.github.io/zhaba/?page=docs
10
18
11
-
## Hello world!
19
+
## VS Code support
20
+
21
+
You can code in your's favorite frog programming language in your favorite IDE -> https://marketplace.visualstudio.com/items?itemName=wgmlgz.zhaba-script
22
+
23
+
# Hello world! 👋
12
24
13
25
```zh
14
26
use std
@@ -17,25 +29,22 @@ fn main
17
29
< 'hi world!' <
18
30
```
19
31
20
-
## Setup
32
+
#List of features
21
33
22
-
- Set environment variable `zhstd` to `repo_path/std`
23
-
- If you are using VSCode you can install [this](https://marketplace.visualstudio.com/items?itemName=wgmlgz.zhaba-script) extension for syntax highlighting
24
-
- To develop
25
-
- This is a CMake project, so you need to check how to set up it in your IDE
26
-
- VSCode: I am using vscode with CMake extension, so to set up project run command `CMake: Configure`, and to add run arguments add `"cmake.debugConfig": { "args": [ your args here ] }` to settings.json
27
-
- CLion: You probably can just open it with none or some minimal configuration
28
-
- use compiled binary to run your `.zh` files with `./zhaba <filename.zh>`
29
-
- To use zhaba-script
30
-
- Download the latest binary from [releases](https://github.com/Wgmlgz/zhaba-script/releases) / or use [web IDE](https://wgmlgz.github.io/zhaba/)
34
+
- Complier & dev environment:
31
35
32
-
## List of features
36
+
- Interpretation (throw bytecode)
37
+
- Interpretation in web environment
38
+
- Web code editor
39
+
- Docs website
40
+
- Translation to C
33
41
34
42
- Basics:
35
43
36
44
- Basic types like int, bool or char
45
+
- Variables (and local redefinition)
37
46
- All C operators like (+ - \* %)
38
-
- If, else, else if
47
+
- If, else, elif
39
48
- While loop
40
49
- C-style for loop
41
50
- Single and multi-line comments
@@ -45,40 +54,175 @@ fn main
45
54
- More advanced features:
46
55
47
56
- Foreach loop
57
+
- Patten matching
48
58
- Functions overloading
49
59
- Any operator overloading
60
+
- Subscript `[]` and call `()` overload
50
61
- New operators creation
51
62
- Local (relative to scope) functions and operators definition
52
63
- Pointers
53
-
- References
64
+
- References (pass, return and store)
54
65
55
-
-OOP:
66
+
-Objects:
56
67
57
-
-Classes
68
+
-Custom types (classes/structs)
58
69
- Member functions
59
70
- Constructors
60
-
- Destructors
61
-
- generic types like `Vec<T>`
71
+
- Copy constructors (and implicit calls)
72
+
- Destructors (and implicit calls)
73
+
- Generic types like `Vec<T>`
62
74
63
75
- Standard library
64
76
-`Vec<T>` - generic dynamic array
65
77
-`Str` - String class
66
-
-`Range` - int range, can be created with `..` operator
67
-
-`'frog.zh'` - file with cool ASCII image of 🐸
78
+
- Easy input/output throw `<` and `>` overloaded operators
79
+
-`Range` - int range, can be created with `..` operator, used in loops or `Vec` slicing
80
+
-`frog.zh` - file with cool ASCII image of 🐸
68
81
-`operators.zh` - more advanced operators like %%
82
+
-`brainfuck.zh` - brainfuck interpreter
83
+
84
+
# Why? 🤔
69
85
70
86
## Motivation
71
87
72
88
C++ is one of my favorite languages because of it's power and performance, but at the same time it is very old and doest't have lots of amazing features of modern programming languages. For example to simply loop over int range you have to use something like this: `for (int i = 0; i < n; ++i)`. Can we do better? In python you can use `for i in range(0, n)`, this is already a huge improvement, but can we do even better? Of course! Zhaba-script solution to this task looks like this: `@ i 0..n`. This example can show how some of the syntax elements are not necessary and can be reduced. To be fair in C++20 we can do `for (auto i : std::ranges::iota_view(0, 10))` or with reduced namespaces `for (auto i : iota_view(0, 10))`, this is definitely good, but still longer then python.
73
89
74
90
## Goal
75
91
76
-
So, the main goal of zhaba-script is to make your programs smaller while also maintain readability and performance. To do this, zhaba-script is using C++ low level semantic concepts and bringing them with python-like syntax.
92
+
So, the main goal of zhaba-script is to make your programs smaller while also maintain readability and performance. To do this, zhaba-script is using C++ low level semantic concepts and bringing them with short python-like syntax.
77
93
78
94
## Syntax
79
95
80
-
The zhaba-script syntax is the most different and interesting part from other programming languages and mostly resembles python, which does't use `{}` to declare blocks of code. But zhaba-script takes a step forward by removing almost all unnecessary syntax elements like `,` in some places. For example in this expression: `print(1, 2, 4)` it is obvious where commas should be so you don't need to explicitly write them. Other syntax elements like `;` or `:` are not required, but their use is put to make your code even shorter. Also most common keywords such as `if` or `return` are reduced to simple symbols, to make code shorter and even more readable. You can read more about all the syntax elements TODO [here]().
96
+
The zhaba-script syntax is the most different and interesting part from other programming languages and mostly resembles python, which does't use `{}` to declare blocks of code. But zhaba-script takes a step forward by removing almost all unnecessary syntax elements like `,` in some places. For example in this expression: `print(1, 2, 4)` it is obvious where commas should be so you don't need to explicitly write them. Other syntax elements like `;` or `:` are not required, but their use is put to make your code even shorter. Also most common keywords such as `if` or `return` are reduced to simple symbols, to make code shorter and even more readable. Other very big feature is ability to overload any operator and even create your onw new ones. You can read more about all the syntax elements TODO [here](https://wgmlgz.github.io/zhaba/?page=docs&chapter=2).
81
97
82
98
## Memory model
83
99
84
-
Zhaba-script memory model is similar to the C memory model, which consists of stack, heap and pointers to manage it. In general: stack is faster and used for storing variables, while heap is slower, but can be accessed in any part of a program thought pointers.
100
+
Zhaba-script memory model is similar to the C memory model, which consists of stack, heap and pointers to manage it.
101
+
102
+
# Compatibility
103
+
104
+
Zhaba-script currently requires zero external dependencies in interpretation mode and C compiler like GCC if you want to translate programs to C. Also You will need a C++20 compiler with Cmake to build it. Pinecone has been successfully tested on Linux, MacOS and Windows.
105
+
106
+
# Setup ⚙️
107
+
108
+
If you want to run/develop zhaba-script on your own machine here is instruction for you
109
+
110
+
- Set environment variable `zhstd` to `repo_path/std`
111
+
- If you are using VSCode you can install [this](https://marketplace.visualstudio.com/items?itemName=wgmlgz.zhaba-script) extension for syntax highlighting
112
+
- To develop
113
+
- This is a CMake project, so you need to check how to set up it in your IDE
114
+
- VSCode: I am using vscode with CMake extension, so to set up project run command `CMake: Configure`, and to add run arguments add `"cmake.debugConfig": { "args": [ your args here ] }` to settings.json
115
+
- CLion: You probably can just open it with none or some minimal configuration
116
+
- use compiled binary to run your `.zh` files with `./zhaba <filename.zh>`
117
+
- To use zhaba-script
118
+
- Download the latest binary from [releases](https://github.com/Wgmlgz/zhaba-script/releases) / or use [web IDE](https://wgmlgz.github.io/zhaba/)
119
+
120
+
# Some demonstration examples
121
+
122
+
Classic FizzBuzz:
123
+
124
+
```zh
125
+
use std
126
+
127
+
fn fizz_buzz int mx
128
+
@ i 1..mx+1
129
+
? i %% 15: <'FizzBuzz'<
130
+
| i %% 3: <'Fizz'<
131
+
| i %% 5: <'Buzz'<
132
+
\ <i<
133
+
134
+
fn main: fizz_buzz(20)
135
+
```
136
+
137
+
Brainfuck 🤯 interpreter:
138
+
139
+
```zh
140
+
fn brainfuck str s
141
+
p := malloc(3000) as u8P
142
+
b := 0
143
+
@ i 0..len(s)
144
+
v := *p
145
+
c := s^i
146
+
?? c
147
+
'>': p = p + 1
148
+
'<': p = p - 1
149
+
'+': ++(*p)
150
+
'-': --(*p)
151
+
'.': put (v as char)
152
+
',': >(*p)
153
+
'[': ? !v:
154
+
++b
155
+
@ ! !b
156
+
++i
157
+
? s^i == '[': ++b
158
+
? s^i == ']': --b
159
+
']': ? ! !v:
160
+
? c == ']': ++b
161
+
@ ! !b
162
+
--i
163
+
?s^i=='[': --b
164
+
?s^i==']': ++b
165
+
--i
166
+
167
+
/** Hello world! */
168
+
fn main: brainfuck(`
169
+
++++++++[>++++[>++>+++>+++>+<<<<-]>+>->+>>
170
+
+[<]<-]>>.>>---.+++++++..+++.>.<<-.>.+++.-
171
+
-----.--------.>+.>++.
172
+
`)
173
+
174
+
```
175
+
176
+
Here is my favorite demonstration of zhaba-script standard library. There is `Vec`, slicing, `Range` and also overloaded output `<` and `>` operators. And all of this is make throw zhaba-script code, so that means that you can also replicate this in your own code, ore eve do more crazy stuff!
177
+
178
+
```zh
179
+
use std
180
+
181
+
fn main
182
+
v := iota(0 10) ; < v < // [0 1 2 3 4 5 6 7 8 9]
183
+
g0 := v[2] ; < g0 < // 2
184
+
g1 := v[-1] ; < g1 < // 9
185
+
g2 := v[2..4] ; < g2 < // [2 3]
186
+
g3 := v[..3] ; < g3 < // [0 1 2]
187
+
g4 := v[3..] ; < g4 < // [3 4 5 6 7 8 9]
188
+
g5 := v[] ; < g5 < // [0 1 2 3 4 5 6 7 8 9]
189
+
g6 := v[-4..-2] ; < g6 < // [6 7]
190
+
g7 := v[-4..] ; < g7 < // [6 7 8 9]
191
+
g8 := v[..-2] ; < g8 < // [0 1 2 3 4 5 6 7]
192
+
193
+
r := 0..10
194
+
g9 := r() ; < g9 < // [0 1 2 3 4 5 6 7 8 9]
195
+
```
196
+
197
+
And of course zhaba-script is shipped with frog by default 🐸!
198
+
199
+
```zh
200
+
use std
201
+
202
+
fn main
203
+
frog := frog()
204
+
< frog <
205
+
206
+
/**
207
+
_____
208
+
/ \__
209
+
/ \
210
+
/ 0 0 |
211
+
| .. |
212
+
/| _/ /
213
+
/ .\_____/ /
214
+
/U\| \___| |__/
215
+
/ /
216
+
|/U\
217
+
*/
218
+
```
219
+
220
+
# The end!
221
+
222
+
So now I welcome you to can play with zhaba-script in this web IDE -> https://wgmlgz.github.io/zhaba
0 commit comments