JAYSON

From Esolang
Jump to navigation Jump to search

About

JAYSON is a JSON-based programming language designed to look and feel like JSON itself. This language interprets JSON objects as programming instructions, enabling code to be written entirely in JSON format. The language interpreter is built in Node.js, and files using JAYSON syntax must be saved with a `.jayson` extension.

Features

  • Basic Math Operations: Addition, subtraction, multiplication, and division.
  • Comparison Operations: Equality, greater than, less than.
  • Logical Operations: AND, OR, NOT.
  • Control Flow: If statements, while loops.
  • Functions: Define reusable code blocks.

Syntax

JAYSON code is structured as a JSON object with keys representing constructs. Here’s an overview:

Structure

A JAYSON program consists of:

  • variables: Define initial variables and values.
  • functions: Define functions with parameters and a body of operations.
  • main: Main program body with a sequence of operations.

Example

Below demonstrates a basic JAYSON program:

{
  "program": {
    "variables": {
      "x": 10,
      "y": 5
    },
    "functions": {
      "addAndPrint": {
        "parameters": ["a", "b"],
        "body": [
          { "operation": "print", "value": { "operation": "add", "left": "a", "right": "b" } }
        ]
      }
    },
    "main": [
      { "operation": "call", "function": "addAndPrint", "arguments": ["x", "y"] }
    ]
  }
}

Operations

JAYSON supports a variety of operations, each specified as an `operation` object with a type and associated values.

Math Operations

  • add: Adds two values.
  • subtract: Subtracts one value from another.
  • multiply: Multiplies two values.
  • divide: Divides one value by another.

Comparison Operations

  • equals: Checks if two values are equal.
  • greater_than: Checks if the first value is greater than the second.
  • less_than: Checks if the first value is less than the second.

Logical Operations

  • and: Returns true if both conditions are true.
  • or: Returns true if at least one condition is true.
  • not: Returns the opposite boolean value.

Control Flow

  • if: Executes a series of operations if a condition is true.
  • while: Loops through operations while a condition is true.

Functions

Functions in JAYSON are defined with parameters and a body. Parameters are placeholders for values, while the body consists of a list of operations to execute.

Example of a Function

"functions": {
  "multiplyAndPrint": {
    "parameters": ["a", "b"],
    "body": [
      { "operation": "print", "value": { "operation": "multiply", "left": "a", "right": "b" } }
    ]
  }
}

Example Program

Below is a more complex example that uses variables, functions, and loops:

{
  "program": {
    "variables": {
      "x": 10,
      "factor": 2
    },
    "functions": {
      "multiplyAndPrintLoop": {
        "parameters": ["count"],
        "body": [
          {
            "operation": "while",
            "condition": { "operation": "greater_than", "left": "count", "right": 0 },
            "body": [
              { "operation": "print", "value": "count" },
              {
                "operation": "set",
                "variable": "x",
                "value": { "operation": "multiply", "left": "x", "right": "factor" }
              },
              {
                "operation": "set",
                "variable": "count",
                "value": { "operation": "subtract", "left": "count", "right": 1 }
              }
            ]
          }
        ]
      }
    },
    "main": [
      { "operation": "call", "function": "multiplyAndPrintLoop", "arguments": [3] }
    ]
  }
}

Summary

JAYSON is a JSON-structured programming language, ideal for those interested in a structured, minimalistic syntax. With operations for math, logic, and control flow, JAYSON supports simple to moderately complex programs. (This is made with ChatGPT 4o-mini)