Code Monkey home page Code Monkey logo

sca-lang's Introduction

Sca Language

Project created during my Master's Degree in Computer Science for the Languages and Compilers class.

(please do not judge the code quality, it was written in 1 week of rush and hurry)


Project Goals

Project a suitable abstract syntax similar to Scala language, and write in Haskell a compiler for the new engineered language.

Sub-Goals

  • Project an Abstract Syntax
  • Type-System
  • Lexer (using Alex)
  • Parser (using Happy)
  • Type-Checker
  • Three-address code (intermediate code generation)

Usage

Type and run from you terminal make demo, it will automatically create a demo. Or simply run ./Compiler filename.sca to compile the source code from filename.sca, there is also a verbose debug mode: ./Compiler -d filename.sca.

Sca language syntax

// Basic Declaration
var k: Boolean = ! true;
var w: Boolean = (1 <= 5) && (true || false); 
var c: Char = 'c';
var c: Int = -1;
var x: Int = 5 + 6;
var y: Int = 5 * 4;
var z: Int = 5 / 4;
var p: *Int = &c;
var kk: *Int = p;
var zza: Float = 5.0;
var zzzz: Int = zza;

// Compound Declaration
var s: Array[Array[Char](2)](2) = Array(Array('a', 'b'), Array('a', 'b'));
var i: Array[Array[Int](2)](2) = Array(Array(1+2,3), Array(5+3/7,1));
var a: Boolean = true;

def proc(valres c: Int, b: Boolean): Int = {
    return (c);
}

// Function Declaration
def func(a: Int, b: Boolean, d: Char, n: Float, l: Boolean, m: Array[Array[Char](2)](2)): Int = {
    // Basic Declaration
    var counter: Int = a;
    var z: Int = proc(counter, b);
    zza = 5;
    counter = a;
    counter += a;
    x = ++x + x;

    // Iteration Statement
    while (b == true) {
        // Function Call
        var z: Int = proc(counter, b);
        break;
        continue;
        proc(counter, b);
    }

    // Selection Statement
    if ((10 >= 8) || (counter > 5)) {
        var counter: Int = 2;
    } else {
        var counter: Int = 4;
    }

    if ((!true) || (counter > 5)) {
        var counter: Int = 2;
    }

    // Left Expression Declaration
    ++counter;
    --counter;

    // Primitive function call
    writeInt(a);

    x = readInt("anything");

    x = ++(++x) + ++x;
    x = ++x + x;
    y-- = x-- - ++x--;
    y-- = x;
    y++;

    s[1][2];
    d = s[1][1];
    s[1][0] = 'a';

    *p = 5;


    for (c <- 1 to 10){
        c = 5;
        if (x>5) {
            x++;
        }
        
        continue;
        break;
    }

    // Try Catch
    try {
        x=5;
    } catch {
        case ex: Exception => {

        }
    }

    // Jump Statement
    return (1+1);
}

def main(): Unit = {
    val z: Int = func(1, true, 'a', 3, false, s);
    return;
}

// Program execution
val run: Unit = main();

License

Do whatever you want to.

sca-lang's People

Contributors

alexprut avatar tommy91 avatar

Stargazers

 avatar

Watchers

 avatar  avatar  avatar

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.