Lexical Analysis
A program written in one high level language (source language) producing output in low level language (object or target language) is called compiler.
Cross Compiler
A compiler that runs on one machine 'A' and produces a code for another machine 'B'.
Example : (a) Compiler runs on machine A , which takes input language X and produces output language Y.
(b) Compiler runs on machine A and produces code Y for another machine B.
Compiler Parts
There are two major parts of a compiler:
1. Analysis Phase : An intermediate representation is created from the given source program
(i) Lexical Analyzer
(ii) Syntax Analyzer
(iii) Semantic Analyzer
2. Synthesis Phase : Equivalent target program is created from intermediate representation
(i) Intermediate Code Generator
(ii) Code Generator
(iii) Code Optimizer
Compiler Phases
Language Processing System
LEXICAL ANALYSIS
Lexical analyzer reads a source program character by character to produce tokens.
A token can represent more than one lexeme , additional information should be held for that specific lexeme.This additional information is called as attribute of the token.
Token type and its attribute uniquely identify a lexeme.
Regular expressions are used to specify patterns and finite automata is used to recognise tokens.
Token identified by lexical analyzer : Keyword , constants , identifiers , operators and symbols.
Designing of Lexical Analyzer
Write a formal description of the tokens and use a software tool that constructs table-driven lexical analyzer.
Design a state diagram that describes the tokens and write a program that implement the state diagram.
Design a state diagram that description the tokens and hand-construct a table-driven implement of the state diagram.
No comments