Skip to main content

A custom programming language jxlang

Project description

JxLang 0.3.1

A lightweight custom programming language designed for simplicity and interactive scripting. Built with Python, jxlang provides a REPL environment and supports basic programming constructs, including variables, loops, functions, and library imports.

Installation

Install jxlang via PyPI:

pip install jxlang

Update Content

  • Added function definition and calling capabilities
  • Implemented multi-line code input support
  • Enhanced Python library import with alias support
  • Optimized string definition and list operations
  • Improved underlying code logic and performance
  • Added support for '.jl' code file execution

Features

  • Single-Line Comments: # stands for single-line comments.
  • Variable Declaration: Use let to declare variables.
  • Loops: for loops with range-based iteration.
  • I/O Operations: enter() for input, say() for output.
  • Library Imports: Import Python libraries via cite with optional aliases.
  • List/Table Structures: Create and manipulate lists (table(...)).
  • Function Support: Define and call custom functions.
  • Multi-line Input: Support for multi-line code input in REPL.
  • Exit Session: endend() for exiting current session.
  • REPL Support: Interactive shell for quick testing.

Quick Examples

1. Variable Declaration and Printing

let x: 5
say(x + 3)  # Output: 8
# You can use double quotation marks or single quotation marks when assigning strings to variable names
let a: "hello"
say(a)      # hello
let a: 'hello'
say(a)      # hello

2. Loop

(i -> 1 && 5).for(
    say(i)
    )
# Output: 1 2 3 4 5

3. Function Definition and Calling

func(x && y -> add):
    out x + y

say(add(5, 3))  # Output: 8

# Multi-line function definition
func(x && y -> calculate):
    let temp: x * 2
    out temp + y

say(calculate(3, 4))  # Output: 10

4. Input and Output

let name: enter()  # User enters "Alice"
say("Hello, " + name)  # Output: Hello, Alice

5. Import Python Libraries with Aliases

cite math as m
say(m.sqrt(25))  # Output: 5.0

cite numpy as np
let a: np.array([1,2,3])
say(a)          # Output: [1,2,3]

# Import specific module with alias
cite pandas as pd
let df: pd.DataFrame({'A': [1,2,3]})
say(df)         # Output: DataFrame with column A

# Data visualization with matplotlib
cite matplotlib.pyplot as plt
let x: np.linspace(0, 10, 100)
let y: np.sin(x)
plt.plot(x, y)
plt.title("Sine Wave")
plt.show()      # Displays the plot

* JxLang can call Python Libraries only if they are installed in your Python environment.

6. List and Table Operations

let lst: table(1, 2, 3)
say(lst[0])       # Output: 1
say(lst)          # Output: [1,2,3]

let tbl: table(1, 2; 3, 4)
say(tbl)          # Output: [[1, 2], [3, 4]]

# List manipulation
push 1 -> lst     # Add 1 to the end of the list
say(lst)          # [1,2,3,1]

push tbl -> lst
say(lst)          # [1,2,3,1,[[1,2],[3,4]]]

out 1 -> lst      # Remove first occurrence of 1 and store in outlist
say(lst)          # [2,3,[[1,2],[3,4]]]
say(lst.outlist)  # [1,1]

throw 2 -> lst    # Permanently remove 2 from the list
say(lst)          # [3,[[1,2],[3,4]]]

let lst[0]: 2     # Replace element at index 0 with 2
say(lst)          # [2,[[1,2],[3,4]]]

* JxLang creates n+1 dimensional lists using n semicolons as separators.

Using the REPL

Start the interactive environment by running:

jxlang

Example REPL session with multi-line input:

jxlang> func(x && y -> add):
    ... out x + y
    ... 
jxlang> say(add(5, 3))
8
jxlang> endend(0)  # you can use numbers from 0 to 9 for endend()
Exiting with code 0

Contributing

Contributions are welcome! Please fork the repository and submit a pull request.
For major changes, open an issue first to discuss your ideas.

License

This project is licensed under the Apache License.


Happy coding! 🚀

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

jxlang-0.3.112.tar.gz (21.5 kB view details)

Uploaded Source

Built Distribution

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

jxlang-0.3.112-py3-none-any.whl (22.1 kB view details)

Uploaded Python 3

File details

Details for the file jxlang-0.3.112.tar.gz.

File metadata

  • Download URL: jxlang-0.3.112.tar.gz
  • Upload date:
  • Size: 21.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.8.20

File hashes

Hashes for jxlang-0.3.112.tar.gz
Algorithm Hash digest
SHA256 fb227325596fc29ac497542901b020b2c73223662007dac2bbc2c0c980fc5520
MD5 83144d0363d573022ec6ad481f9be63c
BLAKE2b-256 ad2778c89c0deeea6f89557f6e0ff1669ad84accd5c410906d7a9ee267180808

See more details on using hashes here.

File details

Details for the file jxlang-0.3.112-py3-none-any.whl.

File metadata

  • Download URL: jxlang-0.3.112-py3-none-any.whl
  • Upload date:
  • Size: 22.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.8.20

File hashes

Hashes for jxlang-0.3.112-py3-none-any.whl
Algorithm Hash digest
SHA256 bb1ffbbf443fdbbdb04b5891adfac803e8839855a3ef388fb55c23cabd869b20
MD5 7e5db946981b5e296556e57e384f3104
BLAKE2b-256 b30b1d99bed55677cc4d1b7365dc2c89927df4586800701ebdf06c62b44a7391

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