Skip to content

MrJulus/JSONTY

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

5 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

JSONTY - JSON-based Programming Language

📌 Introduction

JSONTY is a minimalist programming language based on JSON. It allows you to manipulate variables, perform operations, execute conditions, loops, and define functions. Created by MrJulus

Requirements

fs, readline-sync

NPM Package

You can also use the NPM Package : npm install jsonty


Features

Available

[✅] Add functions with multiple return values
[✅] Add logical operators (>, <, =, !=, <=, >=)
[✅] Allow dynamic inputs (ask can be enhanced to support numbers).
[✅] Convert variables
[✅] Add a switch structure

Coming soon...

[❌] Add ternary operator (? :)
[❌] Add break and continue in loops
[❌] Add arrays and objects (set could allow more complex structures).
[❌] Add logical operators && and || for if and while.
[❌] Import from other files


📖 Syntax

🔹 Defining Variables

{
    "set": {
        "x": "10",
        "y": "20"
    }
}

🔹 Displaying Messages

{
    "show": ["(x)"]
}

🔹 Mathematical Operations

{
    "set": {
        "z": "(x) (+) (y)"
    }
}

Different mathematical operations: +, -, *, /, =, !=, <=, and >=

🔄 Control Structures

✅ Conditions (if, else if, else)

{
    "if": {
        "condition": "(x) (>) 5",
        "do": {
            "show": ["x is greater than 5"]
        }
    },
    "else if": {
        "condition": "(x) (<) 5",
        "do": {
            "show": ["x is less than 5"]
        }
    },
    "else": {
        "do": {
            "show": ["x is equal to 5"]
        }
    }
}

🔁 Loops (for, while)

{
    "for": {
        "i": [1, 5],
        "do": {
            "show": ["(i)"]
        }
    }
}

{
    "while": {
        "condition": "(x) (<) 20",
        "do": {
            "set": {
                "x": "(x) (+) 1"
            },
            "show": ["(x)"]
        }
    }
}

🔧 Functions

🔹 Defining a Function

{
    "fct": {
        "name": "calcul",
        "args": ["a", "b"],
        "do": {
            "set": {
                "result": "(a) (+) (b)"
            },
            "return": "(result)"
        }
    }
}

🔹 Defining a Function with Multiple Outputs

{
    "fct": {
        "name": "calcul",
        "args": ["a", "b"],
        "do": {
            "set": {
                "addition": "(a) (+) (b)",
                "moins": "(a) (-) (b)"
            },
            "return": ["(result)", "(moins)"]
        }
    }
}

🔹 Calling a Function

{
    "call": {
        "name": "calcul",
        "args": ["10", "5"]
    },
    "show": ["(result)"]
}

🔹 Calling a Function with Multiple Outputs

{
    "call": {
        "name": "calcul",
        "args": ["10", "5"]
    },
    "show": ["(result[0]), (result[1])"]
}

Switch Function

{
    "switch": {
        "value": "(a)",
        "1": {
            "do": { 
                "show": ["a is 1"] 
            }
        },
        "2": {
            "do": {
                "show": ["a is 2"] 
            }
        },
        "default": {
            "do": { 
                "show": ["a is neither 1 nor 2"] 
            }
        }
    }
}

⌨️ User Input

{
    "ask": {
        "q": "Enter your name"
    },
    "show": ["Hello, (q)!"]
}

⚠️ Error Handling (try/catch)

{
    "try": {
        "do": {
            "set": {
                "x": "1 (/) 0"
            }
        }
    },
    "catch": {
        "do": {
            "show": ["Error detected: (error)"]
        }
    }
}

Contributors

Mr_Julus (@MrJulus)

About

JSONTY is a minimalist programming language based on JSON.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published