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

53 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

ST Language

An interpreted language with a JavaScript-like syntax, written in Typescript. It features a lexer, ast, parser, interpreter, 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 PI = 3
let bar = "Hello, World!"

Control Flow

If-Else

limited to if-else for now, parentheses are optional

if 3 > 2 {
  print("3 is greater than 2")
} else {
  print("foo")
}
For Loop
for let i = 0; i < 10; i = i + 1 {
  print(i)
}
While Loop
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

Ensure you have Bun (v1.1.x or higher) installed.

bun install

Available Scripts

Command Description
bun lint Lint
bun test Test
bun run repl Run the REPL
bun file <file> Run a file

Usage

Example file program.st:

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

let result = add(3, 4)

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

if foo["is" + "Bar"] {
  print("foo is bar")
} else {
  print("foo is not bar")
}

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

for let i = 0; i < 10; i = i + 1 {
  print(i)
}

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

const increment = counter()

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

Run file: bun file program.st

Roadmap

  • Control Flow (elif)
  • Update expressions (++, --) postfix/prefix and (+=, -=, ...)
  • Error handling (try-catch, throw)
  • Better error messages with line numbers, context, etc.
  • OOP
  • Types
  • Standard library
  • Modules
  • Improve REPL, add history, autocomplete, etc.
  • Syntax highlighting (VSCode extension)
  • Rewrite in Rust

Contributing

  1. Fork the project
  2. Create your feature branch (git checkout -b fix/tokenizer-number-parsing)
  3. Commit your changes (git commit -m 'fix: parsing numbers')
  4. Push to the branch (git push origin fix/tokenizer)
  5. Open a PR

License

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

Acknowledgements

Releases

No releases published

Packages

No packages published