2022-04-29 10:30:44 +00:00
# Langatator
2022-05-17 07:28:31 +00:00
A very basic interpreted imperative programming language.
2022-04-29 10:30:44 +00:00
## Background
The goal of this project is to create a simple implementation of a BASIC-like language just to learn a few things along the way and practice my C programming skills.
2022-04-20 18:10:00 +00:00
2022-05-17 07:28:31 +00:00
No need to do complex things, just to create a simple interpreted language that can be used to do some arithmetics and create for example a number guessing game.
2022-04-29 10:30:44 +00:00
I didn't really study how others languages works beforehand, I'm just guessing how I'm implementing things so that I can make mistakes to learn from.
## Progress
2022-05-15 17:58:52 +00:00
- 2022-04-29 Implementation of a basic evaluator engine to evaluate arithmetic expressions and call functions
- 2022-05-15 Clear progress being able to use simple while and if though thre are many glitches
2022-04-20 18:10:00 +00:00
2022-04-29 10:30:44 +00:00
ToDo List:
2022-04-20 18:10:00 +00:00
2022-04-30 16:01:22 +00:00
- [X] pow operator
2022-05-06 11:13:58 +00:00
- [X] binary operators
2022-04-30 16:01:22 +00:00
- [X] implement basic math functions
- [X] implement random_int(min, max)
2022-05-06 11:13:58 +00:00
- [X] implement print_number(message)
2022-05-15 16:46:16 +00:00
- [X] add unit tests
- [X] allow to set variables
- [X] read line comments
2022-05-15 19:16:34 +00:00
- [X] add modulus operator '%'
2022-05-16 06:29:14 +00:00
- [X] add input_number() std function
2022-05-17 07:01:58 +00:00
- [X] add NULL type (dirty way to handle no returns and some errors)
- [X] add type() std function and others type checking functions
2022-05-16 08:53:45 +00:00
- [X] add ceil() and floor() std functions
2022-05-15 17:58:52 +00:00
- [X] base of the CLI
- [X] read a file
- [X] if statements
2022-05-16 06:29:14 +00:00
- [X] while statements (with break and continue)
2022-05-17 07:28:31 +00:00
- [ ] add multiple characters operators
- [ ] add inclusive operators like '!=', '>=', '< ='
2022-05-15 16:46:16 +00:00
- [ ] add functions support
2022-05-17 07:28:31 +00:00
- [ ] add priority operators
- [ ] add multiline expressions
- [ ] add short hand if without 'end'
- [ ] add repeat statement
2022-05-15 17:58:52 +00:00
- [ ] add static string support (just for ui)
- [ ] add print_string function
- [ ] add basic number list support
- [ ] add fully features strings support
2022-05-17 08:35:58 +00:00
- [ ] add function to access to environment variables
2022-05-17 07:28:31 +00:00
2022-05-17 08:35:58 +00:00
- [ ] add REPL environment
2022-05-17 07:28:31 +00:00
- [ ] evaluate expression from stdin
2022-05-17 08:35:58 +00:00
- [X] add config header file
- [X] ability to modify keywords and customize the lang
- [ ] add more config options
2022-05-17 07:28:31 +00:00
2022-05-15 17:58:52 +00:00
- [ ] add [classic problem solving ](https://rosettacode.org ) with code examples
2022-05-15 18:49:23 +00:00
- [ ] add Web Assembly support and publish a demo website
2022-05-17 07:28:31 +00:00
2022-05-17 07:01:58 +00:00
- [ ] refactor: use malloc for list
2022-05-16 08:53:45 +00:00
- [ ] refactor: remove inconsistency on how functions returns error codes
2022-05-15 17:58:52 +00:00
## Installation
You will need to compile the code from source.
- Clone this repository
- Then compile (eg. with `make` )
I use GNU Make with GCC, but I'm sure you can use any C compilers though you may need to edit some part of the code to cope with other compilers (eg. binary constants).
2022-05-15 16:46:16 +00:00
2022-05-17 07:28:31 +00:00
## Unit testing
I try to have some sort of code coverage, you can run the unit tests by issuing `make test`
2022-04-20 18:10:00 +00:00
2022-04-29 10:30:44 +00:00
## The language
2022-04-20 18:10:00 +00:00
2022-04-29 10:30:44 +00:00
You would be able to use the lang directly via CLI, via a REPL or by writing in a file (file ext `.ltor` ).
2022-04-20 18:10:00 +00:00
2022-04-29 10:30:44 +00:00
One instruction set per line.
2022-04-20 18:10:00 +00:00
2022-04-29 10:30:44 +00:00
### Comments
Can only use single line comments with `#`
2022-04-20 18:10:00 +00:00
```
# this is a comment
```
2022-05-15 17:58:52 +00:00
### Data types
To begin with and order to simplify things we would only have numbers as datatypes.
2022-04-20 18:10:00 +00:00
2022-05-15 17:58:52 +00:00
When a variable is declared it can be 32 bit integer or 32 bit float.
The language may support strings literals in the future.
### Expression evaluation
2022-04-20 18:10:00 +00:00
function calls: func(arg_a, arg_b)
2022-05-15 17:58:52 +00:00
operators: +, *, /, ^, %, =, < , >, & , |, !
2022-04-29 10:30:44 +00:00
### Set a variable
```
set {VARNAME} to {EXPRESSION}
```
2022-05-15 17:58:52 +00:00
### Evaluate an expression without using the result
2022-04-29 10:30:44 +00:00
```
2022-05-15 17:58:52 +00:00
print_number(42)
2022-04-29 10:30:44 +00:00
```
2022-04-20 18:10:00 +00:00
### function definition
```
2022-05-15 17:58:52 +00:00
function {NAME} do
...
2022-04-20 18:10:00 +00:00
end
```
### Conditional structure
```
if {EXPRESSION} then
2022-05-15 17:58:52 +00:00
...
2022-04-20 18:10:00 +00:00
end
```
### Conditional loop
```
while {EXPRESSION} do
2022-05-15 17:58:52 +00:00
...
2022-04-20 18:10:00 +00:00
end
```
### Unconditional loop
```
2022-05-15 17:58:52 +00:00
repeat {INT EXPRESSION} do
...
end
```
2022-04-20 18:10:00 +00:00
2022-05-15 17:58:52 +00:00
```
repeat i from {INT EXPRESSION} to {INT EXPRESSION} do
...
2022-04-20 18:10:00 +00:00
end
```
### std functions
```
2022-04-29 10:30:44 +00:00
abs(nb)
sqrt,sin,cos,exp,ln,log etc.
2022-05-15 19:00:32 +00:00
print_number(nb)
2022-04-29 10:30:44 +00:00
input_number()
2022-05-16 06:29:14 +00:00
ceil(nb)
floor(nb)
2022-04-20 18:10:00 +00:00
random_int(min, max)
2022-05-15 17:58:52 +00:00
random_float(min, max)
2022-05-15 19:00:32 +00:00
type(var) -> return the type of a var as int
2022-05-16 09:02:04 +00:00
is_null(var)
2022-05-17 07:01:58 +00:00
is_number(var)
2022-05-15 19:00:32 +00:00
print_string(str)
print_newline()
print_ascii(nb)
2022-04-20 18:10:00 +00:00
```