Giter Club home page Giter Club logo

madcompiler's Introduction

MadCompiler

Overview

MadCompiler is a compiler course design project from the NCHU computer science department.

Features

  • Lexical Analysis: Tokenizes the input source code.
  • Syntax Analysis: Builds an Abstract Syntax Tree (AST).
  • Semantic Analysis: Checks for semantic errors.
  • Code Generation: Produces intermediate code.

Installation

  1. Clone the repository:
    git clone https://github.com/aqpower/MadCompiler.git
  2. Build the project using CMake:
    cd MadCompiler
    mkdir build
    cmake -S . -B build
    cmake --build build

Usage

Run the compiler with the following command:

./build/src/madcompiler <source_code_file> -o <output_file>

Generate the lexical analysis output:

./build/src/madcompiler <source_code_file> -l <output_file>

Recognized Tokens

  1. Keywords: if, if else, while; token type 1.
  2. Identifiers: token type 2.
  3. Constants: Unsigned integers; token type 3.
  4. Operators: +, -, *, /, =, >, <, <=, !=; token type 4.
  5. Separators: ,, ;, {, }, (, ); token type 5.
  6. Other Tokens: Defined by the following regular expressions:
    • ID = letter(letter | digit)*
    • NUM = digit digit*

Grammar Rules

The start symbol of the grammar is program. The following production rules are implemented:

  • program -> block
  • block -> { stmts }
  • stmts -> stmt stmts | ε
  • stmt -> id = expr ;
    • | if ( bool ) stmt
    • | if ( bool) stmt else stmt
    • | while (bool) stmt
    • | block
  • bool -> expr < expr
    • | expr <= expr
    • | expr > expr
    • | expr >= expr
    • | expr
  • expr -> expr + term
    • | expr - term
    • | term
  • term -> term * factor
    • | term / factor
    • | factor
  • factor -> ( expr ) | ID | NUM

License

MIT License

madcompiler's People

Contributors

aqpower avatar

Stargazers

 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.