DUSL = Dynamic Utility And Scripting Language
(WIP) A simple scripting interpreted language written in C++, meant for utility scripts and other similar scripting needs, not meant for performance critical tasks.
println("Hello World")
print("Hello World\n")
print("Enter your name: ")
name = readLine()
a = "Hello, world" #string
b = 123 #int64
c = 1342.292 #float64
d = [1, 2, 3, "A", "B"] # list
e = {"Key1": "value1", "key2": "value2", 35: 3+5, "sub": {"sub": 1}} # dictionary
# accessing values
list_item = d[0] # gets first item
dict_item = e.key1 # or just e["key1"]
str_val = a[0] # gets first character
fn add(a, b) {
return a + b
}
# Closures
sub = fn(a, b) {
return a - b
}
# Closures can also have names
sub2 = fn withName() {
return "Hello"
}
# Note: All functions return the last element by default same for closures
# we have range its syntax is 0..100 this means 0 to 100
# we can use range for for-loop, like:
for item from 0..10 {
println(item)
}
# or use an iterable object like string and list
value = "Hello world"
for c from value {
# loops over each charcer
println("Character", c)
}
#list
val_list = [3, 4, 5, 6]
result = 0
for item from list {
result = result + item
}
println("result", result)
# note "break" also exist for for-loop and while loop
Extensions lets you add functions to DUSL and let DUSL import call C++ functions. Examples will be added soon
# bubble sort
fn bubbleSort(list) {
n = list.size
swapped = true
while swapped {
swapped = false
i = 0
while i < n - 1 {
if (list[i] > list[i + 1]) {
temp = list[i]
list[i] = list[i + 1]
list[i + 1] = temp
swapped = true
}
i = i + 1
}
}
}
# binary search implementation
# expects a sorted list
fn binarySearch(list, target) {
low = 0
high = list.size - 1
while low <= high {
mid = floor((low + high) / 2)
if (list[mid] == target) {
return mid
}
elseif (list[mid] < target) {
low = mid + 1
}
else {
high = mid - 1
}
}
return -1
}
More on examples directory
mkdir build
cmake -DCMAKE_BUILD_TYPE=Release -S . -B build
cmake --build build --config Release