My small language written in C.
Find a file
2022-05-17 14:33:23 +02:00
examples feat: add syntax config constants 2022-05-17 10:27:32 +02:00
src fix: naming mistake 2022-05-17 14:33:23 +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
LICENSE add GPLv3 license 2022-05-17 10:35:58 +02:00
Makefile feat: add while loops 2022-05-15 18:46:16 +02:00
README.md feat: REPL environment 2022-05-17 11:37:50 +02:00
sandbox.c feat: REPL environment 2022-05-17 11:37:50 +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:

  • feat: pow operator

  • feat: binary operators

  • feat: basic math functions

  • feat: random_int(min, max)

  • feat: print_number(message)

  • base of unit tests

  • feat: set variables

  • feat: read line comments

  • feat: modulus operator '%'

  • feat: input_number() std function

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

  • feat: type() std function and others type checking functions

  • feat: ceil() and floor() std functions

  • feat: base of the CLI

  • feat: process from a file

  • feat: if statements

  • feat: while statements (with break and continue)

  • feat(Evaluator): multiple characters operators

  • feat(Evaluator): inclusive operators like '!=', '>=', '<='

  • feat: functions support

  • feat(Evaluator): priority operators

  • feat: multiline expressions

  • feat: short hand if statement without 'end'

  • feat: repeat statement

  • feat: static string support (just for ui)

  • feat: print_string function

  • feat: basic number list support

  • feat: fully features strings support

  • feat: function to access to environment variables

  • feat: REPL environment

  • feat: add history to REPL

  • evaluate expression from stdin

  • feat: config header file

  • ability to modify keywords and customize the lang

  • more config options

  • add classic problem solving with code examples

  • feat: web Assembly support and publish a demo website

  • refactor: add 'Literal' struct with type and data

  • refactor(Evaluator): if branching around token identification

  • refactor(List): use malloc

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