Presentation is loading. Please wait.

Presentation is loading. Please wait.

-by Nisarg Vasavada (Compiled*)

Similar presentations


Presentation on theme: "-by Nisarg Vasavada (Compiled*)"— Presentation transcript:

1 -by Nisarg Vasavada (Compiled*)
Compiler Review -by (Not compiled) $ gcc above.whatever Compiler Review -by Nisarg Vasavada (Compiled*) *Note: It doesn’t work this way… This is just for understanding

2 The Compiler Compilation is a process that translates a program from the source code into an equivalent program in another language called the object code. The tool or chain of tools which perform the process of compilation is called a compiler!

3 Compiler vs. Interpreter (I’m feeling Lucky!)
Compiler takes Entire Program as Input Interpreter takes single instruction as input. Intermediate Object code is generated. No Intermediate object code is generated. Conditional control statements are executed faster Conditional control statements are executed slowest Memory Requirement: More Memory Requirements: Less Program need to be compiled every time Every time Higher level Program is converted into lower level one. Errors are displayed after the entire program is checked Errors are displayed after each and every instruction (if there are any) Example: a C Compiler Example: BASIC

4 Compilation Phases

5 A demo program //program foo(input, output); /*var*/ x:integer;
//begin readln(x); writeln(’value read =’,x); end.

6 Lexical Analysis A lexical analyzer or scanner is a program that groups sequences of characters into lexemes, and outputs (to the syntax analyzer) a sequence of tokens. Tokens are symbolic names for the entities that make up the text of the program A pattern is a rule that specifies when a sequence of characters from the input constitutes a token A lexeme is a sequence of characters from the input that match a pattern (and hence constitute an instance of a token)

7 Symbol Table A symbol table is a data structure containing all the identifiers (i.e. names of variables, procedures etc.) of a source program together with all the attributes of each identifier. For variables, typical attributes include: its type, how much memory it occupies, its scope. For procedures and functions, typical attributes include: the number and type of each argument (if any), the method of passing each argument, and the type of value returned (if any). The purpose of the symbol table is to provide quick and uniform access to identifier attributes throughout the compilation process. Information is usually put into the symbol table during the lexical analysis and/or syntax analysis phases.

8 Other Blocks A syntax analyzer or parser is a program that groups sequences of tokens from the lexical analysis phase into phrases each with an associated phrase type. A phrase is a logical unit with respect to the rules of the source language. A semantic analyzer takes its input from the syntax analysis phase in the form of a parse tree and a symbol table. Its purpose is to determine if the input has a well-defined meaning; in practice semantic analyzers are mainly concerned with type checking and type coercion based on type rules. Each of the six phases (but mainly the analysis phases) of a compiler can encounter errors. Thus an error detector and handler are required. An optimizer attempts to improve the time and space requirements of a program. There are many ways in which code can be optimized, but most are expensive in terms of time and space to implement.

9 Relocation Object files
Linker Linking is the final stage of compilation. It takes one or more object files or libraries as input and combines them to produce a single (usually executable) file. In doing so, it resolves references to external symbols, assigns final addresses to procedures/functions and variables, and revises code and data to reflect new addresses (a process called relocation). Linker Library files Relocation Object files Other Modules

10  Thank You 


Download ppt "-by Nisarg Vasavada (Compiled*)"

Similar presentations


Ads by Google