FSKalc/Readme.md

136 lines
2.9 KiB
Markdown
Raw Permalink Normal View History

2023-01-13 21:45:24 +01:00
# Building
2023-01-13 22:10:34 +01:00
1. Have dotnet-sdk installed
2023-01-13 21:45:24 +01:00
2. Go to the directory where fskalc is located
3. Run `dotnet restore` to restore the `obj/` directory
4. Run `dotnet run` for debug run
2023-01-13 22:10:34 +01:00
5. `./release.sh` for release run, the binary will be found in bin/Release/net[version]/[platform]/publish/fskalc, and also will be copied to the active directory
2023-01-13 21:45:24 +01:00
2023-01-13 19:26:20 +01:00
# Reference
The following is an informal overview of FSKalc's capabilties.
## Expressions
### Number literal
Example:
```
8.5
```
### Variable read
Example:
```
a
```
Will print an error message if variable is undefined. The `ans` variable implicitly refers to the result of the last expression statement.
### Parentheses for precedence
Example:
```
(5+6)*7
```
Parentheses increase precedence.
### Function calls
2023-01-13 19:26:20 +01:00
Functions are called with !.
2023-01-13 19:26:20 +01:00
Example:
```
sin! pi/2
2023-01-13 19:26:20 +01:00
```
Multile arguments need to be separated with commas.
```
logx! 5, 3
```
2023-01-13 19:26:20 +01:00
### Arithmetic operators
The following operators are valid, in decreasing precedence:
- `^` power; right associative
- `-` unary negation; note that multiple negations next to eachother are invalid!
- factor precedence:
- `*` multiplication; left associative
- `/` division; left associative
- `//` integer (flooring) division; left associative
- `%` modulo; left associative
- if no binary operator is found, multiplication is assumed
2023-01-13 19:26:20 +01:00
- term precedence:
- `+` addition; left associative
- `-` subtraction; left associative
## Statements
Statements are the top level construct. Every line in an FSKalc program has to be a statement.
### Expression statement
Any valid expression is also a valid statement. The result of expression statements is printed to the screen, and also assigned to the variable names `ans`.
### Variable assignments
Variable assignments have the following syntax:
```
identifier = expression
```
Where the identifier is a string of characters containing only letters and underscores.
Existing variables or functions can be overwritten by new variables/functions.
### Function declaration
Function declaration has the following syntax, demonstrated by an example below.
```
double x = x * 2
```
Multiple parameters need to be declared with commas separating.
```
sum x, y = x + y
```
2023-01-13 19:26:20 +01:00
Warning! as there are no scopes in FSKalc, passing
arguments to functions will modify the global scope.
## Builtins
### Builtin Constants
- pi
- tau (pi * 2)
- e (euler's number)
- inf (infinity)
- nan (not a number)
### Builtin Functions
- sin, cos, tan - they take 1 argument, in radians
- arcsin, arccos, arctan - they take 1 argument, they return in radians
- sqrt - returns square root
- log - logarithm base of 10
2023-01-13 19:26:20 +01:00
- ln - natural logarithm
- exp - returns e to the power of the argument
- rtx - returns the xth root (1st argument: base, 2nd argument: val)
- logx - returns the base x log (1st argument: base, 2nd argument: val)
2023-01-13 19:26:20 +01:00
## Comments
Comments can be inside matching `(*`, `*)` parentheses.