GithubHelp home page GithubHelp logo

xiaocongdong / simple Goto Github PK

View Code? Open in Web Editor NEW
27.0 0.0 4.0 647 KB

Simple is a programming language aims to implement JavaScript Syntax with TypeScript just for fun๐Ÿ‘จโ€๐Ÿณโ€๐Ÿ‘จโ€๐Ÿณโ€๐Ÿ‘จโ€๐Ÿณโ€.

Home Page: https://superseany.com/opensource/simple/build

License: MIT License

TypeScript 99.04% JavaScript 0.96%

simple's Introduction

Simple

Life is short, keep it simple.

Simple is a simple programming language (subset of JavaScript) powered by TypeScript.

Grammar

Data Types

Currently simple support the following data types:

  • number
  • string
  • boolean
  • array
  • object
  • function

Variable Declaration

Using let to declare variable and const to declare constant:

let n = 10; // integer
let b = true; // boolean
let s = "string"; // string value
let f = function(x, y, z) {return x + y * z}; // function
let a = [1, 2, 3, {1, 2, 3}, "hi"]; // array
let o = {
  name: 'sean',
  age: 27
}; // object

Operators

Support almost all of the mathematical and logic operators.

1+1
1-1
1*1
1/1

a+=1
a-=1
a*=1
a/=1

a++
a--

a = 1 + (1 * 2 + 4)/2

a||b
a&&b

Function Declaration

function sum(x, y) {
  return x + y;
};

Lexical Scope

function sumGenerator() {
  let sum = 1;

  function add(number) {
    sum += number;
    return sum;
  };

  return add;
}
const sum = sumGenerator();
for(let i = 0; i < 10; i++) {
  console.log(sum(i));
};

Functional programming:

function invokeCallback(callback) {
  callback()
}

invokeCallback(function () {
  console.log('callback is invoked')
})

Object

let x = {
  a: 1,
  b: {
    c: 'cc'
  }
};
console.log(x.b.c);

Array

let arr = [1, 2, 3, 4];
let length = arr.length - 1;
console.log(arr[0]);
console.log(arr[2]);

If condition

if

let grade = 10;
if (grade >= 90) {
  console.log('you are a good student');
} else if (grade >= 60){
  console.log('you are not that bad');
} else {
  console.log('stop playing computer game!');
};

while

let i = 0;
while(true) {
  console.log('this is a infinite loop');
};

for

for(let i = 0; i < 10; i++) {
  console.log(i);
};

this binding

const person = {
  name: "Hello world",
  sayName: function() {
    console.log(this.name); // "Hello world"

    function inner() {
      console.log(this.name); // undefined
    };

    inner();
  }
};
person.sayName();

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.