Skip to content

Instantly share code, notes, and snippets.

@dipu-bd
Last active January 13, 2024 00:24
Show Gist options
  • Save dipu-bd/a18d30007c00adb82bba8034ec13eb0f to your computer and use it in GitHub Desktop.
Save dipu-bd/a18d30007c00adb82bba8034ec13eb0f to your computer and use it in GitHub Desktop.
JSON schema for a Turing complete machine
{
"$schema": "http://json-schema.org/schema",
"title": "JSON schema for a turing complete machine",
"type": "object",
"definitions": {
"statement": {
"description": "",
"type": "object",
"maxProperties": 1,
"properties": {
"set": {
"description": "Declare a set of variable names and their values. Previous declaration of the variable will be replaced by this declaration.",
"type": "object",
"propertyNames": { "minLength": 1 }
},
"copy": {
"description": "Copy a variable to a new variable.\n\nThe pattern is: ```{ 'new-variable-name': 'existing-variable-name' }```.\n\nHere keys are the names of new variables, and values are names of existing variables. If a variable does not exists, new variable's value will be set to null. If new variable name already exists, it's value will be replaced.",
"type": "object",
"propertyNames": { "minLength": 1 },
"patternProperties": {
"": { "type": "string" }
}
},
"set-state": {
"description": "Set a constant value to the current state"
},
"copy-state": {
"description": "Copy the value from a variable to the current state",
"type": "string"
},
"move-state": {
"description": "Copy the value of the current state to a variable",
"type": "string"
},
"block": {
"description": "A block of statements",
"type": "array",
"items": {
"$ref": "#/definitions/statement"
}
},
"if": {
"description": "Runs this block only if the current state evaluates to True. A state will be evaluated to True, when it is not zero, empty, null, or undefined.",
"$ref": "#/definitions/statement/properties/block"
},
"else": {
"description": "Runs this block only if the current state evaluates to False. A state will be evaluated to True, when it is not zero, empty, null, or undefined.",
"$ref": "#/definitions/statement/properties/block"
},
"loop": {
"description": "Loop over every elements of the current state. Inside the loop, the current state is set to the loop iterator. All variable accessed by the parent block, can also be accessed here by adding `parent:` prefix to the variable name. e.g., to access parent's state, variable name would be `parent:state`.\n\nAt the end of this block, you must set the `loop:result` variable. The next state will be an array of this `loop:result` values.",
"$ref": "#/definitions/statement/properties/block"
},
"dot": {
"description": "Access any property of the current state. The next state will be the value of that property",
"type": "string"
},
"at": {
"description": "Access an indexed element of the current state. The current state must be an array, or map or support access via index. The next state will be the accessed value",
"type": ["string", "integer"]
},
"call": {
"description": "Calls a function with current state as argument. The next state will be the output of the function",
"type": "string",
"enum": [
"foo_method",
"bar_method"
]
},
"dot-call": {
"description": "Calls a method of the current state, with some arguments. The next state will be the output of the method",
"type": "object",
"properties": {
"args": {
"description": "The arguments to pass",
"type": "array"
},
"kwargs": {
"description": "The keyword arguments to pass",
"type": "object",
"propertyNames": { "minLength": 1 }
},
"named-args": {
"description": "List of variable names to pass as arguments",
"type": "array",
"items": { "type": "string", "minLength": 1 }
},
"named-kwargs": {
"description": "List of variable names to pass as keyword arguments",
"type": "object",
"propertyNames": { "minLength": 1 },
"patternProperties": {
"": { "type": "string" }
}
}
}
}
}
}
},
"properties": {
"program": {
"$ref": "#/definitions/statement"
}
}
}
@dipu-bd
Copy link
Author

dipu-bd commented May 6, 2020

This schema can be used to write any simple programs, which can be run on any environment, as long as there is an interpreter available.

It can be used to create user-written apps. An UI can be made available to enable making programs easier for kids or non-programmers.

Desktop, web or mobile - nowhere the boundary lies.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment