Giter Site home page Giter Site logo

snow-lang's Introduction

Syntax Examples

The semicolon(;) is optional like JavaScript.

1. Declare and Assignment

let a = 1;
a = 2;
let str = "Hello, Snow";
let bool = true;

2. Loop with for

let sum = 0;

for (let i = 0; i < 50; i = i + 1) {
    sum = sum + i;
}

3. Condition

let a = true;
let b = 0;

if (a) {
    b = 1;
} else {
    b = 2;
}

4. Function

fn add(x, y) {
    // `return` is optional
  x + y
}

add(1, 2);

fn fibonacci(num) {
    // `bracket` is optional 
    if num < 2 {
        return num
    } else {
        return fibonacci(num - 1) + fibonacci(num - 2)
    }
}

fibonacci(5);

5. Array and Maps

let arr = [1, "2", 3 + 4, 5];
let num = arr[2];
arr[3] = 6;
arr[2] = 1 + 7;

let map = {"name": "Jack", "Age": 24, "Gender": "Male"};
let name = map["name"];
let age = map["age"];
map["age"] = 23;
map["newest_field"] = "I am newest field";

6. Mathematical operations

let a = 1 + 1;
let b = 1 - 1;
let c = 1 * 1;
let d = 1 / 1;
let e = a + b;
let f = b - c;
let g = true;
let h = false;
let i = true == false
let j = 1 < 2;
let k = 1 >= 2;
let l = g == h;
let m = g != h;

7. Built-in Functions

let str = "Hello, Snow!";
let arr = [1, 1, 1, 0];
let map = {"Name": "Snow", "Age": 27, "Gender": "Femal"};

len(str); // 13
len(arr); // 4
head(str); // "H"
head(arr); // 1
tail(str); // "!"
tail(arr); // 0
rest(str); // "ello, Snow"
rest(arr); // [1, 1]
push(str, "!"); // "ello, Snow!"
push(arr, 1); // [1, 1, 1]
print(str, "world"); // "ello, Snow!"\n"world"
print(arr) // [1, 1, 1]
timestamp() // milliseconds since '1970-01-01 00:00:00 UTC'

Why named 'Snow Lang'?

It' simple and crystal, Snow is the homonym of snowflakes in Chinese(雪花), and the 雪花 is homophonic for my girlfriend's name in Chinese.

Can I use Snow Lang for production?

Of course not. Snow Lang is just toy and I learn the compilers principle through it.

Roadmap

Finished:

  • Lexing and defining tokens.
  • Simple REPL.
  • Parsing let statements.
  • Parsing return statements.
  • Parsing expressions.
  • Parsing grouped expressions.
  • Parsing Boolean
  • Parsing block statements.
  • Parsing if / if else statements.
  • Parsing fn literal.
  • Parsing function calling expression.
  • Read parse print loop.
  • Evaluation.
    • Integer evaluation.
    • Boolean evaluation.
    • Bang(!) operator evaluation.
    • if statements evaluation.
    • Error handling.
    • Environment & Bindings.
    • Functions & Functions calling.

WIP:

  • Interpreter Extending.
    • Strings
    • Built-in Function: len()
    • Array
      • Parsing array literal
      • Support index operation
      • Evaluating array literals
    • Maps
    • Built-in Function: head()
    • Built-in Function: tail()
    • Built-in Function: rest()
    • Built-in Function: push()
    • Built-in Function: print()
    • Built-in Function: timestamp()
  • Makefile build script.
  • Evaluation codes from *.snow files.
  • Releasing CI/CD scripts.

Yeah, Long way to go. :)

Reference

snow-lang's People

Contributors

yai-dev avatar kochamcie avatar

Stargazers

 avatar  avatar lll1412 avatar gotkx avatar  avatar  avatar

Watchers

 avatar

Forkers

kochamcie

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.