Git Product home page Git Product logo

compiler's Introduction

Compiler

This repository contains a Rust compiler developed as part of a graduation project. The compiler is currently in development and is designed for creating our own programming language. The main goal of the project is to have fun while exploring compiler construction concepts.

Current Status

We are actively working on building the foundational components of the compiler, including:

  • Code translation to C
  • Syntax Analyses
    • Vectors and strings
  • Semantic Analyses
    • Number implicit conversions
    • Control flow graph

Stay tuned for updates as we make progress on the project!

Getting Started

To get started with the compiler, follow these steps:

  1. Step 1: Clone the repository
  2. Step 2: Build the compiler
  3. Step 3: Run the compiler

Step 1: Clone the repository

Clone this repository to your local machine using:

git clone https://github.com/caiquetorres/compiler.git

Step 2: Build the compiler

Navigate to the project directory and build the compiler using:

cd compiler
cargo build

Step 3: Run the compiler

After building, you can run the compiler using:

cargo run -- --compile path/to/file

Sneak a Peek at the Compiler 🚀

Here's a snippet that the compiler totally can compile right now:

fun main() {
    let bin = 1101001;
    println "Result: ", convertToDecimal(bin);
}

fun convertToDecimal(number: u64) -> u32 {
    let n = number;
    let i = 0;
    let decimal = 0;

    while n > 0 {
        decimal += (n % 10) * pow(2, i);
        n /= 10;
        i += 1;
    }

    return decimal;
}

fun pow(base: i32, exponent: i32) -> i32 {
    if exponent == 0 {
        return 1;
    }

    if exponent % 2 == 0 {
        let halfPow = pow(base, exponent / 2);
        return halfPow * halfPow;
    }

    return base * pow(base, exponent - 1);
}

The compiler translates the code into C language. Below is an example demonstrating the converted code.

#include <stdio.h>
unsigned int convertToDecimal(unsigned long long int number);
signed int pow(signed int base, signed int exponent);
signed int main() {
  signed int bin = 1101001;
  printf("%s", "Result: ");
  printf("%u", convertToDecimal(bin));
  printf("\n");
  return 0;
}
unsigned int convertToDecimal(unsigned long long int number) {
  unsigned long long int n = number;
  signed int i = 0;
  signed int decimal = 0;
  while (n > 0) {
    decimal += (n % 10) * pow(2, i);
    n /= 10;
    i += 1;
  }
  return decimal;
}
signed int pow(signed int base, signed int exponent) {
  if (exponent == 0) {
    return 1;
  }
  if (exponent % 2 == 0) {
    signed int halfPow = pow(base, exponent / 2);
    return halfPow * halfPow;
  }
  return base * pow(base, exponent - 1);
}

License

This project is licensed under the MIT License see the LICENSE file for details.

compiler's People

Contributors

caiquetorres avatar

Stargazers

José Bieco avatar

Watchers

 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.