![]() |
![]() |
![]() |
![]() |
![]() |
Lexical Analyzer
The lexical analyze is the first phase of a compiler. Its main task is to read input characters and produce as output a sequence of tokens that the parser uses for the next phase, the syntax analysis.
Since the lexical analyzer is the part of a compiler that reads the source text, it may also perform certain secondary tasks at the user interface. One such task is stripping out comments and white space in the form of blank, tab, and newline character. Another is correlating error messages from the compiler with the source program. For example, the lexical analyzer may keep track of the number of newline characters seen, so that a line number can be associated with an error message.
In lexical analysis the stream of characters making up the program is read from left-to-right and grouped into tokens that are sequences of characters having a collective meaning.
For example, the characters in the assignment statement below:
position := initial + rate * 60would be grouped into the following tokens:
- The identifier position
- The assignment symbol :=
- The identifier initial
- The plus sign
- The identifier rate
- The multiplicand sign
- The number 60
The blanks separating the characters of these tokens would normally be eliminated during lexical analysis.
http://www.ibm.com/rational |
![]() |
![]() |
![]() |
![]() |