The document provides an overview of compilers and interpreters. It discusses that a compiler translates source code into machine code that can be executed, while an interpreter executes source code directly without compilation. The document then covers the typical phases of a compiler in more detail, including the front-end (lexical analysis, syntax analysis, semantic analysis), middle-end/optimizer, and back-end (code generation). It also discusses interpreters, intermediate code representation, symbol tables, and compiler construction tools.
The document discusses the phases of a compiler and their functions. It describes:
1) Lexical analysis converts the source code to tokens by recognizing patterns in the input. It identifies tokens like identifiers, keywords, and numbers.
2) Syntax analysis/parsing checks that tokens are arranged according to grammar rules by constructing a parse tree.
3) Semantic analysis validates the program semantics and performs type checking using the parse tree and symbol table.
The document discusses the phases of a compiler:
1) Lexical analysis scans the source code and converts it to tokens which are passed to the syntax analyzer.
2) Syntax analysis/parsing checks the token arrangements against the language grammar and generates a parse tree.
3) Semantic analysis checks that the parse tree follows the language rules by using the syntax tree and symbol table, performing type checking.
4) Intermediate code generation represents the program for an abstract machine in a machine-independent form like 3-address code.
The document discusses the different phases of a compiler:
1. Lexical analysis scans source code and converts it to tokens.
2. Syntax analysis checks token arrangements against the grammar to validate syntax.
3. Semantic analysis checks that rules like type compatibility are followed.
4. Intermediate code is generated for an abstract machine.
5. Code is optimized in the intermediate representation.
6. Code generation produces machine code from the optimized intermediate code.
The document summarizes the key phases of a compiler:
1. The compiler takes source code as input and goes through several phases including lexical analysis, syntax analysis, semantic analysis, code optimization, and code generation to produce machine code as output.
2. Lexical analysis converts the source code into tokens, syntax analysis checks the grammar and produces a parse tree, and semantic analysis validates meanings.
3. Code optimization improves the intermediate code before code generation translates it into machine instructions.
The compiler is software that converts source code written in a high-level language into machine code. It works in two major phases - analysis and synthesis. The analysis phase performs lexical analysis, syntax analysis, and semantic analysis to generate an intermediate representation from the source code. The synthesis phase performs code optimization and code generation to create the target machine code from the intermediate representation. The compiler uses various components like a symbol table, parser, and code generator to perform this translation.
This document provides an overview of a compiler design course, including prerequisites, textbook, course outline, and introductions to key compiler concepts. The course outline covers topics such as lexical analysis, syntax analysis, parsing techniques, semantic analysis, intermediate code generation, code optimization, and code generation. Compiler design involves translating a program from a source language to a target language. Key phases of compilation include lexical analysis, syntax analysis, semantic analysis, intermediate code generation, code optimization, and code generation. Parsing techniques can be top-down or bottom-up.
The document discusses the phases of a compiler and their functions. It describes:
1) Lexical analysis converts the source code to tokens by recognizing patterns in the input. It identifies tokens like identifiers, keywords, and numbers.
2) Syntax analysis/parsing checks that tokens are arranged according to grammar rules by constructing a parse tree.
3) Semantic analysis validates the program semantics and performs type checking using the parse tree and symbol table.
The document discusses the phases of a compiler:
1) Lexical analysis scans the source code and converts it to tokens which are passed to the syntax analyzer.
2) Syntax analysis/parsing checks the token arrangements against the language grammar and generates a parse tree.
3) Semantic analysis checks that the parse tree follows the language rules by using the syntax tree and symbol table, performing type checking.
4) Intermediate code generation represents the program for an abstract machine in a machine-independent form like 3-address code.
The document discusses the different phases of a compiler:
1. Lexical analysis scans source code and converts it to tokens.
2. Syntax analysis checks token arrangements against the grammar to validate syntax.
3. Semantic analysis checks that rules like type compatibility are followed.
4. Intermediate code is generated for an abstract machine.
5. Code is optimized in the intermediate representation.
6. Code generation produces machine code from the optimized intermediate code.
The document summarizes the key phases of a compiler:
1. The compiler takes source code as input and goes through several phases including lexical analysis, syntax analysis, semantic analysis, code optimization, and code generation to produce machine code as output.
2. Lexical analysis converts the source code into tokens, syntax analysis checks the grammar and produces a parse tree, and semantic analysis validates meanings.
3. Code optimization improves the intermediate code before code generation translates it into machine instructions.
The compiler is software that converts source code written in a high-level language into machine code. It works in two major phases - analysis and synthesis. The analysis phase performs lexical analysis, syntax analysis, and semantic analysis to generate an intermediate representation from the source code. The synthesis phase performs code optimization and code generation to create the target machine code from the intermediate representation. The compiler uses various components like a symbol table, parser, and code generator to perform this translation.
This document provides an overview of a compiler design course, including prerequisites, textbook, course outline, and introductions to key compiler concepts. The course outline covers topics such as lexical analysis, syntax analysis, parsing techniques, semantic analysis, intermediate code generation, code optimization, and code generation. Compiler design involves translating a program from a source language to a target language. Key phases of compilation include lexical analysis, syntax analysis, semantic analysis, intermediate code generation, code optimization, and code generation. Parsing techniques can be top-down or bottom-up.
We have learnt that any computer system is made of hardware and software.
The hardware understands a language, which humans cannot understand. So we write programs in high-level language, which is easier for us to understand and remember.
These programs are then fed into a series of tools and OS components to get the desired code that can be used by the machine.
This is known as Language Processing System.
- The document outlines the goals, outcomes, prerequisites, topics covered, and grading for a compiler design course.
- The major goals are to provide an understanding of compiler phases like scanning, parsing, semantic analysis and code generation, and have students implement parts of a compiler for a small language.
- By the end of the course students will be familiar with compiler phases and be able to define the semantic rules of a programming language.
- Prerequisites include knowledge of programming languages, algorithms, and grammar theories.
- The course covers topics like scanning, parsing, semantic analysis, code generation and optimization.
The document discusses the differences between compilers and interpreters. It states that a compiler translates an entire program into machine code in one pass, while an interpreter translates and executes code line by line. A compiler is generally faster than an interpreter, but is more complex. The document also provides an overview of the lexical analysis phase of compiling, including how it breaks source code into tokens, creates a symbol table, and identifies patterns in lexemes.
System software module 4 presentation filejithujithin657
The document discusses the various phases of a compiler:
1. Lexical analysis scans source code and transforms it into tokens.
2. Syntax analysis validates the structure and checks for syntax errors.
3. Semantic analysis ensures declarations and statements follow language guidelines.
4. Intermediate code generation develops three-address codes as an intermediate representation.
5. Code generation translates the optimized intermediate code into machine code.
This document provides information about the CS213 Programming Languages Concepts course taught by Prof. Taymoor Mohamed Nazmy in the computer science department at Ain Shams University in Cairo, Egypt. It describes the syntax and semantics of programming languages, discusses different programming language paradigms like imperative, functional, and object-oriented, and explains concepts like lexical analysis, parsing, semantic analysis, symbol tables, intermediate code generation, optimization, and code generation which are parts of the compiler design process.
This document provides an introduction to compilers. It discusses how compilers bridge the gap between high-level programming languages that are easier for humans to write in and machine languages that computers can actually execute. It describes the various phases of compilation like lexical analysis, syntax analysis, semantic analysis, code generation, and optimization. It also compares compilers to interpreters and discusses different types of translators like compilers, interpreters, and assemblers.
Translation of a program written in a source language into a semantically equivalent program written in a target language
It also reports to its users the presence of errors in the source program
The document provides an overview of the compilation process and the different phases involved in compiler construction. It can be summarized as follows:
1. A compiler translates a program written in a source language into an equivalent program in a target language. It performs analysis, synthesis and error checking during this translation process.
2. The major phases of a compiler include lexical analysis, syntax analysis, semantic analysis, intermediate code generation, code optimization, code generation and linking. Tools like Lex and Yacc are commonly used to generate lexical and syntax analyzers.
3. Regular expressions are used to specify patterns for tokens during lexical analysis. A lexical analyzer reads the source program and generates a sequence of tokens by matching character sequences to patterns
The document provides an introduction to compilers. It discusses that compilers are language translators that take source code as input and convert it to another language as output. The compilation process involves multiple phases including lexical analysis, syntax analysis, semantic analysis, code generation, and code optimization. It describes the different phases of compilation in detail and explains concepts like intermediate code representation, symbol tables, and grammars.
The document provides an introduction to compilers, including definitions of key terms like compiler, interpreter, assembler, translator, and phases of compilation like lexical analysis, syntax analysis, semantic analysis, code generation, and optimization. It also discusses compiler types like native compilers, cross compilers, source-to-source compilers, and just-in-time compilers. The phases of a compiler include breaking down a program, generating intermediate code, optimizing, and creating target code.
A compiler is a program that translates a program written in a source language into a target language. It has two main parts: analysis and synthesis. The analysis part breaks down the source code using lexical analysis, syntax analysis, and semantic analysis. The synthesis part constructs the target program using intermediate code generation, code optimization, and code generation. A compiler translates the source code into assembly code, which is then assembled into machine code and linked with libraries to create an executable program.
The document discusses the different phases of a compiler including lexical analysis, syntax analysis, semantic analysis, intermediate code generation, code optimization, and code generation. It provides details on each phase and the techniques involved. The overall structure of a compiler is given as taking a source program through various representations until target machine code is generated. Key terms related to compilers like tokens, lexemes, and parsing techniques are also introduced.
This document provides an introduction to compilers, including definitions of key terms like translator, compiler, interpreter, and assembler. It describes the main phases of compilation as lexical analysis, syntax analysis, semantic analysis, intermediate code generation, code optimization, and code generation. It also discusses related concepts like the front-end and back-end of a compiler, multi-pass compilation, and different types of compilers.
The phases of a compiler are:
1. Lexical analysis breaks the source code into tokens
2. Syntax analysis checks the token order and builds a parse tree
3. Semantic analysis checks for type errors and builds symbol tables
4. Code generation converts the parse tree into target code
This document provides an overview of compilers and their various phases. It begins by introducing compilers and their importance for increasing programmer productivity and enabling reverse engineering. It then covers the classification of programming languages and the history of compilers. The rest of the document details each phase of the compiler process, including lexical analysis, syntax analysis, semantic analysis, intermediate code generation, code optimization, code generation, and the role of the symbol table. It provides definitions and examples for each phase to explain how a source program is translated from a high-level language into executable machine code.
The document provides an overview of compiler design and the different phases involved in compiling a program. It discusses:
1) What compilers do by translating source code into machine code while hiding machine-dependent details. Compilers may generate pure machine code, augmented machine code, or virtual machine code.
2) The typical structure of a compiler which includes lexical analysis, syntactic analysis, semantic analysis, code generation, and optimization phases.
3) Lexical analysis involves scanning the source code and grouping characters into tokens. Regular expressions are used to specify patterns for tokens. Scanner generators like Lex and Flex can generate scanners from regular expression definitions.
Compiler construction tools were introduced to aid in the development of compilers. These tools include scanner generators, parser generators, syntax-directed translation engines, and automatic code generators. Scanner generators produce lexical analyzers based on regular expressions to recognize tokens. Parser generators take context-free grammars as input to produce syntax analyzers. Syntax-directed translation engines associate translations with parse trees to generate intermediate code. Automatic code generators take intermediate code as input and output machine language. These tools help automate and simplify the compiler development process.
This document provides an overview of the key concepts and phases in compiler design, including lexical analysis, syntax analysis using context-free grammars and parsing techniques, semantic analysis using attribute grammars, intermediate code generation, code optimization, and code generation. The major parts of a compiler are the analysis phase, which creates an intermediate representation from the source program using lexical analysis, syntax analysis, and semantic analysis, and the synthesis phase, which generates the target program from the intermediate representation using intermediate code generation, code optimization, and code generation.
We have learnt that any computer system is made of hardware and software.
The hardware understands a language, which humans cannot understand. So we write programs in high-level language, which is easier for us to understand and remember.
These programs are then fed into a series of tools and OS components to get the desired code that can be used by the machine.
This is known as Language Processing System.
- The document outlines the goals, outcomes, prerequisites, topics covered, and grading for a compiler design course.
- The major goals are to provide an understanding of compiler phases like scanning, parsing, semantic analysis and code generation, and have students implement parts of a compiler for a small language.
- By the end of the course students will be familiar with compiler phases and be able to define the semantic rules of a programming language.
- Prerequisites include knowledge of programming languages, algorithms, and grammar theories.
- The course covers topics like scanning, parsing, semantic analysis, code generation and optimization.
The document discusses the differences between compilers and interpreters. It states that a compiler translates an entire program into machine code in one pass, while an interpreter translates and executes code line by line. A compiler is generally faster than an interpreter, but is more complex. The document also provides an overview of the lexical analysis phase of compiling, including how it breaks source code into tokens, creates a symbol table, and identifies patterns in lexemes.
System software module 4 presentation filejithujithin657
The document discusses the various phases of a compiler:
1. Lexical analysis scans source code and transforms it into tokens.
2. Syntax analysis validates the structure and checks for syntax errors.
3. Semantic analysis ensures declarations and statements follow language guidelines.
4. Intermediate code generation develops three-address codes as an intermediate representation.
5. Code generation translates the optimized intermediate code into machine code.
This document provides information about the CS213 Programming Languages Concepts course taught by Prof. Taymoor Mohamed Nazmy in the computer science department at Ain Shams University in Cairo, Egypt. It describes the syntax and semantics of programming languages, discusses different programming language paradigms like imperative, functional, and object-oriented, and explains concepts like lexical analysis, parsing, semantic analysis, symbol tables, intermediate code generation, optimization, and code generation which are parts of the compiler design process.
This document provides an introduction to compilers. It discusses how compilers bridge the gap between high-level programming languages that are easier for humans to write in and machine languages that computers can actually execute. It describes the various phases of compilation like lexical analysis, syntax analysis, semantic analysis, code generation, and optimization. It also compares compilers to interpreters and discusses different types of translators like compilers, interpreters, and assemblers.
Translation of a program written in a source language into a semantically equivalent program written in a target language
It also reports to its users the presence of errors in the source program
The document provides an overview of the compilation process and the different phases involved in compiler construction. It can be summarized as follows:
1. A compiler translates a program written in a source language into an equivalent program in a target language. It performs analysis, synthesis and error checking during this translation process.
2. The major phases of a compiler include lexical analysis, syntax analysis, semantic analysis, intermediate code generation, code optimization, code generation and linking. Tools like Lex and Yacc are commonly used to generate lexical and syntax analyzers.
3. Regular expressions are used to specify patterns for tokens during lexical analysis. A lexical analyzer reads the source program and generates a sequence of tokens by matching character sequences to patterns
The document provides an introduction to compilers. It discusses that compilers are language translators that take source code as input and convert it to another language as output. The compilation process involves multiple phases including lexical analysis, syntax analysis, semantic analysis, code generation, and code optimization. It describes the different phases of compilation in detail and explains concepts like intermediate code representation, symbol tables, and grammars.
The document provides an introduction to compilers, including definitions of key terms like compiler, interpreter, assembler, translator, and phases of compilation like lexical analysis, syntax analysis, semantic analysis, code generation, and optimization. It also discusses compiler types like native compilers, cross compilers, source-to-source compilers, and just-in-time compilers. The phases of a compiler include breaking down a program, generating intermediate code, optimizing, and creating target code.
A compiler is a program that translates a program written in a source language into a target language. It has two main parts: analysis and synthesis. The analysis part breaks down the source code using lexical analysis, syntax analysis, and semantic analysis. The synthesis part constructs the target program using intermediate code generation, code optimization, and code generation. A compiler translates the source code into assembly code, which is then assembled into machine code and linked with libraries to create an executable program.
The document discusses the different phases of a compiler including lexical analysis, syntax analysis, semantic analysis, intermediate code generation, code optimization, and code generation. It provides details on each phase and the techniques involved. The overall structure of a compiler is given as taking a source program through various representations until target machine code is generated. Key terms related to compilers like tokens, lexemes, and parsing techniques are also introduced.
This document provides an introduction to compilers, including definitions of key terms like translator, compiler, interpreter, and assembler. It describes the main phases of compilation as lexical analysis, syntax analysis, semantic analysis, intermediate code generation, code optimization, and code generation. It also discusses related concepts like the front-end and back-end of a compiler, multi-pass compilation, and different types of compilers.
The phases of a compiler are:
1. Lexical analysis breaks the source code into tokens
2. Syntax analysis checks the token order and builds a parse tree
3. Semantic analysis checks for type errors and builds symbol tables
4. Code generation converts the parse tree into target code
This document provides an overview of compilers and their various phases. It begins by introducing compilers and their importance for increasing programmer productivity and enabling reverse engineering. It then covers the classification of programming languages and the history of compilers. The rest of the document details each phase of the compiler process, including lexical analysis, syntax analysis, semantic analysis, intermediate code generation, code optimization, code generation, and the role of the symbol table. It provides definitions and examples for each phase to explain how a source program is translated from a high-level language into executable machine code.
The document provides an overview of compiler design and the different phases involved in compiling a program. It discusses:
1) What compilers do by translating source code into machine code while hiding machine-dependent details. Compilers may generate pure machine code, augmented machine code, or virtual machine code.
2) The typical structure of a compiler which includes lexical analysis, syntactic analysis, semantic analysis, code generation, and optimization phases.
3) Lexical analysis involves scanning the source code and grouping characters into tokens. Regular expressions are used to specify patterns for tokens. Scanner generators like Lex and Flex can generate scanners from regular expression definitions.
Compiler construction tools were introduced to aid in the development of compilers. These tools include scanner generators, parser generators, syntax-directed translation engines, and automatic code generators. Scanner generators produce lexical analyzers based on regular expressions to recognize tokens. Parser generators take context-free grammars as input to produce syntax analyzers. Syntax-directed translation engines associate translations with parse trees to generate intermediate code. Automatic code generators take intermediate code as input and output machine language. These tools help automate and simplify the compiler development process.
This document provides an overview of the key concepts and phases in compiler design, including lexical analysis, syntax analysis using context-free grammars and parsing techniques, semantic analysis using attribute grammars, intermediate code generation, code optimization, and code generation. The major parts of a compiler are the analysis phase, which creates an intermediate representation from the source program using lexical analysis, syntax analysis, and semantic analysis, and the synthesis phase, which generates the target program from the intermediate representation using intermediate code generation, code optimization, and code generation.
Visual Style and Aesthetics: Basics of Visual Design
Visual Design for Enterprise Applications
Range of Visual Styles.
Mobile Interfaces:
Challenges and Opportunities of Mobile Design
Approach to Mobile Design
Patterns
Fonts play a crucial role in both User Interface (UI) and User Experience (UX) design. They affect readability, accessibility, aesthetics, and overall user perception.
Storytelling For The Web: Integrate Storytelling in your Design ProcessChiara Aliotta
In this slides I explain how I have used storytelling techniques to elevate websites and brands and create memorable user experiences. You can discover practical tips as I showcase the elements of good storytelling and its applied to some examples of diverse brands/projects..
Connect Conference 2022: Passive House - Economic and Environmental Solution...TE Studio
Passive House: The Economic and Environmental Solution for Sustainable Real Estate. Lecture by Tim Eian of TE Studio Passive House Design in November 2022 in Minneapolis.
- The Built Environment
- Let's imagine the perfect building
- The Passive House standard
- Why Passive House targets
- Clean Energy Plans?!
- How does Passive House compare and fit in?
- The business case for Passive House real estate
- Tools to quantify the value of Passive House
- What can I do?
- Resources
ARENA - Young adults in the workplace (Knight Moves).pdfKnight Moves
Presentations of Bavo Raeymaekers (Project lead youth unemployment at the City of Antwerp), Suzan Martens (Service designer at Knight Moves) and Adriaan De Keersmaeker (Community manager at Talk to C)
during the 'Arena • Young adults in the workplace' conference hosted by Knight Moves.
2. Compiler
• A given source language is either compiled or
interpreted for execution
• compiler is a program that translates a source
program (HLL; C, Java) into target code;
machine re-locatable code or assembly code.
–The generated machine code can be later
executed many times against different data
each time.
–The code generated is not portable to other
systems.
3. Interpreter
In an interpreted language, implementations
execute instructions directly and freely
without previously compiling a program into
machine code instructions.
Translation occurs at the same time as the
program is being executed.
An interpreter reads an executable source
program written in HLL as well as data for this
program, and it runs the program against the
data to produce some results.
–
4. Interpreter
Common interpreters include Perl, Python, and
Ruby interpreters, which execute Perl, Python,
and Ruby code respectively.
Others include Unix shell interpreter, which
runs operating system commands interactively.
Source program is interpreted every time it is
executed (less efficient).
–
5. Interpreter
Interpreted languages are portable since they
are not machine dependent. They can run on
different operating systems and platforms.
They are translated on the spot and thus
optimized for the system on which they’re
being run.
–
6. Compilers and Interpreters
• “Compilation”
– Translation of a program written in a source
language into a semantically equivalent
program written in a target language
Compiler
Error messages
Source
Program
Target
Program
Input
Output
7. Compilers and Interpreters (cont’d)
Interpreter
Source
Program
Input
Output
Error messages
• “Interpretation”
– Performing the operations implied by the
source program
8. The Analysis-Synthesis Model of
Compilation
• There are two parts to compilation:
– Analysis Phase
This is also known as the front-end of the compiler. It
reads the source program, divides it into core parts and
then checks for lexical, grammar and syntax errors. The
analysis phase generates an intermediate representation
of the source program and symbol table, which should
be fed to the Synthesis phase as input
– Synthesis Phase
Its also known as the back-end of the compiler.
It generates the target program with the help of
intermediate source code representation and symbol
table.
9. Other Tools that Use the
Analysis-Synthesis Model
• Editors (syntax highlighting)
• Pretty printers (e.g. Doxygen)
• Static checkers (e.g. Lint and Splint)
• Interpreters
• Text formatters (e.g. TeX and LaTeX)
• Silicon compilers (e.g. VHDL)
• Query interpreters/compilers (Databases)
10. Preprocessors, Compilers, Assemblers and
Linkers
• A preprocessor considered as part of compiler, is a
tool that produces input for compilers. It deals with
macro-processing, file inclusion, language extension,
etc.
• Assembler
An assembler translates assembly language programs
into machine code. The output of an assembler is called
an object file, which contains a combination of
machine instructions as well as the data required to
place these instructions in memory.
11. Preprocessors, Compilers, Assemblers and
Linkers
• Linker
A computer program that links and merges various
object files together in order to make an executable
file.
All these files might have been compiled by separate
assemblers. The major task of a linker is to search
and locate referenced module/routines in a program
and to determine the memory location where these
codes will be loaded, making the program
instruction to have absolute references.
12. Compiler Design - Architecture of a
Compiler
• A compiler can have many phases and passes.
• Pass : A pass refers to the traversal of a compiler
through the entire program.
• Phase : A phase of a compiler is a distinguishable
stage, which takes input from the previous stage,
processes and yields output that can be used as input
for the next stage. A pass can have more than one
phase.
13. Phases of a Compiler
• The compilation process is a sequence of various
phases.
• Each phase takes input from its previous stage and
has its own representation of source program, and
feeds its output to the next phase of the compiler.
14. Traditional three pass compiler
Front end
Source
code
Machine
code
errors
IR
Back end
Middle
end
IR
15. Phases of a Compiler - Front end
The front end analyzes the source code to
build an internal representation of the
program, called the intermediate
representation (IR).
It also manages the symbol table, a data
structure mapping each symbol in the source
code to associated information such as
location, type and scope.
16. Phases of a Compiler - Front end cont’d
The front end includes all analysis phases and
the intermediate code generator.
• Lexical analysis is the first phase of compiler
which is also termed as scanning.
• During this phase, Source program is scanned to
read the stream of characters and those characters are
grouped to form a sequence called lexemes which
produces token as output. Tokens are defined by
regular expressions which are understood by the
lexical analyzer.
17. Lexical Analysis
lexical analysis: The process of converting a sequence
of characters (such as in a computer program) into a
sequence of tokens (strings with an identified
"meaning")
Lexical analysis takes the modified source code from
language preprocessors that are written in the form of
sentences.
The lexical analyzer breaks these syntaxes into a
series of tokens, by removing any whitespace or
comments in the source code.
18. Lexical Analysis
The lexical analyzer (either generated automatically
by a tool like lex, or hand-crafted) reads in a stream
of characters, identifies the lexemes in the stream, and
categorizes them into tokens.
This is called "tokenizing". If the lexer finds an
invalid token, it will report an error.
19. Front end: Terminologies
• Token: Token is a sequence of characters that
represent lexical unit, which matches with
the pattern, such as keywords, operators,
identifiers etc.
• Lexeme: Lexeme is instance of a token i.e.,
group of characters forming a token.
• Pattern: Pattern describes the rule that the
lexemes of a token takes. It is the structure
that must be matched by strings.
20. Token and Lexeme
Once a token is generated the corresponding
entry is made in the symbol table.
At lexical analysis phase,
Input: stream of characters
Output: Token
Token Template:
<token-name, attribute-value>
For example, for c=a+b*5;
Hence,
<id, 1><=>< id, 2>< +><id, 3 >< * >< 5>
22. Syntax Analysis
Syntax Analyze is sometimes called as
parser. It constructs the parse tree. It takes all
the tokens one by one and uses Context Free
Grammar to construct the parse tree.
Why Grammar ?
The rules of programming can be entirely
represented in some few productions. Using
these productions we can represent what the
program actually is. The input has to be
checked whether it is in the desired format or
not.
23. Syntax Analysis cont’d
Syntax error can be detected at this level if
the input is not in accordance with the
grammar.
24. Syntactic Analysis
Parsing or syntactic analysis is the process of
analyzing a string of symbols, either in natural
language or in computer languages,
conforming to the rules of a formal grammar
Parse: analyze (a string or text) into logical
syntactic components, typically in order to test
conformability to a logical grammar.
25. Syntactic Analysis cont’d
If the lexical analyzer finds a token invalid, it
generates an error.
The lexical analyzer works closely with the
syntax analyzer. It reads character streams
from the source code, checks for legal tokens,
and passes the data to the syntax analyzer
when it demands.
26. Semantic Analysis
Semantic analyzer takes the output of syntax
analyzer and produces another tree.
Similarly, intermediate code generator takes a
tree as an input produced by semantic
analyzer and produces intermediate code.
28. Semantic Analysis cont’d
Syntax tree is a compressed representation of
the parse tree (a hierarchical structure that
represents the derivation of the grammar to
obtain input strings) in which the operators
appear as interior nodes and the operands of the
operator are the children of the node for that
operator.
Example of syntax tree
29. Semantic Analyzer
Semantic analysis is the third phase of compiler.
It checks for the semantic consistency.
Type information is gathered and stored in
symbol table or in syntax tree.
Performs type checking.
It verifies the parse tree, whether it’s
meaningful or not. It furthermore produces a
verified parse tree.
31. Front-end, Back-end division
• Front end maps legal code into IR
• Back end maps IR onto target machine
• Allows multiple front ends
• Multiple passes -> better code
Front end
Source
code
Machine
code
errors
IR
Back end
32. Front end
• Recognize legal code
• Report errors
• Produce IR
• Preliminary storage maps
Scanner
Source
code
IR
errors
tokens
Parser
33. Front end
• Scanner:
– Maps characters into tokens – the basic unit of syntax
• x = x + y becomes <id, x> = <id, x> + <id, y>
– Typical tokens: number, id, +, -, *, /, do, end
– Eliminate white space (tabs, blanks, comments)
• A key issue is speed so instead of using a tool like
LEX it sometimes needed to write your own
scanner
Scanner
Source
code
IR
errors
tokens
Parser
34. Front end
• Parser:
– Recognize context-free syntax
– Guide context-sensitive analysis
– Construct IR
– Produce meaningful error messages
– Attempt error correction
• There are parser generators like YACC which
automates much of the work
Scanner
Source
code
IR
errors
tokens
Parser
35. Phases of a Compiler cont’d
Middle End – The Optimizer
The middle end performs optimizations on the
intermediate representation in order to improve the
performance and the quality of the produced
machine code.
The middle end contains those optimizations that
are independent of the CPU architecture being
targeted.
– Effort to realize efficiency
– Can be very computationally intensive
36. Middle end (optimizer)
• Modern optimizers are usually built as a set
of passes
• Typical passes
– Constant propagation
– Common sub-expression elimination
– Redundant store elimination
– Dead code elimination
37. Back end
• Translate IR into target machine code
• Choose instructions for each IR operation
• Decide what to keep in registers at each
point
• Ensure conformance with system interfaces
Instruction
selection
IR
Machine code
errors
Register
Allocation
38. Phases of a Compiler
Back End – This is responsible for the CPU
architecture specific optimizations and for code
generation.
Machine dependent optimizations: optimizations that
depend on the details of the CPU architecture that the
compiler targets
Code generation. The transformed intermediate
language is translated into the output language, usually
the native machine language of the system.
39. Phases of a Compiler
It also involves resource and storage decisions, such
as; deciding which variables to fit into registers and
memory and the selection and scheduling of
appropriate machine instructions along with their
associated addressing modes
– Processor (target) Dependant optimization
•
40. Phases of a Compiler - Instruction selection
• Instruction selection is the stage of a compiler back-
end that transforms its middle-level intermediate
representation (IR) into a low-level IR where each
operation directly corresponds to an instruction
available on the target machine.
• In a typical compiler, instruction selection precedes
both instruction scheduling and register allocation;
hence its output IR has an infinite set of pseudo-
registers
41. Back end
• Have a value in a register when used
• Limited resources
• Optimal allocation is difficult
Instruction
selection
IR
Machine code
errors
Register
Allocation
42. Intermediate Code Generation
After semantic analysis the compiler generates an
intermediate code of the source code for the target
machine.
– It represents a program for some abstract
machine.
– It is in between the high-level language and the
machine language.
– This intermediate code should be generated in
such a way that it makes it easier to be
translated into the target machine code.
43. Code Optimization
Optimization can be assumed as something that
removes unnecessary code lines, and arranges the
sequence of statements in order to speed up the
program execution without wasting resources
(CPU, memory).
44. Code Generation
• In this phase, the code generator takes the
optimized representation of the intermediate code
and maps it to the target machine language.
• The code generator translates the intermediate
code into a sequence of (generally) re-locatable
machine code. Sequence of instructions of
machine code performs the task as the
intermediate code would do.
45. Symbol Table
It is a data-structure maintained throughout all the
phases of a compiler.
All the identifier's names along with their types
are stored here.
The symbol table makes it easier for the compiler
to quickly search the identifier record and retrieve
it. The symbol table is also used for scope
management.
46. Compiler-Construction Tools
• Software development tools are available to
implement one or more compiler phases
– Scanner generators
– Parser generators
– Syntax-directed translation engines
– Automatic code generators
– Data-flow engines