Giter VIP home page Giter VIP logo

sysy's Introduction

SysY Compiler

用于实现SysY编译器的代码框架。

Getting Started

建议使用Ubuntu 22.04系统,原生版本与WSL版本均可。

Ubuntu下载与安装说明

WSL Ubuntu安装说明

SysY编译器前端基于ANTLR工具实现,本仓库已经包含ANTLR 4.9.3版本的可执行程序与C++运行时库,但编译ANTLR运行时库存在一些依赖,需要提前安装。

sudo apt update
sudo apt install -y uuid-dev libutfcpp-dev pkg-config make git cmake openjdk-11-jre

依赖安装完成后,可以开始构建SysY编译器(构建过程包含了ANTLR运行时库的构建)。

git clone https://gitee.com/xsu1989/sysy.git
cd sysy
cmake -S . -B build
cmake --build build

构建完成后,可以运行一个小的测试用例。该测试将逗号分隔的整数或字符串列表进行格式化后重新输出,即将相邻参数之间的分隔统一调整为逗号外加一个空格。

cat /test/funcrparams.sysy
# -> 1,0xa ,  011,	"hellow"
./build/bin/sysyc test/funcrparams.sy
# -> 1, 0xa, 011, "hellow"

Documentation

ANTLR手册

SysY语言规范

SysY运行时库

实验1:用ANTLR实现SysY词法/语法分析器

当前的代码框架已经部署好了编译环境,同学们可专注于程序开发。

在实验1中,同学们需要完成的任务包括

  • 参照SysY语言规范,修改src/SysY.g4文件,实现SysY词法/语法的完整定义
  • 修改任意代码后需要重新执行cmake --build build命令重新构建项目,ANTLR工具会从SysY.g4生成词法/语法分析器,生成的文件位于./build/src目录
  • (进阶内容)修改src/ASTPrinter.hsrc/ASTPrinter.cpp,实现从AST输出源程序,但输出的源程序是经过格式化的,测试用例为test/format-test.sy,格式化后的参考结果为test/format-ref.sy

实验2:从AST生成中间表示

exp2分支为大家准备好了进行实验2的基本代码框架,包括

  • IR相关数据结构的定义:src/IR.h
  • 创建IR对象的工具类src/IRBuilder.h
  • IR生成器的示例代码src/SysYIRGenerator.h

在实验2中,同学们需要完成的任务包括

  • 熟悉掌握IR定义与相关数据结构
  • 从AST生成IR(基于visitor机制)

请同学们仔细阅读代码学习IR的定义。可以使用doxygen工具自动生成HTML文档

sudo apt install doxygen graphviz
doxygen doc/Doxyfile

上述命令执行完毕后,将在doxygen/html下找到生成的代码文档。

sysy's People

Contributors

abnerhexu avatar gp-melon avatar pysuxing avatar

Watchers

 avatar

Forkers

2317891476

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.