Download presentation
Presentation is loading. Please wait.
1
CS 445 Lecture #2 Lexical Analysis
2
Regular Expressions ε is a r.e. Any char in the alphabet is a r.e. If r and s are r.e.’s then r | s is a r.e. If r and s are r.e.’s then r s is a r.e. If r is a r.e. then r* is a r.e. If r is a r.e. then (r) is a r.e.
3
Extended regular expressions r+ is equivalent to rr* r? is equivalent to r|ε [abc] is equivalent to a|b|c [a-z] is equivalent to a | b| … |z [^abc] is equivalent to anything but a,b, or c
4
Lexical Attributes A lexical attribute is a piece of information about a token Compiler writer can define as needed Typically: – Categoryinteger code, used in parsing – Lexemeactual string as appears in source – Line, columnlocation in source code – Valuefor literals, the binary they represent
5
API considerations int yylex(); -- lex API leaves a bit unspecified Lexical analyzer must obtain input Simple file? Other program?... and deliver output to somewhere Next phase (parser) expects what format? l Objects, one at a time?
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.