# JSONLang

This document has description and information on how to use JSONLang.

## Syntax

All the syntax of this language, is fully based on JSON.

### Minimal working program

This program does not do anything, but runs successfully.

Due to JSON syntax as a base, just leaving empty file will crash interpreter.

```json
{
	"variables":"",
	"functions":{
		"main":[]
	}
}
```

### Printing

For printing, func "print" will be used. For example, see example "Hello World".

### Full function list

|-----|-----|-----|
|**ID**|**Arguments**|**Description**|
|-----|-----|-----|
|`print`|`{"data":"Variable's name to print text from"}`|Print text (with newline at end)|
|`cli`|`{"var":"Variable ID to write CLI argumens into", "arg":"Argument to get from CLI. Leave empty to get unparsed cli arguments. Not like text to be used with --, but just 0/1/2/3/4/5 meaning getting N argument."}`|Get CLI parameters|
|`concat`|`{"out":"Variable to concatenate into","vars":["List","of","variables"]}`|Concatenate variables|
|`run`|`{"data":"Function name"}`|Execute function|
|`set`|`{"var":"Variable to change","data":"Variable data"}`|Set variable's value manually|
|`change`|`{"var":"Variable to change","add":"Variable with integer/float content on how much to add. Point it to variable with 0 to not add.","mult":"Same as add but for multiplication"}`|Change variable|
|`if`|`{"o1":"Variable 1","o2":"Variable 2","then":"Function to execute if equal","else":"Function to execute if NOT equal"}`|Compare variables for equality|
|`copy`|`{"src":"Variable to copy contents from","dest":"Variable to copy contents to"}`|Copy contents from variable "src" to variable "dest"|
|`input`|`{"prompt":"Prompt. Leave empty if none","var":"Variable to save user's answer into"}`|Prompt user and store answer|

## Examples

Hello World (obfuscated)
```json
{"variables":{"hlworld":"Hello, World!"},"functions":{"main":[{"func":"print","data":"hlworld"}]}}
```

Fibonacci (obfuscated)
```json
{"variables":{"n":10,"fib":0,"prev":0,"current":1,"index":0,"done":"Done generating Fibonacci sequence.","one":1},"functions":{"end":[{"func":"print","data":"done"}],"printFibonacci":[{"func":"print","data":"current"},{"func":"copy","dest":"fib","src":"current"},{"func":"change","var":"current","add":"prev","mult":"one"},{"func":"copy","dest":"prev","src":"fib"},{"func":"change","var":"index","add":"one","mult":"one"},{"func":"if","o1":"index","o2":"n","then":"end","else":"printFibonacci"}],"main":[{"func":"set","var":"index","data":0},{"func":"if","o1":"index","o2":"n","then":"end","else":"printFibonacci"}]}}
```

`cowsay`
```json
{
  "variables":{
    "inp":"",
    "c_1":" ____",
    "c_2s":"<",
    "c_2":"",
    "c_2e":">",
    "c_3":" ----",
    "c_4":"        |   ^__^",
    "c_5":"         |  (oo)|_______",
    "c_6":"            (__)|       )|/|",
    "c_7":"                ||----w |",
    "c_8":"                ||     ||"
  },
  "functions":{
    "main":[
      {
        "func":"cli",
        "arg":"0",
        "var":"inp"
      },
      {
        "func":"concat",
        "vars":["c_2s", "inp", "c_2e"],
        "out":"c_2"
      },
      {
        "func":"print",
        "data":"c_1"
      },
      {
        "func":"print",
        "data":"c_2"
      },
      {
        "func":"print",
        "data":"c_3"
      },
      {
        "func":"print",
        "data":"c_4"
      },
      {
        "func":"print",
        "data":"c_5"
      },
      {
        "func":"print",
        "data":"c_6"
      },
      {
        "func":"print",
        "data":"c_7"
      },
      {
        "func":"print",
        "data":"c_8"
      }
    ]
  }
}
```

---

Until user asks, write unobfuscated code.

## Installing interpreter

1. Download it from [Romarchive](https://cows.info.gf/games/Openjs%20Nodejs/J/JSONLang%20interpreter%20(Unknown)%5Bsapbot%5D.zip) using curl
2. Unzip it
3. Write your file to `code.json` (replace it, by default contains `cowsay` program)
4. Run `node index.js <cli args if any>`
