PT Pascal Compiler using S/SL

I have been recently working on revising PT Pascal compiler to adjust the grammer similar to c++/java grammer. The whole work is based on Open-source simple compiler developped by Alan Rosselet in 1980.

The compiler has four phases: Screener/Scanner, Parser, Semantic, Code Generation, and three passes. Screener/Scanner and Parser are merged into one pass. Screener/Scanner is to scan the input file using FSA to extract tokens. Parser is to generate a postfix tree, Semantic phase is to generate an annotated parse tree and corresponding T-Code. Code generation is to translate the T-Code into Assembly Code. Usually, compiler used by industry (IBM) will even split into more phases (40 phases?). The more phases, the easier to develop and optimize.

Scanner/Screener: This is the most simple phase. S/SL is a dataless language, it works allmost the same way as regular expression(even easier!)

Parser: A little bit complicated, but still, since S/SL without mechanism operation is just like a push down automa, it is not that hard.

Semantic: This is the most complicated phase. There are quite a lot of tables: symbol table, type table etc al.. At the first sight, it is hard to read their relationships..... And, there are a lot of mechanisms which operate on the all sorts of tables.

Code Generation: This phase is not hard, there are only two stacks to operate on. But it is quite tricky. Becuase this is the last phase, you can compile your code and run it. it is easy to tell whether the output is correct or not. However, it is pretty hard to debug back which former phases had issues.


PT Pascal Compiler in general is a good open source project to get familiar with what compiler is and how does it work. The only difference with the compilers used by industry is there are few optimizations. As stated by Alan, this compiler is used by instructor's illustration in the course. Fair enough though. ;)

For future development in Compiler area, see following resource:

GitHub accout, I unfortunately put them in the wrong dir. erh, anyway, not bad overall.

  https://github.com/TianbinJiang/LeetCode/tree/master/Compiler/project/pt


The pretty famous dragon book. This is the bible to compiler development.

 https://www.amazon.ca/Compilers-Principles-Techniques-Tools-Edition/dp/0321486811



  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值