CSE 428: Lecture notes 4.1

The role of parse trees in the implementation of programming languages

Parse-trees are are used as an internal representation of the source program by the interpreter or the compiler. In very schematic terms, we can represent the various phases of the implementation as follows

Interpreter case

           _________     ________            __________     _____________  
          |         |   |        |          |          |   |             |  
 source ->| scanner |-->| parser |- parse ->| static   |-->| interpreter |-> results  
          |_________|   |________|  tree    | analyzer |   |_____________|  
                                            |__________|          ^  
                                                                  |  
                                                                 data 

Compiler case

           _________     ________            __________     __________                _________  
          |         |   |        |          |          |   |          |              |         |  
 source ->| scanner |-->| parser |- parse ->| static   |-->| compiler |-> compiled ->| machine |-> results  
          |_________|   |________|  tree    | analyzer |   |__________|     code     |_________|  
                                            |__________|                                  ^  
                                                                                          |  
                                                                                         data 

Actually, real implementations are often a combination of compilation and interpretation: the code gets compiled into an intermediate language (something in between the source langauge and the machine language) and then interpreted.