Flex/Le X: Javeria Akram (276) Ifra Zahid
Flex/Le X: Javeria Akram (276) Ifra Zahid
X
JAVERIA AKRAM (276)
IFRA ZAHID (277)
FLEX
FLEX stands for fast lexical analyzer generator.
flex reads the given input files, or its standard input if no file names are given, for
a description of a scanner to generate. The description is in the form of pairs of
regular expressions and C code, called rules.
LEX
Lex is a program designed to generate scanners, also known as tokenizers, which recognize
lexical patterns in text.
The main job of a lexical analyzer (scanner) is to break up an input stream into more usable
elements (tokens)
a = b + c * d ;
Lex will read patterns (regular expressions); then produces C code for a lexical analyzer that
scans for identifiers.
Continued..
A rule in a LEX program comprises of a 'pattern' part (specified by a
regular expression) and a corresponding (semantic) 'action' part (a
sequence of C statements)..
The statements in the action part will be executed when the pattern is
detected in the input.
“integer” {return ID_TYPE_INTEGER}
RULES:
The rules section associates regular expression patterns with C statements. When the lexer
sees text in the input matching a given pattern, it will execute the associated C code.
AUXILARY FUNCTIONS:
This section contains C statements and functions. These statements