/test-joker-lang

Primary LanguageTypeScriptMIT LicenseMIT

joker Lang

Total alerts Language grade: JavaScript Build Build Build

This is official repository for joker-lang.

joker lang is a toy programming language written in Typescript.


Installation

npm i -g jokerlang

Usage

Create a new file (test.joker)

Edit the file with a text editor. You can also try out your code on joker Lang PlayGround

hi joker
  tell joker "Hello joker";
bye joker

Run

jokerlang test.joker

Output

hello joker

Documentation

General

hi joker is the entrypoint for the program and all program must end with bye joker. Anything outside of it will be ignored.


This will be ignored

hi joker
// Write code here
bye joker

This too

Variables

Variables can be declared using joker ye hai.


hi joker
  joker ye hai a = 10;
  joker ye hai b = "two";
  joker ye hai c = 15;
  a = a + 1;
  b = 21;
  c *= 2;
bye joker

Types

Numbers and strings are like other languages. Null values can be denoted using zero. sahi and galat are the boolean values.


hi joker
  joker ye hai a = 10;
  joker ye hai b = 10 + (15*20);
  joker ye hai c = "two";
  joker ye hai d = 'ok';
  joker ye hai e = zero;
  joker ye hai f = sahi;
  joker ye hai g = galat;
bye joker

Built-ins

Use tell joker to print anything to console.


hi joker
  tell joker "Hello World";
  joker ye hai a = 10;
  {
    joker ye hai b = 20;
    tell joker a + b;
  }
  tell joker 5, 'ok', zero , sahi , galat;
bye joker

Conditionals

jokerlang supports if-else-if ladder construct , if joker block will execute if condition is sahi, otherwise one of the subsequently added nahi to joker blocks will execute if their respective condition is sahi, and the else joker block will eventually execute if all of the above conditions are galat


hi joker
  joker ye hai a = 10;
  if joker (a < 20) {
    tell joker "a is less than 20";
  } nahi to joker ( a < 25 ) {
    tell joker "a is less than 25";
  } else joker {
    tell joker "a is greater than or equal to 25";
  }
bye joker

Loops

Statements inside jab tak joker blocks are executed as long as a specified condition evaluates to sahi. If the condition becomes galat, statement within the loop stops executing and control passes to the statement following the loop. Use stop this joker to break the loop and look for next joker to continue within loop.


hi joker
  joker ye hai a = 0;
  jab tak joker (a < 10) {
   a += 1;
   if joker (a == 5) {
    tell joker "andar se tell joker ", a;
    look for next joker;
   }
   if joker (a == 6) {
    stop this joker;
   }
   tell joker a;
  }
  tell joker "done";
bye joker

Development

You can explore abstract syntax tree(AST) of jokerlang here.