0% found this document useful (0 votes)
50 views

Compiler Design: Hoor Fatima

This document discusses compiler design. It defines high-level and low-level programming languages. It describes the structure of a program including the lexical, syntactic, contextual, and semantic structure levels. It discusses the analysis and synthesis model of compilation which involves analyzing the source code through linear, hierarchical, and semantic analysis to create an intermediate representation which is then used to synthesize the target code.

Uploaded by

Hoor Fatima
Copyright
© © All Rights Reserved
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
50 views

Compiler Design: Hoor Fatima

This document discusses compiler design. It defines high-level and low-level programming languages. It describes the structure of a program including the lexical, syntactic, contextual, and semantic structure levels. It discusses the analysis and synthesis model of compilation which involves analyzing the source code through linear, hierarchical, and semantic analysis to create an intermediate representation which is then used to synthesize the target code.

Uploaded by

Hoor Fatima
Copyright
© © All Rights Reserved
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 19

compiler design

by
Hoor Fatima

Computer Science and Engineering Department


Sharda University
Greter Noida 1
High level programming language
A programming language designed to suit the requirement of the programmer
irrespective of the machine code of any particular computer is called high level
programming language.
For ex., BASIC, FORTRAN, C++, JAVA etc.

Low level programming language


A programming language such as assemble language which reflect the machine
codes of specific computer is called the machine or low level language.
Syntax and semantic of the language
Syntax of a programming language is the form of it’s expression
statement and program modules.

Semantic of a programming language is the meaning given to


various semantic structure.
Structure of the program
Lexical structure level

Syntactic structure level

Contextual structure level

Semantic structure level


Lexical Structure
At this level computer programs are viewed as simple sequence of lexical items
i.e, tokens.
i. Identifiers:- It is chosen to represent data items, functions and procedures.
ii. Keywords:- Chosen be language designer to represent facts of particular
language constructs which cannot be used as identifiers.
iii. Operators:- Special keywords used to identify operations to be performed
iv. Separators:- These are punctuations marks used to group together sequences
of token that have unit meaning.
v. Literals:- That denote direct values i.e., numbers that is 1,123,-123 or a
character that is ‘a’
vi. Comment:- we can increase by understandability by including meaningful
comment in our code
syNtactic Structure

The syntactic level describes the way that program statements are
constructed from tokens. Always defined in terms of context free
grammar.
Compilers
• A compiler is a program that reads a program written in one
language
–– the source language –– and translates it into an
equivalent
program in another language –– the target language.

• As an important part of this translation process, the compiler


reports to its user the presence of errors in the source program.
Compilers
• At first glance, the variety of compilers may appear overwhelming.

• There are thousands of source languages, ranging from traditional


programming languages such as FORTRAN and Pascal to specialized
languages.

• Target languages are equally as varied;

• A target language may be another programming language, or the


machine language of any computer.
Compilers
Compilers are sometimes classified as:

 single-pass
 multi-pass
 load-and-go
 Debugging
 optimizing
The Analysis-Synthesis Model of Compilation

There are two parts of compilation:

 Analysis: The analysis part breaks up the source program


into constituent pieces

 Synthesis: Creates an intermediate representation of the


source program.
The Analysis-Synthesis Model of Compilation

The synthesis part constructs the desired target program from the
intermediate representation.

source Front IR Back machine


code End End code

errors
The Analysis-Synthesis Model of Compilation
 During analysis, the operations implied by the source program
are determined and recorded in a hierarchical structure called a
tree.

 Often, a special kind of tree called a syntax tree is used.


 In syntax tree each node represents an operation and the
children of

 the node represent the arguments of the operation.

 For example, a syntax tree of an assignment statement is


shown below.
The Analysis-Synthesis Model of Compilation

ANKUR SRIVASTAVA ASSISTANT PROFESSOR JIT


Analysis of the Source Program

In compiling, analysis consists of three phases:

 Linear Analysis:
 Hierarchical Analysis:
 Semantic Analysis:
Analysis of the Source Program
Linear Analysis:
In which the stream of characters making up the source program is
read from left-to-right and grouped into tokens that are sequences of
characters having a collective meaning.

Scanning or Lexical Analysis


 In a compiler, linear analysis is called lexical analysis or scanning.

 For example, in lexical analysis the characters in the


assignment statement
Position: = initial + rate * 60
 Would be grouped into the following tokens:
Scanning or Lexical Analysis (Linear Analysis)

 The identifier, position.


 The assignment symbol :=
 The identifier initial.
 The plus sign.
 The identifier rate.
 The multiplication sign.
 The number 60.
The blanks separating the characters of these tokens would normally be
eliminated during the lexical analysis.
Analysis of the Source Program

Hierarchical Analysis:

 In which characters or tokens are grouped hierarchically into


nested collections with collective meaning.
 The grammatical phrases of the source program are
represented by a parse tree.
 Hierarchical analysis is called parsing or syntax analysis.
 It involves grouping the tokens of the source program into
grammatical phases that are used by the compiler to
synthesize output.
Syntax Analysis or Hierarchical Analysis
(Parsing)
Assignment
Statement
:=

Identifier Position Expression


+

Expression Identifier Initial Expression


*

Expressio Expressio
n n Number
Identifier 60
Rate

ANKUR SRIVSTAVA ASSISTANT PROFESSOR JIT

You might also like