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

PT Pascal Compiler using S/SL_第1张图片


你可能感兴趣的:(开源,pascal,compiler)