System so ware is designed to manage computer Macro Processor Design Op ons: The phases of a compiler are:
hardware and provide a pla orm for running Simple Macro Processor: Expands macros directly Lexical Analysis: Breaks the source code into tokens
applica on so ware. It includes the opera ng and inserts them into the code without complex (keywords, operators, etc.).
system (OS), device drivers, u lity programs, and handling or op miza ons. It’s basic and fast but Syntax Analysis: Checks the token sequence for
firmware. System so ware controls hardware lacks advanced features. gramma cal correctness (parsing).
resources, manages processes, and ensures the Advanced Macro Processor: Supports more complex Seman c Analysis: Ensures the program's logic is
overall func onality, security, and stability of the features like condi onal macro expansion, recursive meaningful (e.g., type checking).
system, enabling other so ware to operate macros, and parameterized macros. It allows for Intermediate Code Genera on: Converts code into an
efficiently. more flexibility and control but is more complex to intermediate form for op miza on.
Assemblers are programs that convert assembly implement. Op miza on: Improves the intermediate code for
language code, which is a low-level programming Two-Pass Macro Processor: The first pass scans the performance.
language, into machine code or executable code source code for macro defini ons, and the second Code Genera on: Translates the op mized code into
that a computer's processor can understand and pass performs macro expansion, ensuring all machine code or assembly.
execute. macros are properly processed and inserted. Code Linking and Assembly: Combines code and
Design Assemblers are a specific type of These design op ons determine how macros are libraries into the final executable.
assembler used for op mizing or transforming handled and expanded during the compila on These phases work together to transform high-level
assembly code in the design phase of hardware process. code into executable machine code.
development, o en for more efficient or targeted Sta c Loading: In sta c loading, all program Lex is a tool for genera ng lexical analyzers, which
machine code genera on. modules and libraries are combined into a single convert raw input (source code) into tokens for further
Loaders are programs that load executable files executable during the compile me. The en re processing in compilers.
into memory so that they can be executed by the program is loaded into memory before execu on. Func on of Lex in Textual Format:
computer. They prepare the program by Dynamic Loading: In dynamic loading, parts of the Pa ern Matching: Lex uses regular expressions to
alloca ng memory, se ng up necessary program or libraries are loaded into memory only define pa erns (tokens) that it searches for in the input
addresses, and transferring control to the when needed during execu on. This saves memory text.
program’s entry point. and allows for more flexibility. Token Genera on: When a pa ern matches, Lex
Types of Loaders: Sta c Linking: In sta c linking, all necessary code generates tokens (e.g., keywords, operators) and passes
Absolute Loader: Loads a program at a fixed and libraries are combined into the executable them to the next stage in the compiler.
memory loca on. during compile me, resul ng in a larger, self- Ac on Execu on: Lex can execute specified ac ons
Reloca ng Loader: Adjusts the program to run at contained file that doesn't require external libraries (e.g., storing values or prin ng results) whenever a
any available memory address. at run me. pa ern is matched.
Dynamic Loader: Loads programs or parts of Dynamic Linking: In dynamic linking, libraries are In short, Lex transforms text into structured tokens,
programs into memory as needed during linked at run me, reducing the executable size. The enabling easier syntax analysis in compiler design.
execu on. program references external libraries, which must YACC (Yet Another Compiler Compiler) is a tool used to
Bootstrap Loader: Ini alizes the system and loads be available when the program runs. generate parsers for context-free grammars. It takes a
the opera ng system during boot-up. An overlay is a technique used in programming formal grammar as input and generates code (usually in
Linking is the process of combining various where only a por on of a program is loaded into C) that can parse the syntax of the language defined by
program modules or libraries into a single memory at a me. It helps manage limited memory the grammar.
executable file. by swapping different code segments (overlays) in Types of YACC:
Types of Linking: and out of memory as needed, allowing larger LALR (Look-Ahead Le -to-Right): The most common
Sta c Linking: Combines all code and libraries programs to run in smaller memory spaces. type, which uses a lookahead symbol to decide which
into one executable at compile me. A relocatable program is a program whose machine grammar rule to apply in case of ambiguity. It is
Dynamic Linking: Links libraries at run me, code can be loaded into different memory loca ons efficient and widely used in many compilers.
reducing executable size and enabling shared without modifica on. It contains placeholders for SLR (Simple LR): A simpler, less powerful version of
library use. memory addresses, which are adjusted when the LALR. It uses a simpler parsing strategy but may not
A compiler is a so ware program that translates program is loaded, allowing it to run anywhere in handle as many grammar types.
high-level source code wri en in programming memory. Canonical LR: The most powerful form, capable of
languages (like C, Java) into machine code or an Non-relocatable Program: A non-relocatable handling the largest range of grammars, but it is more
intermediate code that a computer's processor program must be loaded into a specific memory complex and requires more memory and computa on.
can execute. It checks for errors, op mizes the loca on, as its code contains fixed memory In short, YACC is used to automate the genera on of
code, and produces an executable file for the addresses that cannot be changed during loading. parsers, simplifying syntax analysis in compiler design.
program. Self-relocatable Program: A self-relocatable
An interpreter is a program that directly executes program can be loaded into any memory loca on
instruc ons wri en in a high-level programming without modifica on. It adjusts its memory
language, transla ng them into machine code addresses automa cally when loaded, allowing
line-by-line, without producing a separate flexibility in memory alloca on.
executable file. It processes the code in real- me, Compiler Phases are the steps through which a
o en used for scrip ng languages like Python. compiler processes source code to generate an
A macro is a set of instruc ons or commands that executable. They include:
are grouped together and given a name. When Lexical Analysis: Converts the source code into
the macro is called, it executes the predefined set tokens (keywords, operators, etc.).
of ac ons automa cally. Macros are o en used Syntax Analysis: Checks the syntax of the tokens,
to automate repe ve tasks in programming or ensuring they follow the language's grammar.
so ware applica ons. Seman c Analysis: Ensures the program's logic is
A macro processor is a tool that processes macros meaningful (e.g., type checking).
by expanding them into the actual code during Intermediate Code Genera on: Converts the code
compila on, simplifying the coding process and into an intermediate representa on.
reducing repe on. Op miza on: Enhances the intermediate code for
Procedure Call and Macro Call are concepts in be er performance.
programming related to invoking func ons or Code Genera on: Converts the intermediate code
code blocks. into machine code or assembly language.
Procedure Call: It refers to invoking a func on or Code Linking and Assembly: Combines object code
procedure during run me. The code is executed and libraries into a final executable.
sequen ally and may involve stack opera ons for These phases help transform high-level code into a
passing parameters and returning results. form that can be executed by a computer.
Macro Call: It involves calling a macro, which is A symbol table is a data structure used by a
expanded during preprocessing or compila on. compiler to store informa on about variables,
Unlike procedure calls, macros are replaced with func ons, objects, and other iden fiers in a
their defined code before execu on, reducing program. It keeps track of their names, types,
run me overhead. scopes, and memory loca ons, helping during the
Features of Macros: compila on process for tasks like seman c analysis
Code Reusability: Macros allow code to be reused and code genera on.
mul ple mes, reducing redundancy. Error-Correc ng Rou nes are mechanisms in
Preprocessing: Macros are expanded before compilers or programs that detect and handle
compila on, improving execu on speed. errors in code during compila on or execu on.
Parameteriza on: Macros can accept parameters, These rou nes iden fy syntax, seman c, or run me
allowing flexible code genera on. errors and either a empt to fix them automa cally
No Run me Overhead: Unlike func on calls, or provide informa ve messages to help the
macros don't incur run me overhead as they are developer correct them.
directly replaced by code during compila on.