0.0.1 • Published 3 years ago

ds-beta v0.0.1

Weekly downloads
-
License
MIT
Repository
github
Last release
3 years ago

DreamScript

DreamScript is an OpenSource superset of JavaScript that compiles to clean JavaScript output.

Build Status Coverage License

NPM

DS Installation

  • Install NodeJs
  • Open your Console
  • Install globally using NPM

npm install -g dreamscript

  • or as a library

npm install --save dreamscript

Get Started

  • Command
~$ dreamscript run <your file or directory file>
atau
~$ ds run <your file or directory file>
atau
~$ ds <your file or directory file>

for help:
~$ ds -h
  • Directory

Example

.
├── code
└── lib
    ├── index.ds
    └── code.ds

$ dreamscript d code lib

this command will compile all files in the lib folder and write the compilation results to the code folder with the same name and the extension js

.
├── code
│   ├── index.js
│   └── code.js
└── lib
    ├── index.ds
    └── code.ds

Example Compile

const ds = require("dreamscript");

var code = `
    func ds(){
        write("hello, world");
    }
    ds();
`;

// compile code
ds.compile(code).then(compiled => {
    console.log(compiled);
});
  • You can see other examples at Example

DreamScript Codes

  • DS Function
func ds(){
    write("hello, earth");
}
ds();
  • If Statement
var me = "jelek";

tulis("sekarang saya " + saya);

jika(saya tidak "ganteng"){
    saya = "ganteng";
}

tulis("sekarang saya " + saya);
  • ulangi
ulangi(var i sebanyak 20 kali){
    tulis(i);
}
  • selama atau while
var i = 10;
selama(i > 0){
    i--;
    tulis(i);
}
  • untuk atau for
untuk(var i = 0;i kurangDari 10;i++){
    tulis(i);
}
  • perulangan dan objek
var a = 1;

untuk(var i = 1;i kurangDari 10;i++){
    a *= i;
    tulis(i);
}

var manusia = {
    nama: "dinda",
    uang: "Rp" + a
}

tulis(manusia.nama + " mempunyai uang sebanyak " + manusia.uang);
  • Math Basic
write(3 + 2 - 12 + 32 * 21 / 2);
  • Input
var name = inp("Whats Your Name: ");
write("hi" + name);
  • Kelas atau class
kelas Mamalia{
    konstruksi(){
        ini.bertulangBelakang = benar
        ini.menyusui = benar
    }
}

kelas Kucing turunan Mamalia{
    konstruksi(){
        // selalu panggil fungsi super() untuk mengunakan variabel induk
        super();
        tulis(ini.menyusui);
    }
}

var neko = buat Kucing();
  • Pyramid
var baris = 5;
var k = 0;
var i = 1;
var j = 1;

selama(i <= baris){
    var hasil = "";
    untuk(j = 1; j <= baris dikurangi i; j++){
        hasil += " ";
    }
    selama(k bukan 2 dikali i dikurangi 1){
        hasil += "*";
        k++;
    }
    tulis(hasil);
    i++;
    k = 0;
}
  • Number
var a = inp("angka a: "); 
var b = inp("angka b: "); 

write(a + b) // "32"

var c = numb(inp("angka c: "));
var d = numb(inp("angka d: ")); 

write(c + d) // 5
  • Teks atau String
tulis(2 + 2); // 4

tulis(Teks(2 + 2)); // "22"

Difference Syntax

DreamScriptJavaScript
func()function()
write()console.log()
type{}class{}
struct()constructor()
inp()~~~

CREDITS