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

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

View Full Document Right Arrow Icon

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

View Full DocumentRight Arrow Icon

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

View Full DocumentRight Arrow Icon

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

View Full DocumentRight Arrow Icon

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

View Full DocumentRight Arrow Icon
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!) Dont 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

This note was uploaded on 05/05/2010 for the course COMPILER AC 1 taught by Professor Sergio during the Spring '10 term at Institute of Management Technology.

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 Right Arrow Icon
Ask a homework question - tutors are online