Giter VIP home page Giter VIP logo

tigercompiler's Introduction

tiger compiler ===

Final Goal

该项目实现了如下目标:

  • Lexer(词法分析)
  • Parser(语法分析)
  • AST (语法树)
  • Elaborator(装饰器):类型检查,继承检查等
  • Codegen(代码生成):可以生成Java字节码,C,Go,XML
  • GC(垃圾回收):实现简单的复制回收

=== Lab4

  • gc中使用了Linux C的库函数,测试时需要在Linux系统中进行;
  • 命令行参数的格式如下:
$./a.out @tiger -heapSize 1024 @
$./a.out @tiger -logGc @
  • gc_log.txt 中记录的是收集的垃圾大小,即from 中已分配空间的大小减去复制到to中的大小;原来的测试用例如果发生了GC,往往是把from完全复到to中,收集到的垃圾为0 Bytes. test目录下的testGC.java可以作为很好的测试用例:
$./a.out @tiger -heapSize 500 -logGc @
  • 求数组长度在lib.c中定义为库函数,声明为:
int len(char *array);

Enjoy!


Lab3

  1. 由于 glue code 中使用了 Linux中的指令,测试时需要在Linux系统中进行.
  2. 若系统为Linux,默认设置为直接编译运行,输入:
$java Tiger inputfile -codegen C
$java Tiger inputfile -codegen bytecode

时,会直接执行 linkrun 步骤,输出在控制台.

  1. 如果您的系统不是 Linux,需要手动编译,运行生成的代码.

  2. Tiger_new_array 与老师提供方法不同,我们的实现方式是通过库函数调用新建数组,求长 度等.


Lab2

由于我们采用的语法与MiniJava不太一样,为了方便您更好地理解代码,对程序做如下说明:

  1. statement语句 与 vardecl 可以混合在一起,写程序时可以随处定义变量;

  2. 变量可以先使用后声明:

i = 1;
int i;

在程序中是合法的,因为在生成ast时会先收集decs信息,然后处理stms;

  1. PrettyPrintVisitor时,仍会把所有声明打印在所有语句之前, 即内部的语法解释和MiniJava相同,只是在写的时候增加了程序员的自由度;

  2. 为了处理方便,定义ast.DecOrStm类作为ast.dec.Tast.stm.T的抽象父类;

  3. Block作为重要结构处理:

Block -> { statements | vardecls}
  1. 定义BlockTable类,作为每个Block的符号表;

  2. MainClass里面的main重新定义为:

main -> public static void main(String[] a) Block
  1. 测试Sum时和Fac类似:
java Tiger -testSum

tigercompiler's People

Contributors

kangkona avatar

Stargazers

 avatar  avatar  avatar

Watchers

 avatar  avatar

Forkers

lance2088

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.