EXP5SPCC
EXP5SPCC
Outcome: Students are able to design and implement lexical analyzer for given
language.
Theory: The very first phase of compiler is lexical analysis. The lexical analyzer read
the input characters and generates a sequence of tokens that are used by parser for
syntax analysis. The figure 7.1 summarizes the interaction between lexical analyzer and
parser.
q0 q1 q0
q1 q1 q2
q2 q1 q3
q3 q3 q3
Now we will simulate this DFA to generate lexical analyzer for the language L.
%option noyywrap
%{
%}
%s A B
%%
void main()
{
yylex();
}
B.2 Input and Output:
B.4 Conclusion:
Implementation of Lexical Analyzer for given language using Lex tool has been
completed successfully
B.5 Question of Curiosity:
1) What is token?
Ans:
A token is the smallest element of a program that is meaningful to the compiler. Tokens
can be classified as follows:
• Keywords
• Identifiers
• Constants
• Strings
• Special Symbols
• Operators
o Spelling error.
o Exceeding length of identifier or numeric constants.
o Appearance of illegal characters.
o To remove the character that should be present.
o To replace a character with an incorrect character.
o Transposition of two characters.