Details

Compiler Construction Using Java, JavaCC, and Yacc


Compiler Construction Using Java, JavaCC, and Yacc


1. Aufl.

von: Anthony J. Dos Reis

96,99 €

Verlag: Wiley
Format: PDF
Veröffentl.: 23.02.2012
ISBN/EAN: 9781118112878
Sprache: englisch
Anzahl Seiten: 664

DRM-geschütztes eBook, Sie benötigen z.B. Adobe Digital Editions und eine Adobe ID zum Lesen.

Beschreibungen

Broad in scope, involving theory, the application of that theory, and programming technology, compiler construction is a moving target, with constant advances in compiler technology taking place. Today, a renewed focus on do-it-yourself programming makes a quality textbook on compilers, that both students and instructors will enjoy using, of even more vital importance. This book covers every topic essential to learning compilers from the ground up and is accompanied by a powerful and flexible software package for evaluating projects, as well as several tutorials, well-defined projects, and test cases.
<p>Preface xv</p> <p><b>Chapter 1 Strings, Languages, and Compilers 1</b></p> <p>1.1 Introduction 1</p> <p>1.2 Basic Language Concepts 1</p> <p>1.3 Basic Compiler Concepts 3</p> <p>1.4 Basic Set Theory 4</p> <p>1.5 Null String 6</p> <p>1.6 Concatenation 7</p> <p>1.7 Exponent Notation 7</p> <p>1.8 Star Operator 8</p> <p>1.9 Concatenation of Sets of Strings 9</p> <p>1.10 Plus Operator 11</p> <p>1.11 Question Mark Operator 11</p> <p>1.12 Shorthand Notation for a Set Containing a Single String 12</p> <p>1.13 Operator Precedence 12</p> <p>1.14 Regular Expressions 13</p> <p>1.15 Limitations of Regular Expressions 15</p> <p>Problems 16</p> <p><b>Chapter 2 Context-Free Grammars, Part 1 19</b></p> <p>2.1 Introduction 19</p> <p>2.2 What is a Context-Free Grammar? 20</p> <p>2.3 Derivations Using a Context-Free Grammar 21</p> <p>2.4 Language Defined by a Context-Free Grammar 23</p> <p>2.5 Different Ways of Representing Contet-Free Grammars 25</p> <p>2.6 Some Simple Grammars 26</p> <p>2.7 Techniques for Generating Languages with Context-Free Grammars 29</p> <p>2.8 Regular and Right Linear Grammars 35</p> <p>2.9 Counting with Regular Grammars 37</p> <p>2.0 Grammars for Lists 39</p> <p>2.10 An Important Language that is Not Context Free 44</p> <p>Problems 45</p> <p><b>Chapter 3 Context-Free Grammars, Part 2 49</b></p> <p>3.1 Introduction 49</p> <p>3.2 Parse Trees 49</p> <p>3.3 Leftmost and Rightmost Derivations 51</p> <p>3.4 Substitution 52</p> <p>3.5 Ambiguous Grammars 54</p> <p>3.6 Determining Nullable Nonterminals 59</p> <p>3.7 Eliminating Lambda Productions 60</p> <p>3.8 Eliminating Unit Productions 64</p> <p>3.9 Eliminating Useless Nonterminals 66</p> <p>3.10 Recursion Conversions 71</p> <p>3.11 Adding the Null String to a Language 76</p> <p>Problems 77</p> <p><b>Chapter 4 Context-Free Grammars, Part 3 83</b></p> <p>4.1 Introduction 83</p> <p>4.2 Grammars for Arithmetic Expressions 83</p> <p>4.3 Specifying Associativity and Precedence in Grammars 90</p> <p>4.4 Backus-Naur Form 92</p> <p>4.5 Syntax Diagrams 94</p> <p>4.6 Abstract Syntax Trees and Three-Address Code 96</p> <p>4.7 Noncontracting Grammars 97</p> <p>4.8 Essentially Noncontracting Grammars 97</p> <p>4.9 Converting a Context-Free Grammar to an Essentially Noncontracting Grammar 98</p> <p>4.10 Pumping Property of Context-Free Languages 101</p> <p>Problems 104</p> <p><b>Chapter 5 Chomsky’s Hierarchy 107</b></p> <p>5.1 Introduction 107</p> <p>5.2 Context-Sensitive Productions 107</p> <p>5.3 Context-Sensitive Grammars no</p> <p>5.4 Unrestricted Grammars 111</p> <p>Problems 112</p> <p><b>Chapter 6 Top-Down Parsing 115</b></p> <p>6.1 Introduction 115</p> <p>6.2 Top-Down Construction of a Parse Tree 115</p> <p>6.3 Parses that Fail 117</p> <p>6.4 A Bad Grammar for Top-Down Parsing 118</p> <p>6.5 Deterministic Parsers 119</p> <p>6.6 A Parser that Uses a Stack 120</p> <p>6.7 Table Representation of a Stack Parser 124</p> <p>6.8 Handling Productions with Nonleading Terminal 126</p> <p>6.9 Writing a Stack Parser in Java 127</p> <p>Problems 134</p> <p><b>Chapter 7 LL(1) Grammars 137</b></p> <p>7.1 Introduction 137</p> <p>7.2 FIRST Set of the Right Side of a Production 137</p> <p>7.3 Determining Operation Sequences 140</p> <p>7.4 Determining Selection Sets of Lambda Productions 142</p> <p>7.5 Whatever-Follows-Left-Follows-Rightmost Rule 145</p> <p>7.6 Selection Sets for Productions with Nullable Right Sides 147</p> <p>7.7 Selection Sets Containing End-of-Input Symbol 149</p> <p>7.8 A Stack Parser for a Grammar with Lambda Productions 152</p> <p>7.9 Converting a Non-LL( 1) Grammar to an LL( 1) Grammar 153</p> <p>7.10 Parsing with an Ambiguous Grammar 160</p> <p>7.11 Computing FIRST and FOLLOW Sets 163</p> <p>Problems 165</p> <p><b>Chapter 8 Table-Driven Stack Parser 171</b></p> <p>8.1 Introduction 171</p> <p>8.2 Unifying the Operations of a Stack Parser 172</p> <p>8.3 Implementing a Table-Driven Stack Parser 175</p> <p>8.4 Improving Our Table-Driven Stack Parser 180</p> <p>8.5 Parsers that are Not Deterministic—A Digression on Theory 181</p> <p>Problems 183</p> <p><b>Chapter 9 Recursive-Descent Parsing 185</b></p> <p>9.1 Introduction 185</p> <p>9.2 Simple Recursive-Descent Parser 185</p> <p>9.3 Handling Lambda Productions 192</p> <p>9.4 A Common Error 197</p> <p>9.5 Java Code for Productions 198</p> <p>9.6 Left Factoring in a Recursive-Descent Parser 199</p> <p>9.7 Eliminating Tail Recursion 204</p> <p>9.8 Translating the Star, Plus, and Question Mark Operators 108</p> <p>9.9 Doing Things Backward 210</p> <p>Problems 211</p> <p><b>Chapter 10 Recursive-Descent Translation 215</b></p> <p>10.1 introduction 215</p> <p>10.2 A Simple Translation Grammar 215</p> <p>10.3 Converting a Translation Grammar to Java Code 217</p> <p>10.4 Specifications for a Translation Grammar 218</p> <p>10.5 Passing Information During a Parse 231</p> <p>10.6 L-Attributed Grammars 236</p> <p>10.7 New Token Manager 238</p> <p>10.8 Solving the Token Lookahead Problem 241</p> <p>10.9 Code for the New Token Manager 241</p> <p>10.10 Translation Grammar for Prefix Expression Compiler 253</p> <p>10.11 An Interesting Use of Recursion 257</p> <p>Problems 261</p> <p><b>Chapter 11 Assembly Language 265</b></p> <p>11.1 Introduction 265</p> <p>11.2 Structure of the J1 Computer 265</p> <p>11.3 Machine Language Instructions 266</p> <p>11.4 Assembly Language Instructions 268</p> <p>11.5 Pushing Characters 269</p> <p>11.6 aout Instruction 270</p> <p>11.7 Using Labels 270</p> <p>11.8 Using the Assembler 272</p> <p>11.9 stav Instruction 275</p> <p>11.10 Compiling an Assignment Statement 277</p> <p>11.11 Compiling print and printin 280</p> <p>11.12 Outputting Strings 28,</p> <p>11.13 Inputting Decimal Numbers 283</p> <p>11.14 Entry Directive 284</p> <p>11.15 More Assembly Language 285</p> <p>Problems 285</p> <p><b>Chapter 12 SI—A Simple Compiler 289</b></p> <p>12.1 Introduction 289</p> <p>12.2 The Source Language 289</p> <p>12.3 Grammar for Source Language 290</p> <p>12.4 The Target Language 291</p> <p>12.5 Symbol Table 292</p> <p>12.6 Code Generator 293</p> <p>12.7 Token Class 293</p> <p>12.8 Writing the Translation Grammar 294</p> <p>12.9 Implementing the SI Compiler 299</p> <p>12.10 Trying Out SI 315</p> <p>12.11 Advice on Extending the SI Compiler 318</p> <p>12.12 Specifications for S2 320</p> <p>Problems 324</p> <p><b>Chapter 13 JavaCC 331</b></p> <p>13.1 Introduction 331</p> <p>13.2 JavaCC Extended Regular Expressions 333</p> <p>13.3 JavaCC Input File 337</p> <p>13.4 Specifying Actions for Regular Expressions 344</p> <p>13.5 JavaCC Input File for Slj 348</p> <p>13.6 Files Produced by JavaCC 355</p> <p>13.7 Using the Star and Plus Operators 359</p> <p>13.8 Choice Points and the Lookahead Directive 362</p> <p>13.9 JavaCC’s Choice Algorithm 367</p> <p>13.10 Syntactic and Semantic Lookahead 371</p> <p>13.11 Using JavaCC to Create a Token Manager Only 372</p> <p>13.12 Using the Token Chain 373</p> <p>13.13 Suppressing Warning Messages 377</p> <p>Problems 387</p> <p><b>Chapter 14 Building on S2 383</b></p> <p>14.1 Introduction 383</p> <p>14.2 Extending println and print 383</p> <p>14.3 Cascaded Assignment Statement 388</p> <p>14.4 Unary Plus and Minus 313</p> <p>14.5 readint Statement 393</p> <p>14.6 Controlling the Token Trace from the Command Line 395</p> <p>14.7 Specifications for S3 396</p> <p>Problems 396</p> <p><b>Chapter 15 Compiling Control Structures 399</b></p> <p>15.1 Introduction 399</p> <p>15.2 while Statement 399</p> <p>15.3 if Statement 403</p> <p>15.4 do-while Statement 407</p> <p>15.5 Range Checking of Numerical Constants 408</p> <p>15.6 Handling Backslash-Quote in a String 410</p> <p>15.7 Handling Backslash-Quote with JavaCC 411</p> <p>15.8 Universal Blocks in JavaCC 416</p> <p>15.9 Handling Strings that Span Lines 418</p> <p>15.10 Handling Strings that Span Lines Using JavaCC 419</p> <p>15.11 SPECIAL_TOKEN Block in JavaCC 422</p> <p>15.12 Error Recovery 424</p> <p>15.13 Error Recovery in JavaCC 429</p> <p>15.14 Specifications for S4 430</p> <p>Problems 431</p> <p><b>Chapter 16 Compiling Programs in Functional Form 435</b></p> <p>16.1 Introduction 435</p> <p>16.2 Separate Assembly and Linking 435</p> <p>16.3 Calling and Returning from Fuctions 439</p> <p>16.4 Source Language for S5 443</p> <p>16.5 Symbol Table for S5 445</p> <p>16.6 Code Generator for S5 446</p> <p>16.7 Translation Grammar forS5 447</p> <p>16.8 Linking with a Library 457</p> <p>16.9 Specifications for S5 458</p> <p>16.10 Extending S5 458</p> <p>Problems 461</p> <p><b>Chapter 17 Finite Automata 465</b></p> <p>17.1 Introduction 465</p> <p>17.2 Deterministic Finite Automata 466</p> <p>17.3 Converting a DFA to a Regular Expression 468</p> <p>17.4 Java Code for a DFA 472</p> <p>17.5 Nondeterministic Finite Automata 474</p> <p>17.6 Using an NFA as an Algorithm 476</p> <p>17.7 Converting an NFA to a DFA with the Subset Algorithm 478</p> <p>17.8 Converting a DFA to a Regular Grammar 479</p> <p>17.9 Converting a Regular Grammar to an NFA 482 </p> <p>17.10 Converting a Regular Expression to an NF A 484</p> <p>17.11 Finding the Minimal DFA 488</p> <p>17.12 Pumping Property of Regular Languages 493</p> <p>Problems 495</p> <p><b>Chapter 18 Capstone Project: Implementing Grep Using Compiler Technology 499</b></p> <p>18.1 Introduction 499</p> <p>18.2 Regular Expressions for Our Grep Program 501</p> <p>18.3 Token Manager for Regular Expression 501</p> <p>18.4 Grammar for Regular Expressions 503</p> <p>18.5 Target Language for Our Regular Expression Compiler 503</p> <p>18.6 Using an NFA for Pattern Matching 508</p> <p>Problems 513</p> <p><b>Chapter 19 Compiling to a Register-Oriented Architecture 515</b></p> <p>19.1 Introduction 515</p> <p>19.2 Using the Register Instruction Set 516</p> <p>19.3 Modifications to the Symbol Table for R1 517</p> <p>19.4 Parser and Code Generator for R1 518</p> <p>Problems 526</p> <p><b>Chapter 20 Optimization 529</b></p> <p>20.1 Introduction 529</p> <p>20.2 Using the ldc Instruction 531</p> <p>20.3 Reusing Temporary Variables 532</p> <p>20.4 Constant Folding 535</p> <p>20.5 Register Allocation 537</p> <p>20.6 Peephole Optimization 540</p> <p>Problems 543</p> <p><b>Chapter 21 Interpreters 547</b></p> <p>21.1 Introduction 547</p> <p>21.2 Converting SI to 11 549</p> <p>21.3 Interpreting Statements that Transfer Control 552</p> <p>21.4 Implementing the Compiler-Interpreter Cl 1 553</p> <p>21.5 Advantages of Interpreters 558</p> <p>Problems 559</p> <p><b>Chapter 22 Bottom-Up Parsing 561</b></p> <p>22.1 Introduction 561</p> <p>22.2 Principles of Bottom-Up Parsing 561</p> <p>22.3 Parsing with Right- versus Left-Recursive Grammars 565</p> <p>22.4 Bottom-Up Parsing with an Ambiguous Grammar 566</p> <p>22.5 Do-Not-Reduce Rule 569</p> <p>22.6 SLR(l) Parsing 570</p> <p>22.7 Shift/Reduce Conflicts 577</p> <p>22.8 Reduce/Reduce Conflicts 579</p> <p>22.9 LR(1) Parsing 579</p> <p>Problems 584</p> <p><b>Chapter 23 yacc 587</b></p> <p>23.1 Introduction 587</p> <p>23.2 yacc Input and Output Files 587</p> <p>23.3 A Simple yacc-Generated Parser 588</p> <p>23.4 Passing Values Using the Value Stack 596</p> <p>23.5 Using yacc With an Ambiguous Grammar 602</p> <p>23.6 Passing Values down the Parse Tree 604</p> <p>23.7 Implementing Sly 606</p> <p>23.8 jflex 612</p> <p>Problems 618</p> <p>Appendix A Stack Instruction Set 621</p> <p>Appendix B Register Instruction Set 625</p> <p>References 629</p> <p>Index</p>
"Compiler Construction Using Java, JavaCC, and Yacc covers every topic essential to learning compilers from the ground up and is accompanied by a powerful and flexible software package for evaluating projects, as well as several tutorials, well-defined projects, and test cases." (Ulitzer, 5 December 2011) <p> </p>
<p><b>ANTHONY J. DOS REIS</b> is Associate Professor of Computer Science at the State University of New York at New Paltz. Before becoming a professor, Dr. Dos Reis worked at IBM as a systems programmer, creating IBM operating systems and compilers. His teaching interests include computer engineering, program translation, Java, and formal languages.
<p><b>A student-friendly, course-friendly guide to compiler theory, applications, and programming technology</b> <p>Compiler construction is a tricky subject, involving theory, the application of that theory, and programming technology. Virtually every day, advances in computer technology propel advances in compiler technology. Compiler Construction Using Java<sup>™</sup>, JavaCC, and Yacc covers every topic essential to learning compilers from the ground up and is accompanied by a powerful and flexible software package for evaluating projects as well as several tutorials, well-defined projects, and test cases. While the coverage of JavaCC is entirely optional, this book provides the only comprehensive introduction to the topic currently available. <p>Far easier to read and understand than any other compiler guide, this book sets a new standard for learning this invaluable skill. It provides: <ul> <li>Strong coverage of formal languages, including context-sensitive and unrestricted languages as well as regular and context-free languages</li> <li>A clear exposition of compiler design and implementation theory</li> <li>Numerous well-defined projects, using source language with six levels of complexity</li> <li>A complete teaching support software package that evaluates compiler projects for correctness, run time, and size of code, and runs on multiple platforms</li> <li>Immediate feedback for students on their projects</li> </ul> <p>Compiler Construction Using Java<sup>™</sup>, JavaCC, and Yacc provides substantial support for each project, many of which are incremental enhancements of previous projects. The goals at each new level are challenging but achievable and can be reached in several different ways, for example, by writing a compiler or interpreter by hand, with JavaCC, or with Yacc.

Diese Produkte könnten Sie auch interessieren:

Domain Architectures
Domain Architectures
von: Daniel J. Duffy
PDF ebook
31,99 €