lec07mod - CS415 Compilers Lexical Analysis These slides...

Info iconThis preview shows pages 1–8. Sign up to view the full content.

View Full Document Right Arrow Icon
CS415 Compilers Lexical Analysis These slides are based on slides copyrighted by Keith Cooper, Ken Kennedy & Linda Torczon at Rice University
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Lecture 7 2 cs415, spring 10 Review - The Big Picture Why study lexical analysis? We want to avoid writing scanners by hand Goals: To simplify specification & implementation of scanners To understand the underlying techniques and technologies Scanner Scanner Generator specifications source code parts of speech & words tables or code Specifications written as “regular expressions” Represent words as indices into a global table
Background image of page 2
Lecture 7 3 cs415, spring 10 Regular Expressions Lexical patterns form a regular language *** any finite language is regular Regular expressions ( RE s) describe regular languages Regular Expression (over alphabet Σ ) ε is a RE denoting the set { ε } If a is in Σ , then a is a RE denoting {a } If x and y are RE sdenot ing L(x) and L(y) then x |y is an RE denoting L(x) L(y) xy is an RE denoting L(x)L(y) x * is an RE denoting L(x)* Precedence is closure, then concatenation, then alternation Ever type “rm *.o a.out” ?
Background image of page 3

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Lecture 7 4 cs415, spring 10 These definitions should be well known Operation Definition Set Operations Union of L and M Written L M L M = { s | s L or s M } Concatenation of L and M Written LM LM = { st | s L and t M } Kleene closure of L Written L * L * = 0 i ≤∞ L i Positive Closure of L + L + = 1 i ≤∞ L i
Background image of page 4
Lecture 7 5 cs415, spring 10 Examples of Regular Expressions Identifiers: Letter (a |b |c | … |z |A |B |C | … |Z ) Digit (0 |1 |2 | … |9 ) Identifier Letter( Letter | Digit) * Numbers: Integer (+ |- | ε ) (0 | (1 |2 |3 | … |9 )(Digit * ) ) Decimal Integer . * Real ( Integer | Decimal ) E (+ |- | ε ) Digit * Complex ( Real, Real ) Numbers can get much more complicated!
Background image of page 5

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Lecture 7 6 cs415, spring 10 Regular Expressions ( the point ) Regular expressions can be used to specify the words to be translated to parts of speech by a lexical analyzer Using results from automata theory and theory of algorithms, we can automatically build recognizers from regular expressions We study RE s and associated theory to automate scanner construction !
Background image of page 6
Lecture 7 7 cs415, spring 10 Consider the problem of recognizing ILOC register names Register r (0 |1 |2 | … | 9 )(0 |1 |2 | … | 9 ) * Allows registers of arbitrary number Requires at least one digit RE corresponds to a recognizer (or DFA ) Transitions on other inputs go to an error state, s e Example S 0 S 2 S 1 r (0 |1 |2 | … 9 ) accepting state (0 |1 |2 | … 9 ) Recognizer for Register
Background image of page 7

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Image of page 8
This is the end of the preview. Sign up to access the rest of the document.

This note was uploaded on 10/29/2010 for the course CS 198:415 taught by Professor Kremer,u. during the Spring '10 term at Rutgers.

Page1 / 26

lec07mod - CS415 Compilers Lexical Analysis These slides...

This preview shows document pages 1 - 8. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online