Syntax - Glebanister/peach GitHub Wiki
Integers
Integer can contain only digits. Integer range is from -2147483648 to 2147483647.
Unary operators
Unary operator is placed before value. It takes this value and processes it.
Unary operators in peach in descending order of priority:
| Operator | Meaning |
|---|---|
! |
logical negation |
Binary operators
Binary operator is placed between two values. It takes corresponding values and processes them.
Binary operators in peach in descending order of priority:
| Operator | Meaning |
|---|---|
** |
binary power |
* |
multiplication |
/ |
integer division |
% |
taking modulo |
+ |
summation |
- |
subtraction |
== |
equal |
!= |
not equal |
> |
greater |
>= |
greater or equal |
< |
less |
<= |
less or equal |
& |
logical and |
| ` | ` |
Expressions
Expressions may contain values, operatos, assignation operators, variables and round brackets.
For example:
(11 + 12) * 100
!(1 + variable) ** 100 - 1
(12) ** (10)
Variables
Variable name can start with latin or underscore and can contain latin letters, digits and underscores.
You can't use undeclared variable. You can declare it with let keyword:
let variable = 239
let zero_variable
In this case, variable will be set to 239 and zero_variable will have default value 0.
Variable declaration can be placed only in indentation block beginning.
Conditional expressions
Conditional expressions contains if condition, if way expression and else way expression. If if condition is not zero, then if way evaluates, else way otherwise. else way is not required.
Syntax:
if if_condition
if_way
else
else_way
if way and else way requires one indentation block.
Examples:
let variable = 4
let result = 4
if !(variable % 2)
result *= 10
else
result -= 1
let a = 0
let res = 12
if a
res = 2 ** 10
While loops
Contains condition and body. body evaluates while condition not equals to 0.
Syntax:
while condition
body
Examples:
let infinite_loop_iterations
while 1
infinite_loop_iterations += 1
let n = 123
let even = 0
let odd = 0
while n > 0
if n % 2 == 0
even += 1
else
odd += 1