lecture04

lecture04 - Written Assignments WA1 assigned today...

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

View Full Document Right Arrow Icon
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
Background image of page 1

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

View Full DocumentRight Arrow Icon
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
Background image of page 2
Image of page 3
This is the end of the preview. Sign up to access the rest of the document.

This document was uploaded on 04/06/2012.

Page1 / 6

lecture04 - Written Assignments WA1 assigned today...

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

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