NovaScript-X - A lightweight, modern programming language runtime
Project description
NovaScript-X - A Lightweight Programming Language Runtime
A Python-based interpreter for the NovaScript programming language, designed as a modern, lightweight alternative to Node.js. Write full-stack applications with a unified language runtime.
Package Name: novascript-x
CLI Command: novax
Current Version: 1.0.0
Status: Beta (Core language features complete, web runtime in development)
๐ Quick Start
Installation
Install NovaScript-X globally via pip:
# From PyPI (recommended)
pip install novascript-x
# Or from source (development mode)
cd NovaScript
pip install -e .
After installation, the novax command will be available globally on your system.
Run Your First Program
Create a file called hello.nova:
print("Hello, Nova!")
var name = "World"
print("Welcome to " + name)
Run it:
novax hello.nova
Interactive REPL
Start the interactive interpreter:
novax
Type NovaScript code and see results instantly:
nova> var x = 10
nova> print(x + 5)
15
nova> exit
๐ Language Features
Variables
var name = "Alice"
var age = 25
var pi = 3.14159
Functions
function greet(person):
{
print("Hello, " + person)
}
greet("Bob")
function add(a, b):
{
return a + b
}
var sum = add(3, 5)
Control Flow
# If / Else
if (age >= 18): {
print("Adult")
} else: {
print("Minor")
}
# While loop
var count = 0
while (count < 5): {
print(count)
count = count + 1
}
# For loop
for (var i = 1 : i <= 5 : i = i + 1): {
print("Number: " + i)
}
Operators
- Arithmetic:
+,-,*,/,% - Comparison:
==,!=,<,>,<=,>= - Logical:
and,or,!
Advanced Features
- Recursion
- String concatenation with automatic type coercion
- Comments with
#
๐ ๏ธ CLI Commands
The novax command supports various options:
Run a Script
novax script.nova
Interactive REPL
novax
Watch Mode (Auto-run on Changes)
novax --watch script.nova
# or
novax -w script.nova
Execute Code Inline
novax -c 'print("Hello NovaScript-X")'
Debug Mode
novax --debug script.nova
Show Version
novax --version
# or
novax -v
Display Help
nova --help
# or
nova -h
๐ฆ Standard Library (In Development)
NovaScript includes a standard library for common tasks. Import modules using require():
Available Modules
fs - File System
var fs = require("fs")
# Write to file
fs.writeFile("test.txt", "Hello")
# Read from file
var content = fs.readFile("test.txt")
# Check if file exists
if (fs.fileExists("test.txt")): {
print("File exists")
}
console - Logging
var console = require("console")
console.log("Regular message")
console.warn("Warning!")
console.error("Error occurred")
console.info("Info")
console.debug("Debug message")
math - Mathematics
var math = require("math")
print(math.sqrt(16)) # 4.0
print(math.pow(2, 3)) # 8
print(math.abs(-5)) # 5
print(math.floor(4.7)) # 4
print(math.pi) # 3.14159...
random - Random Numbers
var random = require("random")
var n = random.randInt(1, 100) # Random int 1-100
var f = random.randFloat() # Random 0.0-1.0
date - Date/Time
var date = require("date")
print(date.now()) # Current timestamp
print(date.format("%Y-%m-%d")) # Formatted date
print(date.addDays(5)) # Date 5 days from now
http - HTTP Requests
var http = require("http")
# GET request
var response = http.get("https://api.example.com/data")
# POST request
var result = http.post("https://api.example.com", {key: "value"})
๐ Project Structure
nova/
โโโ __init__.py # Package initialization
โโโ interpreter.py # Core language interpreter
โ โโโ Lexer # Tokenizes source code
โ โโโ Parser # Builds AST
โ โโโ Executor # Executes code
โโโ stdlib/ # Standard library
โโโ fs.py # File system
โโโ console.py # Logging
โโโ math.py # Math functions
โโโ random.py # Random numbers
โโโ date.py # Date/time
โโโ http.py # HTTP requests
nova_cli.py # Command-line interface
setup.py # Installation configuration
examples/ # Example programs
๐ Examples
See the examples/ directory for complete working programs:
- hello_world/ - Basic variables and printing
- functions_loops/ - Functions, loops, recursion, and conditions
Run examples:
nova examples/hello_world/main.nova
nova examples/functions_loops/main.nova
๐ง Features & Roadmap
โ Completed (v1.0)
- Core language interpreter (Lexer, Parser, Executor)
- CLI with argparse support
- Watch mode for development
- Standard library modules (fs, console, math, random, date, http)
- REPL mode
- Cross-platform (Windows, macOS, Linux)
- pip installation support
๐ง In Development
-
require()function for module imports - Web server/HTTP routing support
- Web framework with
nova createscaffold - Server-side rendering
- Hot reloading
๐ Planned (v1.1+)
- Array/List support
- Object/Dictionary support
- Classes and OOP
- Async/await
- Package manager
- Type system
- Testing framework
- Build tools
๐ Tutorial & Documentation
Your First Program
Create script.nova:
# Variables and printing
var greeting = "Welcome to NovaScript"
print(greeting)
# Functions
function multiply(a, b):
{
return a * b
}
# Using the function
var result = multiply(6, 7)
print("6 * 7 = " + result)
# Loops
for (var i = 1 : i <= 3 : i = i + 1): {
print("Iteration " + i)
}
Run it:
nova script.nova
Conditionals
var score = 85
if (score >= 90): {
print("Grade A")
} else: {
if (score >= 80): {
print("Grade B")
} else: {
print("Grade C")
}
}
Recursion
# Calculate factorial
function factorial(n):
{
if (n <= 1): {
return 1
}
return n * factorial(n - 1)
}
print(factorial(5)) # 120
๐ Web Runtime (Coming Soon)
In future versions, run NovaScript as an HTTP server:
# Start web server
nova --serve app.nova
# app.nova
function handleRequest(req, res):
{
res.send("Hello from NovaScript!")
}
๐ Troubleshooting
Command not found: nova
Make sure you installed NovaScript:
pip install -e .
Verify installation:
which nova
nova --version
Import errors
Make sure you're in the correct directory and the nova package is properly installed:
pip install -e .
python -c "import nova; print(nova.__version__)"
File not found
Use absolute paths or relative paths from your current directory:
# Absolute path
nova /full/path/to/script.nova
# Relative path
nova ./scripts/script.nova
๐ License
MIT License - See LICENSE file for details
๐ค Contributing
Contributions are welcome! Please feel free to submit issues and pull requests.
๐ Support
For issues and questions:
- Open an issue on GitHub
- Check documentation in
examples/directory - Review test files in
tests/directory
๐ Acknowledgments
NovaScript is inspired by Node.js, Python, and JavaScript, bringing together the best features of modern runtimes into a lightweight, easy-to-learn language.
Features
- Variables: Declare variables with
var - Functions: Create functions with
functionkeyword andreturnstatements - Print: Output values with
print() - Conditionals:
if/elsestatements with boolean logic - Loops:
whileandforloops - Arithmetic: Full arithmetic operations (+, -, *, /, %)
- String Concatenation: Use
+operator to concatenate strings - Operators: Comparison (==, !=, <, >, <=, >=), logical (and, or), unary (!, -)
Usage
Running a NovaScript File
python nova_interpreter.py program.nova
Interactive REPL Mode
python nova_interpreter.py
Then type NovaScript commands at the nova> prompt. Type exit to quit.
Syntax
Variables
var name = value
var x = 10
var greeting = "Hello"
Functions
function functionName(param1, param2):
{
# Function body
return result
}
Example:
function add(a, b):
{
return a + b
}
var result = add(5, 3)
print("Result: " + result) # Output: Result: 8
Print Statement
print("Hello, World")
print("Value: " + x)
print("Sum: " + (5 + 3))
Conditionals
if (condition): {
# Then body
} else: {
# Else body
}
Example:
var age = 25
if (age >= 18): {
print("Adult")
} else: {
print("Minor")
}
While Loop
while (condition): {
# Loop body
}
Example:
var count = 1
while (count <= 3): {
print("Count: " + count)
count = count + 1
}
For Loop
for (init : condition : update): {
# Loop body
}
Example:
for (var i = 1 : i <= 5 : i = i + 1): {
print("i = " + i)
}
Arithmetic Operators
+: Addition and string concatenation-: Subtraction*: Multiplication/: Division (integer division for integers)%: Modulo
Comparison Operators
==: Equal to!=: Not equal to<: Less than>: Greater than<=: Less than or equal to>=: Greater than or equal to
Logical Operators
and: Logical ANDor: Logical OR!: Logical NOT
Comments
# This is a comment
Interpreter Architecture
The interpreter is modular with three main components:
-
Lexer: Tokenizes NovaScript source code
- Recognizes keywords, operators, literals, and identifiers
- Handles string literals with escape sequences
- Produces a stream of Token objects
-
Parser: Parses tokens into an abstract syntax tree (AST)
- Implements recursive descent parsing with operator precedence
- Produces a list of statement dictionaries
- Handles all NovaScript language constructs
-
Executor: Executes the parsed AST
- Manages global and local scope
- Evaluates expressions and executes statements
- Handles function calls and returns
Example Program
# Variables
var name = "NovaScript"
print("Language: " + name)
# Functions
function greet(person):
{
print("Hello, " + person)
}
greet("World")
# Fibonacci with recursion
function fibonacci(n):
{
if (n <= 1): {
return n
}
return fibonacci(n - 1) + fibonacci(n - 2)
}
print("Fibonacci(7) = " + fibonacci(7))
# Loops
for (var i = 1 : i <= 5 : i = i + 1): {
var square = i * i
print("Square of " + i + " = " + square)
}
# Conditionals
var score = 85
if (score >= 90): {
print("Grade: A")
} else: {
if (score >= 80): {
print("Grade: B")
} else: {
print("Grade: C")
}
}
Project File Structure
Core Interpreter
- nova_interpreter.py (893 lines)
Lexerclass: Tokenizes source code, handles keywords, operators, strings, numbersParserclass: Recursive descent parser, builds abstract syntax tree (AST)Executorclass: Executes AST, manages scopes, evaluates expressions- REPL mode for interactive execution
Web IDE Backend
- server.py (152 lines)
- Flask web server configuration
GET /route: Serves the IDE interface (index.html)POST /api/executeroute: Receives code, executes it, captures output, returns JSONGET /api/highlight-keywordsroute: Returns language keywords for syntax highlighting- Error handling and output capture with
io.StringIO
Web IDE Frontend
-
- CodeMirror 5 editor integration for syntax highlighting
- Dark theme styling
- Output console for displaying results
- Buttons: Run Code (Ctrl+Enter), Clear, Reset
- AJAX communication with Flask backend
-
static/style.css (700+ lines)
- Professional dark theme (GitHub dark mode inspired)
- CSS variables for theming and layout control
- Responsive grid layout (editor + console)
- Terminal-style console output styling
-
static/script.js (300+ lines)
- CodeMirror editor initialization and configuration
- AJAX request/response handling for code execution
- Console message formatting and display
- Event listeners for Run, Clear, Reset buttons
- Keyboard shortcuts (Ctrl+Enter to run)
Configuration Files
- requirements.txt: Python dependencies (Flask==2.3.3, Werkzeug==2.3.7)
- test.nova: Sample NovaScript program for testing
Extending the Interpreter
The modular design makes it easy to add new features:
- Add Keywords: Add to
Lexer.KEYWORDSand create a parse method - Add Operators: Extend the binary/unary operator parsing and evaluation
- Add Data Types: Add new value types to the executor
- Add Built-in Functions: Add to the executor for built-in functions
Limitations
- Requires braces for multi-statement blocks (indentation-based syntax can be added)
- No array/list support yet (can be added)
- No object/dictionary support yet (can be added)
- No file I/O support yet (can be added)
- No module/import system yet (can be added)
Error Handling
The interpreter provides helpful error messages:
- Syntax errors from the lexer and parser
- Runtime errors from the executor
- Type errors for invalid operations
- Name errors for undefined variables/functions
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distributions
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file novascript_x-1.0.0-py3-none-any.whl.
File metadata
- Download URL: novascript_x-1.0.0-py3-none-any.whl
- Upload date:
- Size: 24.8 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.14.3
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
d0f4535f9ba3ab15c1c7c88bc1030ca85837f59189d74ddf462a138187ab6bb4
|
|
| MD5 |
f17e3584bf0bc4a32288bffa8962eb1f
|
|
| BLAKE2b-256 |
d0b00a11984f45590f740c9244ae5ae9c0ebdab45c71ad9f5d69c22b24ebce07
|