Skip to content

Aira is a simple script language based on python3

Notifications You must be signed in to change notification settings

qpalzmqaz123/airapy

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

AIRA

Aira is a simple script language based on python3, it intend to learn how to make a script language.

Installation

$ git clone https://github.com/qpalzmqaz123/aira.git

$ cd aira

$ python3 setup.py install

Usage

Usage: aira [OPTIONS] FILE

Options:
  --debug  Show debug info.
  --help   Show this message and exit.

Examples

hello world

print('hello world')

Variable

a = 1
a = b = '123'

Function

sum = fn(x, y) do
    return x + y
end

print(sum(2, 3))

Branch

a = 1

if a >= 1 do
    print('a >= 1')
else
    print('a < 1')
end

Loop

i = 0
while i < 5 do
    print(i)

    i += 1
end

Exception

a = 0

try do
    a = 1
    throw Error()
catch err do
    a = 2
end

print(a)

Array & Hash

a = [1, 2, 3]
a.insert(0, 0)
a.pop()
print(a)

b = {'a': 1}
b.b = 2
print(b)

Closure

get_counter = fn() do
    cnt = 0

    return fn() do
       return @cnt += 1
    end
end

counter = get_counter()

print(counter())
print(counter())
print(counter())
print(counter())
print(counter())

Fibonacci sequence

n = 10

res = []

sum = fn(index) do
    if index <= 0 do
        throw Error('index must be greater than 0')
    end

    if index == 1 or index == 2 do
        return 1
    end

    return sum(index - 1) + sum(index - 2)
end

i = 1
while i < n + 1 do
    res.push(sum(i))

    i += 1
end

print(res)

About

Aira is a simple script language based on python3

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages