basics_of_compiler_design

basics_of_compiler_design - Basics of Compiler Design...

Info iconThis preview shows pages 1–5. 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
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: Basics of Compiler Design Torben AEgidius Mogensen DIKU University of Copenhagen Publishing address: DIKU University of Copenhagen Universitetsparken 1 DK-2100 Copenhagen DENMARK c Torben AEgidius Mogensen 2000 – 2007 torbenm@diku.dk Book homepage: http://www.diku.dk/˜torbenm/Basics First published 2000 This edition: April 10, 2007 Contents 1 Introduction 13 1.1 What is a compiler? . . . . . . . . . . . . . . . . . . . . . . . . . 13 1.2 The phases of a compiler . . . . . . . . . . . . . . . . . . . . . . 14 1.3 Interpreters . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 15 1.4 Why learn about compilers? . . . . . . . . . . . . . . . . . . . . 16 1.5 The structure of this book . . . . . . . . . . . . . . . . . . . . . . 17 1.6 To the lecturer . . . . . . . . . . . . . . . . . . . . . . . . . . . . 18 1.7 Acknowledgements . . . . . . . . . . . . . . . . . . . . . . . . . 19 1.8 Permission to use . . . . . . . . . . . . . . . . . . . . . . . . . . 19 2 Lexical Analysis 21 2.1 Introduction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 21 2.2 Regular expressions . . . . . . . . . . . . . . . . . . . . . . . . . 22 2.2.1 Shorthands . . . . . . . . . . . . . . . . . . . . . . . . . 24 2.2.2 Examples . . . . . . . . . . . . . . . . . . . . . . . . . . 25 2.3 Nondeterministic finite automata . . . . . . . . . . . . . . . . . . 27 2.4 Converting a regular expression to an NFA . . . . . . . . . . . . . 30 2.4.1 Optimisations . . . . . . . . . . . . . . . . . . . . . . . . 30 2.5 Deterministic finite automata . . . . . . . . . . . . . . . . . . . . 32 2.6 Converting an NFA to a DFA . . . . . . . . . . . . . . . . . . . . 34 2.6.1 Solving set equations . . . . . . . . . . . . . . . . . . . . 35 2.6.2 The subset construction . . . . . . . . . . . . . . . . . . . 37 2.7 Size versus speed . . . . . . . . . . . . . . . . . . . . . . . . . . 40 2.8 Minimisation of DFAs . . . . . . . . . . . . . . . . . . . . . . . 41 2.8.1 Example . . . . . . . . . . . . . . . . . . . . . . . . . . 42 2.8.2 Dead states . . . . . . . . . . . . . . . . . . . . . . . . . 45 2.9 Lexers and lexer generators . . . . . . . . . . . . . . . . . . . . . 46 2.9.1 Lexer generators . . . . . . . . . . . . . . . . . . . . . . 51 2.10 Properties of regular languages . . . . . . . . . . . . . . . . . . . 52 2.10.1 Relative expressive power . . . . . . . . . . . . . . . . . 53 2.10.2 Limits to expressive power . . . . . . . . . . . . . . . . . 54 3 4 CONTENTS 2.10.3 Closure properties . . . . . . . . . . . . . . . . . . . . . 55 2.11 Further reading . . . . . . . . . . . . . . . . . . . . . . . . . . . 56 Exercises . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 56 3 Syntax Analysis 63 3.1 Introduction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 63 3.2 Context-free grammars . . . . . . . . . . . . . . . . . . . . . . . 64 3.2.1 How to write context free grammars . . . . . . . . . . . . 66 3.3 Derivation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .Derivation ....
View Full Document

This document was uploaded on 08/10/2011.

Page1 / 232

basics_of_compiler_design - Basics of Compiler Design...

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

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