Documente Academic
Documente Profesional
Documente Cultură
A complier is program that reads program written in one language (Source Language) and translate it into
equivalent program in another language.
https://www.geeksforgeeks.org/introduction-compiler-design/
ANALYSIS PHASE
In this part source program are break up into sub-pieces and creates and intermediate representation of
source program.
In other words it create database after analysis on which synthesis phase is based.
1. Lexical Analyzer
2. Syntax Analyzer
3. Semantic Analyzer
Lexical Analyzer
Lexical Analyzer reads the source program character by character and returns the tokens of the source
program. A (Deterministic) Finite State Automaton can be used in the implementation of a lexical analyzer.
The lexical analyzer reads the stream of characters making up the source program and groups the characters
into meaningful sequences called lexemes.
For each lexeme, the lexical analyzer produces as output a token of the form
<Token-name, attribute-value>
https://engineersview.wordpress.com/2013/11/06/lexical-analysis
A token describes a pattern of characters having same meaning in the source program. Such as identifiers,
operators, keywords, numbers, and delimiters. Puts information about identifiers into the symbol table.
http://www2.dcs.hull.ac.uk/people/bct/08348/08208-9697
Specifications of Tokens in Compiler Design
Alphabets: Any finite set of symbols {0,1} is a set of binary alphabets, {0,1,2,3,4,5,6,7,8,9,A,B,C,D,E,F}
is a set of Hexadecimal alphabets, {a-z, A-Z} is a set of English language alphabets.
Strings: A string is a finite sequence of alphabets. The total number of occurrences of the alphabets is
considered as the length of the string.
Language: A finite sent of strings over some finite set of alphabets is known as language.
1. Hand Coding:
Programmer has to perform the following task Specify the tokens by writing regular expressions
Construct Finite Automata equivalent to a regular expression Recognize the tokens by a constructed Finite
Automata Whereas Lexical analyzer generator, programmer will do step1 remaining two steps are done by
lexical analyzer generator automatically
Lexical Analyzer Generator introduce a tool called Lex, which allows one to specify a lexical analyzer by
specifying regular expressions to describe pattern for tokens
The input for the lex tool is lex language.
1. Specify regular expressions for all of the kinds of tokens in the language. The disjunction of all
of the regular expressions thus describes any possible token in the language.
2. Convert the overall regular expression specifying all possible tokens into a deterministic finite
automaton (DFA).
3. Translate the DFA into a program that simulates the DFA. This program is the lexical analyzer.
Syntax Analyzers:
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.
The parser analyzes the source code (token stream) against the production rules to detect any errors in the
code. This way, the parser accomplishes two tasks, i.e., parsing the code, looking for errors and generating
a parse tree as the output of the phase .Parsers are expected to parse the whole code even if some errors
exist in the program.
hdttps://cs.stackexchange.com/questions/51295
Parsers use error recovering strategies.
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.
The syntax analyzer deals with recursive constructs of the language.
The lexical analyzer simplifies the job of the syntax analyzer.
The syntax analyzer works on the smallest meaningful units (tokens) in a source program to
recognize meaningful structures in our programming language.
https://slideplayer.com/slide/7975656/
hdttps://cs.stackexchange.com/questions/51295
https://www.slideshare.net/appasami/cs6660-compiler-design-notes?from_action=save