Zenith is a programming language (and transpiler) designed for "physics-oriented development". It currently targets JavaScript as its output language.
The goal of Zenith is to provide a highly readable, prose-like syntax for defining constants and variables, making it well-suited for configuration, descriptions, or educational purposes.
- Transpilation to JavaScript: Compiles Zenith code directly to executable JavaScript.
- Readable Syntax: Focuses on natural language constructs.
- Physics-Oriented: (Conceptual) Designed with physics definitions and constants in mind.
- Identifier String Literals: Unquoted sequences of identifiers are treated as strings, allowing for clean text definitions.
Clone the repository and build the project using sbt:
git clone <repository-url>
cd zenith
sbt assemblyThis will produce an executable JAR file in target/scala-3.3.6/zenith.jar.
You can run the Zenith compiler using the generated JAR file:
java -jar target/scala-3.3.6/zenith.jar [options] <input-file>| Option | Description |
|---|---|
<input-file> |
The source file to compile. |
-o <file>, --output <file> |
Specify the output file path. |
--verbose |
Enable verbose logging. |
--show-ast |
Print the Abstract Syntax Tree (AST) to the console. |
--show-analysis |
Print the semantic analysis results to the console. |
--target <lang> |
Set the target language (default: js). |
Create a file named physics.zenith:
gravity is integer = 10 but constant
message = Hello World
velocity = 25 but mutable
Run the compiler:
java -jar target/scala-3.3.6/zenith.jar physics.zenith -o physics.jsThe output physics.js will contain the equivalent JavaScript code.
Zenith uses a declarative syntax for variables and constants.
Format:
<identifier> [is <type>] = <value> [but constant|mutable]
- Default Mutability: Variables are mutable by default if
but constantis not specified. - Types: Optional explicit type definition (
integer,string).
Examples:
# Constant integer
g = 10 but constant
# Mutable variable (type inferred)
speed = 100
# Explicit mutable
force = 50 but mutable
# Explicit float
pi is float = 3.14159
val is decimal = 10.5
Print statements provide a declarative way to output values during simulations, ideal for debugging and logging physics calculations.
Syntax:
print <expression>
String Interpolation:
Zenith supports string interpolation in print statements, allowing you to embed variables and expressions directly within strings:
- Simple variable injection: Use
$variableto inject a variable's value - Expression injection: Use
$(expression)to inject the result of an expression
Examples:
velocity = 100
altitude = 1000
# Simple string interpolation
print "Velocity is $velocity"
print "Altitude is $altitude"
# Expression interpolation
print "Sum is $(velocity plus altitude)"
print "Double velocity: $(velocity times 2)"
# Traditional separate prints (still supported)
print "Velocity is"
print velocity
print "Altitude is"
print altitude
# Print expressions
force = mass times g
print force
Generated JavaScript:
// String interpolation uses template literals
console.log(`Velocity is ${velocity}`);
console.log(`Sum is ${(velocity + altitude)}`);
// Traditional prints
console.log("Velocity is");
console.log(velocity);Zenith supports verbose, readable arithmetic operators that make physics equations more intuitive.
Binary Operators:
| Operator | Syntax | Example | JavaScript |
|---|---|---|---|
| Addition | plus, added to |
a plus b, a added to b |
a + b |
| Subtraction | minus, less |
a minus b, a less b |
a - b |
| Multiplication | times, multiplied by |
a times b, a multiplied by b |
a * b |
| Division | divided by, over |
a divided by b, a over b |
a / b |
| Floor Division | floor divided by |
a floor divided by b |
Math.floor(a / b) |
| Modulo | modulo |
a modulo b |
a % b |
| Power | to the power, raised to |
a raised to b |
a ** b |
| Squared | squared |
a squared |
a ** 2 |
Unary Operators:
| Operator | Syntax | Example | JavaScript |
|---|---|---|---|
| Negation | negative, minus |
negative a |
-a |
| Square Root | square root of |
square root of a |
Math.sqrt(a) |
Examples:
# Physics calculations with readable operators
mass = 10
velocity = 20
# Kinetic energy: KE = (m * v²) / 2
kinetic_energy = mass times velocity squared divided by 2
# Force calculation
acceleration = 5
force = mass times acceleration
# Complex expressions with precedence
result = 2 added to 3 times 4 # Result: 14 (3*4 + 2)
result2 = (2 added to 3) times 4 # Result: 20
# Floor division for integer results
quotient = 10 floor divided by 3 # Result: 3
# Modulo operation
remainder = 10 modulo 3 # Result: 1
# Square root
distance = square root of 64 # Result: 8
# Negative values
temp = negative 5 # Result: -5
integer: Whole numbers.float(ordecimal): Floating-point numbers.string: Text.
- Integers: Standard numeric literals (e.g.,
42). - Floats: Decimal literals (e.g.,
3.14,0.001). - Strings (Quoted): Standard string literals (e.g.,
"Hello"). - Strings (Unquoted): A sequence of identifiers is automatically treated as a space-separated string.
greeting = Welcome to the simulation # Becomes string "Welcome to the simulation"
Zenith supports prose-like arithmetic operators that read like physics equations, using words instead of symbols for enhanced clarity.
Basic Operations:
-
Addition:
plus,added tototal = force plus friction result = 5 added to 3 # String Concatenation greeting = "Hello" plus " World" msg = "Value is " added to 42 -
Subtraction:
minus,lessnet_force = thrust minus drag difference = 10 less 2 -
Multiplication:
times,multiplied byarea = width times height product = mass multiplied by acceleration -
Division:
divided by,overspeed = distance divided by time ratio = numerator over denominator -
Modulus:
moduloremainder = value modulo 360 -
Power:
to the power,raised to,squaredarea = radius to the power 2 volume = side raised to 3 kinetic = mass times velocity squared
Advanced Operations:
-
Floor Division:
floor divided by(returns integer result)quotient = 10 floor divided by 3 # Results in Math.floor(10 / 3) -
Square Root:
square root of(unary prefix)distance = square root of sum -
Negation:
negative,minus(unary prefix)opposite = negative velocity inverted = minus 5
Precedence and Grouping:
Operators follow standard mathematical precedence: Power > Multiplication/Division > Addition/Subtraction. Use parentheses for explicit grouping:
# Precedence example
result = 2 added to 3 times 4 # Evaluates as 2 + (3 * 4) = 14
# Grouping with parentheses
result = (2 added to 3) times 4 # Evaluates as (2 + 3) * 4 = 20
# Complex physics equation
kinetic_energy = mass times velocity squared divided by 2
period = two times pi times square root of (length over gravity)
Zenith provides two distinct syntaxes for conditional logic: a standard "programmatic" style and a "physics-flavored" style.
Use if ... then do ... end blocks for standard conditional logic.
if velocity greater 10 then do
print "Slow down"
end if
else do
print "Cruising"
end else
Use when ... holds do ... end blocks for a more declarative, physics-oriented feel.
when mass greater 0 holds do
force = gravity times mass
end when
otherwise do
force = 0
end otherwise
Comparison Operators:
| Operator | Syntax | JavaScript |
|---|---|---|
| Greater Than | greater |
> |
| Less Than | less |
< |
| Equal To | is (context dependent) or equal (future) |
=== |
Note: Currently greater is the primary exposed comparison operator.
# Physics simulation with print statements
g = 10 but constant
mass = 50
velocity = 100
# Calculate kinetic energy
kinetic = mass times velocity squared divided by 2
# Print results
print "Physics Simulation"
print "Mass:"
print mass
print "Velocity:"
print velocity
print "Kinetic Energy:"
print kinetic
# Force calculation
acceleration = 5
force = mass times acceleration
print "Force (F = ma):"
print force
Copyright (C) 2025 abh80. This project is licensed under the GNU General Public License v3.0. See LICENSE for details.