{[ promptMessage ]}

Bookmark it

{[ promptMessage ]}

# lecture04 - CS 143 Lecture 4 1 I mplementation of Lexical...

This preview shows pages 1–9. Sign up to view the full content.

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

View Full Document

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

View Full Document

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

View Full Document

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

View Full Document
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: CS 143 Lecture 4 1 I mplementation of Lexical Analysis Lecture 4 CS 143 Lecture 4 2 Tips on Building Lar ge Systems • KI SS (Keep I t Simple, Stupid!) • Don’t optimize prematurely • Design systems that can be tested • I t is easier to modify a working system than to get a system working CS 143 Lecture 4 3 Outline • Specifying lexical structure using regular expressions • Finite automata – Deterministic Finite Automata (DFAs) – Non-deterministic Finite Automata (NFAs) • I mplementation of regular expressions RegExp => NFA => DFA => Tables CS 143 Lecture 4 4 N otation • There is variation in regular expression notation • Union: A | B ≡ A + B • Option: A + ε ≡ A? • Range: ‘a’+’b’+…+’z’ ≡ [a-z] • Excluded range: complement of [a-z] ≡ [^ a-z] CS 143 Lecture 4 5 Regular Expr essions in Lexical Specification • Last lecture: a specification for the predicate s ∈ L(R) • But a yes/ no answer is not enough! • I nstead: partition the input into tokens • We adapt regular expressions to this goal CS 143 Lecture 4 6 Regular Expr essions => Lexical Spec. (1) 1. Write a rexp for the lexemes of each token • Number = digit + • Keyword = ‘if’ + ‘else’ + … • I dentifier = letter (letter + digit)* • OpenPar = ‘(‘ • … CS 143 Lecture 4 7 Regular Expr essions => Lexical Spec. (2) 1. Construct R , matching all lexemes for all tokens R = Keyword + I dentifier + Number + … = R 1 + R 2 + … CS 143 Lecture 4 8 Regular Expr essions => Lexical Spec. (3) 1. Let input be x 1 …x n For 1 ≤ i ≤ n check x 1 …x i ∈ L(R) 1. I f success, then we know that x 1 …x i ∈ L(R j ) for some j 1. Remove x 1 …x i from input and go to (3) CS 143...
View Full Document

{[ snackBarMessage ]}

### Page1 / 35

lecture04 - CS 143 Lecture 4 1 I mplementation of Lexical...

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

View Full Document
Ask a homework question - tutors are online