cs 614: theory and construction of compilers lecture 5 fall 2003 department of computer science...
DESCRIPTION
Lecture 5©2003 Joel Jones3 Lexing Tool Basics Translate lexing specification to program Regular expressions Action codeTRANSCRIPT
![Page 1: CS 614: Theory and Construction of Compilers Lecture 5 Fall 2003 Department of Computer Science University of Alabama Joel Jones](https://reader036.vdocuments.us/reader036/viewer/2022082510/5a4d1b187f8b9ab059992967/html5/thumbnails/1.jpg)
CS 614: Theory and Construction of Compilers
Lecture 5Fall 2003Department of Computer ScienceUniversity of AlabamaJoel Jones
![Page 2: CS 614: Theory and Construction of Compilers Lecture 5 Fall 2003 Department of Computer Science University of Alabama Joel Jones](https://reader036.vdocuments.us/reader036/viewer/2022082510/5a4d1b187f8b9ab059992967/html5/thumbnails/2.jpg)
Lecture 5 ©2003 Joel Jones 2
Introduction to Lexing Tools C is action language
lex flex
Java is action language Jlex
![Page 3: CS 614: Theory and Construction of Compilers Lecture 5 Fall 2003 Department of Computer Science University of Alabama Joel Jones](https://reader036.vdocuments.us/reader036/viewer/2022082510/5a4d1b187f8b9ab059992967/html5/thumbnails/3.jpg)
Lecture 5 ©2003 Joel Jones 3
Lexing Tool Basics Translate lexing specification to program Regular expressions Action code
![Page 4: CS 614: Theory and Construction of Compilers Lecture 5 Fall 2003 Department of Computer Science University of Alabama Joel Jones](https://reader036.vdocuments.us/reader036/viewer/2022082510/5a4d1b187f8b9ab059992967/html5/thumbnails/4.jpg)
Lecture 5 ©2003 Joel Jones 4
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
![Page 5: CS 614: Theory and Construction of Compilers Lecture 5 Fall 2003 Department of Computer Science University of Alabama Joel Jones](https://reader036.vdocuments.us/reader036/viewer/2022082510/5a4d1b187f8b9ab059992967/html5/thumbnails/5.jpg)
Lecture 5 ©2003 Joel Jones 5
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
![Page 6: CS 614: Theory and Construction of Compilers Lecture 5 Fall 2003 Department of Computer Science University of Alabama Joel Jones](https://reader036.vdocuments.us/reader036/viewer/2022082510/5a4d1b187f8b9ab059992967/html5/thumbnails/6.jpg)
Lecture 5 ©2003 Joel Jones 6
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
![Page 7: CS 614: Theory and Construction of Compilers Lecture 5 Fall 2003 Department of Computer Science University of Alabama Joel Jones](https://reader036.vdocuments.us/reader036/viewer/2022082510/5a4d1b187f8b9ab059992967/html5/thumbnails/7.jpg)
Lecture 5 ©2003 Joel Jones 7
JLex Structuren user coden %%n JLex directivesn %%n regular expression rules
![Page 8: CS 614: Theory and Construction of Compilers Lecture 5 Fall 2003 Department of Computer Science University of Alabama Joel Jones](https://reader036.vdocuments.us/reader036/viewer/2022082510/5a4d1b187f8b9ab059992967/html5/thumbnails/8.jpg)
Lecture 5 ©2003 Joel Jones 8
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