Embed presentation





![Declarations section
• Code between %{ and }% is inserted directly into the lex.yy.c. Should
contain:
– Manifest constants (#define for each token)
– Global variables, function declarations, typedefs
• Outside %{ and }%, REGULAR DEFINITIONS are declared.
Examples:
delim [ tn]
ws {delim}+
letter [A-Za-z]
Each definition is a name
followed by a pattern.
Declared names can be used in
later patterns, if surrounded by
{ }.](https://image.slidesharecdn.com/lexical-analysis-using-lex-140416012050-phpapp02/75/Lexical-analysis-using-lex-6-2048.jpg)


Lexical analysis is the first step in compiler construction and involves breaking a program into individual tokens. A Lex program has three sections: declarations, translation rules, and auxiliary code. The declarations section defines regular expressions and global variables. The translation rules section matches regular expressions to tokens and executes C code actions. When a regular expression is matched in the input stream, its corresponding action is executed to return the appropriate token.





![Declarations section
• Code between %{ and }% is inserted directly into the lex.yy.c. Should
contain:
– Manifest constants (#define for each token)
– Global variables, function declarations, typedefs
• Outside %{ and }%, REGULAR DEFINITIONS are declared.
Examples:
delim [ tn]
ws {delim}+
letter [A-Za-z]
Each definition is a name
followed by a pattern.
Declared names can be used in
later patterns, if surrounded by
{ }.](https://image.slidesharecdn.com/lexical-analysis-using-lex-140416012050-phpapp02/75/Lexical-analysis-using-lex-6-2048.jpg)
