0% found this document useful (0 votes)
41 views2 pages

4 Syntax Analysis 191

This document discusses parsing and syntax analysis in compiler design. It covers topics such as context-free grammars, top-down and bottom-up parsing including LR parsing, ambiguity, error handling and parser generators like Yacc.

Uploaded by

ravi
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
41 views2 pages

4 Syntax Analysis 191

This document discusses parsing and syntax analysis in compiler design. It covers topics such as context-free grammars, top-down and bottom-up parsing including LR parsing, ambiguity, error handling and parser generators like Yacc.

Uploaded by

ravi
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 2

xii TABLE OF CONTENTS

3.7.1 Conversion of an NFA to a DFA 152


3.7.2 Simulation of an NFA 156
3.7.3 Efficiency of NFA Simulation 157
3.7.4 Construction of an NFA from a Regular Expression . . .159
3.7.5 Efficiency of String-Processing Algorithms 163
3.7.6 Exercises for Section 3.7 166
3.8 Design of a Lexical-Analyzer Generator 166
3.8.1 T h e Structure of the Generated Analyzer 167
3.8.2 P a t t e r n Matching Based on NFA's 168
3.8.3 DFA's for Lexical Analyzers 170
3.8.4 Implementing the Lookahead Operator 171
3.8.5 Exercises for Section 3.8 172
3.9 Optimization of DFA-Based P a t t e r n Matchers 173
3.9.1 Important States of an NFA 173
3.9.2 Functions Computed From the Syntax Tree 175
3.9.3 Computing unliable, firstpos, and lastpos 176
3.9.4 Computing followpos 177
3.9.5 Converting a Regular Expression Directly to a DFA . . . 179
3.9.6 Minimizing the Number of States of a DFA 180
3.9.7 State Minimization in Lexical Analyzers .184
3.9.8 Trading Time for Space in DFA Simulation 185
3.9.9 Exercises for Section 3.9 186
3.10 Summary of Chapter 3 187
3.11 References for Chapter 3 189

4 Syntax Analysis 191


4.1 Introduction 192
4.1.1 T h e Role of t h e Parser 192
4.1.2 Representative G r a m m a r s 193
4.1.3 Syntax Error Handling 194
4.1.4 Error-Recovery Strategies 195
4.2 Context-Free G r a m m a r s 197
4.2.1 The Formal Definition of a Context-Free G r a m m a r . . . . 197
4.2.2 Notational Conventions 198
4.2.3 Derivations 199
4.2.4 Parse Trees and Derivations 201
4.2.5 Ambiguity 203
4.2.6 Verifying t h e Language Generated b y a G r a m m a r . . . . 204
4.2.7 Context-Free G r a m m a r s Versus Regular Expressions . . . 205
4.2.8 Exercises for Section 4.2 206
4.3 Writing a G r a m m a r 209
4.3.1 Lexical Versus Syntactic Analysis 209
4.3.2 Eliminating Ambiguity 210
4.3.3 Elimination of Left Recursion 212
4.3.4 Left Factoring 214
x i i i
TABLE OF CONTENTS

4.3.5 Non-Context-Free Language Constructs 215


4.3.6 Exercises for Section 4.3 216
4.4 Top-Down Parsing 217
4.4.1 Recursive-Descent Parsing 219
4.4.2 F I R S T and F O L L O W 220
4.4.3 LL(1) G r a m m a r s 222
4.4.4 Nonrecursive Predictive Parsing 226
4.4.5 Error Recovery in Predictive Parsing 228
4.4.6 Exercises for Section 4.4 231
4.5 Bottom-Up Parsing 233
4.5.1 Reductions 234
4.5.2 Handle Pruning 235
4.5.3 Shift-Reduce Parsing 236
4.5.4 Conflicts During Shift-Reduce Parsing 238
4.5.5 Exercises for Section 4.5 240
4.6 Introduction to LR Parsing: Simple LR 241
4.6.1 Why LR Parsers? 241
4.6.2 Items and the LR(0) Automaton 242
4.6.3 T h e LR-Parsing Algorithm 248
4.6.4 Constructing SLR-Parsing Tables 252
4.6.5 Viable Prefixes 256
4.6.6 Exercises for Section 4.6 257
4.7 More Powerful LR Parsers 259
4.7.1 Canonical LR(1) Items 260
4.7.2 Constructing LR(1) Sets of Items 261
4.7.3 Canonical LR(1) Parsing Tables 265
4.7.4 Constructing LALR Parsing Tables 266
4.7.5 Efficient Construction of LALR Parsing Tables 270
4.7.6 Compaction of LR Parsing Tables 275
4.7.7 Exercises for Section 4.7 277
4.8 Using Ambiguous G r a m m a r s 278
4.8.1 Precedence and Associativity t o Resolve Conflicts . . . . 279
4.8.2 The "Dangling-Else" Ambiguity 281
4.8.3 Error Recovery in LR Parsing 283
4.8.4 Exercises for Section 4.8 285
4.9 Parser Generators 287
4.9.1 The Parser Generator Yacc 287
4.9.2 Using Yacc with Ambiguous G r a m m a r s 291
4.9.3 Creating Yacc Lexical Analyzers with Lex 294
4.9.4 Error Recovery in Yacc 295
4.9.5 Exercises for Section 4.9 297
4.10 Summary of Chapter 4 297
4.11 References for Chapter 4 300

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy