01-02lex - Problems for you Lexical analysis: Part II:...

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

View Full Document Right Arrow Icon
1 CSE 450: Compilers K. Stirewalt Lexical analysis: Part II: Using lex Topics: Overview of lex/flex Interactive examples CSE 450: Compilers K. Stirewalt Problems for you Given the following regular expressions: r1 = 0 (10)* 1+ r2 = (01)+ 0? Find: 1. a string that matches r1 but not r2 2. a string that matches r2 but not r1 3. a string that matches r1 and r2 4. a string that matches neither CSE 450: Compilers K. Stirewalt Question How would you write a lexical analyzer that tokenizes its inputs by matching text against r1 and r2? Doable in this case, but not completely trivial. Much more difficult as the number of patterns grows. .. CSE 450: Compilers K. Stirewalt Lex A lexical-analyzer generator: – Reads a file that contains token patterns, expressed as regular expressions and actions to perform on a match – Generates C code for a lexical analyzer that matches these patterns and performs these actions – Code is nearly always faster than handwritten code Generated code accessible via an api function:
Background image of page 1

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

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

Page1 / 2

01-02lex - Problems for you Lexical analysis: Part II:...

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

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