A single file, dependency free language written in python. The goal of this project is to show that programming languages are not a black box and that you could learn the basic concpets required to implement your own language. While this language is not a real programming language however a lot of the internal concepts displayed in this language is taken from other real programming languages.
how to Run
python -m pjscript <file.js>
#or you could use the lexer, parser and interpreter in your python file
from pjcript import *
lexer = Lexer("var x = 1;")
tree = Parser(lexer)
interpreter = Interpreter(tree)
interpreter.interpret()
Data types:
- Int (positive & negitive)
- String
- Array
- Object
- Null
Basic statemnets
/* this is a comment */
var age = 2;
var name = "jack";
var newage = age;
name = "jack and me";
log(1, "it's working fuck yea", name);
var x = add(age, add(2,3));
log(x);
Functions and Scope
var x = "hello world";
function printme(st1, st2, st3){
log(st1);
log(st2);
log(st3);
};
function testfunc(){
var x = "new thing";
printme(x, 1, 3);
};
testfunc();
log(x);
Expressions
var x = 0 + add(2, 3);
var x = x + add(2, 3);
var x = (x * 2) / 2;
log(x); /* should log 10*/
function Mul(){
return add(2, add(2 * 3, 2));
};
var result = Mul();
log(result);
/* post-increment and decrement */
var x = 2;
log("x: ", x);
var y = x++ * 2;
log("y: ", y); /* output y: 4 */
log("x: ", x); /* output y: 3 */
/* pre-increment and decrement */
var x = 2;
log("x: ", x);
var y = ++x * 2;
log("y: ", y);/* output y: 6 */
log("x: ", x);/* output y: 3 */
/* Comparison Operators */
var x = 2;
var y = x >= 2;
log("y: ", y); /* True */
log("x: ", x); /* 2 */
For Loops
for(var i = 0; i < 5; i++){
log(i);
};
/* or */
var i = 0;
for(i = 2; i < 5; i++){
log(i);
};
/* infinite loop */
var i = 0;
for(; ; i++){
log(i);
};
IF ELSE
var x = 0;
if(x == 3){
log("if");
} else if(x == 2){
log("else if");
} else if (x == 1){
log("else if second");
}else{
log("else");
};
var y = 2;
if (x == 2){
log("if only");
};
for(var i = 0; i < 5; i++){
if(i == 3){
log(i);
};
};
Array
// numbers
var numbers = [1, 2, 3];
log(numbers);
log(numbers[2]);
// Strings
var person = ["jack", "jay", "nick"];
for(var i = 0; i < 3; i++){
log(person[i]);
};
Object
// Object
var person = {
name: "jack",
age: 23
};
log(person.name);
log(person.age);
Release files for pjscript 0.0.4
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| pjscript-0.0.4.tar.gz | 13.1 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| pjscript-0.0.4-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 26.2 kB
Release files / pjscript-0.0.4.tar.gz
| Download URL | pjscript-0.0.4.tar.gz |
|---|---|
| Size | 13.1 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
7ee381cf1311eb6ee1cd98dc8ca596352904306a1ee92a8e9eacc89c6c4349bf
|
|
BLAKE2b-256 checksum How to use checksums |
39c64562ed1459f6c4c8c891ee9cc6ec3abad7ccf7a55fdeb05f07e270a37370
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/3.2.0 pkginfo/1.5.0.1 requests/2.24.0 setuptools/49.3.1 requests-toolbelt/0.9.1 tqdm/4.48.2 CPython/3.8.2
|
Release files / pjscript-0.0.4-py3-none-any.whl
| Download URL | pjscript-0.0.4-py3-none-any.whl |
|---|---|
| Size | 13.1 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
3d830053f58ee41201ee17a67a3cda787c62b4e4ae8f6d0ba7b7862b6795e28b
|
|
BLAKE2b-256 checksum How to use checksums |
a55c422d7a54e8885da474614e6b198a8c2f4804ac4e18e536790fabb0758103
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/3.2.0 pkginfo/1.5.0.1 requests/2.24.0 setuptools/49.3.1 requests-toolbelt/0.9.1 tqdm/4.48.2 CPython/3.8.2
|