ToyLang
ToyLang is interpreted high-level fully OOP language with Python-like syntax and dynamic typing.
Complex is better than complicated.
As a multi-paradigm language, ToyLang supports object-oriented and imperative programming styles both.
Installation
$ gem install toylang
Usage
Run REPL:
toylang
or run file:
toylang your_code.tlg
Examples of code
println("Hello World")
"Hello World".println
println(2 + 2 ** 5)
def hello(name):
"Hi, " + name + "!"
hello("Max").println
a = 23
b = a + 2
println(b)
Hey = 5
if (2 > 1):
println("Yeah!")
else:
println("Something goes bad!")
if (false):
print("Won't be printed")
Cycles:
a = 0
while (a != 3):
println(a)
a = a + 1
OOP:
class Klass:
def my_method:
true
k = Klass.new
k.my_method.print
class Number:
def ten:
10
1.ten.println
class Number:
def ten:
11
1.ten.println
class Animal:
def is_a_human:
false
def say:
"..."
class Dog < Animal:
def say:
"Bark!"
dog = Dog.new
animal = Animal.new
println(animal.say)
println(dog.say)
println(dog.is_a_human)
Building
Pre-reqs
To build and run this app locally you will need a few things:
- Install Ruby (tested on 2.6);
- Using Racc as parser
Getting start
git clone --depth=1 https://github.com/maxbarsukov/toylang.git
cd toylang
bundle install
./bin/toylang input.tlg
./bin/toylang
bundle exec rspec
bundle exec rubocop
Contributing
Bug reports and pull requests are welcome on GitHub at https://github.com/maxbarsukov/toylang. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the code of conduct.
License
The gem is available as open source under the terms of the MIT License.
Code of Conduct
Everyone interacting in the Toylang project's codebases, issue trackers, chat rooms and mailing lists is expected to follow the code of conduct.