8000 GitHub - radeqq007/Sunbird: An interpreter for the Sunbird programming language.
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

radeqq007/Sunbird

Repository files navigation

Sunbird

The Sunbird programming language

Build Tests License: MIT Repo size

Sunbird is a simple, interpreted, dynamically typed language.

Documentation

Comments

Single line comments start with // and continue to the end of the line.

// This is a single line comment

Block comments are enclosed within /* ... */ and can span multiple lines.

/*
This comment
spans multiple
lines
*/

Declaring variables

In Sunbird you declare variables using the var keyword:

var foo = "Hello, World!"

Data types

Sunbird supports all the basic data types:

var str = "hello!" // string
var int = 10 // integer
var float = 3.14 // float
var bool = true // booleans
var foo = null // null

Arrays

Arrays are an ordered list of elements of possibly different types identified by a number index. Each element in an array can be accessed individually by their index. Arrays are constructed as a comma separated list of elements, can contain any type of value, and are enclosed by square brackets:

var arr = [1, "sunbird", 10, 2.2]

To get a value from an array you use the bracket notation:

arr[0]

Negative indices can be used to access elements from the end of the array:

arr[-1] // Returns the last element from the array

Functions

Functions in Sunbird are defined using the func keyword:

var add = func(a, b) {
  return a + b
}

You can also skip the return:

var add = func(a, b) {
  a + b
}

Functions can be called like this:

var result = add(10, 5) // 15

Conditional statements

Sunbird supports if, else if, and else statements:

var x = 5
var y = 10

if x > y {
    println("x is greater than y")
} else if x == y {
    println("x is equal to y")
} else {
    println("x is less than y")
}

For loops

A for loop is used to execute a block of code multiple times.

  for i = 0; i < 10; i = i + 1 {
    println("This code will run 10 times")
  }

Pipe operator

Embedded function calls can get messsy and hard to follow. For example:

var result = foo(bar(baz(another_func(data))))

in that case you can use the pipe operator:

var result = data |> another_func |> baz |> bar |> foo

Note: documentation is work in progress

About

An interpreter for the Sunbird programming language.

Topics

Resources

License

Code of conduct

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

0