Skip to content

Commit 0190f44

Browse files
committed
Thicc docs update
1 parent 94484a6 commit 0190f44

13 files changed

+389
-49
lines changed

README.md

Lines changed: 168 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,23 @@ Zhaba script (Russian: ˈʐabə, жаба(frog)) - is a multi-paradigm, high-lev
44

55
Inspired by JS, Rust, C++, and Python🐍
66

7-
## Docs
7+
![frog_img](/img/frog.jpg)
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 📑
816

917
Here is a zhaba-script docs website with syntax highlighting -> https://wgmlgz.github.io/zhaba/?page=docs
1018

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! 👋
1224

1325
```zh
1426
use std
@@ -17,25 +29,22 @@ fn main
1729
< 'hi world!' <
1830
```
1931

20-
## Setup
32+
# List of features
2133

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:
3135

32-
## List of features
36+
- Interpretation (throw bytecode)
37+
- Interpretation in web environment
38+
- Web code editor
39+
- Docs website
40+
- Translation to C
3341

3442
- Basics:
3543

3644
- Basic types like int, bool or char
45+
- Variables (and local redefinition)
3746
- All C operators like (+ - \* %)
38-
- If, else, else if
47+
- If, else, elif
3948
- While loop
4049
- C-style for loop
4150
- Single and multi-line comments
@@ -45,40 +54,175 @@ fn main
4554
- More advanced features:
4655

4756
- Foreach loop
57+
- Patten matching
4858
- Functions overloading
4959
- Any operator overloading
60+
- Subscript `[]` and call `()` overload
5061
- New operators creation
5162
- Local (relative to scope) functions and operators definition
5263
- Pointers
53-
- References
64+
- References (pass, return and store)
5465

55-
- OOP:
66+
- Objects:
5667

57-
- Classes
68+
- Custom types (classes/structs)
5869
- Member functions
5970
- 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>`
6274

6375
- Standard library
6476
- `Vec<T>` - generic dynamic array
6577
- `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 🐸
6881
- `operators.zh` - more advanced operators like %%
82+
- `brainfuck.zh` - brainfuck interpreter
83+
84+
# Why? 🤔
6985

7086
## Motivation
7187

7288
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.
7389

7490
## Goal
7591

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.
7793

7894
## Syntax
7995

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).
8197

8298
## Memory model
8399

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
223+
224+
Love frogs and frogs will love you 🐸💖.
225+
226+
⭐ this repo if you liked it!
227+
228+
![frog_img](/img/cute-frog.jpg)

0 commit comments

Comments
 (0)