Computer Science Related Others Courses AvailableThe Best Codder.blogspot.com

ANALYSIS OF THE SOURCE PROGRAM

 ANALYSIS OF THE SOURCE PROGRAM

In compiling, analysis consists of three phases:

  •  Lexical Analysis 
  •  Syntax Analysis 
  •  Semantic Analysis 

Lexical Analysis (Scanning)

 In a compiler linear analysis is called lexical analysis or scanning. The lexical analysis phase reads the characters in the source program and grouped into tokens that are sequence of characters having a collective meaning. 

EXAMPLE position : = initial + rate * 60

This can be grouped into the following tokens;

 1. The identifier position. 

2. The assignment symbol : = 

3. The identifier initial 

4. The plus sign

 5. The identifier rate

 6. The multiplication sign 

7. The number 60 

Blanks separating characters of these tokens are normally eliminated during lexical analysis. 

Syntax Analysis (Parsing) 

Hierarchical Analysis is called parsing or syntax analysis. 

It involves grouping the tokens of the source program into grammatical phrases that are used by the complier to synthesize output. They are represented using a syntax tree. 

A syntax tree is the tree generated as a result of syntax analysis in which the interior nodes are the operators and the exterior nodes are the operands. This analysis shows an error when the syntax is incorrect.

Semantic Analysis

 This phase checks the source program for semantic errors and gathers type information for subsequent code generation phase.

 An important component of semantic analysis is type checking. 

 Here the compiler checks that each operator has operands that are permitted by the source language specification.

Post a Comment

© Compiler Design. The Best Codder All rights reserved. Distributed by