GithubHelp home page GithubHelp logo

tariqs26 / st Goto Github PK

View Code? Open in Web Editor NEW
0.0 1.0 0.0 32 KB

Interpreted language with a javascript-like syntax and some overlapping features from Python

License: MIT License

TypeScript 100.00%
ast lexer parser programming-language interpreter scope repl

st's Introduction

st-programming-language

An interpreted language with a javascript-like syntax and some overlapping features from Python, written in Typescript. Features a lexer, ast, parser, and interpreter, with a repl and file runner.

Table of Contents

Syntax and Features

Data Types

  • Number 3, 3.14
  • String "Hello, World!"
  • Boolean true, false
  • Null null
  • Array [1, 2, 3]
  • Object { key: "value" }

Expressions

Unary

  • Logical !
  • Negation -

Binary

  • Multiplicative (\*, /, //, %)
  • Additive (+, -)
  • Relational (==, !=, <, <=, >, >=)
  • Logical (&&, ||)

Assignment

x = 3

Member Access

Computed
foo[0]
foo[3 + 4]
foo["bar"]
Object With Identifier
foo.bar
Type Specific Built-in Properties
const foo = []

foo.length
foo.push(3)

Function Call

add(3, 4)

Statements

Variable Declaration

const foo = 3
let bar = "Hello, World!"

Control Flow

limited to if-else for now, parentheses are optional

if 3 > 2 {
  print("3 is greater than 2")
} else {
  print("3 is equal to 2")
}

Loops

While
let i = 0

while i < 10 {
  print(i)
  i = i + 1
}

Function Declaration

Function declarations support both closures and recursion.

fn fib(n) {
  if n <= 1 {
    return n
  }

  return fib(n - 1) + fib(n - 2)
}

Comments

# this is a comment

Native Functions

print("Hello, World!")

const name = input("What is your name?")

random()
random(1, 10)

typeof(3)

Installation

bun install

Available Scripts

Command Description Example
bun run repl Run the repl
bun file <file> Run a file bun file program.st

Usage

Example file program.st:

fn add(a, b) {
  let sum = a + b
  return sum
}

const result = add(3, 4)

const foo = {
  result: result / 3,
  add,
  isBar: 1 > 2 || 3 < 4,
}

let key = "isBar"

if foo[key] == "isBar" {
  print("foo is bar")
} else {
  print("foo is not bar")
}

print(foo.result)
print(foo.add(3, 4))

fn counter() {
  let count = 0
  fn increment() {
    count = count + 1
    return count
  }

  return increment
}

let increment = counter()

while increment() < 10 {
  print(increment())
}

Run file: bun file program.st

Todo

  • Fix binary operators and unary for different types
  • Control Flow (elif)
  • Update expression (++, --) postfix/prefix
  • Better Error Messages with Line Numbers and Context
  • Error Handling (try-catch, throw)

Contributing

  1. Fork the Project
  2. Create your Feature Branch (git checkout -b feature/AmazingFeature)
  3. Commit your Changes (git commit -m 'Add some AmazingFeature')
  4. Push to the Branch (git push origin feature/AmazingFeature)
  5. Open a Pull Request

License

Distributed under the MIT License. See LICENSE for more information.

Acknowledgements

st's People

Contributors

tariqs26 avatar

Watchers

 avatar

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.