GithubHelp home page GithubHelp logo

ilyas-kalandar / rita Goto Github PK

View Code? Open in Web Editor NEW
10.0 1.0 1.0 583 KB

Just programming language, created fully from scratch for learning compilers.

CMake 3.15% C++ 96.48% Python 0.37%
compiler computerscience interpreter evalulator

rita's Introduction

Rita - just programming language created from scratch!

Motivation.

Every programmer must write at least one compiler/interpreter, I follow this idea :D

What can Rita?

Currently interpreter can execute this program

fun main(){
    print("LOG: Main function loaded");

    var a = 1;
    var b = -1;
    var c = -20;

    print("LOG: Variables created");

    var d = (b * b) - (4 * a * c);

    print("LOG: Discriminant computed, value is", d.toString(d));

    print("LOG: Checking for D < 0");

    if(d < 0){
        print("No roots.");
        return;
    }

    print("LOG: Checking for D equals to 0");

    if(d == 0){
        print("One root.");
        print("Root", -b / (2 * a));

        return;
    }
    

    var x1 = (-b + sqr(d)) / (2 * a);
    var x2 = (-b - sqr(d)) / (2 * a);

    print("LOG: Roots computed.");

    print("Two roots.");
    print("First root:", x1.toString(x1));
    print("Second root:", x2.toString(x2));
}

main();

Tutorial

Variables

Rita is dynamically typed language, you don't need to provide a typename for creating a variable, just only use var-keyword provide name and value!

var varName = "Hello, Rita!";

Functions

Rita support functions (fully), you can create, call, return values and provide arguments to your functions

// Create function with fun - keyword.

fun functionName(arg){
  anotherFunc(); // call another function.
  print(arg);
  return;
}

If statements.

If statement in Rita is similiar to Rust, if keyword, expression and body.

if a > 0{
  print("Really, a is bigger than 0!");
}

While statements

Rita support while statements, use while-keyword, provide expression and code-block.

var a = 100;

while a > 0 {
    print("working");
    a -= 1;
}

Operators

Yes, you can use operators, priorities in Rita are fully correct.

var a = 2 + 2 * 3; // a equals to 8

Standard-functions

sqr(); // Returns a square root of Int-object.
print(); // Prints string to terminal
input(); // EXPERIMENTAL! Returns a string given from user.

Building

Clone repo

git clone https://github.com/ilyas-kalandar/Rita

Create directory for build & move

cd Rita && mkdir build && cd build

Build

cmake .. && cmake --build .

Running

./rita

Output of ./rita --help

Usage: rita --file filename.rt
--ast - Show ast.
--tokens - Show tokens from tokenizer.
--help - Show this menu.
--version - Output version of language.

TODO

  • - While-loops
  • - Classes
  • - Floats

Author

Created with โ™ฅ by Ilyas Qalandarzoda (Awaitable)

Contacts

I always check my telegram

rita's People

Contributors

icoder-new avatar ilyas-kalandar avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar

Forkers

icoder-new

rita's Issues

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.