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

Method 1: Install via PyPI

pip install jxlang

Method 2: One-Click Installation (Recommended for users without Python)

Click above to download the appropriate installation script for your operating system:

  • Windows: Download install_jxlang.bat
  • macOS: Download install_jxlang_macOS.sh
  • Linux: Download install_jxlang_linux.sh

Then run the script:

  • Windows: Double-click install_jxlang.bat
  • macOS: Open terminal and run:
chmod +x install_jxlang_macOS.sh
./install_jxlang_macOS.sh
  • Linux: Open terminal and run:
chmod +x install_jxlang_linux.sh
./install_jxlang_linux.sh

The script will automatically install Python (if not present) and JxLang.

Update Content

  • Added flexible dynamic struct functionality
  • Enhanced multi-line input display with improved formatting
  • Fixed variable type display issues
  • 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 with improved formatting.
  • Dynamic Structs: Create and manipulate flexible data structures.
  • Type Inspection: Use shape() to inspect variable types.
  • 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.

7. Dynamic Structs and Type Inspection

# Define a struct
struct Person {
    name: string,
    age: int,
    address: string
}

# Create a struct instance
let person: Person {
    name: "John",
    age: 30,
    address: "New York"
}

# Create nested struct
struct Info {
    info: Person
}

let i: Info {
    info: Person {
        name: "John",
        age: 30,
        address: "New York"
    }
}

# Access struct members
say(person->name)      # Output: John
say(person->age)       # Output: 30
say(i->info->name)     # Output: John
say(i->info->age)      # Output: 30

# Dynamically modify struct values
let person->name: 'Mike'
let person->age: 40
say(person->name)     # Output: Mike
say(person->age)      # Output: 40

8. Type Checking

let a: 100
let b: 'Alice'
let c: table(1,2,3)

func (i -> add):
    out i

# Display types
shape(a)    # Output: int
shape(b)    # Output: string
shape(c)    # Output: list
shape(add)  # Output: function

# Other types can be checked using the shape method in the same way

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.126.tar.gz (23.6 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.126-py3-none-any.whl (23.3 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: jxlang-0.3.126.tar.gz
  • Upload date:
  • Size: 23.6 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.126.tar.gz
Algorithm Hash digest
SHA256 2c06d7fd90d3034124cfadf24a727d1018c72ae12322b42e4816ef29ae4a182d
MD5 b05655d032934816322812ec4c469d98
BLAKE2b-256 0c243b136640ea6651d22a8c12209e0e4e02a504af92d830b50300f8b1014716

See more details on using hashes here.

File details

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

File metadata

  • Download URL: jxlang-0.3.126-py3-none-any.whl
  • Upload date:
  • Size: 23.3 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.126-py3-none-any.whl
Algorithm Hash digest
SHA256 2c0814ec33070a860da054c93d0ebccaf06dc9ad9027c9797f8fc91e38947958
MD5 7094353522b5257b9895d514e46c6967
BLAKE2b-256 b4ca84e37d92a374209b4cab1702f5b54795cd8f15c5c49602a19ed5abe449f8

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