@selei/dscript v0.1.0
DScript
DScript or DS is an interpreted and strongly typed programming language developed in Node.js.
Table of Contents
Introduction
DScript is being released in version 0.1.0, with support only for declaring, assigning, reassigning and logging variables or primitively typed values.
At the moment it's more of a draft of what I plan for the future, being not only a simple language, but a highly customizable one so that in the future you can integrate it with JavaScript code.
Before version 1.0 we will only post updates that add basic features that every language needs. After the release of version 1.0 I will start working on a way to build functional applications, such as servers and complete websites with just a few lines of code (I'm not talking about low code), and I already have a draft of how I will do this.
This is a project that I'm very excited about, and I'm posting it incomplete, because I want to do it alongside the community, soon I'll be creating a YouTube channel to talk more about this project, so if you're interested in supporting it financially, with ideas, or just want to follow the development, send an email to:
seleimendev@gmail.com
Features
List of features added in version 0.1.0
- Declaration of variables with the keywords: num, str and bool
- Declaration of constants with the keyword: final
- Assigning and reassigning values
- Basic mathematical calculations with +, -, *, / and %
Getting Started
You need to have Node.js and npm installed on your machine to use DScript.
Installation
To install DScript:
npm i -g @selei/dscript
Initialization
To create a DScript project, type in the terminal:
$ ds
You can also use the following commands:
name <string>
- Project name--template, -T <string>
- Define a preset for the project, at the moment there is only "empty".
$ ds name hello-world --template empty
The above command will generate the app.ds and ds.config.json files.
At the moment ds.config.json only stores project information, such as name and version.
Usage
Num
To declare variables, we use: num, str and bool.
The num keyword is used to declare numeric types, either integers or floats.
num age = 10;
Str
The str keyword is used to declare characters and strings.
Strings are defined obligatorily and only with backticks.
str message =
`hello world
`;
Bool
The bool keyword defines boolean types that are represented by the values T (true) and F (false).
bool isDscriptCool = T;
Null
You can assign a null value with the N keyword.
num nullishValue = N;
bool isNull = N;
str noMessage = N;
There is an internal coercion of the keyword N.
In numeric types it represents 0, in booleans the special value F and in strings an empty string.
Internal States
Variables have two internal states: null and valued.
When variables are not assigned values, they enter a null internal state, which is different from the null value assigned using N.
num age;
Trying to use a variable with a null internal state will generate an error, so assign a value to be able to use it.
age = 10;
The null internal state is only used to declare a variable without an initializer, but it is mandatory to set a value to it in order to use it in your code later.
Constants
To declare constants, use the final keyword before defining the variable's type.
Constants cannot have a null internal state or receive the value N.
final str name =
`John Doe
`;
Math Operators
You can also perform addition (+), subtraction (-), multiplication (*), division (/) and modulus (%) calculations.
Print Values
To print the value in the terminal, simply type the value itself or the name of the variable that stores the value.
num age = 20;
age;
// or
10 + 10;
Semicolon
The semicolon at the end of the expression is mandatory.
Code Execution
To run the code, type it into the terminal:
$ ds exec
Creator
The developer of DScript is Victor Seleimend.
License
MIT
2 years ago