The document discusses macro processors, compilers, and interpreters. It provides details on:
- The phases of a compiler including lexical analysis, syntax analysis, semantic analysis, intermediate code generation, code optimization, and code generation.
- Macro processors which take source code with macro definitions and calls and replace calls with macro bodies. This includes details on macro expansion, formal/actual parameters, and nested macro calls.
- The design of a macro preprocessor which accepts assembly code with macros and removes macros to generate assembly without macros.
- How compilers translate programs written in a source language into an equivalent program in a target language through various analysis and synthesis phases.
Introduction, Macro Definition and Call, Macro Expansion, Nested Macro Calls, Advanced Macro Facilities, Design Of a Macro Preprocessor, Design of a Macro Assembler, Functions of a Macro Processor, Basic Tasks of a Macro Processor, Design Issues of Macro Processors, Features, Macro Processor Design Options, Two-Pass Macro Processors, One-Pass Macro Processors
A macro processor is a system software. Macro is that the Section of code that the programmer writes (defines) once, and then can use or invokes many times.
loader and linker are both system software which capable of loads the object code, assembled by an assembler, (loader) and link a different kind of block of a huge program. both software works at the bottom of the operation (i.e. closer to the hardware). in fact, both have machine dependent and independent features.
Introduction, Macro Definition and Call, Macro Expansion, Nested Macro Calls, Advanced Macro Facilities, Design Of a Macro Preprocessor, Design of a Macro Assembler, Functions of a Macro Processor, Basic Tasks of a Macro Processor, Design Issues of Macro Processors, Features, Macro Processor Design Options, Two-Pass Macro Processors, One-Pass Macro Processors
A macro processor is a system software. Macro is that the Section of code that the programmer writes (defines) once, and then can use or invokes many times.
loader and linker are both system software which capable of loads the object code, assembled by an assembler, (loader) and link a different kind of block of a huge program. both software works at the bottom of the operation (i.e. closer to the hardware). in fact, both have machine dependent and independent features.
Assemblers Elements of Assembly Language Programming, Design of the Assembler, Assembler Design Criteria, Types of Assemblers, Two-Pass Assemblers, One-Pass Assemblers, Single pass Assembler for Intel x86 , Algorithm of Single Pass Assembler, Multi-Pass Assemblers, Advanced Assembly Process, Variants of Assemblers Design of two pass assembler
Description of all types of Loaders from System programming subjects.
eg. Compile-Go Loader
General Loader
Absolute Loader
Relocating Loader
Practical Relocating Loader
Linking Loader
Linker Vs. Loader
general relocatable loader
Assembler is a kind of system software that translate mnemonic codes written in assembly language (which is, in turn, a low-level language) into its equivalent object code (which is, in turn, need to change into executable code by loader and linker)
presentation on design of a 2 pass assembler, and variant I and variant II in the subject of systems programming. especially helpful to GTU students, CSE and IT engineers
The purpose of types:
To define what the program should do.
e.g. read an array of integers and return a double
To guarantee that the program is meaningful.
that it does not add a string to an integer
that variables are declared before they are used
To document the programmer's intentions.
better than comments, which are not checked by the compiler
To optimize the use of hardware.
reserve the minimal amount of memory, but not more
use the most appropriate machine instructions.
Assemblers Elements of Assembly Language Programming, Design of the Assembler, Assembler Design Criteria, Types of Assemblers, Two-Pass Assemblers, One-Pass Assemblers, Single pass Assembler for Intel x86 , Algorithm of Single Pass Assembler, Multi-Pass Assemblers, Advanced Assembly Process, Variants of Assemblers Design of two pass assembler
Description of all types of Loaders from System programming subjects.
eg. Compile-Go Loader
General Loader
Absolute Loader
Relocating Loader
Practical Relocating Loader
Linking Loader
Linker Vs. Loader
general relocatable loader
Assembler is a kind of system software that translate mnemonic codes written in assembly language (which is, in turn, a low-level language) into its equivalent object code (which is, in turn, need to change into executable code by loader and linker)
presentation on design of a 2 pass assembler, and variant I and variant II in the subject of systems programming. especially helpful to GTU students, CSE and IT engineers
The purpose of types:
To define what the program should do.
e.g. read an array of integers and return a double
To guarantee that the program is meaningful.
that it does not add a string to an integer
that variables are declared before they are used
To document the programmer's intentions.
better than comments, which are not checked by the compiler
To optimize the use of hardware.
reserve the minimal amount of memory, but not more
use the most appropriate machine instructions.
Design And Implementation Of A Bangla CompilerMJ Ferdous
It is evident that the familiar programming environment accelerates the efficiency of the
programmer. If a programmer has a chance to write a program in his/her native language
then undoubtedly it will enhance the overall performance of programming. Keeping in
this mind, this project tries to design and implement a Bangla compiler. This compiler
has been named as Ekushe. The whole project may be divided into two phases. The first
phase is the designing of a high-level Bangla programming language. The implemented
language follows the top down approach of popular structured programming languages.
Many basic features of imperative programming languages such as: loop, block structure,
conditional branching etc have been included in Ekushe.
In the second phase the compiler has been designed and implemented. This part actually
includes lexical, syntax and semantics issues of the language. Finally, it deals with
generating assembly code. The final job is to execute the file by creating executable file.
However, as this is the first step of our venture, many complexities of the language have
been avoided. But the major features of any contemporary languages have been included
in our implemented compiler Ekushe.
Basic laws from the relationship of pressure, volume and temperature to deriv...Nousrat Bibi Jouman
The presentation is mainly for learners to have an insight of the basic laws used to derive the equation of state for an ideal gas.
The relationship between pressure, volume and temperature have been investigated by the scientists and each have a law for themselves which have been merged to get one equation.
Motivation
Types of Distributed Operating Systems
Network Structure
Network Topology
Communication Structure
Communication Protocols
Robustness
Design Issues
An Example: Networking
Task Perform addition subtraction division and multiplic.pdfacsmadurai
Task: Perform addition, subtraction, division, and multiplication, of rational numbers on MIPS Mars
Programming Simulator by writing a code and print the answers (using macros) from the pictures
provided. Also, when you write the code make sure you follow this format,
format:
.macro print_int (%x)
li $v0, 1
add $a0, $zero, %x
syscall
.end_macro
print_int ($s0)
print_int (10)
Intro Settings Syscalls IDE Debugging Command Tools History Limitations Exception Handlers
Macros Acknowledgements MARS home Writing and Using Macros .macro, .end_macro,.eqv and
.include directives are new in MARS 4.3 Introduction to macros Patterson and Hennessy define a
macro as a pattern-matching and replacement facility that provides a simple mechanism to name
a frequently used sequence of instructions [1]. This permits the programmer to specify the
instruction sequence by invoking the macro. This requires only one line of code for each use
instead of repeatedly typing in the instruction sequence each time. It follows the axiom "define
once, use many times," which not only reduces the chance for error but also facilitates program
maintenance. Macros are like procedures (subroutines) in this sense but operate differently than
procedures. Procedures in MIPS assembly language follow particular protocols for procedure
definition, call and return. Macros operate by substituting the macro body for each use at the time
of assembly. This substitution is called macro expansion.. They do not require the protocols and
execution overhead of procedures. As a simple example, you may want to terminate your program
from a number of locations. If you are running from the MARS IDE, you will use system call 10,
exit. The instruction sequence is pretty easy 1i$v0,10syscal1 but still tedious. You can define a
macro, let's call it done, to represent this sequence [ begin{array}{l} text { macro done } text { i1 } $
text { vo, } 10 text { syscali } text { +end_macro } end{array} ] then invoke it whenever you wish
with the statement done At assembly time, the assembler will replace each occurrence of the
statement done with the two-statement sequence 1i$v0,10syscali This is the macro expansion.
The runtime simulator is unaware of macros or macro expansion. If running MARS from the
command line, perhaps you want to return a termination value. This can be done with syscall 17,
exit2, which takes the termination value as an argument. An equivalent macro, let's call it
terminate would be macro terminate (stermination_value) ii $a0, itermination_value li $v0,17
syscali .end_macro This macro defines a formal parameter to represent the termination value. You
would invoke it with the statement terminate (1) to terminate with value 1. Upon assembly, the
statement terminate (1) would be replaced byterninate (1) to terminate with value 1. Upon
assembly, the statement terainate (1) would be replaced by the three-statement sequence The
argument value, 1, is substituted wherever the formal parameter teermi.
C Preprocessor directives:
i\ Before a C program is compiled in a compiler, source code is processed by a program called preprocessor. This process is called preprocessing.
Commands used in preprocessor are called preprocessor directives and they begin with “#” symbol.
A command macro is a text file that contains one or more commands and/or command macro statements and that has a name ending with the suffix .cm. You invoke a macro by entering its name. The operating system then sequentially executes the commands and macro statements in the file.
A command macro is useful to replace one of the following:
a long command string that you issue frequently
a group of internal commands, command macros, and/or program modules that together perform an operation you regularly require
a sequence of internal commands, command macros, and/or program modules that you execute in a certain way depending on external factors
Subprograms, Design Issues, Local Referencing, Parameter Passing, Overloaded Methods, Generic Methods, Design Issues for functions, Semantics of call and return, implementing simple subprograms, stack and dynamic local variables, nested subprograms, blocks and dynamic scoping,
How to Make a Field invisible in Odoo 17Celine George
It is possible to hide or invisible some fields in odoo. Commonly using “invisible” attribute in the field definition to invisible the fields. This slide will show how to make a field invisible in odoo 17.
The Roman Empire A Historical Colossus.pdfkaushalkr1407
The Roman Empire, a vast and enduring power, stands as one of history's most remarkable civilizations, leaving an indelible imprint on the world. It emerged from the Roman Republic, transitioning into an imperial powerhouse under the leadership of Augustus Caesar in 27 BCE. This transformation marked the beginning of an era defined by unprecedented territorial expansion, architectural marvels, and profound cultural influence.
The empire's roots lie in the city of Rome, founded, according to legend, by Romulus in 753 BCE. Over centuries, Rome evolved from a small settlement to a formidable republic, characterized by a complex political system with elected officials and checks on power. However, internal strife, class conflicts, and military ambitions paved the way for the end of the Republic. Julius Caesar’s dictatorship and subsequent assassination in 44 BCE created a power vacuum, leading to a civil war. Octavian, later Augustus, emerged victorious, heralding the Roman Empire’s birth.
Under Augustus, the empire experienced the Pax Romana, a 200-year period of relative peace and stability. Augustus reformed the military, established efficient administrative systems, and initiated grand construction projects. The empire's borders expanded, encompassing territories from Britain to Egypt and from Spain to the Euphrates. Roman legions, renowned for their discipline and engineering prowess, secured and maintained these vast territories, building roads, fortifications, and cities that facilitated control and integration.
The Roman Empire’s society was hierarchical, with a rigid class system. At the top were the patricians, wealthy elites who held significant political power. Below them were the plebeians, free citizens with limited political influence, and the vast numbers of slaves who formed the backbone of the economy. The family unit was central, governed by the paterfamilias, the male head who held absolute authority.
Culturally, the Romans were eclectic, absorbing and adapting elements from the civilizations they encountered, particularly the Greeks. Roman art, literature, and philosophy reflected this synthesis, creating a rich cultural tapestry. Latin, the Roman language, became the lingua franca of the Western world, influencing numerous modern languages.
Roman architecture and engineering achievements were monumental. They perfected the arch, vault, and dome, constructing enduring structures like the Colosseum, Pantheon, and aqueducts. These engineering marvels not only showcased Roman ingenuity but also served practical purposes, from public entertainment to water supply.
Read| The latest issue of The Challenger is here! We are thrilled to announce that our school paper has qualified for the NATIONAL SCHOOLS PRESS CONFERENCE (NSPC) 2024. Thank you for your unwavering support and trust. Dive into the stories that made us stand out!
Biological screening of herbal drugs: Introduction and Need for
Phyto-Pharmacological Screening, New Strategies for evaluating
Natural Products, In vitro evaluation techniques for Antioxidants, Antimicrobial and Anticancer drugs. In vivo evaluation techniques
for Anti-inflammatory, Antiulcer, Anticancer, Wound healing, Antidiabetic, Hepatoprotective, Cardio protective, Diuretics and
Antifertility, Toxicity studies as per OECD guidelines
June 3, 2024 Anti-Semitism Letter Sent to MIT President Kornbluth and MIT Cor...Levi Shapiro
Letter from the Congress of the United States regarding Anti-Semitism sent June 3rd to MIT President Sally Kornbluth, MIT Corp Chair, Mark Gorenberg
Dear Dr. Kornbluth and Mr. Gorenberg,
The US House of Representatives is deeply concerned by ongoing and pervasive acts of antisemitic
harassment and intimidation at the Massachusetts Institute of Technology (MIT). Failing to act decisively to ensure a safe learning environment for all students would be a grave dereliction of your responsibilities as President of MIT and Chair of the MIT Corporation.
This Congress will not stand idly by and allow an environment hostile to Jewish students to persist. The House believes that your institution is in violation of Title VI of the Civil Rights Act, and the inability or
unwillingness to rectify this violation through action requires accountability.
Postsecondary education is a unique opportunity for students to learn and have their ideas and beliefs challenged. However, universities receiving hundreds of millions of federal funds annually have denied
students that opportunity and have been hijacked to become venues for the promotion of terrorism, antisemitic harassment and intimidation, unlawful encampments, and in some cases, assaults and riots.
The House of Representatives will not countenance the use of federal funds to indoctrinate students into hateful, antisemitic, anti-American supporters of terrorism. Investigations into campus antisemitism by the Committee on Education and the Workforce and the Committee on Ways and Means have been expanded into a Congress-wide probe across all relevant jurisdictions to address this national crisis. The undersigned Committees will conduct oversight into the use of federal funds at MIT and its learning environment under authorities granted to each Committee.
• The Committee on Education and the Workforce has been investigating your institution since December 7, 2023. The Committee has broad jurisdiction over postsecondary education, including its compliance with Title VI of the Civil Rights Act, campus safety concerns over disruptions to the learning environment, and the awarding of federal student aid under the Higher Education Act.
• The Committee on Oversight and Accountability is investigating the sources of funding and other support flowing to groups espousing pro-Hamas propaganda and engaged in antisemitic harassment and intimidation of students. The Committee on Oversight and Accountability is the principal oversight committee of the US House of Representatives and has broad authority to investigate “any matter” at “any time” under House Rule X.
• The Committee on Ways and Means has been investigating several universities since November 15, 2023, when the Committee held a hearing entitled From Ivory Towers to Dark Corners: Investigating the Nexus Between Antisemitism, Tax-Exempt Universities, and Terror Financing. The Committee followed the hearing with letters to those institutions on January 10, 202
Macroeconomics- Movie Location
This will be used as part of your Personal Professional Portfolio once graded.
Objective:
Prepare a presentation or a paper using research, basic comparative analysis, data organization and application of economic information. You will make an informed assessment of an economic climate outside of the United States to accomplish an entertainment industry objective.
Instructions for Submissions thorugh G- Classroom.pptxJheel Barad
This presentation provides a briefing on how to upload submissions and documents in Google Classroom. It was prepared as part of an orientation for new Sainik School in-service teacher trainees. As a training officer, my goal is to ensure that you are comfortable and proficient with this essential tool for managing assignments and fostering student engagement.
Welcome to TechSoup New Member Orientation and Q&A (May 2024).pdfTechSoup
In this webinar you will learn how your organization can access TechSoup's wide variety of product discount and donation programs. From hardware to software, we'll give you a tour of the tools available to help your nonprofit with productivity, collaboration, financial management, donor tracking, security, and more.
Synthetic Fiber Construction in lab .pptxPavel ( NSTU)
Synthetic fiber production is a fascinating and complex field that blends chemistry, engineering, and environmental science. By understanding these aspects, students can gain a comprehensive view of synthetic fiber production, its impact on society and the environment, and the potential for future innovations. Synthetic fibers play a crucial role in modern society, impacting various aspects of daily life, industry, and the environment. ynthetic fibers are integral to modern life, offering a range of benefits from cost-effectiveness and versatility to innovative applications and performance characteristics. While they pose environmental challenges, ongoing research and development aim to create more sustainable and eco-friendly alternatives. Understanding the importance of synthetic fibers helps in appreciating their role in the economy, industry, and daily life, while also emphasizing the need for sustainable practices and innovation.
2. Macro definition and call, macro expansion, Machine Independent
macro processor features,
Nested macro calls, advanced macro facilities, Design of macro
preprocessor.preprocessor.
Basic compliers function, Phases of compilation, memory allocation,
compilation of expression,
compilation of expressions, compilation of control structures, code of
optimization, interpreter.
3. Macro are used to provide a program generation facility through
macro expansion.
Definition :- A macro is a unit of specification for program
generation through expansion.
A macro consists of a name, set of formal parameter and body ofA macro consists of a name, set of formal parameter and body of
code.
The use of a macro name with a set of actual parameters is replaced
by some code generated from its body. This is called macro
expansion
4. Examples of Macro
If we have to Re-writing a program then with the help of macros we can
write¡¡.
Start of definitionStart of definitionStart of definitionStart of definition MacroMacroMacroMacro
Macro name My macro
Macro body ADD AREG,X
ADD BREG, X
End of the macro
definition
MEND
write¡¡.
Original program program with macro
ADD AREG,X
ADD BREG, X
ADD AREG,X
ADD BREG, X
ADD AREG,X
ADD BREG, X
My macro
My macro
My macro
5. A macro processor takes a source with macro definition and macro
calls and replace each with its body.
Target codeTarget codeTarget codeTarget code
ADD AREG,X
ADD BREG, X
Source programSource programSource programSource program
MACRO
Mymacro
ADD AREG,X
ADD AREG,X
ADD BREG, X
ADD AREG,X
ADD BREG, X
MacroMacroMacroMacro
ProcessorProcessorProcessorProcessor
ADD AREG,X
ADD BREG, X
MEND
mymacro
mymacro
mymacro
Inpu
t
output
6. Two kinds of expansion
1. Lexical Expansion
2. Semantic Expansion
Lexical Expansion :- Lexical Expansion implies replacement of
character string by another character string during programcharacter string by another character string during program
generation .Lexical expansion employed to replace occurrences of
formal parameters by corresponding actual parameters.
7. Semantic expansion : Semantic expansion implies generation of
instructions tailored to the requirements of specific usage. For
Examples Generation of type specific instructions for manipulation
of byte and words operands.
8. A macro is a set of tasks combined together so that you can run or
replay the entire task together with a single command. Macros are a
powerful productivity tool.
With macros you can perform long or boring tasks just by a single
click.click.
Macro allows a sequence of source language code to be defined once
and then referred to by name each time it is to be referred..
9. A macro definition is enclosed between a macro header statement
and macro end statement. Macro definition are typically located at
the start of a program. A macro definition consists of
A macro prototype statement
One or more model statementsOne or more model statements
Macro preprocessor statements
10. A macro prototype statement:- The Macro protoype statement
declares the name of macro and kinds of its parameters.
One or more model statements: A model statement is a statement
from which an assembly language statement may be generated
during macro expansion.during macro expansion.
Macro preprocessor statements: A preprocessor statement is used to
perform auxiliary functions during macro expansion.
11. Macros are typically defined at a start of a program. A macro
definition
consists of
(1) MACRO pseudo opcode.
(2) MACRO name.
(3) Sequence of statements to be abbreviated.
(4) MEND pseudo opcode terminating macro definition.
The structure of a macro is:The structure of a macro is:
%MACRO macro_name;
<macro_text>
%MEND <macro_name>;
Example:
MACRO
INCR &ARG
ADD AREG ,& ARG
ADD BREG ,& ARG
ADD CREG ,& ARG
MEND
12. A macro is called by writing macro name with actual parameters in
an assembly program.
The macro call has following syntax:
< macro name > [ < list of parameters > ]
For example,For example,
INCR X
Will call the macro INCR with the actual parameter X.
13. A macro call leads to macro expansion .
During macro expansion, the macro call statement is replaced by a
sequence of assembly statements.
To differentiate between the original statements of program and theTo differentiate between the original statements of program and the
statement resulting from macro expansion ,each expanded statement
is marked with a ‘+’ preceding its label filed.
Two key notions concerning macro expansion are:
1.Expansion time control flow
2.Lexical substitution
14. 1.Expansion time control flow:- This determine the order in which model
statement are visited during macro expansion
The flow of control during macro expansion is implemented using a macro
expansion counter(MEC).
Algorithm: (outline of macro expansion)
1. MEC: statement number of first statement following the prototype statement
2. While statement pointed by MEC is not a MEND statement2. While statement pointed by MEC is not a MEND statement
(a) If a model statement then
(i) Expand the statement
(ii) MEC:= MEC+1;
(b) Else (i.e a preprocessors statement )
(i) MEC:= new value specified in the statement ;
3. Exit from macro expansion .
15. 2.Lexical substitution :- Lexical substitution is used to generate an
assembly statement from a model statement.
A model statement consists of 3 types of string
(1) An ordinary string, which stands for itself
(2) The name of Formal parameter which is preceded(2) The name of Formal parameter which is preceded
by the character ‘&’.
(3) The name of a preprocessor variable , which is
also preceded by the character ‘&’
16. A macro may be defined with:
(1) Positional parameters.
(2) Keyword parameters.
Positional Parameters: A positional parameter is written as & parameter_name.
For example , INCR &VARIABLE.
Keyword Parameters: During call to a micro , a keyword parameter is specifiedKeyword Parameters: During call to a micro , a keyword parameter is specified
by its name.
It takes following form:
< parameter name > = < parameter value >
17. DEFINATION:-
A model statement in a macro may constitute a call on
another macro i.e. macro call within a macro. Such calls are known
as “Nested Macro Calls”.
18. Macro containing the nested call is known as “Outer Macro". A
called macro is known as “Inner macro”.
Expansion of nested macro calls follows “last-in- first-out(LIFO)
rules". Thus inner structure of nested macro calls ,the expansion of
latest macro call is completed first.latest macro call is completed first.
`
19. Example:-Consider program segment :-
MACRO
COMPUTE &ARG
MOVER AREG ,&ARG
ADD AREG ,=‘1’
MOVEN AREG,&ARG
MEND
MACRO
COMPUTE &ARG1,ARG2,ARG3COMPUTE &ARG1,ARG2,ARG3
COMPUTE &ARG1
COMPUTE &ARG2
COMPUTE &ARG3
MEND
The definition of macros “COMPUTE1” contains three separate calls to a define macro
“ COMPUTE”.
Such macros are expanded on multiple levels.
Expansion of “COMPUTE1 x,y,z” as follows:-
21. Advanced macro facilities are aimed at supporting semantic expansion. These facilities can
be grouped into :
1) Facilities for alteration of flow of control during expansion.
2) Expansion time variables.
3) Attributes of parameters.
22. Two features are provided to facilitate alteration of flow of control
during expansion:-
1)Expansion time sequencing symbols.
2)Expansion time statements AIF,AGO and ANOP.
AIF is similar to IF statement,the label used for branching is knownAIF is similar to IF statement,the label used for branching is known
as a sequencing symbol.
AGO is similar to GOTO statement.
Sequencing symbol has the syntax:
<ordinary string>
23. An AIF statement has the syntax:
AIF(<expression>)<sequencing symbol>
where <expression> is relational expression involving ordinary
string formal parameters etc.
AIF is conditional branch Pseudo-opcode.AIF is conditional branch Pseudo-opcode.
An AGO statement has the syntax:
AGO<sequencing symbol>
AGO is unconditional branch Pseudo-opcode
where transfer of expansion time control to the statement containing
<sequencing symbol> in its label field takes place unconditionally.
24. An ANOP statement has the syntax
<sequencing symbol> ANOP
It simply has the effect of defining the sequencing symbol.
25. Expansion of time variables(EV) are variables which can only be use
during the expansion of macro calls.
A local EV is created for use only during the a particular macro call .
Its syntax is:-
LCL<&variable name>[,< variable name>¡.]
A global EV exist across all macro calls situated in a program & can beA global EV exist across all macro calls situated in a program & can be
used in any macro which has a declaration for it.
Its syntax is:
GBL<&variable name>[,< variable name>¡.]
Expansion of time variables(EV) can be manipulated through the statement
SET .
Syntax:-
< Expansion time variables>SET< expression>
26. Example:-
MACRO
CONSTANTS
LCL &A
&A SET 1
DB &A
&A SET &A+1&A SET &A+1
DB &A
MEND
A call on macro CONSTANTS is explained as follows:
The local EV A is created.The first SET statement assigns the value ‘1’ to it .The first DB
statement thus declares a byte constant ‘1’. The second SET statement assigns the value
‘2’ to A and the second DB statement declares a constant ‘2’.
27. An attribute is written using the syntax:-
<attribute name>’<formal parameter spec>
and represents information about the value of the formal parameter i.e.
about the corresponding actual parameter. The type,length and size
attributes have the names T,L and S.attributes have the names T,L and S.
28. Example:-
MACRO
DCL_CONST &A
AIF (L’ &A EQ 1) .NEXT
_ _
.NEXT _ _.NEXT _ _
_ _
MEND
Here expansion time control is transferred to the statement having.NEXT
in its label field only if the actual parameter corresponding to the formal
parameter corresponding to the formal parameters A has the length of ‘1’.
29.
30. The macro preprocessor accepts an assembly program containing
definitions and calls and translate it into an assembly program which
does not contain any macro definitions or calls.
The program from output by macro preprocessor can now be handed
over to an assembler to obtain the target language from of theover to an assembler to obtain the target language from of the
program.
Thus the macro preprocessor segregates macro expansion from the
process of program assembly.
It is economical because
31. We begin the design by listing all tasks involved in macro
expansion.
1. Identify macro calls in the program.
2. Determine the values of formal parameters.
3. Maintain the values of expansion time variables declared in macros.3. Maintain the values of expansion time variables declared in macros.
4. Organize expansion time control flow.
5. Determine the values of sequencing symbols.
6. Perform expansion of model statement.
32. 1. Identify the information necessary to perform a task.
2. Design a suitable data structure to record the information.
3. Determine the processing necessary to obtain the information.
4. Determine the processing necessary to perform the task.4. Determine the processing necessary to perform the task.
33. A compiler is a program takes a program written in a source language and
translates it into an equivalent program in a target language.
Source program COMPILER target program
error messages
33
( Normally a program written in
a high-level programming language)
( Normally the equivalent program in
machine code – relocatable object file)
34. In addition to the development of a compiler, the techniques used in compiler design can be
applicable to many problems in computer science.
◦ Techniques used in a lexical analyzer can be used in text editors, information retrieval
system, and pattern recognition programs.
◦ Techniques used in a parser can be used in a query processing system such as SQL.
◦ Many software having a complex front-end may need techniques used in compiler design.Many software having a complex front-end may need techniques used in compiler design.
A symbolic equation solver which takes an equation as input. That program should
parse the given input equation.
◦ Most of the techniques used in compiler design can be used in Natural Language
Processing (NLP) systems.
34
35. There are two major parts of a compiler: Analysis and Synthesis
In analysis phase, an intermediate representation is created from the
given source program.
◦ Lexical Analyzer, Syntax Analyzer and Semantic Analyzer are the parts of this phase.◦ Lexical Analyzer, Syntax Analyzer and Semantic Analyzer are the parts of this phase.
In synthesis phase, the equivalent target program is created from this
intermediate representation.
◦ Intermediate Code Generator, Code Generator, and Code Optimizer are the parts of this phase.
35
37. Lexical analyzer
Syntax analyzer
Semantic analyzer
E
R
R
O
R
S
Y
M
B
O
L
Semantic analyzer
Intermediate code generator
Code optimizer
Code generator
R
H
N
D
L
E
R
T
B
L
M
N
G
R
38. Lexical Analyzer reads the source program character by character and
returns the tokens of the source program.
A token describes a pattern of characters having same meaning in the
source program. (such as identifiers, operators, keywords, numbers,
delimeters and so on)
Ex: newval := oldval + 12 => tokens: newval identifierEx: newval := oldval + 12 => tokens:
:= assignment operator
oldval identifier
+ add operator
12 a number
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.
38
39. 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.
assgstmt
identifier := expression
newval expression + expression
identifier number
oldval 12
39
• In a parse tree, all terminals are at leave
• All inner nodes are non-terminals in
a context free grammar.
40. 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.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
40
41. 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 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.
41
42. Depending on how the parse tree is created, there are different parsing techniques.
These parsing techniques are categorized into two groups:
◦ Top-Down Parsing,
◦ Bottom-Up Parsing
Top-Down Parsing:
◦ Construction of the parse tree starts at the root, and proceeds towards the leaves.
◦ Efficient top-down parsers can be easily constructed by hand.
◦ Recursive Predictive Parsing, Non-Recursive Predictive Parsing (LL Parsing).◦ Recursive Predictive Parsing, Non-Recursive Predictive Parsing (LL Parsing).
Bottom-Up Parsing:
◦ Construction of the parse tree starts at the leaves, and proceeds towards the root.
◦ Normally efficient bottom-up parsers are created with the help of some software tools.
◦ Bottom-up parsing is also known as shift-reduce parsing.
◦ Operator-Precedence Parsing – simple, restrictive, easy to implement
◦ LR Parsing – much general form of shift-reduce parsing, LR, SLR, LALR
42
43. A semantic analyzer checks the source program for semantic errors and
collects the type information for the code generation.
Type-checking is an important part of semantic analyzer.
Normally semantic information cannot be represented by a context-free
language used in syntax analyzers.
Context-free grammars used in the syntax analysis are integrated withContext-free grammars used in the syntax analysis are integrated with
attributes (semantic rules)
◦ the result is a syntax-directed translation,
◦ Attribute grammars
Ex:
newval := oldval + 12
The type of the identifier newval must match with type of the expression (oldval+12)
43
44. 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 of
machine codes.
Ex:Ex:
newval := oldval * fact + 1
id1 := id2 * id3 + 1
MULT id2,id3,temp1 Intermediates Codes
(Quadraples)
ADD temp1,#1,temp2
MOV temp2,,id1
44
45. The code optimizer optimizes the code produced by the intermediate
code generator in the terms of time and space.
Ex:
MULT id2,id3,temp1
ADD temp1,#1,id1
CS416 Compiler Design 45
46. Produces the target language in a specific architecture.
The target program is normally is a reloadable object file containing the
machine codes.
Ex:
( assume that we have an architecture with instructions whose at least one of
its operands is
a machine register)
MOVE id2,R1
MULT id3,R1
ADD #1,R1
MOVE R1,id1
CS416 Compiler Design 46
47. A compiler is a computer program that
translates a program in a source language
into an equivalent program in a target
language.
A source program/code is a program/code
written in the source language, which is
usually a high-level language. compiler
Source
program
Target
programusually a high-level language.
A target program/code is a program/code
written in the target language, which often
is a machine language or an intermediate
code. Error
message
48. scanner
parser
Semantic analyzer
Stream of charactersStream of charactersStream of charactersStream of characters
Stream of tokensStream of tokensStream of tokensStream of tokens
Parse/syntax treeParse/syntax treeParse/syntax treeParse/syntax tree
Annotated treeAnnotated treeAnnotated treeAnnotated tree
Intermediate code generator
Code optimization
Code generator
Code optimization
Intermediate codeIntermediate codeIntermediate codeIntermediate code
Intermediate codeIntermediate codeIntermediate codeIntermediate code
Target codeTarget codeTarget codeTarget code
Target codeTarget codeTarget codeTarget code
50. • Lexical analysis involves scanning of the source programme from
left to right and
• Separating them into tokens.
• A token is a sequence of characters having a collective meaning.
• Tokens are seperated by blanks,operators and special symbols.
• A lexical analysis on the statement.• A lexical analysis on the statement.
• X=Y+Z*30;
• Will generate the following tokens
X = ;30*Y + Z
51. X is an identifier.
= is a terminal symbol.
Y is an identifier.
+ is a terminal symbol.
Z is an identifier.
* Is a terminal symbol.
30 is literal.30 is literal.
;is a terminal symbol.
• Blank s seperating the token are eliminated.
• Lexical phase discards comments since they have no effect on the processing Of the program.
• Identifiers are stored in the symbol table.
• Literals are stored in the literal table.
52. • Syntax analysis deals with the syntax error detection and correction.
• In the program if the spelling is wrong,then in syntax analysis the spelling is
Corrected according to the syntax table.
• This syntax table is the table in which for a wrong keyword in code,the
different Corrections are available.
• Example:- for iffff & thennn in the code, thee syntax table will be- then
than
if
If then
53. It gets the parse tree from the parser together with information
about some syntactic elements
It determines if the semantics or meaning of the program is
correct.
This part deals with static semantic.
◦
This part deals with static semantic.
◦ semantic of programs that can be checked by reading off from
the program only.
◦ syntax of the language which cannot be described in context-
free grammar.
Mostly, a semantic analyzer does type checking.
It modifies the parse tree in order to get that (static) semantically
correct code.
54. An intermediate code generator
◦ takes a parse tree from the semantic analyzer
◦ generates a program in the intermediate language.
In some compilers, a source program is translated into an
intermediate code first and then the intermediate code is translatedintermediate code first and then the intermediate code is translated
into the target language.
In other compilers, a source program is translated directly into the
target language.
54
55. Using intermediate code is beneficial when compilers which
translates a single source language to many target languages are
required.
◦ The front-end of a compiler – scanner to intermediate code generator – can be◦ The front-end of a compiler – scanner to intermediate code generator – can be
used for every compilers.
◦ Different back-ends – code optimizer and code generator– is required for each
target language.
One of the popular intermediate code is three-address code. A
three-address code instruction is in the form of x = y op z.
56. Replacing an inefficient sequence of instructions with a better
sequence of instructions.
Sometimes called code improvement.
Code optimization can be done:
◦ after semantic analyzing
performed on a parse treeperformed on a parse tree
◦ After intermediate code generation
performed on a intermediate code
◦ after code generation
performed on a target code
57. A code generator
◦ takes either an intermediate code or a parse tree
◦ produces a target program.
58. Static memory allocation refers to the process of allocating memory
at compile-time before the associated program is executed.
Dynamic memory allocation is automatic memory allocation
where memory is allocated as required at run-time.
59. • An application of this technique involves a program module (e.g. function or
subroutine) declaring static data locally, such that these data are inaccessible in
other modules unless references to it are passed as parameters or returned.
• A single copy of static data is retained and accessible through many calls to the
function in which it is declared.
• Static memory allocation therefore has the advantage of modularising data within a
program design in the situation where these data must be retained through the
runtime of the program.runtime of the program.
• The use of static variables within a class in object oriented programming enables a
single copy of such data to be shared between all the objects of that class.
• Object constants known at compile-time, like string literals, are usually allocated
statically. In object-oriented programming, the virtual method tables of classes are
usually allocated statically.
• A statically defined value can also be global in its scope ensuring the same
immutable value is used throughout a run for consistency.
60. Code A
Data A
Code B Code A
Code A
Code B
Data B
Code C
Code B
Code C
Data A
Code C
Data A
Data BData C
a)Static
allocation
b) Dynamic allocation
The main program A
Is active.
c)Dynamic allocation
The main program A calls
The function B
61. Advantages of static memory allocation:-
• It is simple to implement.
• Binding is performed during compilation.
• Execution is faster as there is no binding during the run time and addresses of
• Variables is directly encoded in machine instructions.
Disadvantages of static memory allocation:-
• It is almost impossible to handle recursion.
• Memory requirement is higher.Variables remain allocated even when the
Function is not active.
62. Advantages of Dynamic memory allocation:-
In dynamic memory allocation , memory is allocated and deallocated during execution of a program.
• Dynamic memory allocation has optimal utilization of memory.
• Recursion can be implemented using dynamic memory allocation.• Recursion can be implemented using dynamic memory allocation.
63. Compilation Of Control Structure:-
Some of the control structures are:
There are language features which govern the sequencing of control
through a Program.
Some of the control structures are:
1)If statement.
2)While loop statement.
64. If Statement:-
We can translate an If statement into three address code. A program containing
If statement can be mapped into an equivalent program containing explicit goto’s.
A sample if statement is compiled into three-address code in following fig.
If (E) 100:if(E) then goto 102
{ 101 : goto 104
s1 ; 102 : s1 ;
} => 103 : goto 105
Else 104 : s2 ;
{ 105 : s3 ;
s2;
}
S3;
65. It should be clear that if E is true then the two statements s1 and s3 will be execute
If E is false then the two statements s2 and s3 will be executed.
While statement:-
•We can translate while-statement into three address code. A program containing w
•Statement can be mapped into an equivalent program containing explicit goto’s.
•A sample while statement is compiled into three address codes.
While (E) 100 : if (E) then goto 102
{ 101 : goto 105
s1 ; 102: s1
66. S2; => 103 : s2
} 104 : goto 100
S3; 105 : s3
• It should be clear that if E is true then control enters the body of the loo
executes S1 and s2.subsequently,it goes back to the beginning of the lexecutes S1 and s2.subsequently,it goes back to the beginning of the l
• If E is false then control is transferred to the statement s3.
67. An interpreter accepts the source program and performs the actions
associated with the instructions
It creates virtual execution environment
An interpreter reads source code one instruction or a line at a time,
converts this into machine code or some intermediate form andconverts this into machine code or some intermediate form and
executes it.
68. COMPILERCOMPILERCOMPILERCOMPILER INTERPRETERINTERPRETERINTERPRETERINTERPRETER
1. Compiler translates the
entire program into
machine code
2. If there is a problem in the
code, compiled programs
make the programmer wait
for the execution of entire
program.
1. Interpreter translates code
one line at a time
executing each line as it is
translated.
2. An interpreter lets
programmer know
immediately when and
where problems exist inprogram.
3. Compilers produce better
optimized codes that
generally runs fast.
4. It spends lot of time
analyzing and generating
machine code. It is not
suited during program
development.
where problems exist in
the code.
3. Program execution is
relatively slow due to
interpreter overhead.
4. Relatively little time is
spent in analyzing as it
executes line by line.