Compiler_Design_Unit_I
Compiler_Design_Unit_I
A compiler transforms source code into executable code in distinct phases: lexical analysis, syntax
analysis, semantic analysis, intermediate code generation, code optimization, code generation, and
linking. Phases are logical stages in compilation, while passes are actual traversals over the code. A
single-pass compiler processes code in one go; a multi-pass compiler uses several traversals for
better optimization.
2. Bootstrapping:
implemented in another language. It compiles its own source code into executable form, enabling
compiler self-improvement.
FSMs are used to recognize token patterns defined by regular expressions. Regular expressions
describe lexical elements like identifiers and numbers. They are converted to DFAs for efficient
To improve performance, DFAs are optimized by reducing redundant states and transitions.
Techniques like state minimization enhance lexical analyzer speed and efficiency.
Lexical analyzers convert character streams into tokens. They can be manually written or generated
using tools. Efficient implementation ensures fast and accurate token recognition.
6. Lexical-Analyzer Generator - LEX:
LEX generates lexical analyzers from regular expressions and actions. It outputs C code to scan
and tokenize input based on defined rules. Often used with YACC for parser generation.
Formal grammars define language syntax, commonly using context-free grammars (CFGs). Parsers
use these to verify source code structure and generate parse trees.
BNF is a notation for specifying grammar. Ambiguity occurs when a grammar produces multiple
parse trees for a string. YACC generates parsers from BNF-like grammar rules, resolving many
ambiguities.
CFGs consist of terminals, non-terminals, production rules, and a start symbol. Derivations generate
strings, and parse trees represent the syntactic structure. CFGs handle most programming syntax
CFGs define loops, expressions, and conditionals but not semantic aspects like variable type