quickjs-lang
v1.0.4
Published
Another js-made lang that is lightweight, fast, flexible, and easy to learn
Downloads
8
Readme
QuickJS
A lightweight Quick JavaScript-inspired interpreter with extended features like show cut, delay, case statements, and module imports. Designed for simple scripting with readable syntax and powerful constructs.
Installation
- Clone the repository:
git clone https://github.com/JeckAsChristopher/Quickjs
cd Quickjs- Install dependencies:
npm install readline-sync- Run QuickJS scripts:
node index.js <script>.qjsBasic Syntax
Variables
x = 10;
name = "Alice";- Variables can store numbers or strings.
- Assignment uses
=.
Input
input "Enter a number: "; // stored in default variable 'input'
x = input; // assign to variableinputreads user input.- Optional prompt is displayed.
Show
show x; // prints value
show "Hello, " and name; // concatenate multiple values
show x cut; // print in same line, replace previous output
show x cut 2; // cut last 2 characters/numberscutreplaces previous output in the same line.cut Nremoves last N characters or digits.
Delay
delay 10; // 10 ms
delay 100; // 100 ms
delay 1000; // 1 second- Works well in loops to create pauses between prints.
Loops
While Loop
while x < 10:
show x;
x = x + 1;
endFor Loop
for i = 1 to 10 step 2:
show i;
end- Supports negative steps:
for i = 10 to 1 step -1:
show i cut;
delay 100;
endIf / Else / Else If
if x == 1:
show "One";
else if x == 2:
show "Two";
else:
show "Other";
end- Supports multiple
else ifclauses.
Case Statement
case input:
when 1:
show "One!";
when 2:
show "Two!";
else:
show "Other!";
end- Acts like a switch-case structure.
- Optional
elsefor default case.
Functions
func greet:
show "Hello World!";
end
greet; // call function- Functions defined with
func name:and closed withend. - Supports zero or more statements.
From / Import
from test // load test.qjs
import test // import function `test`
show "Unpacking Package...";
test;fromloads the file and executes it in the current interpreter scope.importregisters functions or variables from the module for later use.
Comments
# This is a comment- Lines starting with
#are ignored.
Binary Operations
x + y
x - y
x * y
x / y
x % y
x == y
x != y
x < y
x <= y
x > y
x >= y- Standard arithmetic and comparison operators.
Example Script
input "Enter a number: ";
case input:
when 1:
show "One!";
when 2:
show "Two!";
else:
show "Other!";
end
func countdown:
for i = input to 1 step -1:
show i cut;
delay 100;
end
show "Done!";
end
countdown;Output (example for input=5):
Enter a number: 5
Other!
54321Done!QuickJS is designed for easy scripting with real-time output updates and is extendable with functions and modules.
Author: Jeck Christopher Anog License: MIT
Note
Some syntax are not working fine properly this is only v1.0 Other syntax will be release soon!
