0

GoatLang

A programming language for the bests.

GoatLang is a programming language for the bests. It is a simple language that is easy to learn and use.

This is a work in progress, the language is not ready yet.

Syntax

include "goat/operations.goat"
include "goat/conditions.goat"
include "goat/blueprint.goat"
include "goat/parser.goat"
include "goat/scope.goat"
include "goat/loop.goat"
 
decl Rabbit(name: str, children_count: int = 0)
 
    func greet(self) print("Hello, my name is: " + name) end
    func is_parent(self) self.children_count > 0 end
end
 
let dad Rabbit("Steven", 3) end
let child1 Rabbit("Mark") end
 
func get_rabbit_name()
    dad.name
end
 
print("Dad's name is: " get_rabbit_name())
 
if dad.is_parent()
    print("Dad is a parent with " + dad.children_count + " children")
else
    print("Dad has no children")
end

Features

It is a both dynamically and staticly typed language like python, which means that you don't have to specify the type of a variable when you declare it.

let name = "Steven" end
let age = 20 end
let is_goat = true end

It is a scripting language, here is the simple calculator example:

let a = 20 end
let b = 10 end
 
print(a + b) -- 30 
print(a - b) -- 10
print(a * b) -- 200
print(a / b) -- 2

It can also be used as an object oriented language, here is the simple class example:

decl Human(name: str)
 
    func greet(self) print("Hello, my name is: " + name) end
end

It can also be used as a functional language, here is the simple function example:

func add(a: int, b: int)
    a + b
end
 
add(10, 20)

GoatLang has portals, which are protocols that can be used to communicate with other languages (only python for now). Here is the simple portal example:

include "random" with "python"
 
random.randint(0, 10)

Most of languages have conditions, and GoatLang is not an exception. Here is the simple condition example:

let condition = true end
 
if condition
    print("Condition is true")
else
    print("Condition is false")
end

In GoatLang, conditions are expressions, which means that you can assign them to a variable.

let message if 10 > 20
    "10 is greater than 20"
else if 10 < 20
    "10 is less than 20"
else
    "10 is equal to 20"
end
 
print(message)
Loops

4 (For) Keyword indicates the start of a loop:

4 let i 1 end, i < 4, let i i + 1 end
  print(i > 4)
end
-- false
-- false
-- false
Scopes

GoatLang can differentiate between scopes:

func print_two()
  let one 1 end
  print(one + 1)
end
 
let one 9999 end
print(one) -- 9999
print_two() -- 2
 
-- testing global and local scope
print(one) -- 9999
Blueprints

GoatLang classes are called blueprints:

decl Proxy(val: str | Proxy) do
        let self.val val end
    end
end
 
let p Proxy("5") end
let pp Proxy(p) end
let ppp Proxy(pp) end
 
print(ppp.val.val) -- 5

For Developers

GoatLang is interpreted by the python for now, so you need to have python installed on your machine to run it. You can run the language by typing the following command in the terminal:

python goat.py $file_name
Parser Implementation Details

Our parser can parse the following code:

-- results of 8
print(add(3, 5))
print(add(sub(8, 5), 5))
print(add(sub(8, 5), div(25, 5)))
print(add(sub(8, 5), mul(div(25, 5), 1)))
 
print(div(
-- comment
  mul(add(3, 5,)
                , -2 + -5,), 25 * 100
                  --     ^ trailing comma
          -- ^ trailing comma
    ,
--  ^ trailing comma
))
 

Roadmap

We are planning to remove python dependency and make the language compiled instead of interpreted. We are planned to use LLVM as the compiler backend. We are also planning to add a package manager for the language.