1 / 17

Compiler design

Compiler design. Lecture one introduction. What is a compiler. Compilers are the bridges: Tools to translate programs written in high level languages to efficient executable code Program that reads a program written in one language and translates it into another language.

gbondurant
Download Presentation

Compiler design

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Compiler design Lecture one introduction

  2. What is a compiler Compilers are the bridges: Tools to translate programs written in high level languages to efficient executable code • Program that reads a program written in one language and translates it into another language.

  3. Lexical analysis example

  4. Another example:

  5. Syntax Analysis -Context free Grammar -Build a parse tree that reflects the structure of the input sentence . = x + y 1

  6. Another example of syntax tree Input : result =a + b * 10 assign result + * a b 10

  7. Semantic analysis Perform type checking Check semantic error X=y + true error

  8. Intermediate Code Generation -Translate each hierarchical structure decorated as tree in to intermediate code. -intermediate code hides many machine level details but has instruction level mapping to many assembly languages. -One commonly used from is “Three address Code

  9. Example :

  10. Code Optimization -Apply a series of transformations to improve the time and space efficiency of the generated code. -Global optimizations : reorder , remove or add instructions to change the structure of generated code

  11. Code Generation • -Map instruction in the intermediate code to specific machine instructions -Memory management , register allocation , instruction selection ,….. e.x: Mov x,r5 Add 1,r5 Mov r5,x

  12. Symbol table • The symbol table is a data structure containing a record for each identifier with fields for the attributes of the identifier.

  13. Error Detection , Recovery and Reporting • -Each phase can encounter error • -Specific types of error can be detected by specific phases: • -Lexical Error :int abc , 1num; • -Syntax Error : total1=capital +rate year; • - Semantic Error : value = myarray [real index]; • - should be able to link the error with the source program • -find more errors.

  14. The end

More Related