Designing an Intermediate View for the Compiler

I watched the compiler design. I spent one semester at the university and read “Modern Compiler Design” by Grune et al, this book seems to protect the annotated abstract syntax tree as an intermediate code, and this is what we used in the course.

My question is what are the advantages of this approach compared to creating any kind of stack machine language or low-level pseudo-code, especially with regard to a compiler that can target many machines.

Is it possible to simply orient an existing low-level view, such as LLVM, and use this as an intermediate view?

+3
source share
3 answers

If your language is complex enough, you will end up with a sequence of slightly different intermediate representations. And it doesn’t matter which representation will be your ultimate goal - llvm, C, native code, CLR, JVM, whatever. This should not affect the design and architecture of your compiler.

And, in my personal experience, the more complex steps you have, with the transformations between them as trivial as possible, the better your compiler architecture.

+3
source

AST and low-level pseudocode are two different travel abstractions that the compiler uses from a high-level language to object code.

, , , . , .

, . .

, , . , , .

+1

, AST (Abstract Syntax Tree).

AST, , , . , , parens .. .

. icode - . , move, goto ..

Code → AST → ICode. ICode .

ICode, .

, , . icode . , , , , ?

, , , , mov, goto ..

I need to pick up this book. I learned everything from the dragon book and searched for ANTRL, yacc, byson and custom tokenizers and parsers.

0
source

Source: https://habr.com/ru/post/1783777/


All Articles