-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
docs + return fix + array get index + exponentiation
- Loading branch information
Showing
27 changed files
with
713 additions
and
59 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -161,3 +161,6 @@ cython_debug/ | |
|
||
# PyPI upload script | ||
upload.py | ||
|
||
# Generated documentation website | ||
docs/site |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file not shown.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
# Using the CLI | ||
The CLI is where all the eryx functionality is. With it you can [run programs](#running-a-program), [start the REPL](#starting-the-repl), [start the web playground](#starting-the-web-playground) and [run the all of the current version's tests](#running-the-tests). | ||
|
||
## Check the current installed version | ||
To run a check what version of Eryx you have installed, simply use: | ||
```sh | ||
eryx --version | ||
# Eryx, version 0.1.3 | ||
``` | ||
|
||
## Running a program | ||
To run a program use: | ||
```sh | ||
eryx run <filepath> | ||
``` | ||
Supported debug arguments are: | ||
|
||
* **--tokenize**: Print the tokenized code | ||
* **--ast**: Print the AST (Abstract Syntax Tree) | ||
* **--result**: Print the result of the code evaluation | ||
|
||
## Starting the repl | ||
To start the Eryx REPL (Read-Eval-Print-Loop) use: | ||
```sh | ||
eryx repl | ||
``` | ||
|
||
This will start an interactive shell that you can use to run Eryx code: | ||
```sh | ||
Eryx v0.1.3 | ||
> | ||
``` | ||
|
||
To exit the REPL use either `CTRL + C` or use the command `exit()`. | ||
|
||
Supported debug arguments are: | ||
|
||
* **--tokenize**: Print the tokenized code | ||
* **--ast**: Print the AST | ||
* **--result**: Print the result of the code evaluation | ||
|
||
## Starting the web playground | ||
The web playground can be used to run programs or use the REPL directly from your browser. | ||
To start it use: | ||
|
||
```sh | ||
eryx playground [--ip ("0.0.0.0")] [--port (80)] | ||
``` | ||
Default ip is `0.0.0.0` (all available network interfaces) and the default port is `80`. | ||
|
||
## Running the tests | ||
Eryx uses [pytest](https://pytest.org) for handling and running tests to make sure the language is working as expected. | ||
To run said tests use: | ||
|
||
```sh | ||
eryx test | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,281 @@ | ||
# Eryx examples | ||
This page contains many example programs made using eryx and their corresponding output. | ||
|
||
## Simple examples | ||
|
||
### Variables | ||
```C title="variables.eryx" linenums="1" | ||
let a = 1; | ||
let b = -2; | ||
let c = 3.14; | ||
let d = a; | ||
let e = "Hello, World!"; | ||
let f = true; | ||
let g = null; | ||
let h = [1, 2, 3]; | ||
let i = {key: "value", num: 10}; | ||
|
||
print(a) | ||
print(b) | ||
print(c) | ||
print(d) | ||
print(e) | ||
print(f) | ||
print(g) | ||
print(h) | ||
print(i) | ||
``` | ||
<details><summary>Output</summary> | ||
```C linenums="1" | ||
1 | ||
-2 | ||
3.14 | ||
1 | ||
Hello, World! | ||
true | ||
null | ||
[ 1, 2, 3 ] | ||
{ key: "value", num: 10 } | ||
``` | ||
</details> | ||
|
||
### Functions | ||
```C title="functions.eryx" linenums="1" | ||
func add(x, y) { | ||
return x + y; | ||
} | ||
|
||
print(add(1, 2)) | ||
``` | ||
<details><summary>Output</summary> | ||
```C linenums="1" | ||
3 | ||
``` | ||
</details> | ||
|
||
### If/Else statements | ||
```C title="if_else.eryx" linenums="1" | ||
let x = 10; | ||
let y = 5; | ||
|
||
if (x == y) { | ||
print("x is equal y") | ||
} else { | ||
print("x is not equal y") | ||
} | ||
|
||
``` | ||
<details><summary>Output</summary> | ||
```C linenums="1" | ||
x is not equal y | ||
``` | ||
</details> | ||
|
||
### Arithmetic operations | ||
```C title="arithmetic.eryx" linenums="1" | ||
let x = 10; | ||
let y = 5; | ||
|
||
print(x + y) | ||
print(x - y) | ||
print(x * y) | ||
print(x / y) | ||
print(x % y) | ||
print(x + y * 2 + x * (y + 2) - 5) | ||
``` | ||
<details><summary>Output</summary> | ||
```C linenums="1" | ||
15 | ||
5 | ||
50 | ||
2 | ||
0 | ||
85 | ||
``` | ||
</details> | ||
|
||
### Comparison operations | ||
```C title="comparisons.eryx" linenums="1" | ||
let x = 10; | ||
let y = 5; | ||
|
||
print(x == y) | ||
print(x != y) | ||
print(x < y) | ||
print(x > y) | ||
print(x <= y) | ||
print(x >= y) | ||
``` | ||
<details><summary>Output</summary> | ||
```C linenums="1" | ||
false | ||
true | ||
false | ||
true | ||
false | ||
true | ||
``` | ||
</details> | ||
|
||
## Complex examples | ||
|
||
### Factorial | ||
Calculate the factorial of a number. | ||
```C title="factorial.eryx" linenums="1" | ||
func factorial(n) { | ||
if (n <= 1) { | ||
return 1; | ||
} | ||
return n * factorial(n - 1); | ||
} | ||
|
||
print(factorial(5)) | ||
``` | ||
<details><summary>Output</summary> | ||
```C linenums="1" | ||
120 | ||
``` | ||
</details> | ||
|
||
### Fibonacci | ||
Calculate the nth Fibonacci number. | ||
```C title="fibonacci.eryx" linenums="1" | ||
func fibonacci(n) { | ||
if (n <= 0) { | ||
return 0; | ||
} | ||
if (n == 1) { | ||
return 1; | ||
} | ||
return fibonacci(n - 1) + fibonacci(n - 2); | ||
} | ||
|
||
print(fibonacci(10)) | ||
``` | ||
<details> <summary>Output</summary> | ||
```C linenums="1" | ||
55 | ||
``` | ||
</details> | ||
|
||
### GCD | ||
Find the greatest common divisor of two numbers using Euclid's algorithm. | ||
```C title="gcd.eryx" linenums="1" | ||
func gcd(a, b) { | ||
if (b == 0) { | ||
return a; | ||
} | ||
return gcd(b, a % b); | ||
} | ||
|
||
print(gcd(48, 18)) | ||
``` | ||
<details> <summary>Output</summary> | ||
```C linenums="1" | ||
6 | ||
``` | ||
</details> | ||
|
||
### Prime Check | ||
Check if a number is a prime number. | ||
```C title="is_prime.eryx" linenums="1" | ||
func isPrime(n, divisor) { | ||
if (n <= 1) { | ||
return false; | ||
} | ||
if (divisor == 1) { | ||
return true; | ||
} | ||
if (n % divisor == 0) { | ||
return false; | ||
} | ||
return isPrime(n, divisor - 1); | ||
} | ||
|
||
let number = 17; | ||
print(isPrime(number, int(number ** 0.5))) | ||
``` | ||
<details> <summary>Output</summary> | ||
```C linenums="1" | ||
true | ||
``` | ||
</details> | ||
|
||
### Offset adder | ||
Create an adder with an offset then use it. | ||
```C title="adder.eryx" linenums="1" | ||
func makeAdder(offset) { | ||
func add(x, y) { | ||
return x + y + offset; | ||
} | ||
|
||
return add; | ||
} | ||
|
||
let adder = makeAdder(10); | ||
print(adder(5, 10)) | ||
``` | ||
<details> <summary>Output</summary> | ||
```C linenums="1" | ||
25 | ||
``` | ||
</details> | ||
|
||
### Sum digits | ||
Sum all digits of a number. | ||
```C title="sum_digits.eryx" linenums="1" | ||
func sumOfDigits(n) { | ||
if (n == 0) { | ||
return 0; | ||
} | ||
return (n % 10) + sumOfDigits(int(n / 10)); | ||
} | ||
|
||
print(sumOfDigits(12345)) | ||
``` | ||
<details> <summary>Output</summary> | ||
```C linenums="1" | ||
15 | ||
``` | ||
</details> | ||
|
||
### Reverse number | ||
Reverse the digits of a number. | ||
```C title="reverse_number.eryx" linenums="1" | ||
func reverseNumber(n, reversed) { | ||
if (n == 0) { | ||
return reversed; | ||
} | ||
reversed = reversed * 10 + (n % 10) | ||
return reverseNumber(int(n / 10), reversed); | ||
} | ||
|
||
print(reverseNumber(12345, 0)) | ||
``` | ||
<details> <summary>Output</summary> | ||
```C linenums="1" | ||
54321 | ||
``` | ||
</details> | ||
|
||
### Is sorted | ||
Check if a list is sorted. | ||
```C title="is_sorted.eryx" linenums="1" | ||
func isSorted(arr, idx) { | ||
if (idx == 0) { | ||
return true; | ||
} | ||
if (arr[idx] < arr[idx - 1]) { | ||
return false; | ||
} | ||
return isSorted(arr, idx - 1); | ||
} | ||
|
||
let nums = [1, 2, 3, 4, 5]; | ||
print(isSorted(nums, len(nums) - 1)) | ||
``` | ||
<details> <summary>Output</summary> | ||
```C linenums="1" | ||
true | ||
``` | ||
</details> |
Oops, something went wrong.