CS 614: Theory and Construction of Compilers Lecture 5 Fall 2003 Department of Computer Science University of Alabama Joel Jones
Lecture 5©2003 Joel Jones2 Introduction to Lexing Tools C is action language lex flex Java is action language Jlex
Lecture 5©2003 Joel Jones3 Lexing Tool Basics Translate lexing specification to program Regular expressions Action code
Lecture 5©2003 Joel Jones4 Regular Expressions. Matches any single character * Matches zero or more copies of the preceding expression [] Character class which matches any character within the brackets. If it starts with a circumflex ‘^’ negates test. A dash indicates a range ^ Matches the beginning of a line $ Matches the end of a line \ escapes metacharacters e.g. “\n” is a newline character, “\*” is a literal asterisk + Matches one or more occurrences ? Matches zero or one occurences
Lecture 5©2003 Joel Jones5 Regular Expression (Continued) | Matches either the regular expression before or after “…” Interprets everything inside quotes literally () Groups a series of regular expression together into a new regular expression
Lecture 5©2003 Joel Jones6 Regular Expression Examples Digit Integer Optional Unary Minus Decimal Numbers (0.0, 4.5, but not 0 or 2, or unary minus) Decimal Numbers (no unary minus) Decimal Numbers (with unary minus) Float style exponent (just the exponent, ‘e’ or ‘E’, optionally signed) Complete Real number
Lecture 5©2003 Joel Jones7 JLex Structure n user code n % n JLex directives n % n regular expression rules
Lecture 5©2003 Joel Jones8 Reading & Questions for Next Class JLex webpages Home Page Tutorial torial.html