Skip to main content

PyHorizon custom language interpreter

Project description

PyHorizon

PyHorizon is a tiny custom programming language written in Python. Program files use the .pyh extension and are executed by pyhori.

Project Structure

  • main.py - command-line entry point. Reads a .pyh file and runs it.
  • lexer.py - converts source code into tokens.
  • parser.py - turns tokens into an abstract syntax tree.
  • ast_nodes.py - AST node definitions.
  • interpreter.py - executes the AST.
  • environment.py - variable scope handling.
  • errors.py - readable lexer, parser, and runtime errors.
  • tokens.py - token data model.
  • example.pyh - sample program in the language.
  • calculator.pyh - interactive calculator app written in PyHorizon.
  • app.pyh - GUI app that opens a window.
  • telegram_send.pyh - Telegram Bot API example.
  • ai_request.pyh - AI HTTP request example with object and list literals.
  • ai_starter.pyh - AI starter template.
  • pyhori_ai.py - machine-readable AI manifest.

Syntax

Supported commands:

  • say "Hello"
  • say Hello world name
  • imp x = 10
  • x = x + 1
  • if x > 5 ... else ... end
  • loop x < 10 ... end
  • func add(a, b) ... end
  • return value
  • # comment

In say, plain words without quotes are treated as text, and variables are inserted automatically. Example:

imp name = Gh
say Hello name

ask reads user input and automatically converts numbers and booleans when possible:

imp value = ask Введи число

Built-ins for bots and AI:

  • http_get(url)
  • http_post(url, body)
  • http_post_headers(url, body, headers_json)
  • json_parse(text)
  • json_stringify(value)
  • sleep(seconds)
  • run_cmd(command)
  • to_text(value)

JSON data can be accessed with brackets:

imp data = json_parse("{\"ok\": true, \"n\": 3}")
imp value = data["n"]
say value

You can build structured payloads directly with object literals instead of concatenating JSON strings:

imp body = {
    chat_id: chat_id
    text: text
}

imp headers = {
    Authorization: "Bearer " + token
}

imp response = http_post_headers(url, body, headers)

Lists work too, so nested JSON like messages: [ { role: "user" content: prompt } ] can be written directly.

If you want the easiest version for typing on a PC keyboard, use obj and list blocks:

imp body = obj
    chat_id chat_id
    text text
end

imp headers = obj
    Authorization "Bearer " + token
end

How It Works

  1. The lexer reads text from a .pyh file and turns it into tokens.
  2. The parser builds a structured tree of statements and expressions.
  3. The interpreter walks that tree and executes the program.

Run

Install

From PyPI:

pip install pyhori

From local source:

pip install .

Windows

pyhori example.pyh

Linux

pyhori example.pyh

Termux

pkg install python
pip install .
pyhori example.pyh

You can also run your own file:

pyhori program.pyh

Run the included app:

pyhori calculator.pyh

Open the GUI app:

pyhori app.pyh

Run the Telegram example:

pyhori telegram_send.pyh

Run the AI example:

pyhori ai_request.pyh

Run the AI starter template:

pyhori ai_starter.pyh

Print the machine-readable AI manifest:

python pyhori_ai.py

Show the version:

pyhori --version

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

pyhori-0.1.5.tar.gz (15.4 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

pyhori-0.1.5-py3-none-any.whl (15.3 kB view details)

Uploaded Python 3

File details

Details for the file pyhori-0.1.5.tar.gz.

File metadata

  • Download URL: pyhori-0.1.5.tar.gz
  • Upload date:
  • Size: 15.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.10.11

File hashes

Hashes for pyhori-0.1.5.tar.gz
Algorithm Hash digest
SHA256 6a2645e19e9c008662c9ebdacea96f66a6430d8118f028490858185e53190eef
MD5 bc93b21f54882c4491bb1fec9b608437
BLAKE2b-256 d64942fb0a09f338578965d555d9ee2e97242b7c6a270c88f4a6bba47f780877

See more details on using hashes here.

File details

Details for the file pyhori-0.1.5-py3-none-any.whl.

File metadata

  • Download URL: pyhori-0.1.5-py3-none-any.whl
  • Upload date:
  • Size: 15.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.10.11

File hashes

Hashes for pyhori-0.1.5-py3-none-any.whl
Algorithm Hash digest
SHA256 c25be6e292d29ef84f1d9e751c8e327ca17a130b334d4eb710cc4e5b6e938e85
MD5 e4c48d9edd606614b36f7729e0dfb189
BLAKE2b-256 bcf231f566602f9142631e02b06d2613904f672495880e5fe98928b2a175d200

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page