GithubHelp home page GithubHelp logo

compiler's Introduction

编译C语言的一个小型编译器

详细要求见http://os.hit.edu.cn/?p=7

LOGS:

--------V2.0------------

  • 支持词法分析、语法分析、语义分析、生成汇编
  • 最终输出AT&T格式的汇编代码

--------V1.0------------

  • 实现了基本的词法分析和语法分析
  • 输出Tokens和语法分析树

用法(假设源文件为source.c)

  • 帮助:

    python compiler.py -h

  • 查看词法分析结果:

    python compiler.py -s source.c -l

  • 查看语法树:

    python compiler.py -s source.c -p

  • 生成汇编:

    python compiler.py -s source.c -a

  • 将汇编文件编译成二进制:

    gcc source.S -o source

注意:

生成的汇编文件仅能在linux在编译,OS X虽然是unix like, 但是其gcc编译器与linux下的生成语法不同

TODO:

只实现了该网站中出现的语法句型,还有很多语法状态没有实现。 比如,不支持嵌套的控制语句等。

Test Environment

  • Ubuntu 12.04
  • Python version: 2.7

compiler's People

Contributors

shiyanhui avatar wongjiahau avatar

Watchers

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