FlazeNaive / compiler

2021-summer compiler

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Compiler

Course Project of Compiler Principle (2021-Spring-Summer)

A toy compiler for our self-designed simple programming language CMM (C--).

Structure

  • lex and yacc parser by Fusion
  • AST Generator & Semantic Analyzer by Fusion
  • LLVM IR Generator by andongfan
  • Test Cases by Flaze
    • Quicksort
    • Matrix Multiplication
    • Auto Advisor for Course Enrollment

Features

  • Simple semantic analysis
    • Attribute calculation
    • Symbol table
    • Type checking
  • Global / Local variable declaration
  • Function definition and call
  • Arithmetical / Logical expression evaluation
  • Control flow statments (if, loop, break, continue, return...)
  • Arrays (with arbitrary dimensions)
    • Support complex indexing like a[b[c[x]]][d[y]]
  • C-Style IO
  • Closure
    • Value capturing
    • Support escaping closure
  • Passing function as an argument to function call
    • Make implement map and filter possible

Build

CMake 3 and LLVM 12.0.0 are necessary. You may need to specify your LLVM installation path to CMake.

cmake .
make

Run

./compiler ./source.cmm 

Then a LLVM IR assembly file will be produced.

Option: -e to produce a executable. You can also use lli to interpret the IR file or llc to compiler it to assembly of any target.

About

2021-summer compiler


Languages

Language:C++ 83.6%Language:Yacc 10.9%Language:Lex 3.1%Language:CMake 1.7%Language:Shell 0.6%