Skip to content

ll-bat/custom-language

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

35 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Custom Language


Program starts with "PROGRAM" keyword followed by "ID"(program name)

   PROGRAM Part10 { } 

Variable declaration

    var x, y : integer;
    var s    : real; 
    var c    : string;
    var f    : boolean;
    
    var a1   : integer = 5;
    var c, s : string = "same values"
Assignment statements
    x = 1 * 2 + 3 - 4 / 5 * (1 + 2)
    f = true;
    s = 1.5;
    c = "My language"
Boolean expressions
    flag = True and False or !False and (True and False)
    flag = 1 < 2 and 2 > 1 

Function declaration

    function foo(s: STRING) {
        VAR c : STRING;
    }   

Builtin functions

    function foo(s: STRING) {
        ... 
        print(s) 
    
        function bar() {
            return 2;
        }
        
        return bar(); 
    }   
    
    print(foo("bar")); // prints 2

Function call

    foo("Custom" + " " + "language");

If statement

    x = 10 
    if x > 5 
    {
        print("x is greater than 5");
    }
    elif x < 5
    {
        print("x is less than 5")
    }
    else
    {
        print("x equals to 5")
    }

    if true or false
    {
        print("true")
    }
    
    if true and !false
    {
        print("true")
    }

For loop

    for i = 0; i < 10; i = i + 1 {
        for j = 0; j < 10; j = j + 1 {
            for k = 0; k < 10; k = k + 1 {
                print(i * j * k)
            }   
        }       
    }   

Comments

    // This is one line comment 
    
    {{
        This is multi-line comment
    }}

Program snippet

    
PROGRAM Part10
{
    function fib(n: int) {
        if n < 1 {
            return 0;
        }
        elif n < 3 {
            return 1;
        }
        return fib(n - 1) + fib(n - 2);
    }


    for i = 0; i < 10; i = i + 1 {
        print(fib(i));
    }

}

About

Custom Language implemented in Python (for fun)

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages