The document provides an overview of a compilers design and construction course. It discusses the various phases of compilation including lexical analysis, syntax analysis, semantic analysis, code generation, and optimization. The course aims to introduce the principles and techniques used in compiler construction and the issues that arise in developing a compiler. The course will cover topics like lexical analysis, syntax analysis, semantic analysis, intermediate code generation, control flow, code optimization and code generation over its 12 weeks.
C Programming Lecture 1 - Introduction to C.pptxMurali M
CENTURION UNIVERSITY OF TECHNOLOGY AND MANAGEMENT
ANDHRAPRADESH
SUBJECT NAME: (FULL NAME)
SUBJECT CODE: CUTM1046
MODULE NO:
S.No WRT
1 Explain in detail about intrinsic and extrinsic semiconductors with neat diagrams. 8
2 Explain about PN junction diode operation and draw V-I characteristics. 8
3 Derive PN junction diode current equation. 8
4 Explain about carrier concentration of fully injected light illumination on semiconductor bar and 8
5 What is hall effect ??, derive hall coefficient by drawing neat diagram and write the applications of it. 8
6 Explain about Zener diode and avalanche breakdown in detail. 8
7 Design all the logic gates using diodes and explain the operation with truth tables. 8
8 Draw half wave rectifier circuit, explain its operation and explain all the parameters of half wave rectifier. 8
9 Draw full wave rectifier circuit, explain its operation and explain all the parameters of full wave rectifier. 8
10 Draw energy band diagrams of PN junction diode and define diffusion length and life time of the carrier. 8
11 Explain about half wave rectifier 4
12 Explain about full wave rectifier 4
13 Explain PN junction characteristics 4
14 Explain about Light Emitting Diode 4
15 Explain Zener diode characteristics 4
16 i) Define ionic bond and covalent bond
ii) Explain intrinsic semiconductors 4
17 Explain about extrinsic semiconductor 4
18 Explain about hall effect in detail 4
19 Draw AND and OR logic gates using Diodes 4
20 Draw energy band diagram of PN junction diode. 4
Low level, High level and Middle level programming languages
,Bug and Debugging ,difference between compiler and interpreter,instructions and program,source code and object code ,language translators
How Does XfilesPro Ensure Security While Sharing Documents in Salesforce?XfilesPro
Worried about document security while sharing them in Salesforce? Fret no more! Here are the top-notch security standards XfilesPro upholds to ensure strong security for your Salesforce documents while sharing with internal or external people.
To learn more, read the blog: https://www.xfilespro.com/how-does-xfilespro-make-document-sharing-secure-and-seamless-in-salesforce/
A Comprehensive Look at Generative AI in Retail App Testing.pdfkalichargn70th171
Traditional software testing methods are being challenged in retail, where customer expectations and technological advancements continually shape the landscape. Enter generative AI—a transformative subset of artificial intelligence technologies poised to revolutionize software testing.
C Programming Lecture 1 - Introduction to C.pptxMurali M
CENTURION UNIVERSITY OF TECHNOLOGY AND MANAGEMENT
ANDHRAPRADESH
SUBJECT NAME: (FULL NAME)
SUBJECT CODE: CUTM1046
MODULE NO:
S.No WRT
1 Explain in detail about intrinsic and extrinsic semiconductors with neat diagrams. 8
2 Explain about PN junction diode operation and draw V-I characteristics. 8
3 Derive PN junction diode current equation. 8
4 Explain about carrier concentration of fully injected light illumination on semiconductor bar and 8
5 What is hall effect ??, derive hall coefficient by drawing neat diagram and write the applications of it. 8
6 Explain about Zener diode and avalanche breakdown in detail. 8
7 Design all the logic gates using diodes and explain the operation with truth tables. 8
8 Draw half wave rectifier circuit, explain its operation and explain all the parameters of half wave rectifier. 8
9 Draw full wave rectifier circuit, explain its operation and explain all the parameters of full wave rectifier. 8
10 Draw energy band diagrams of PN junction diode and define diffusion length and life time of the carrier. 8
11 Explain about half wave rectifier 4
12 Explain about full wave rectifier 4
13 Explain PN junction characteristics 4
14 Explain about Light Emitting Diode 4
15 Explain Zener diode characteristics 4
16 i) Define ionic bond and covalent bond
ii) Explain intrinsic semiconductors 4
17 Explain about extrinsic semiconductor 4
18 Explain about hall effect in detail 4
19 Draw AND and OR logic gates using Diodes 4
20 Draw energy band diagram of PN junction diode. 4
Low level, High level and Middle level programming languages
,Bug and Debugging ,difference between compiler and interpreter,instructions and program,source code and object code ,language translators
How Does XfilesPro Ensure Security While Sharing Documents in Salesforce?XfilesPro
Worried about document security while sharing them in Salesforce? Fret no more! Here are the top-notch security standards XfilesPro upholds to ensure strong security for your Salesforce documents while sharing with internal or external people.
To learn more, read the blog: https://www.xfilespro.com/how-does-xfilespro-make-document-sharing-secure-and-seamless-in-salesforce/
A Comprehensive Look at Generative AI in Retail App Testing.pdfkalichargn70th171
Traditional software testing methods are being challenged in retail, where customer expectations and technological advancements continually shape the landscape. Enter generative AI—a transformative subset of artificial intelligence technologies poised to revolutionize software testing.
In software engineering, the right architecture is essential for robust, scalable platforms. Wix has undergone a pivotal shift from event sourcing to a CRUD-based model for its microservices. This talk will chart the course of this pivotal journey.
Event sourcing, which records state changes as immutable events, provided robust auditing and "time travel" debugging for Wix Stores' microservices. Despite its benefits, the complexity it introduced in state management slowed development. Wix responded by adopting a simpler, unified CRUD model. This talk will explore the challenges of event sourcing and the advantages of Wix's new "CRUD on steroids" approach, which streamlines API integration and domain event management while preserving data integrity and system resilience.
Participants will gain valuable insights into Wix's strategies for ensuring atomicity in database updates and event production, as well as caching, materialization, and performance optimization techniques within a distributed system.
Join us to discover how Wix has mastered the art of balancing simplicity and extensibility, and learn how the re-adoption of the modest CRUD has turbocharged their development velocity, resilience, and scalability in a high-growth environment.
Quarkus Hidden and Forbidden ExtensionsMax Andersen
Quarkus has a vast extension ecosystem and is known for its subsonic and subatomic feature set. Some of these features are not as well known, and some extensions are less talked about, but that does not make them less interesting - quite the opposite.
Come join this talk to see some tips and tricks for using Quarkus and some of the lesser known features, extensions and development techniques.
Providing Globus Services to Users of JASMIN for Environmental Data AnalysisGlobus
JASMIN is the UK’s high-performance data analysis platform for environmental science, operated by STFC on behalf of the UK Natural Environment Research Council (NERC). In addition to its role in hosting the CEDA Archive (NERC’s long-term repository for climate, atmospheric science & Earth observation data in the UK), JASMIN provides a collaborative platform to a community of around 2,000 scientists in the UK and beyond, providing nearly 400 environmental science projects with working space, compute resources and tools to facilitate their work. High-performance data transfer into and out of JASMIN has always been a key feature, with many scientists bringing model outputs from supercomputers elsewhere in the UK, to analyse against observational or other model data in the CEDA Archive. A growing number of JASMIN users are now realising the benefits of using the Globus service to provide reliable and efficient data movement and other tasks in this and other contexts. Further use cases involve long-distance (intercontinental) transfers to and from JASMIN, and collecting results from a mobile atmospheric radar system, pushing data to JASMIN via a lightweight Globus deployment. We provide details of how Globus fits into our current infrastructure, our experience of the recent migration to GCSv5.4, and of our interest in developing use of the wider ecosystem of Globus services for the benefit of our user community.
TROUBLESHOOTING 9 TYPES OF OUTOFMEMORYERRORTier1 app
Even though at surface level ‘java.lang.OutOfMemoryError’ appears as one single error; underlyingly there are 9 types of OutOfMemoryError. Each type of OutOfMemoryError has different causes, diagnosis approaches and solutions. This session equips you with the knowledge, tools, and techniques needed to troubleshoot and conquer OutOfMemoryError in all its forms, ensuring smoother, more efficient Java applications.
Climate Science Flows: Enabling Petabyte-Scale Climate Analysis with the Eart...Globus
The Earth System Grid Federation (ESGF) is a global network of data servers that archives and distributes the planet’s largest collection of Earth system model output for thousands of climate and environmental scientists worldwide. Many of these petabyte-scale data archives are located in proximity to large high-performance computing (HPC) or cloud computing resources, but the primary workflow for data users consists of transferring data, and applying computations on a different system. As a part of the ESGF 2.0 US project (funded by the United States Department of Energy Office of Science), we developed pre-defined data workflows, which can be run on-demand, capable of applying many data reduction and data analysis to the large ESGF data archives, transferring only the resultant analysis (ex. visualizations, smaller data files). In this talk, we will showcase a few of these workflows, highlighting how Globus Flows can be used for petabyte-scale climate analysis.
First Steps with Globus Compute Multi-User EndpointsGlobus
In this presentation we will share our experiences around getting started with the Globus Compute multi-user endpoint. Working with the Pharmacology group at the University of Auckland, we have previously written an application using Globus Compute that can offload computationally expensive steps in the researcher's workflows, which they wish to manage from their familiar Windows environments, onto the NeSI (New Zealand eScience Infrastructure) cluster. Some of the challenges we have encountered were that each researcher had to set up and manage their own single-user globus compute endpoint and that the workloads had varying resource requirements (CPUs, memory and wall time) between different runs. We hope that the multi-user endpoint will help to address these challenges and share an update on our progress here.
SOCRadar Research Team: Latest Activities of IntelBrokerSOCRadar
The European Union Agency for Law Enforcement Cooperation (Europol) has suffered an alleged data breach after a notorious threat actor claimed to have exfiltrated data from its systems. Infamous data leaker IntelBroker posted on the even more infamous BreachForums hacking forum, saying that Europol suffered a data breach this month.
The alleged breach affected Europol agencies CCSE, EC3, Europol Platform for Experts, Law Enforcement Forum, and SIRIUS. Infiltration of these entities can disrupt ongoing investigations and compromise sensitive intelligence shared among international law enforcement agencies.
However, this is neither the first nor the last activity of IntekBroker. We have compiled for you what happened in the last few days. To track such hacker activities on dark web sources like hacker forums, private Telegram channels, and other hidden platforms where cyber threats often originate, you can check SOCRadar’s Dark Web News.
Stay Informed on Threat Actors’ Activity on the Dark Web with SOCRadar!
Enhancing Research Orchestration Capabilities at ORNL.pdfGlobus
Cross-facility research orchestration comes with ever-changing constraints regarding the availability and suitability of various compute and data resources. In short, a flexible data and processing fabric is needed to enable the dynamic redirection of data and compute tasks throughout the lifecycle of an experiment. In this talk, we illustrate how we easily leveraged Globus services to instrument the ACE research testbed at the Oak Ridge Leadership Computing Facility with flexible data and task orchestration capabilities.
Paketo Buildpacks : la meilleure façon de construire des images OCI? DevopsDa...Anthony Dahanne
Les Buildpacks existent depuis plus de 10 ans ! D’abord, ils étaient utilisés pour détecter et construire une application avant de la déployer sur certains PaaS. Ensuite, nous avons pu créer des images Docker (OCI) avec leur dernière génération, les Cloud Native Buildpacks (CNCF en incubation). Sont-ils une bonne alternative au Dockerfile ? Que sont les buildpacks Paketo ? Quelles communautés les soutiennent et comment ?
Venez le découvrir lors de cette session ignite
Unleash Unlimited Potential with One-Time Purchase
BoxLang is more than just a language; it's a community. By choosing a Visionary License, you're not just investing in your success, you're actively contributing to the ongoing development and support of BoxLang.
Modern design is crucial in today's digital environment, and this is especially true for SharePoint intranets. The design of these digital hubs is critical to user engagement and productivity enhancement. They are the cornerstone of internal collaboration and interaction within enterprises.
Prosigns: Transforming Business with Tailored Technology SolutionsProsigns
Unlocking Business Potential: Tailored Technology Solutions by Prosigns
Discover how Prosigns, a leading technology solutions provider, partners with businesses to drive innovation and success. Our presentation showcases our comprehensive range of services, including custom software development, web and mobile app development, AI & ML solutions, blockchain integration, DevOps services, and Microsoft Dynamics 365 support.
Custom Software Development: Prosigns specializes in creating bespoke software solutions that cater to your unique business needs. Our team of experts works closely with you to understand your requirements and deliver tailor-made software that enhances efficiency and drives growth.
Web and Mobile App Development: From responsive websites to intuitive mobile applications, Prosigns develops cutting-edge solutions that engage users and deliver seamless experiences across devices.
AI & ML Solutions: Harnessing the power of Artificial Intelligence and Machine Learning, Prosigns provides smart solutions that automate processes, provide valuable insights, and drive informed decision-making.
Blockchain Integration: Prosigns offers comprehensive blockchain solutions, including development, integration, and consulting services, enabling businesses to leverage blockchain technology for enhanced security, transparency, and efficiency.
DevOps Services: Prosigns' DevOps services streamline development and operations processes, ensuring faster and more reliable software delivery through automation and continuous integration.
Microsoft Dynamics 365 Support: Prosigns provides comprehensive support and maintenance services for Microsoft Dynamics 365, ensuring your system is always up-to-date, secure, and running smoothly.
Learn how our collaborative approach and dedication to excellence help businesses achieve their goals and stay ahead in today's digital landscape. From concept to deployment, Prosigns is your trusted partner for transforming ideas into reality and unlocking the full potential of your business.
Join us on a journey of innovation and growth. Let's partner for success with Prosigns.
Designing for Privacy in Amazon Web ServicesKrzysztofKkol1
Data privacy is one of the most critical issues that businesses face. This presentation shares insights on the principles and best practices for ensuring the resilience and security of your workload.
Drawing on a real-life project from the HR industry, the various challenges will be demonstrated: data protection, self-healing, business continuity, security, and transparency of data processing. This systematized approach allowed to create a secure AWS cloud infrastructure that not only met strict compliance rules but also exceeded the client's expectations.
In 2015, I used to write extensions for Joomla, WordPress, phpBB3, etc and I ...Juraj Vysvader
In 2015, I used to write extensions for Joomla, WordPress, phpBB3, etc and I didn't get rich from it but it did have 63K downloads (powered possible tens of thousands of websites).
Developing Distributed High-performance Computing Capabilities of an Open Sci...Globus
COVID-19 had an unprecedented impact on scientific collaboration. The pandemic and its broad response from the scientific community has forged new relationships among public health practitioners, mathematical modelers, and scientific computing specialists, while revealing critical gaps in exploiting advanced computing systems to support urgent decision making. Informed by our team’s work in applying high-performance computing in support of public health decision makers during the COVID-19 pandemic, we present how Globus technologies are enabling the development of an open science platform for robust epidemic analysis, with the goal of collaborative, secure, distributed, on-demand, and fast time-to-solution analyses to support public health.
2. • Any program written in a programming language
must be translated before it can be executed.
• This translation is typically accomplished by a
software system called compiler.
• This course aims to introduce the principles and
techniques used to perform this translation and the
issues that arise in the construction of a compiler.
Course Aims
6. 6
Learning Outcomes:
• A student successfully completing this course should be able to:
• understand the principles governing all phases of the compilation
process.
• understand the role of each of the basic components of a
standard compiler.
• show awareness of the problems of and methods and techniques
applied to each phase of the compilation process.
• apply standard techniques to solve basic problems that arise in
compiler construction.
• understand how the compiler can take advantage of particular
processor characteristics to generate good code.
7. References
• Class textbook
• Compilers: Principles, Techniques, and
Tools by Aho, Sethi, and Ullman
• Other useful books
• Advanced Compiler Design &
Implementation, Steven Muchnick
• Building an Optimizing Compiler,
Robert Morgan
• Modern Compiler Implementation in
Java, Andrew Appel
8. Software Categories
• System SW
• Programs written for computer systems
• Compilers, operating systems, …
• Application SW
• Programs written for computer users
• Word-processors, spreadsheets, & other application packages
9. A Layered View of a Computer from the perspective of compiler
Machine with all its hardware
System Software
Compilers, Interpreters, Preprocessors, etc.
Operating System, Device Drivers
Application Programs
Word-Processors, Spreadsheets,
Database Software, IDEs,
etc…
10. Programs
• Any program can be written in any programming language
• A programming language(PL) is
• A set of rules and symbols used to construct a computer program
• A language used to interact with the computer
11. 11
Why study Compilation Technology?
• Success stories (one of the earliest branches in CS)
• Applying theory to practice (scanning, parsing, static analysis)
• Ideas from different parts of computer science are involved:
• AI: Heuristic search techniques; greedy algorithms - Algorithms: graph
algorithms - Theory: pattern matching - Also: Systems, Architecture
• Compiler construction can be challenging and fun:
• new architectures always create new challenges; success requires
mastery of complex interactions; results are useful; opportunity to
achieve performance.
13. 13
Principles of Compilation
The compiler must:
• preserve the meaning of the program being compiled.
• “improve” the source code in some way.
• Space (size of compiled code)
• Feedback (information provided to the user)
• Debugging
• Compilation time efficiency (fast or slow compiler?)
15. Compilers
• “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
Target program : an executable machine-language program.
17. History
IBM developed 704 in 1954. All programming was done in assembly
language. Cost of software development far exceeded cost of hardware.
Low productivity.
• Speedcoding interpreter: programs ran about 10 times slower than
hand written assembly code
• John Backus (in 1954): Proposed a program that translated high level
expressions into native machine code. Skeptism all around. Most people
thought it was impossible
• Fortran I project (1954-1957): The
first compiler was released
18. Fortran I
• The first compiler had a huge impact on the programming
languages and computer science. The whole new field of
compiler design was started.
• More than half the programmers were using Fortran by 1958.
• The development time was cut down to half.
• Modern compilers preserve the basic structure of the Fortran I
compiler !!!
19. Computer Languages
– Machine Language
• Uses binary code
• Machine-dependent
• Not portable
• Assembly Language
• Uses mnemonics(list of words to remembers)
• Machine-dependent
• Not usually portable
• High-Level Language (HLL)
• Uses English-like language
• Portable (but must be compiled for different platforms)
• Examples: Pascal, C, C++, Java, Fortran, . . .
20. Machine Language
• The representation of a computer program which is actually read and understood
by the computer.
• A program in machine code consists of a sequence of machine instructions.
• Instructions:
• Machine instructions are in binary code
• Instructions specify operations and memory cells involved in the operation
Example:
Operation Address
0010 0000 0000 0100
0100 0000 0000 0101
0011 0000 0000 0110
21. Assembly Language
A symbolic representation of the machine language of a specific processor.
Is converted to machine code by an assembler.
Each line of assembly code produces one machine instruction (One-to-one correspondence).
Programming in assembly language is slow and error-prone but is more efficient in terms of
hardware performance.
Mnemonic representation of the instructions and data
Example:
Load Price
Add Tax
Store Cost
22. High-level language
• A programming language which use statements consisting of English-like keywords
such as "FOR", "PRINT" or “IF“, ... etc.
• Each statement corresponds to several machine language instructions (one-to-many
correspondence).
• Much easier to program than in assembly language.
• Operations can be described using familiar symbols
• Example:
Cost = Price + Tax
24. Editors , Preprocessors , Linker & Loader
• - Editors
• Compiler have been bundled together with editor and other programs into an interactive
development environment (IDE)
• May include some operations of a compiler, informing some errors
• - Preprocessors
• Delete comments, include other files, and perform macro substitutions
• - Linkers
• Collect separate object files into a directly executable file
• Connect an object program to the code for standard library functions and to resource supplied by OS
• - Loaders
• Resolve all re-locatable address relative to a given base
• Make executable code more flexible
25. Compiling and running C programs
Editor
Compiler
Linker
Source code
file.c
Object code
file.obj
Executable code
file.exe
Libraries
26. Debuggers
• Used to determine execution error in a compiled program
• Keep tracks of most or all of the source code information
• Stop execution at pre-specified locations called breakpoints
28. Interpreters
• Execute the source program immediately rather than generating
object code
• Examples: BASIC, LISP, used often in educational or development
situations
• Speed of execution is slower than compiled code
• Share many of their operations with compilers
29. How to translate?
• Direct translation is difficult. Why?
• • Source code and machine code mismatch in level of abstraction
• – Variables vs Memory locations/registers
• – Functions vs jump/return
• – Parameter passing
• – structs
• • Some languages are farther from machine code than others
• – For example, languages supporting Object Oriented Paradigm
30. How to translate easily?
• Translate in steps. Each step handles a reasonably simple, logical, and
well defined task
• • Design a series of program representations
• • Intermediate representations should be amenable to program
manipulation of various kinds (type checking, optimization, code
generation etc.)
• • Representations become more machine specific and less language
specific as the translation proceeds
31. The first few steps
• The first few steps can be understood by analogies to how humans
comprehend a natural language
• • The first step is recognizing/knowing alphabets of a language. For
example
• – English text consists of lower and upper case alphabets, digits,
punctuations and white spaces
• –Written programs consist of characters from the ASCII characters set
(normally 9-13, 32-126)
32. The first few steps
• The next step to understand the sentence is recognizing words
• –How to recognize English words?
• –Words found in standard dictionaries
• –Dictionaries are updated regularly
33. The first few steps
• How to recognize words in a programming language?
• – a dictionary (of keywords etc.)
• – rules for constructing words (identifiers, numbers etc.)
• • This is called lexical analysis
• • Recognizing words is not completely trivial.
• For example: w hat ist his se nte nce?
34. Lexical Analysis: Challenges
• • We must know what the word separators are
• • The language must define rules for breaking a sentence into a
sequence of words.
• • Normally white spaces and punctuations are word separators in
languages.
35. Lexical Analysis: Challenges
• • In programming languages a character from a different class may also
be treated as word separator.
• • The lexical analyzer breaks a sentence into a sequence of words or
tokens:
• – If a == b then a = 1 ; else a = 2 ;
• – Sequence of words (total 14 words)
• if a == b then a = 1 ; else a = 2 ;
36. The next step
• • Once the words are understood, the next step is to understand the
structure of the sentence
• • The process is known as syntax checking or parsing
37. Parsing
Parsing a program is exactly the same process as shown in
previous slide.
• Consider an expression
if x == y then z = 1 else z = 2
38. Understanding the meaning
• • Once the sentence structure is understood we try to
understand the meaning of the sentence (semantic
analysis)
• • A challenging task
• • Example: Prateek said Nitin left his assignment at home
• • What does his refer to? Prateek or Nitin?
39. Understanding the meaning
• • Worse case Amit said Amit left his assignment at
home
• • Even worse Amit said Amit left Amit’s assignment at
home
• • How many Amits are there? Which one left the
assignment? Whose assignment got left?
40. Semantic Analysis
• • Too hard for compilers.
• They do not have capabilities similar to human understanding
• • However, compilers do perform analysis to understand the meaning
and catch inconsistencies
• • Programming languages define strict rules to avoid such ambiguities
• { int Amit = 3;
{
int Amit = 4;
cout << Amit;
}
• }
41. More on Semantic Analysis
• • Compilers perform many other checks besides variable
bindings
• • Type checking Amit left her work at home
• • There is a type mismatch between her and Amit. Presumably
Amit is a male. And they are not the same person.
42. Code Optimization
• • No strong counter part with English, but is similar to
editing/précis writing
• • Automatically modify programs so that they
• –Run faster
• –Use less resources (memory, registers, space, fewer fetches
etc.)
43. Code Optimization
• • Some common optimizations
• –Common sub-expression elimination
• –Copy propagation
• –Dead code elimination
• –Code motion
• –Strength reduction
• –Constant folding
• • Example: x = 15 * 3 is transformed to x = 45
45. Compilers
• Analysis of the source program.
• Synthesis into a machine-language program.
1
2 3
46. Parts of Compilers
1. Lexical Analysis
2. Syntax Analysis
3. Semantic Analysis
4. Code Generation
5. Optimization
Analysis
Synthesis
Front
End
Back
End
47. Compilers
• Analysis
• Front End
• Split source code into
different constitute
pieces(token).
• Put the pieces based on
grammatical rules(Parse).
• Report Errors.
• Synthesis
• Back End
• Produce intermediate code
• Optimize Intermediate code
• Generate target
code(machine language
code)
48. 48
Structure of a Compiler
• Front end: analysis
• Read source program and understand its structure and meaning
• Back end: synthesis
• Generate equivalent target language program
Source Target
Front End Back End
49. Phases of a Compiler
49
Code
Generator
Code
Optimizer
Intermediate
Code
Generator
Semantic
Analyzer
Syntax
Analyzer
Lexical
Analyzer
Error Handler
Symbol Table
Manager
Target
Program
Source
Program
50. The Structure of a Compiler
50
Scanner Parser
Semantic
Routines
Code
Generator
Optimizer
Source
Program Tokens Syntactic
Structure
Symbol and
Attribute
Tables
(Used by all Phases of The Compiler)
(Character Stream)
Intermediate
Representation
Target machine code
Analysis phase
Synthesis phase
51. by Neng-Fa Zhou
Analysis source program
lexical analyzer
syntax analyzer
semantic analyzer
source program
tokens
parse trees
parse trees
52. The Structure of a Compiler
52
Scanner Parser
Semantic
Routines
Code
Generator
Optimizer
Source
Program Tokens Syntactic
Structure
Symbol and
Attribute
Tables
(Used by all
Phases of
The Compiler)
Scanner (Lexical Analyzer)
The scanner begins the analysis of the source program by reading the
input, character by character, and grouping characters into individual
words and symbols (tokens)
Puts information about identifiers into the symbol table.
Regular expressions are used to describe tokens (lexical
constructs).
A (Deterministic) Finite State Automaton can be used in the
implementation of a lexical analyzer.
(Character Stream)
Intermediate
Representation
Target machine code
54. The Structure of a Compiler
54
Scanner Parser
Semantic
Routines
Code
Generator
Optimizer
Source
Program Tokens Syntactic
Structure
Symbol and
Attribute
Tables
(Used by all
Phases of
The Compiler)
Parser (Syntax Analyzer)
Given a formal syntax specification (typically as a context-free grammar [CFG] ),
the parse reads tokens and groups them into units as specified by the productions
of the CFG being used.
As syntactic structure is recognized, the parser either calls corresponding semantic
routines directly or builds a syntax tree.
CFG ( Context-Free Grammar )
BNF ( Backus-Naur Form )
GAA ( Grammar Analysis Algorithms )
(Character Stream)
Intermediate
Representation
Target machine code
55. 55
Parser (Syntax Analyzer)
• A Syntax Analyzer creates the syntactic structure (generally a
parse tree) of the given program.
• A syntax analyzer is also called as a parser.
• A parse tree describes a syntactic structure.
parse tree
56. 56
Parser (Syntax Analyzer (CFG) )
• The syntax of a language is specified by a context free grammar
(CFG).
• The rules in a CFG are mostly recursive.
• A syntax analyzer checks whether a given program satisfies the rules
implied by a CFG or not.
• If it satisfies, the syntax analyzer creates a parse tree for the given program.
• Ex: We use BNF (Backus Naur Form) to specify a CFG
assgstmt -> identifier := expression
expression -> identifier
expression -> number
expression -> expression + expression
57. 57
Syntax Analyzer versus Lexical Analyzer
• Which constructs of a program should be recognized by the
lexical analyzer, and which ones by the syntax analyzer?
• Both of them do similar things; But the lexical analyzer deals with
simple non-recursive constructs of the language.
• The syntax analyzer deals with recursive constructs of the language.
• The lexical analyzer simplifies the job of the syntax analyzer.
• The lexical analyzer recognizes the smallest meaningful units (tokens) in
a source program.
• The syntax analyzer works on the smallest meaningful units (tokens) in
a source program to recognize meaningful structures in our
programming language.
58. The Structure of a Compiler
58
Scanner Parser
Semantic
Routines
Code
Generator
Optimizer
Source
Program
(Character Stream)
Tokens Syntactic
Structure
Intermediate
Representation
Symbol and
Attribute
Tables
(Used by all
Phases of
The Compiler)
Semantic Routines
Perform two functions
Check the static semantics of each construct
Do the actual translation
The heart of a compiler
Result is: Syntax Directed Translation
Semantic Processing Techniques
Ex:
newval = oldval + 12
The type of the identifier newval must match with type of the expression (oldval+12)
Target machine code
60. Symbol Table
• There is a record for each identifier
• The attributes include name, type, location, etc.
61. Synthesis of Object Code
intermediate code generator
code optimizer
code generator
parse tree & symbol table
intermediate code
optimized intermediate code
target program
62. The Structure of a Compiler
62
Scanner Parser
Semantic
Routines
Code
Generator
Optimizer
Source
Program
(Character Stream)
Tokens Syntactic
Structure
Intermediate
Representation
Symbol and
Attribute
Tables
(Used by all
Phases of
The Compiler)
Intermediate Code Generation
A compiler may produce an explicit intermediate codes representing the
source program.
These intermediate codes are generally machine (architecture independent).
But the level of intermediate codes is close to the level
Target machine code
64. The Structure of a Compiler
64
Scanner Parser
Semantic
Routines
Code
Generator
Optimizer
Source
Program Tokens Syntactic
Structure
Symbol and
Attribute
Tables
(Used by all
Phases of
The Compiler)
Optimizer
The IR code generated by the semantic routines is analyzed
and transformed into functionally equivalent but improved IR
code
This phase can be very complex and slow
Peephole optimization
loop optimization, register allocation, code scheduling
(Character Stream)
Intermediate
Representation
Target machine code
66. The Structure of a Compiler
66
Source
Program
(Character Stream)
Scanner
Tokens
Parser
Syntactic
Structure
Semantic
Routines
Intermediate
Representation
Optimizer
Code
Generator
Code Generator
Produces the target language in a specific
architecture.
The target program is normally is a relocatable object
file containing the machine codes.
Target machine code