Giter VIP home page Giter VIP logo

sysycompiler's Introduction

RUC 2023春编译原理大作业

本代码为编译原理课程的大作业存档,实现了一个将SysY语言编译到X86 AT&T语法汇编的编译器。

代码主要参考了北大编译实践在线文档,对于其中LV1 - LV8和LV9的大部分测试用例, 编译器都能够生成正确的X86汇编。

文件结构

  • sysy.l:词法分析器源代码。
  • sysy.y:语法分析器和语义分析器源代码。
  • Makefile:用于生成编译器的可执行文件的 Makefile。
  • tests/:包含测试用例的目录,其中包括 1.sy2.sy3.sy4.sytest.sy
  • test.sh:测试脚本,用于编译和运行测试用例。

使用方法

  1. 使用 make 命令生成编译器的可执行文件:

    make
    
  2. 使用 ./sysy_compiler 命令编译 SysY 源代码:

    ./sysy_compiler < input.sy > output.s
    

    其中,input.sy 是 SysY 源代码文件的路径,output.s 是生成的汇编代码文件的路径。

  3. 使用 gcc 命令将汇编代码文件编译成可执行文件:

    gcc output.s -o output 
    

    其中,output 是生成的可执行文件的路径。

  4. 运行可执行文件:

    ./output
    

测试

在使用 make 命令生成编译器的可执行文件后,可以使用 test.sh 脚本来编译和运行测试用例。该脚本支持以下命令行参数:

  • -a:编译 tests/ 目录下的所有 SysY 源代码文件。
  • -r <filename>:编译并运行指定的 SysY 源代码文件。

例如,要编译并运行 tests/1.sy 文件,可以使用以下命令:

./test.sh -r 1.sy

该命令会将 1.sy 文件编译成汇编代码,并将汇编代码编译成可执行文件,最后运行可执行文件。

sysycompiler's People

Contributors

jingyangou 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.