180 likes | 190 Views
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.
E N D
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.
Syntax Analysis -Context free Grammar -Build a parse tree that reflects the structure of the input sentence . = x + y 1
Another example of syntax tree Input : result =a + b * 10 assign result + * a b 10
Semantic analysis Perform type checking Check semantic error X=y + true error
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
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
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
Symbol table • The symbol table is a data structure containing a record for each identifier with fields for the attributes of the identifier.
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.