Question

I'm having difficulties in understanding the exact differences between Syntax Directed Translation (SDT) and Semantic Analysis.

By reading the Dragon Book, I know that SDT is like an extension to CFG. You add rules or actions to the CFG that can be evaluated during parsing and will create an Abstract Syntax Tree. (Or concrete syntax tree that will then be converted to an AST)

However, I don't understand what the purpose of Semantic Analysis will be after this part. Because it seems to me, that with SDT, you will do semantic analysis. Isn't SDT doing some type checking as well if it implements rules/actions?

Thank you.

Was it helpful?

Solution

Syntax Directed Translation (SDT) means that all the translation process is driven by the parser of your language. Many times, this is done without a building an explicit tree of your code. The parser detect an instructions and almost directly it generates the target output.

On the other hand, Semantic Analysis (SA) is an independent concept. This is one of the main stages of a compiler. It's responsible for detecting things like, undefined variables/functions, access out of the scope, and so on.

SDT and SA can be related. If a compiler uses SDT, it must adapt SA stage to do those verifications at parser level.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top