@david0dev/nxt-lang
v3.0.2
Published
NXT Programming Language - Modern, safe, and powerful. Compiles to JavaScript with type checking, tree-shaking, and 3D game support.
Downloads
943
Maintainers
Readme
NXT Programming Language - Complete Documentation
⚠️ IMPORTANT NOTICE: NXT is currently in early development (v3.0.0) and contains many bugs and stability issues. This compiler is experimental and not recommended for production use. Use at your own risk!
Known Issues & Limitations
🐛 Current Known Bugs:
- Type checking is unstable and may produce false errors
- Backend development may encounter compilation errors
- Complex nested structures sometimes fail to compile
- Error messages are not always accurate
- Some edge cases in variable scoping are not handled properly
- Class inheritance has limited support
- Async/await may not work in all contexts
Recommendations:
- Keep code simple and avoid deeply nested structures
- Test frequently and in small increments
- Disable type checking (
typeCheck: false) for more stable compilation - Report bugs on GitHub: https://github.com/Megamexlevi2
Introduction
NXT is an experimental, statically-typed programming language designed for backend development, AI applications, games, and browser-based projects. It compiles to clean, optimized JavaScript and runs on both Node.js and modern browsers.
Key Features:
- Simplified type system with type aliases (str, num, bool, list, map)
- Flexible variable declarations (supports both syntaxes)
- Built-in null safety mechanisms
- Compiles to Node.js and Browser targets
- Full access to npm packages and Node.js APIs
- Tree shaking and code optimization
- Async/await support
- Pattern matching with else support
- Arrow functions with infinite nesting
- Class-based OOP
Getting Started
Installation
Install NXT globally via npm:
npm install -g @david0dev/nxt-langOr use directly with npx:
npx nxt helpYour First Program
Create hello.nxt:
log("Hello, World!")Run it directly:
nxt run hello.nxtCompile it:
nxt nax hello.nxt
node hello.jsCLI Commands
Run Command
Execute a NXT file directly (compiles and runs in one step):
nxt run <file.nxt>Example:
nxt run app.nxtCompile Command (nax)
Compile a single NXT file to JavaScript:
nxt nax <file.nxt>Options:
-b, --browser- Compile for browser environment-m, --minify- Minify the output code-s, --strict- Enable strict type checking (NOT RECOMMENDED - BUGGY)-o, --output <file>- Specify output file path--no-tree-shake- Disable tree shaking--credits- Add compiler credits to output--obfuscate- Obfuscate runtime code
Examples:
nxt nax app.nxt
nxt nax -b app.nxt
nxt nax -m app.nxt
nxt nax -bm app.nxt
nxt nax -o output/app.js app.nxtBuild Command
Build an entire project using a configuration file:
nxt build <config.json>Example:
nxt build nxt.config.jsonInit Command
Create a nxt.config.json template file:
nxt initThis generates a configuration file with default settings.
Watch Command
Watch a file and recompile on changes:
nxt watch <file.nxt>You can also use the -w flag with compile:
nxt nax -w app.nxtREPL Command
Start an interactive REPL (Read-Eval-Print Loop):
nxt replREPL Commands:
exitorquit- Exit the REPLhelp- Show help messageclear- Clear the screenversion- Show version informationreset- Reset the context
Version Command
Show version information:
nxt versionor
nxt -v
nxt --versionHelp Command
Show help message with all commands:
nxt helpor
nxt -h
nxt --helpLanguage Syntax
Output Functions
NXT supports multiple ways to print output:
log("Hello")
print("Hello")
console.log("Hello")All three work identically and compile to console.log().
Variables and Type Annotations
NXT supports TWO syntax styles for maximum flexibility:
Style 1: Type-first (Classic)
name: str = "Alice"
age: num = 30
isActive: bool = true
items: list<str> = ["a", "b", "c"]Style 2: Variable-first (JavaScript-like)
var name: str = "Alice"
var age: num = 30
var isActive: bool = true
var items: list<str> = ["a", "b", "c"]Both syntaxes work! Choose the one you prefer.
Variable Keywords:
var- Mutable variable (can be reassigned)let- Mutable variable (can be reassigned)const- Immutable constant (cannot be reassigned)init- NXT-specific immutable declaration
Type Aliases (Simplified Syntax):
name: str = "Alice"
age: num = 25
isActive: bool = true
items: list<str> = ["apple", "banana"]
config: map = { key: "value" }
data: any = "can be anything"Type Alias Mapping:
str→stringnum→numberbool→booleanlist→Arraymap→Objectany→anyvoid→void
Primitive Types
integer: num = 42
decimal: num = 3.14
text: str = "Hello"
template: str = `Value: ${integer}`
flag: bool = true
empty = null
undef = undefinedComplex Types
numbers: list<num> = [1, 2, 3, 4, 5]
mixed: list<any> = [1, "text", true, null]
person: map = {
name: "Alice",
age: 30,
email: "[email protected]"
}Functions
Function Declaration
Both syntaxes supported:
Style 1: Return type after parameters
fn greet(name: str): str {
return "Hello, " + name
}
fn add(a: num, b: num): num {
return a + b
}Style 2: More verbose
fn processUser(user: map): void {
log(user.name)
}Arrow Functions
double = (x: num) => x * 2
sum = (a: num, b: num) => {
return a + b
}
fetchData = async (url: str) => {
response = await fetch(url)
return await response.json()
}Async Functions
async fn fetchData(url: str): Promise<map> {
response = await fetch(url)
data = await response.json()
return data
}Control Flow
If Statements
score: num = 85
if score >= 90 {
log("Grade: A")
} else if score >= 80 {
log("Grade: B")
} else {
log("Grade: C")
}Ternary Operator
status: str = age >= 18 ? "adult" : "minor"
max: num = a > b ? a : bHave Operator (Null Safety)
value: any? = getValue()
if value have {
processValue(value)
}
user: map? = getUser()
ifhave user {
log("User exists")
}While Loops
count: num = 0
while count < 5 {
log("Count: " + count)
count = count + 1
}For Loops
for i in 5 {
log("Iteration: " + i)
}
items: list<str> = ["a", "b", "c"]
for item of items {
log(item)
}
for i = 0; i < 10; i = i + 1 {
log(i)
}Match Statements
status: str = "success"
match status {
"pending" -> log("Processing...")
"success" -> log("Complete!")
"error" -> log("Failed")
else -> log("Unknown status")
}Complete Example
Here's a working example showing both syntax styles:
fn getUser(id: num): str {
user = database.getUser(id)
if user have {
return user.name ?? "Guest"
}
return "Guest"
}
name: str = "David"
var count: num = 0
fn greet(user: str): str {
return "Hello, " + user
}
fn main(): void {
log(greet(name))
print("Starting counter...")
while count < 5 {
console.log("Counter: " + count)
count = count + 1
}
log("Done!")
}
main()Error Handling
Try-Catch
try {
data = parseJSON(input)
log(data.value)
} catch err {
log("Error:", err.message)
}Async Error Handling
async fn safeRequest(url: str): Promise<map?> {
try {
response = await fetch(url)
return await response.json()
} catch err {
log("Request failed:", err.message)
return null
}
}Classes
class User {
init(name: str, email: str) {
this.name = name
this.email = email
}
fn greet(): str {
return "Hello, " + this.name
}
}
user = new User("Alice", "[email protected]")
log(user.greet())Import/Export
import { helper } from "./utils"
import defaultExport from "./main"
export fn myFunction(): void {
log("Exported function")
}
export { helper, myFunction }Configuration File
Create nxt.config.json:
{
"input": "./src",
"output": "./dist",
"target": "node",
"minify": false,
"sourceMap": false,
"strict": false,
"typeCheck": false,
"treeShake": true,
"credits": false,
"obfuscateRuntime": false
}Recommended settings:
typeCheck: false- Type checking is buggy, keep it disabledstrict: false- Strict mode causes errorstreeShake: true- Tree shaking works well
Troubleshooting
Common Issues
Compilation errors with backend code:
- Try simplifying your code structure
- Avoid deeply nested functions
- Keep functions short and focused
Type checking errors:
- Set
typeCheck: falsein config - Remove type annotations if causing issues
- Use
anytype for problematic variables
Variables not working:
- Both syntaxes work:
name: str = "value"ORvar name: str = "value" - Make sure you're using one consistently
Functions failing:
- Check that all parameters have types
- Use explicit return types
- Avoid complex async patterns
Getting Help
- GitHub: https://github.com/Megamexlevi2
- NPM Package:
@david0dev/nxt-lang - Issues: Report bugs on GitHub with code examples
Best Practices
Do's ✓
- Keep code simple and straightforward
- Use
log(),print(), orconsole.log()- all work - Test frequently during development
- Use
varfor mutable variables - Disable type checking if you encounter issues
- Use arrow functions for callbacks
Don'ts ✗
- Don't use strict type checking in production
- Avoid complex nested structures
- Don't mix too many async operations
- Avoid very large files (split into modules)
- Don't rely on advanced type features yet
Example Programs
Simple Hello World
fn main(): void {
log("Hello, NXT!")
}
main()Counter Program
var count: num = 0
while count < 10 {
print("Count: " + count)
count = count + 1
}User Greeting
fn greet(name: str): str {
return "Welcome, " + name + "!"
}
var userName: str = "Alice"
log(greet(userName))Version History
v3.0.0 (Current - ALPHA/EXPERIMENTAL)
- ⚠️ Early experimental release with known bugs
- Simplified type system (str, num, bool, list, map)
- Support for both variable declaration syntaxes
- Multiple print functions (log, print, console.log)
- Have operator for null safety
- Match with else support
- Arrow functions support
- Improved compiler (still buggy)
- Type checking disabled by default (unstable)
License
NXT is licensed under the Apache License 2.0.
Naming and Identity Protection:
- The project must always be referred to as "NXT Programming Language"
- Releasing the project under a different name is not permitted
- Forks may add identifiers (e.g., NXT-Extended, NXT-Fork) but cannot remove or replace the NXT name
- NXT is an identity-protected programming language
Note: The term "NXT" may be used by other companies or brands in different contexts. This project refers specifically to the NXT Programming Language, which is independent of any company using the name "NXT".
Support
- GitHub: github.com/Megamexlevi2
- NPM Package:
@david0dev/nxt-lang - Author: David Dev
Contributing
Forks are allowed under the terms of the Apache License 2.0. The project identity must be preserved as specified in the license terms.
Help wanted:
- Bug reports with reproducible examples
- Simple bug fixes
- Documentation improvements
- Example programs
Conclusion
NXT v3.0 is an experimental language with many bugs and limitations. It brings simplified syntax and powerful features but is not production-ready. Use it for learning, experimentation, and simple projects only.
Quick Start Recap:
- Install:
npm install -g @david0dev/nxt-lang - Create file:
hello.nxt - Run:
nxt run hello.nxt - Or compile:
nxt nax hello.nxtthennode hello.js
⚠️ Remember: This is early alpha software. Expect bugs, crashes, and breaking changes!
Start experimenting with NXT today, but don't use it for anything critical!
