![]() |
VOOZH | about |
When the token pattern does not match the prefix of the remaining input, the lexical analyzer gets stuck and has to recover from this state to analyze the remaining input. In simple words, a lexical error occurs when a sequence of characters does not match the pattern of any token. It typically happens during the execution of a program.
Types of lexical error that can occur in a lexical analyzer are as follows:
1. Exceeding length of identifier or numeric constants.
Example:
This is a lexical error since signed integer lies between −2,147,483,648 and 2,147,483,647
2. Appearance of illegal characters
Example:
This is a lexical error since an illegal character $ appears at the end of the statement.
3. Unmatched string
Example:
This is a lexical error since the ending of comment "*/" is not present but the beginning is present.
4. Spelling Error
5. Replacing a character with an incorrect character.
6. Removal of the character that should be present.
7. Transposition of two characters.
When a situation arises in which the lexical analyzer is unable to proceed because none of the patterns for tokens matches any prefix of the remaining input. The simplest recovery strategy is "panic mode" recovery. We delete successive characters from the remaining input until the lexical analyzer can identify a well-formed token at the beginning of what input is left.
Error-recovery actions are: