AIM: To Study About Lexical Analyzer Generator (LEX) and Flex (Fast Lexical Analyzer) Lexical Analyzer Generator (LEX)
AIM: To Study About Lexical Analyzer Generator (LEX) and Flex (Fast Lexical Analyzer) Lexical Analyzer Generator (LEX)
AIM: To Study About Lexical Analyzer Generator (LEX) and Flex (Fast Lexical Analyzer) Lexical Analyzer Generator (LEX)
Practical-3
o yylex() :- implies the main entry point for lex, reads the input stream generates
tokens, returns zero at the end of input stream . It is called to invoke the lexer
(or scanner) and each time yylex() is called.
o yytext :- a buffer that holds the input characters that actually match the pattern
(i.e lexeme) or say a pointer to the matched string .
o yyout :- the output stream pointer (i.e it points to a file where it has to keep the
output), however the default output of default main() is stdout .
161040107059 1
Compiler Design Practical-3
Program Structure:
In the input file, there are 3 sections:
Syntax:
%{
// Definitions
%}
2. Rules Section: The rules section contains a series of rules in the form: pattern
action and pattern must be unintended and action begin on the same line in {}
brackets. The rule section is enclosed in “%% %%”.
Syntax:
%%
pattern action
%%
3. User Code Section: This section contain C statements and additional functions.
We can also compile these functions separately and load with the lexical analyzer.
161040107059 2
Compiler Design Practical-3
%%
Rules
%%
161040107059 3