Giter VIP home page Giter VIP logo

compiler-labs's Introduction

Compiler Labs Repository

Python WSL2 License

Note

This documentation is originally written in Chinese and translated into English using GPT translation. You may find some sentences awkward or difficult to understand. It's very possibly not your fault. Please refer to the original Chinese version for better understanding.

English | δΈ­ζ–‡

Introduction

This repository is used to store the experimental code for the Compiler Principles course at Fuzhou University.

The experiments include:

Experiment Number Title Content
1 Lexical Analysis Read the source program, recognize words, and output the word symbol table
2 Syntax Analysis Perform syntax analysis on the word symbol table based on grammar rules and output the analysis result
3 Semantic Analysis Perform semantic analysis on the syntax analysis result and output quadruples and three-address code

Feature

  1. Lexical Analyzer

    • Regular expression analysis
    • Output symbol table
  2. Syntax Analyzer

    • Support custom grammars
    • Detect grammar conflicts (ambiguity)
    • Visualization
      • State machine visualization
      • Syntax analysis tree visualization
    • Output analysis result (including FIRST and FOLLOW sets, ACTION table, and GOTO table)
  3. Semantic Analyzer

    • Support grammars with semantic actions
    • Support custom semantic action functions
    • Support grammar code snippets in Python syntax
    • Generate asm-ish quadruples and three-address code

Preview

Lexical Analysis

Lexical Analysis

Syntax Analysis

Syntax Analysis

Visualization

State Machine

Syntax Analysis Tree

Running the Project

This project is developed based on Python 3.10 on WSL. Please install the relevant dependencies before running.

Linux

If you are a Linux user, you can use the following command to configure the environment:

make

This command will create a virtual environment and install the dependencies in it. Please manually activate the virtual environment after the installation is complete.

Windows

Warning

(The project has not been tested on Windows and may have unknown bugs.)

If you are a Windows user and have the make command in your system, you can use the following command to configure the environment:

make

If you don't have the make command, you can manually execute the following commands:

  1. Install the virtual environment

    python -m venv venv
  2. Activate the virtual environment

  3. Install the dependencies

    pip install -e .

Usage

Detailed usage instructions can be found in the corresponding README.md file in each experiment folder.

You can run

make demo

to run the demonstration provided by each experiment.

Warning

On Windows systems, commands like touch and mkdir may not be available. Please manually create folders and files as needed.

Lexical Analysis

After running make demo, the program will start listening to the source code files under ./tmp/input and output the lexical analysis result to ./outputs.

input is the input file, .out is the output file, and .sym is the symbol table file.

Lexical Analysis

Syntax Analysis

After running make demo, the program will read the ./data/grammar1.txt file and analyze the Token stream b a a b using the LR(1) model, and output the syntax analysis result to ./outputs.

Syntax Analysis

It will also generate visualizations of the state machine and syntax analysis tree. They are saved in ./outputs in the form of interactive web pages.

Visualization

This is the visualization of the state machine

State Machine

This is the visualization of the syntax analysis tree

Syntax Analysis Tree

In the parse tree, different colors are used to distinguish different types of symbols.

Semantic Analysis

After running make demo, the program will monitor the ./tmp/input and ./tmp/grammar.txt files and output the semantic analysis result to ./outputs.

Semantic Analysis

compiler-labs's People

Contributors

fyvv00 avatar izo5o avatar tr1er-rce avatar zenor0 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.