2. Error Handler
• An error is an abnormal condition in source program, which
either stope the compilation or generate undesired results.
• A compiler must not stop at each error.
• It must somehow handle the error, so that compilation
proceeds up to the end of the program.
• At the end a list of errors messages is provided to the user.
• This is the job of the error handler, and also marks the place
where the errors occur.
3. Error Handler
• Error handler contains a set of routines for handling error
encountered in any phase of the compiler.
• The basic tasks of the compiler are:
• Detection
• Reporting
• Recovery
• During compilation process each phase may encounters errors and
has to deal with them.
• For this purpose the Error handler contains error handling routines.
5. Lexical analyzer
• It is the first phase of compiler.
• It is also known as linear analyzer or Scanner.
• It scans or reads the source program from left to right as a stream of
characters, and it groups these characters into a unit called “Tokens”.
OR
• It takes the source code program as a stream of characters and
broken them into tokens.
6. Lexical Analyzer
• Token:
•A sequence of characters having a collective meaning.
•Lexemes are said to be a sequence of characters
(alphanumeric) in a token.
•If the lexical analyzer finds a token invalid, it generates
an error.
•There are some predefined rules for every lexeme to
be identified as a valid token.
•These rules are defined by grammar rules, by means
of a pattern.
7. Lexical Analyzer (Token Cont.)
• A pattern explains what can be a token, and these
patterns are defined by means of regular expressions.
• In programming language, keywords, constants,
identifiers, strings, numbers, operators and
punctuations symbols can be considered as tokens
For example, in C language, the variable declaration line
int value = 100;
contains the tokens:
int (keyword), value (identifier), = (operator), 100 (constant) and ;
(symbol).
8. Lexical Analyzer (Token Cont.)
• The lexical analyzer works closely with the syntax
analyzer.
• It reads character streams from the source code,
checks for legal tokens, and passes the data to the
syntax analyzer when it demands.
Continue To
Next
Lecture