Giter Club home page Giter Club logo

staticscript's Introduction

StaticScript

StaticScript is a statically typed programming language, syntactically like TypeScript.

Github Workflow Status Platform License

GitHub Repo stars GitHub forks GitHub issues GitHub pull requests

GitHub Repository Size GitHub code size in bytes GitHub top language

English | 简体中文

Install

Install on Ubuntu

/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/StaticScript/StaticScript/master/install-ubuntu.sh)"

Or

wget https://raw.githubusercontent.com/StaticScript/StaticScript/master/install-ubuntu.sh
sudo chmod +x install-ubuntu.sh
sudo /bin/bash install-ubuntu.sh

For other linux distributions, you may need to modify the installation script to install properly.

The installation script may request administrator privileges.

Install on macOS

/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/StaticScript/StaticScript/master/install-macos.sh)"

Or

wget https://raw.githubusercontent.com/StaticScript/StaticScript/master/install-macos.sh
sudo chmod +x install-macos.sh
sudo /bin/bash install-macos.sh

The installation script may request administrator privileges.

Install on Windows

Temporarily not supported

Usage

First you need to write a legal StaticScript code file as following.

// test.ss

let content: string = "Hello World";

ss_println_string(content);

Then execute the following command from the command line.

staticscript test.ss -o test
./test

Language Features Summary

Variable and Constant Declaration

Here are some variable declarations.

let flag: boolean = true;
let count: number = 20;
let content: string = "Hello World";

Thanks to the type inference feature of StaticScript, we can write the above variable declaration as follows. They are exactly equivalent.

let flag = true;
let count = 20;
let content = "Hello World";

The compiler of StaticScript cleverly deduced the type of the variable from the initial value.

In addition to using let to declare variables, you can also use const to declare constants.

const name = "StaticScript";
const age = 1;
const developing = true;

The difference between let and const is that constants declared with const cannot be modified.

Variable Evaluation

You can use a wealth of operators to perform operations on variables, including arithmetic operations, bitwise operations, logical operations, relational operations, assignments, and string concatenation.

let a = 1;
let b = 2;

// add, subtract, multiply and divide
let sum = a + b;
let diff = a - b;
let product = a * b;
let quotient = a / b;

a = a << 1; // equivalent to `a <<= 1`
b = b >> 1; // equivalent to `b >>= 1`

let year = "2020", month = "08", day = "06";
let birthday = year + "/" + month + "/" + day;

Control Flow

let a = 1;
let b = 100;
if (a < b) {
    ss_println_string("b is bigger");
} else {
    ss_println_string("b is not bigger");
}


let max = a;
if (a < b) {
    max = b;
}

Loops

StaticScript supports using while statement and for statement to do some repetitive things.

// Calculate the sum of all even numbers between [1, 100]
let sum1 = 0;
let i = 1;
while(i <= 100) {
    if (i % 2 == 0) {
        sum1 += i;
    }
}


// Calculate the sum of all integers between [1, 100]
let sum2 = 0;
for(let i = 1; i <= 100; i++) {
    sum2 += i;
}

Function

StaticScript supports defining functions in the top level scope and using function in any scope.

function add(a: number, b: number): number {
    return a + b;
}

The above function can omit the return type because StaticScript can deduce the return type through the expression of the return statement.

It is important to note that the parameter types of functions must be explicitly declared.

staticscript's People

Contributors

apsarasx avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

staticscript's Issues

Add more specific types

Add types like float (float32), double (float64), uint8, int8, uint16, int16, uint32, int32, uint64, and int64?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.