My small language written in C.
Find a file
Matthieu Bessat a66bfff424 feat: add syntax config constants
fix(VarStore): better hash function
2022-05-17 10:27:32 +02:00
examples feat: add syntax config constants 2022-05-17 10:27:32 +02:00
src feat: add syntax config constants 2022-05-17 10:27:32 +02:00
tests feat: add syntax config constants 2022-05-17 10:27:32 +02:00
.gitignore feat(Evaluator): add pow operator 2022-04-30 16:16:37 +02:00
draft.md readme update 2022-05-17 09:28:31 +02:00
Makefile feat: add while loops 2022-05-15 18:46:16 +02:00
README.md readme update 2022-05-17 09:28:31 +02:00
sandbox.c feat: add syntax config constants 2022-05-17 10:27:32 +02:00

Langatator

A very basic interpreted imperative programming language.

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.

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.

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-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

ToDo List:

  • pow operator

  • binary operators

  • implement basic math functions

  • implement random_int(min, max)

  • implement print_number(message)

  • add unit tests

  • allow to set variables

  • read line comments

  • add modulus operator '%'

  • add input_number() std function

  • add NULL type (dirty way to handle no returns and some errors)

  • add type() std function and others type checking functions

  • add ceil() and floor() std functions

  • base of the CLI

  • read a file

  • if statements

  • while statements (with break and continue)

  • add multiple characters operators

  • add inclusive operators like '!=', '>=', '<='

  • add functions support

  • add priority operators

  • add multiline expressions

  • add short hand if without 'end'

  • add repeat statement

  • add static string support (just for ui)

  • add print_string function

  • add basic number list support

  • add fully features strings support

  • evaluate expression from stdin

  • add config header file

  • ability to modify keywords and customize the lang

  • add classic problem solving with code examples

  • add Web Assembly support and publish a demo website

  • refactor: use malloc for list

  • refactor: remove inconsistency on how functions returns error codes

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).

Unit testing

I try to have some sort of code coverage, you can run the unit tests by issuing make test

The language

You would be able to use the lang directly via CLI, via a REPL or by writing in a file (file ext .ltor).

One instruction set per line.

Comments

Can only use single line comments with #

# this is a comment

Data types

To begin with and order to simplify things we would only have numbers as datatypes.

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

function calls: func(arg_a, arg_b) operators: +, *, /, ^, %, =, <, >, &, |, !

Set a variable

set {VARNAME} to {EXPRESSION}

Evaluate an expression without using the result

print_number(42)

function definition

function {NAME} do
  ...
end

Conditional structure

if {EXPRESSION} then
  ...
end

Conditional loop

while {EXPRESSION} do
  ...
end

Unconditional loop

repeat {INT EXPRESSION} do
  ...
end
repeat i from {INT EXPRESSION} to {INT EXPRESSION} do
  ...
end

std functions

abs(nb)
sqrt,sin,cos,exp,ln,log etc.
print_number(nb)
input_number()
ceil(nb)
floor(nb)
random_int(min, max)
random_float(min, max)
type(var) -> return the type of a var as int
is_null(var)
is_number(var)
print_string(str)
print_newline()
print_ascii(nb)