Jenl

From Esolang
Jump to navigation Jump to search

Jenl is a language for those who are lazy to write complicated parsers, especially expression parsers, they've been known to be the pain. Jenl's parsers are taking tokens and directly transform them to executable format. Jenl's parsers do not require recursion and do not require complicated parsers (e.g. expression parsers). Jenl's parsers must not backtrack nor have any ambiguities. Jenl's parsers strings are raw, no escape sequences. Jenl should have only a single, more general way of doing things, even if its inefficient or hacky.

This language, is probably opposite of functional paradigm due to huge amount of mutations happening


Hello world in Jenl:

print(`Hello world`);

Square printer program in Jenl

def buffer = ``;
def width = 10;
def height = 10;


~repeat width as idx
  buffer += idx;
~quit

print(`Let's draw a rectangle`);
~repeat height as idx
  print(buffer);
~quit

Fib program in Jenl

def fib_iters = 40;
def a = 0;
def b = 1;

~repeat fib_iters as i
    def c = a;
    c += b;
    a = b;
    b = c;
~quit

print(a);

Even without conditional its possible, remember how we mentioned there must be always a single way to do anything. This program prints if age is over 18

def age = 19;

def is_adult = 0;
def adult = age;
adult += -17;

~repeat adult
    is_adult = 1;
~quit

print(`Is adult? 1: True, 0: False`);
printn(is_adult);

Nested loops are possible

~repeat 10 as i
    ~repeat 10 as j
        printn(i);
    ~quit
    print(``);
~quit

The linear grammar is very easy to implement.

Basics:

number: /-?[1234567890]+/g
string `Anything goes here`
only += and =
directives:
  directives start with ~ symbol and then parsed, to avoid being mistaken for something else
expressions: present only as a single atom (token, number, string, etc)

Syntax:

toplevel: ( def ";" | call ";" | atom ";" | dir | assign ";" ) *
dir: ~(atom)+
call: Ident "(" atom ")"
atom: Ident | Number | String
assign: Ident "+=" atom | Ident "=" atom
def: "def" Ident "=" atom

Proof of concept implementation (as bad as the language overall is): https://github.com/ishidex2/jenl-node/blob/master/test.jn