{[ promptMessage ]}

Bookmark it

{[ promptMessage ]}

lecture04

# lecture04 - Written Assignments WA1 assigned today...

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

1 Prof. Aiken CS 143 Lecture 4 1 Implementation of Lexical Analysis Lecture 4 Prof. Aiken CS 143 Lecture 4 2 Written Assignments WA1 assigned today Due in one week By 5pm Turn in In class • In box outside 411 Gates • Electronically Prof. Aiken CS 143 Lecture 4 3 Tips on Building Large Systems KISS (Keep It Simple, Stupid!) Don’t optimize prematurely Design systems that can be tested It is easier to modify a working system than to get a system working Prof. Aiken CS 143 Lecture 4 4 Outline Specifying lexical structure using regular expressions Finite automata Deterministic Finite Automata (DFAs) Non-deterministic Finite Automata (NFAs) Implementation of regular expressions RegExp => NFA => DFA => Tables Prof. Aiken CS 143 Lecture 4 5 Notation 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] Prof. Aiken CS 143 Lecture 4 6 Regular Expressions in Lexical Specification Last lecture: a specification for the predicate s L(R) But a yes/no answer is not enough! Instead: partition the input into tokens We adapt regular expressions to this goal

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

View Full Document
2 Prof. Aiken CS 143 Lecture 4 7 Regular Expressions => Lexical Spec. (1) 1. Write a rexp for the lexemes of each token Number = digit + Keyword = ‘if’ + ‘else’ + … Identifier = letter (letter + digit)* OpenPar = ‘(‘ Prof. Aiken CS 143 Lecture 4 8 Regular Expressions => Lexical Spec. (2) 2. Construct R , matching all lexemes for all tokens R = Keyword + Identifier + Number + … = R 1 + R 2 + … Prof. Aiken CS 143 Lecture 4 9 Regular Expressions => Lexical Spec. (3) 3. Let input be x 1 …x n For 1 i n check x 1 …x i L(R) 4. If success, then we know that x 1 …x i L(R j ) for some j 5.
This is the end of the preview. Sign up to access the rest of the document.

{[ snackBarMessage ]}