Presentation is loading. Please wait.

Presentation is loading. Please wait.

CS 614: Theory and Construction of Compilers Lecture 5 Fall 2003 Department of Computer Science University of Alabama Joel Jones.

Similar presentations


Presentation on theme: "CS 614: Theory and Construction of Compilers Lecture 5 Fall 2003 Department of Computer Science University of Alabama Joel Jones."— Presentation transcript:

1 CS 614: Theory and Construction of Compilers Lecture 5 Fall 2003 Department of Computer Science University of Alabama Joel Jones

2 Lecture 5©2003 Joel Jones2 Introduction to Lexing Tools C is action language lex flex Java is action language Jlex

3 Lecture 5©2003 Joel Jones3 Lexing Tool Basics Translate lexing specification to program Regular expressions Action code

4 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

5 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

6 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

7 Lecture 5©2003 Joel Jones7 JLex Structure n user code n % n JLex directives n % n regular expression rules

8 Lecture 5©2003 Joel Jones8 Reading & Questions for Next Class JLex webpages Home Page http://www.cs.princeton.edu/~appel/modern/java/JLex/ Tutorial http://bmrc.berkeley.edu/courseware/cs164/fall99/assignment/a1/tu torial.html


Download ppt "CS 614: Theory and Construction of Compilers Lecture 5 Fall 2003 Department of Computer Science University of Alabama Joel Jones."

Similar presentations


Ads by Google