Skip to content
/ st Public

Interpreted language with a JavaScript-like syntax

License

Notifications You must be signed in to change notification settings

tariqs26/st

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

26 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

st-programming-language

An interpreted language with a JavaScript-like syntax, 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 -
  • Positive +

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

For
for let i = 0; i < 10; i = i + 1 {
  print(i)
}
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

Roadmap

  • 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

Releases

No releases published

Packages

No packages published