COMPILER DESIGN

LEXICAL ANALYSIS

ROLE OF THE LEXICAL ANALYZER

Question [CLICK ON ANY CHOICE TO KNOW THE RIGHT ANSWER]
A lexical analyzer uses the following patterns to recognize three tokens T1, T2, and T3 over the alphabet {a, b, c}. T1:a? (b∣∣c)∗aT2:b? (a∣∣c)∗bT3:c? (b∣∣a)∗c Note that ‘x?’ means 0 or 1 occurrence of the symbol x. Note also that the analyzer outputs the token that matches the longest possible prefix. If the string bbaacabc is processed by the analyzer, which one of the following is the sequence of tokens it outputs?
A
T1T2T3
B
T1T1T3
C
T2T1T3
D
T3T3
Explanation: 

Detailed explanation-1: -The lexical analyzer is responsible for removing the white spaces and comments from the source program. It corresponds to the error messages with the source program. It helps to identify the tokens. The input characters are read by the lexical analyzer from the source code.

Detailed explanation-2: -Explanation: The process of forming tokens from an input stream of characters is called tokenization. 2. When expression sum=3+2 is tokenized then what is the token category of 3? Sum “Identifier” = “Assignment operator” 3 “Integer literal” + “Addition operator” 2 “Integer literal”; “End of statement".

Detailed explanation-3: -Lexical analyzer recognizes the lexemes (alphanumeric characters in a token ) and recognize the white spaces, comments, tab and ignore them.

Detailed explanation-4: -Lexical Analysis is the first phase of compiler also known as scanner. It converts the High level input program into a sequence of Tokens. Counting all the boxes, the total number of tokens comes out to be 26.

There is 1 question to complete.