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

Set-01-Introduction

A language translator in computing converts code from one programming language to another, with compilers translating entire source code into machine code, interpreters executing code line by line, and assemblers converting assembly language to machine code. Compilers and interpreters differ in that compilers produce an executable program while interpreters execute code directly, with compilers generally being faster but interpreters providing better error diagnostics. The document also outlines the phases of a compiler, including lexical analysis, syntax analysis, semantic analysis, intermediate code generation, code optimization, and code generation, along with the role of a symbol table.

Uploaded by

mohidul17
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
1 views

Set-01-Introduction

A language translator in computing converts code from one programming language to another, with compilers translating entire source code into machine code, interpreters executing code line by line, and assemblers converting assembly language to machine code. Compilers and interpreters differ in that compilers produce an executable program while interpreters execute code directly, with compilers generally being faster but interpreters providing better error diagnostics. The document also outlines the phases of a compiler, including lexical analysis, syntax analysis, semantic analysis, intermediate code generation, code optimization, and code generation, along with the role of a symbol table.

Uploaded by

mohidul17
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 6

Compiler-Introduction

Question: What does language translator means? Give some example of source language, translator and target
language.
A language translator, in computing, is a software program that converts code written in one
programming language into another language that a computer can understand, typically
transforming high-level or assembly language into machine code or another programming
language. The main types of language translators include:
Compiler: Translates the entire source code of a high-level language into machine code at once,
producing an equivalent program that can be executed multiple times without re-translation 1316.
Interpreter: Converts and executes high-level language code line by line, allowing immediate execution
and easier debugging13.
Assembler: Converts assembly language programs into machine code, bridging the gap between low-
level symbolic code and binary instructions.

Question: How do you distinguish between Compiler and interpreter


A compiler is a program that can read a program in one lan guage (the source language) and translate it into an
equivalent program in another language (the target language); see Fig. 1.1. An important role of the compiler is to
report any errors in the source program that it detects during the translation process. If the target program is an
executable machine-language program, it can then be called by the user to process inputs and produce outputs;

An interpreter is another common kind of language processor. Instead of producing a target program as a translation, an
interpreter appears to directly execute the operations speci ed in the source program on inputs supplied by the user, as
shown in Fig. 1.3.

The machine-language target program produced by a compiler is usually much faster than an interpreter at mapping
inputs to outputs . An interpreter, however, can usually give better error diagnostics than a compiler, because it
executes the source program statementby statement.
Question: Show the step of language processing system.
A compiler is a program that can read a program in one lan guage (the source language) and translate it into an
equivalent program in another language (the target language); see Fig. 1.1. An important role of the compiler is to
report any errors in the source program that it detects during the translation process. If the target program is an
executable machine-language program, it can then be called by the user to process inputs and produce outputs;

An interpreter is another common kind of language processor. Instead of producing a target program as a translation, an
interpreter appears to directly execute the operations speci ed in the source program on inputs supplied by the user, as
shown in Fig. 1.3.

The machine-language target program produced by a compiler is usually much faster than an interpreter at mapping
inputs to outputs . An interpreter, however, can usually give better error diagnostics than a compiler, because it
executes the source program statementby statement.

In addition to a compiler, several other programs may be required to create an executable target program. A source
program maybe divided into modules stored in separate les. The task of collecting the source program is sometimes
entrusted to a separate program, called a preprocessor. The modi ed source program is then fed to a compiler. The
compiler may produce an assembly-language program as its output, because assembly lan guage is easier to produce as
output and is easier to debug. The assembly language is then processed by a program called an assembler that produces
relocatable machine code as its output. Large programs are often compiled in pieces, so the relocatable machine code
may have to be linked together with other relocatable object les and library les into the code that actually runs on the
machine.
Question: Show the logical structure of a compiler front end. Chapter 6 question see pano 382
A compiler as a single box that maps a source program into a semantically equivalent target program. If we open up this
box a little, we see that there are two parts to this mapping: analysis and synthesis. The analysis part breaks up the
source program into constituent pieces and imposes a grammatical structure on them. It then uses this structure to cre
ate an intermediate representation of the source program. If the analysis part detects that the source program is either
syntactically ill formed or semanti cally unsound, then it must provide informative messages, so the user can take
corrective action. The analysis part also collects information about the source program and stores it in a data structure
called a symbol table, which is passed along with the intermediate representation to the synthesis part. The analysis part
is often called the front end of the compiler; the synthesis part is the back end.

Question: Illustrate the typical decomposition of a compiler into phases.

Lexical Analyzer: The rst phase of a compiler is called lexical analysis or scanning. The lex ical analyzer reads the stream
of characters making up the source program and groups the characters into meaningful sequences called lexemes. For
each lexeme, the lexical analyzer produces as output a token of the form(<token-name , attribute-value>) that it passes
on to the subsequent phase, syntax analysis.

Syntax Analysis: The second phase of the compiler is syntax analysis or parsing. The parser uses the first components of
the tokens produced by the lexical analyzer to create a tree-like intermediate representation that depicts the
grammatical structure of the token stream.

Semantic Analysis: The semantic analyzer uses the syntax tree and the information in the symbol table to check the
source program for semantic consistency with the language definition. An important part of semantic analysis is type
checking, where the compiler checks that each operator has matching operands. If the operator is applied to a floating-
point number and an integer, the compiler may convert or coerce the integer into a floating-point number. We notice
that the output of the semantic analyzer has an extra node for the operator inttofloat, which explicitly converts its
integer argument into a floating-point number.

Intermediate Code Generation: we consider an intermediate form called three-address code, which consists of a
sequence of assembly-like instructions with three operands per instruction. Each operand can act like a register.
Code Optimization: The machine-independent code-optimization phase attempts to improve the intermediate code so
that better target code will result. Usually better means faster, but other objectives may be desired, such as shorter
code, or target code that consumes less power.

Code Generation: The code generator takes as input an intermediate representation of the source program and maps it
into the target language.
Suppose a source program contains the assignment statement: position = initial + rate * 60, show the representation
of the assignment statement using the different phases in compiler.

Question: Impacts on Compilers

 Language-Compiler Interdependence: Advances in programming languages require compilers to


support new features with innovative algorithms.
 Hardware Adaptation: Compilers must evolve- প্রকাশ করা to utilize new computer architectures
efficiently.
 Performance Enhancement: Compilers reduce execution overhead, promoting high-level language
adoption.
 Architectural Evaluation: Compilers are essential tools for assessing computer architecture performance
before hardware is built.
 Complexity Management: Modern compilers are large and complex, often supporting multiple languages
and platforms, necessitating strong software engineering practices.
 Correctness vs. Optimality: Compilers must ensure correct translation, but generating optimal code is
undecidable, requiring practical trade-offs and heuristics.
 Theory-Practice Integration: Compiler development bridges theoretical concepts with practical
implementation.
 Educational Aim: The primary goal is to teach core principles and methodologies of compiler design, not
exhaustive techniques.
Question: What advantages are there to a language-processing system in which the compiler produces assembly
language rather than machine language?
The compiler may produce an assembly-language program as its output, because assembly lan guage is easier to
produce as output and is easier to debug. The assembly language is then processed by a program called an assembler
that produces relocatable machine code as its output.

Question: A compiler that translates a high-level language into another high-level language is called a source-to-
source translator. What advantages are there to using C as a target language for a compiler?

Using C as a target language for a compiler offers several advantages. First, C is highly portable across different
platforms, ensuring that the generated code can run on a variety of systems. It also provides efficient, low-level control
over system resources, making it ideal for performance-critical applications.

Question: Describe some of the tasks that an assembler needs to per form.

Translate assembly language instructions into machine code3.


Assign memory addresses to instructions and data3.
Generate object code for execution3.
Resolve symbolic labels and variables

Symbol table
The symbol table is a data structure containing a record for eachvariable name, with elds for the attributes of the name.
The data structure should be designed to allow the compiler to nd the record for each name quickly and to store or
retrieve data from that record quickly.

You might also like