ppt - CS 614 Home Page

advertisement
CS 614: Theory and
Construction of Compilers
Lecture 5
Fall 2003
Department of
Computer Science
University of Alabama
Joel Jones
Introduction to Lexing Tools

C is action language



lex
flex
Java is action language

Jlex
Lecture 5
©2003 Joel Jones
2
Lexing Tool Basics



Translate lexing specification to program
Regular expressions
Action code
Lecture 5
©2003 Joel Jones
3
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
Lecture 5





^ 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
©2003 Joel Jones
4
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 Jones
5
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)
Lecture 5



Decimal Numbers
(with unary minus)
Float style exponent
(just the exponent, ‘e’
or ‘E’, optionally
signed)
Complete Real
number
©2003 Joel Jones
6
JLex Structure
n
n
n
n
n
user code
%%
JLex directives
%%
regular expression rules

Lecture 5
©2003 Joel Jones
7
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/tutorial.html
Lecture 5
©2003 Joel Jones
8
Download