QZ Compiler

QZ Language Specification

Overview

QZ is a scripting language with:

Script files use .qzx
Header/module files use .qzh

Script Files

;hello
log "Hello world"

Header Files

@math
pi:3.14159

Used with:

use "math.qzh"

Program Declaration

;program

Values

Numbers

10
-5
3.14

Strings

"hello"
'hello'
`hello`

Booleans

true
false

Built-in Constants

Constant Value
inf Infinity
nan NaN

Math Constants (from math.qzh)

Constant Value
pi π
tau
e Euler's number
phi Golden ratio
use math.qzh
log pi

Variables

asn x,10
log x

Logging

log "Hello"
log 5+5

Errors

err "Something failed"

Input

ask "Name?",name
log name

Math Operators

Operator Meaning
+ Add
- Subtract
* Multiply
/ Divide
% Modulo
& Bitwise AND
| Bitwise OR
^ Bitwise XOR

Root Operator

log 9 // 2

Outputs:

3

Arrays

asn a,[1,2,3]

log a[0]

asn a[1],50

Length Operator

log length "hello"

Outputs:

5

Functions

asn square,fn n{
ret n*n
}

Function Call

log square 5

Return Values

asn double,fn x{
ret x*2
}

log double 10

Outputs:

20

Conditionals

if x>5{
log "big"
}
or x==5{
log "equal"
}
else{
log "small"
}

Comparison Operators

Operator Meaning
== Loose equal
=== Strict equal
!= Loose not equal
!== Strict not equal
> Greater than
< Less than
>= Greater/equal
<= Less/equal

Loops

repeat

repeat 3{
log "hello"
}

while

asn x,0

while x<5{
log x
inc x,1
}

Increment Commands

Command Effect
inc Add
minc Multiply
einc Exponentiate
ainc Bitwise AND
oinc Bitwise OR
xinc Bitwise XOR

Comments

<<
this is ignored
>>

Console Commands

cl
cl-var x
cl-vars
cl-stack f

Program Termination

tm

Modules

use math.qzh

Built-in Modules

math.qzh

Name Description
ln Natural logarithm
sin Sine
cos Cosine
tan Tangent
abs Absolute value
pi π
tau
e Euler's number

time.qzh

Name Description
time Current timestamp
date Current local date/time

debug.qzh

use debug.qzh
debug

js.qzh

use js.qzh
js "alert('hello')"

browser.qzh

open

open "https://example.com"

rdir

rdir "https://example.com"

Uploaded Headers

use "header.qzh"

Example Program

;demo

use math.qzh

asn square,fn x{
ret x*x
}

asn n,5

if n>3{
log "large"
}

log square n

Expected output:

large
25

Language Characteristics