Skip to content

Commit 26e120f

Browse files
authored
Add docs
Add docs
1 parent 93c33c4 commit 26e120f

File tree

1 file changed

+334
-0
lines changed

1 file changed

+334
-0
lines changed

docs/lang.md

Lines changed: 334 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,334 @@
1+
# Fels programming language documentation
2+
3+
## Write you first program
4+
5+
to write first program write code:
6+
```
7+
println("Hello,world!")
8+
```
9+
10+
## Comment you code!
11+
12+
```
13+
//one line comment
14+
/*
15+
This is multiline comment
16+
*/
17+
```
18+
19+
## Variables
20+
21+
to set new variable write:
22+
```
23+
name = "Tom"
24+
age = 60
25+
26+
println("Name is "+name+", age: "+age)
27+
```
28+
29+
## Variable types
30+
31+
```
32+
a = 60//NUMBER
33+
b = "NAME"//STRING
34+
c = func(a,b) = 2//FUNCTION
35+
d = [1,2,3]//Array
36+
//And more
37+
```
38+
39+
## I/O
40+
41+
This is I/O example
42+
43+
```
44+
println("asdf")//Write text to console
45+
print("adsf")//Write text to console with out refactoring to new line
46+
47+
//INPUT
48+
49+
using ["fels.io.scanner"]//Import scanner module
50+
51+
a = scanner.readNum()//Read number from console
52+
println(a)//write variable a to console
53+
54+
```
55+
56+
## Logical gates
57+
58+
This is basic logical gates:
59+
60+
```
61+
println(true or false)
62+
println(true || false)
63+
64+
println(true and false)
65+
println(true && false)
66+
67+
println(not true)
68+
println(!true)
69+
```
70+
71+
Logical operators:
72+
73+
```
74+
a = true
75+
b = false
76+
77+
if(a){
78+
if(a == b){
79+
println("?a == b: "+a==b)
80+
}else{
81+
println("logical else")
82+
}
83+
}
84+
```
85+
86+
## User-Defined functions
87+
88+
### User-defined functions basics
89+
90+
Create you function:
91+
92+
```
93+
func out(text){
94+
println(text)
95+
}
96+
```
97+
98+
Call you function:
99+
100+
```
101+
out("Hello,Fels!")
102+
```
103+
104+
### Extended User-defined functions
105+
106+
Let's add return to you function:
107+
108+
```
109+
func a(){
110+
return "a"
111+
}
112+
println(a())//a
113+
114+
//or use "speed form"
115+
116+
func a() = "a"
117+
println(a())//a
118+
```
119+
120+
### Link to function
121+
122+
Write this code:
123+
124+
```
125+
//LINK NOT EXECUTE YOU FUNCTION
126+
127+
func a() = 2
128+
printn(a())//2
129+
130+
println(::a)//nothink output
131+
132+
```
133+
134+
## Loops
135+
136+
### Basic loops
137+
138+
While loop:
139+
140+
```
141+
a = 0
142+
while(a < 10){
143+
println("a = "+a)
144+
a++
145+
}
146+
```
147+
148+
For loop:
149+
150+
```
151+
for(i = 0,i < 10,i++){
152+
println("i = "+i)
153+
}
154+
```
155+
156+
### Extended loops
157+
158+
For-each loop:
159+
160+
```
161+
array = [1,2,3,4,5]
162+
163+
for(el : array){
164+
println(el)
165+
}
166+
```
167+
168+
Range(python like) loop:
169+
170+
```
171+
range(5){
172+
println("This is range loop!")
173+
}
174+
```
175+
176+
Loop(rust like) loop:
177+
178+
```
179+
a = 10
180+
loop{
181+
if(a == 10) break
182+
println("a = "+a)
183+
a++
184+
}
185+
```
186+
187+
## OOP
188+
189+
Write you first class:
190+
191+
```
192+
class Test{
193+
func Test(){}//CONSTRUCTOR
194+
195+
func getASDF() = "asdf"
196+
}
197+
```
198+
199+
Create object of you class:
200+
201+
```
202+
obj = new Test()
203+
println(obj.getASDF())//asdf
204+
```
205+
206+
This keyword:
207+
208+
```
209+
class Vehicle{
210+
func Vehicle(speed){
211+
this.speed = spedd
212+
}
213+
214+
func getSpeed() = this.speed
215+
216+
func setSpeed(speed){
217+
this.speed = speed
218+
}
219+
}
220+
221+
car = new Vehicle(60)
222+
car.setSpeed(65)
223+
println(car.getSeed())//65
224+
```
225+
## Extended operators
226+
227+
Create extended operator:
228+
229+
```
230+
`a b c d` = 2
231+
println(`a b c d`)//2
232+
```
233+
234+
## Arrays
235+
236+
### 1D arrays
237+
238+
Create you first array:
239+
240+
```
241+
arr = [1,2,3,4,5]
242+
println(arr)//[1,2,3,4,5]
243+
```
244+
245+
Using in for-each:
246+
247+
```
248+
for(el : arr){
249+
print(el)
250+
}
251+
//12345
252+
```
253+
254+
Changing array item:
255+
256+
```
257+
arr = [1,2,3,4,5]
258+
259+
arr[1] = "asdf"
260+
println(arr[1])//asdf
261+
```
262+
263+
Creating empty array:
264+
265+
```
266+
using ["fels.utils.arrays"]
267+
268+
arr = arrsay(5)
269+
arr[0] = 1
270+
println(arr[0])//1
271+
```
272+
273+
Append array:
274+
275+
```
276+
arr1 = [1,2]
277+
arr2 = [3,4]
278+
279+
arr3 = arr1 :: arr2
280+
println(arr3)//[1,2,3,4]
281+
```
282+
283+
## 2D and more arrays
284+
285+
You can yse all functions and methods from 1D arrays
286+
287+
Create 2D arrays
288+
289+
```
290+
arr = [1,2,"3",[1,2,"asdf"]]
291+
292+
println(arr[4][2])
293+
```
294+
295+
Or you can create array using array module
296+
297+
```
298+
using ["fels.utils.arrays"]
299+
300+
arr5 = array(4, 4)
301+
println(arr5)
302+
arr5[1] = arr1
303+
println(arr5)
304+
```
305+
306+
## Map type
307+
308+
Create new map
309+
310+
```
311+
map = {
312+
"key":"value"
313+
}
314+
315+
println(map["key"])
316+
println(map.key)
317+
```
318+
319+
Changing map values:
320+
321+
```
322+
map = {
323+
"key":"value"
324+
}
325+
326+
println(map["key"])
327+
println(map.key)
328+
329+
map1["newkey"] = "newvalue"
330+
map1[0] = "zero"
331+
x = 400
332+
map1[x] = [1, 2, 3]
333+
println( map1)
334+
```

0 commit comments

Comments
 (0)