greydevv / mango-compiler

Mango: Compiled, statically-typed general purpose programming language.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

🥭 Mango Language

📝 Mango is still under development

Introduction

Let's address the elephant in the room: why yet another programming language? Well, I don't really know, I just wanted to make a compiler. The language itself is just a byproduct of it.

This repository houses the compiler for Mango, a statically-typed, general-purpose programming language inspired by Python, Swift, C, C++, and Rust.

Mango Language

About

Mango is a compiled, statically-typed, general purpose programming language created as a byproduct of my passion project, the Mango compiler.

In creating Mango, I took inspiration from the syntax of Swift, C/C++, and Python type-hinting. The following example calculates the factorial of a 32-bit integer.

func factorial(i32 n) -> i32 {
  if (n == 0) {
    return 1;
  }
  return n * factorial(n-1);
}
Typing

As mentioned above, Mango is both statically and strongly typed which is mainly inspired by the type system Rust implements.

i8 x = 10;
i16 y = 356;

x + y;

Compiling this bit of code yields a TypeError because i8 and i16 are not the same type and therefore not compatible in a binary expression.

samples/types.mg -> [4,3]
  |
4 | x + y;
  | ^~~~~  
TypeError: i8 and i16 are not compatible in binary expression

Directory

Stage Module
Lexical analysis src/Lexer.cpp
Syntax analysis src/Parser.cpp
Semantic analysis src/visitors/ASTValidator.cpp
IR generation src/visitors/ASTCodegenner.cpp

Development Progress

  • Front-end
    • Lexer
    • Parser -> AST
  • AST Validation
    • type-checking
    • symbol/reference table
    • integer types (i8, i16, i32, i64, i128, u8, u16, u32, u64, u128)
    • constant folding
      • function overloading
      • strings/arrays
      • pointers (?)
  • IR/Codegen
    • binary expressions (arithmetic, boolean, etc.)
    • conditional control flow (if/else if/else)
    • control flow (while loop)
    • unary expressions

About

Mango: Compiled, statically-typed general purpose programming language.

License:MIT License


Languages

Language:C++ 98.1%Language:Vim Script 0.9%Language:Makefile 0.6%Language:Shell 0.2%Language:C 0.1%Language:Modula-3 0.0%