Compiler Construction Using Java, JavaCC, and Yacc

Cover Image Copyright Year: 2012
Author(s): Anthony J. Dos Reis
Book Type: Wiley-IEEE Press
Content Type : Books & eBooks
Topics: Communication, Networking & Broadcasting ;  Components, Circuits, Devices & Systems ;  Computing & Processing
  • Print

Abstract

A student-friendly, course-friendly guide to compiler theory, applications, and programming technology

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, 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 currentlyavailable.

Far easier to read and understand than any other compiler guide, this booksets a new standard for learning this invaluable skill. It provides:

  • Strong coverage of formal languages, including context-sensitive and unrestricted languages as well as reg lar and context-free languages

  • A clear exposition of compiler design and implementation theory

  • Numerous well-defined projects, using source language with six levels of complexity

  • A complete teaching support software package that evaluates compiler projects for correctness, run time, and size of code, and runs on multiple platforms

  • Immediate feedback for students on their projects

Compiler Construction Using JavaTM, 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.

  •   Click to expandTable of Contents

    • Full text access may be available. Click article title to sign in or learn about subscription options.

      Front Matter

      Page(s): i - xvii
      Copyright Year: 2012

      Wiley-IEEE Press eBook Chapters

      The prelims comprise:
      Half Title
      Board Members
      Title
      Copyright
      Dedication
      Contents
      Preface View full abstract»

    • Full text access may be available. Click article title to sign in or learn about subscription options.

      Strings, Languages, and Compilers

      Copyright Year: 2012

      Wiley-IEEE Press eBook Chapters

      This chapter contains sections titled:

    • Introduction

    • Basic Language Concepts

    • Basic Compiler Concepts

    • Basic Set Theory

    • Null String

    • Concatenation

    • Exponent Notation

    • Star Operator (Also Known as the Zero-or-More Operator)

    • Concatenation of Sets of Strings

    • Plus Operator (Also Known as the One-or-More Operator)

    • Question Mark Operator (Also Known as Zero-or-One Operator)

    • Shorthand Notation for a Set Containing a Single String

    • Operator Precedence

    • Regular Expressions

    • Limitations of Regular Expressions

    • Problems

    • View full abstract»

  • Full text access may be available. Click article title to sign in or learn about subscription options.

    Context-Free Grammars, Part 1

    Copyright Year: 2012

    Wiley-IEEE Press eBook Chapters

    This chapter contains sections titled:

  • Introduction

  • What is a Context-Free Grammar?

  • Derivations Using a Context-Free Grammar

  • Language Defined By a Context-Free Grammar

  • Different Ways of Representing Context-Free Grammars

  • Some Simple Grammars

  • Techniques for Generating Languages with Context-Free Grammars

  • Regular and Right Linear Grammars

  • Counting with Regular Grammars

  • Grammars for Lists

  • An Important Language That is not Context-Free

  • Problems

  • View full abstract»

  • Full text access may be available. Click article title to sign in or learn about subscription options.

    Context-free Grammars, Part 2

    Compiler Construction Using Java, JavaCC, and Yacc
    Copyright Year: 2012

    Wiley-IEEE Press eBook Chapters

    This chapter contains sections titled:

  • Introduction

  • Parse Trees

  • Leftmost and Rightmost Derivations

  • Substitution

  • Ambiguous Grammars

  • Determining Nullable Nonterminals

  • Eliminating Lambda Productions

  • Eliminating Unit Productions

  • Eliminating Useless Nonterminals

  • Recursion Conversions

  • Adding The Null string to a language

  • Problems

  • View full abstract»

  • Full text access may be available. Click article title to sign in or learn about subscription options.

    Context-Free Grammars, Part 3

    Compiler Construction Using Java, JavaCC, and Yacc
    Copyright Year: 2012

    Wiley-IEEE Press eBook Chapters

    This chapter contains sections titled:

  • Introduction

  • Grammars for Arithmetic Expressions

  • Specifying Associativity and Precedence in Grammars

  • Backus-Naur Form

  • Syntax Diagrams

  • Abstract Syntax Trees and Three-Address Code

  • Noncontracting Grammars

  • Essentially Noncontracting Grammars

  • Converting a Context-Free Grammar to an Essentially Noncontracting Grammar

  • Pumping Property of Context-Free Languages (Optional)

  • Problems

  • View full abstract»

  • Full text access may be available. Click article title to sign in or learn about subscription options.

    Chomsky's Hierarchy (Optional)

    Compiler Construction Using Java, JavaCC, and Yacc
    Copyright Year: 2012

    Wiley-IEEE Press eBook Chapters

    This chapter contains sections titled:

  • Introduction

  • Context-Sensitive Productions

  • Context-Sensitive Grammars

  • Unrestricted Grammars

  • Problems

  • View full abstract»

  • Full text access may be available. Click article title to sign in or learn about subscription options.

    Top-Down Parsing

    Compiler Construction Using Java, JavaCC, and Yacc
    Copyright Year: 2012

    Wiley-IEEE Press eBook Chapters

    This chapter contains sections titled:

  • Introduction

  • Top-Down Construction of a Parse Tree

  • Parses That Fail

  • A Bad Grammar for Top-Down Parsing

  • Deterministic Parsers

  • A Parser That Uses a Stack

  • Table Representation of a Stack Parser

  • Handling Productions with Nonleading Terminals

  • Writing a Stack Parser in Java

  • Problems

  • View full abstract»

  • Full text access may be available. Click article title to sign in or learn about subscription options.

    LL(1) Grammars

    Compiler Construction Using Java, JavaCC, and Yacc
    Copyright Year: 2012

    Wiley-IEEE Press eBook Chapters

    This chapter contains sections titled:

  • Introduction

  • First Set of the Right Side of a Production

  • Determining Operation Sequences

  • Determining Selection Sets of Lambda Productions

  • Whatever-Follows-Left-Follows-Rightmost Rule

  • Selection Sets for Productions with Nullable Right Sides

  • Selection Sets Containing the End-of-Input Marker

  • A Stack Parser for a Grammar with Lambda Productions

  • Converting a Non-LL(1) Grammar to an LL(1) Grammar

  • Parsing with an Ambiguous Grammar

  • Computing First and Follow Sets

  • Problems

  • View full abstract»

  • Full text access may be available. Click article title to sign in or learn about subscription options.

    Table-Driven Stack Parser (Optional)

    Compiler Construction Using Java, JavaCC, and Yacc
    Copyright Year: 2012

    Wiley-IEEE Press eBook Chapters

    This chapter contains sections titled:

  • Introduction

  • Unifying the Operations of a Stack Parser

  • Implementing a Table-Driven Stack Parser

  • Improving our Table-Driven Stack Parser

  • Parsers that are not Deterministic¿¿-¿¿A Digression on Theory (Optional)

  • Problems

  • View full abstract»

  • Full text access may be available. Click article title to sign in or learn about subscription options.

    Recursive-Descent Parsing

    Compiler Construction Using Java, JavaCC, and Yacc
    Copyright Year: 2012

    Wiley-IEEE Press eBook Chapters

    This chapter contains sections titled:

  • Introduction

  • A Simple Recursive-Descent Parser

  • Handling Lambda Productions

  • A Common Error

  • Java Code for Productions

  • Left Factoring in a Recursive-Descent Parser

  • Eliminating Tail Recursion

  • Translating the Star, Plus, and Question Mark Operators

  • Doing Things Backward

  • Problems

  • View full abstract»

  • Full text access may be available. Click article title to sign in or learn about subscription options.

    Recursive-Descent Translation

    Compiler Construction Using Java, JavaCC, and Yacc
    Copyright Year: 2012

    Wiley-IEEE Press eBook Chapters

    This chapter contains sections titled:

  • Introduction

  • A Simple Translation Grammar

  • Converting a Translation Grammar to Java Code

  • Specifications for a Translation Grammar

  • Passing Information During the Parse

  • L-Attributed Grammars

  • A New Token Manager

  • Solving the Token Lookahead Problem

  • Code for the New Token Manager

  • Translation Grammar for Prefix Expression Compiler

  • An Interesting Use of Recursion (Optional)

  • Problems

  • View full abstract»

  • Full text access may be available. Click article title to sign in or learn about subscription options.

    Assembly Language

    Compiler Construction Using Java, JavaCC, and Yacc
    Copyright Year: 2012

    Wiley-IEEE Press eBook Chapters

    This chapter contains sections titled:

  • Introduction

  • Structure of the J1 Computer

  • Machine Language Instructions

  • Assembly Language Instructions

  • Pushing Characters

  • aout Instruction

  • Using Labels

  • Using the Assembler

  • stav Instruction

  • Compiling an Assignment Statement

  • Compiling print and println

  • Outputting Strings

  • Inputting Decimal Numbers

  • Entry Directive

  • More Assembly Language

  • Problems

  • View full abstract»

  • Full text access may be available. Click article title to sign in or learn about subscription options.

    S1¿¿-¿¿A Simple Compiler

    Compiler Construction Using Java, JavaCC, and Yacc
    Copyright Year: 2012

    Wiley-IEEE Press eBook Chapters

    This chapter contains sections titled:

  • Introduction

  • The Source Language

  • Grammar for Source Language

  • The Target Language

  • Symbol Table

  • Code Generator

  • token Class

  • Writing The Translation Grammar

  • Implementing the S1 Compiler

  • Trying Out S1

  • Advice on Extending the S1 Compiler

  • Specifications For S2

  • Problems

  • View full abstract»

  • Full text access may be available. Click article title to sign in or learn about subscription options.

    JavaCC (Optional)

    Compiler Construction Using Java, JavaCC, and Yacc
    Copyright Year: 2012

    Wiley-IEEE Press eBook Chapters

    This chapter contains sections titled:

  • Introduction

  • JavaCC Extended Regular Expressions

  • JavaCC Input File

  • Specifying Actions for Regular Expressions

  • JavaCC Input File for S1j

  • Files Produced by JavaCC

  • Using the Star and PLUS Operators

  • Choice Points and Lookahead

  • JavaCC'S Choice Algorithm

  • Syntactic and Semantic Lookahead (Optional)

  • Using JavaCC to Create a Token Manager Only

  • Using the Token Chain

  • Suppressing Warning Messages

  • Problems

  • View full abstract»

  • Full text access may be available. Click article title to sign in or learn about subscription options.

    Building on S2

    Compiler Construction Using Java, JavaCC, and Yacc
    Copyright Year: 2012

    Wiley-IEEE Press eBook Chapters

    This chapter contains sections titled:

  • Introduction

  • Extending println and print

  • Cascaded Assignment Statement

  • Unary Plus and Minus

  • readint Statement

  • Controlling the Token Trace from the Command Line

  • Specifications for S3

  • Problems

  • View full abstract»

  • Full text access may be available. Click article title to sign in or learn about subscription options.

    Compiling Control Structures

    Compiler Construction Using Java, JavaCC, and Yacc
    Copyright Year: 2012

    Wiley-IEEE Press eBook Chapters

    This chapter contains sections titled:

  • Introduction

  • while Statement

  • if Statement

  • do-while Statement

  • Range Checking of Numerical Constants

  • Handling Backslash-Quote in a String

  • Handling Backslash-Quote with JavaCC (Optional)

  • Univeral Blocks in JavaCC (Optional)

  • Handling Strings that Span Lines

  • Handling Strings that Span Lines using JavaCC (Optional)

  • SPECIAL_TOKEN Block in JavaCC (Optional)

  • Error Recovery

  • Error Recovery in JavaCC (Optional)

  • Specifications for S4

  • Problems

  • View full abstract»

  • Full text access may be available. Click article title to sign in or learn about subscription options.

    Compiling Programs in Functional Form

    Compiler Construction Using Java, JavaCC, and Yacc
    Copyright Year: 2012

    Wiley-IEEE Press eBook Chapters

    This chapter contains sections titled:

  • Introduction

  • Separate Assembly and Linking

  • Calling and Returning from Functions

  • Source Language for S5

  • Symbol Table for S5

  • Code Generator for S5

  • Translation Grammar for S5

  • Linking with a Library

  • Specifications for S5

  • Extending S5 (Optional)

  • Problems

  • View full abstract»

  • Full text access may be available. Click article title to sign in or learn about subscription options.

    Finite Automata

    Compiler Construction Using Java, JavaCC, and Yacc
    Copyright Year: 2012

    Wiley-IEEE Press eBook Chapters

    This chapter contains sections titled:

  • Introduction

  • Deterministic Finite Automata

  • Converting a DFA to a Regular Expression

  • Java Code for a DFA

  • Nondeterministic Finite Automata

  • Using an NFA as an Algorithm

  • Converting an NFA to a DFA with the Subset Algorithm

  • Converting a DFA to a Regular Grammar

  • Converting a Regular Grammar to an NFA

  • Converting a Regular Expression to an NFA

  • Finding the Minimal DFA

  • Pumping Property of Regular Languages

  • Problems

  • View full abstract»

  • Full text access may be available. Click article title to sign in or learn about subscription options.

    Capstone Project: Implementing Grep Using Compiler Technology

    Compiler Construction Using Java, JavaCC, and Yacc
    Copyright Year: 2012

    Wiley-IEEE Press eBook Chapters

    This chapter contains sections titled:

  • Introduction

  • Regular Expressions for our Grep Program

  • Token Manager for Regular Expressions

  • Grammar for Regular Expressions

  • Target Language for our Regular Expression Compiler

  • Using an NFA for Pattern Matching

  • Problems

  • View full abstract»

  • Full text access may be available. Click article title to sign in or learn about subscription options.

    Compiling to a Register-Oriented Architecture

    Compiler Construction Using Java, JavaCC, and Yacc
    Copyright Year: 2012

    Wiley-IEEE Press eBook Chapters

    This chapter contains sections titled:

  • Introduction

  • Using the Register Instruction Set

  • Modifications to the Symbol Table for R1

  • Parser and Code Generator for R1

  • Problems

  • View full abstract»

  • Full text access may be available. Click article title to sign in or learn about subscription options.

    Optimization

    Compiler Construction Using Java, JavaCC, and Yacc
    Copyright Year: 2012

    Wiley-IEEE Press eBook Chapters

    This chapter contains sections titled:

  • Introduction

  • Using The ldc Instruction

  • Reusing Temporary Variables

  • Constant Folding

  • Register Allocation

  • Peephole Optimization

  • Problems

  • View full abstract»

  • Full text access may be available. Click article title to sign in or learn about subscription options.

    Interpreters

    Compiler Construction Using Java, JavaCC, and Yacc
    Copyright Year: 2012

    Wiley-IEEE Press eBook Chapters

    This chapter contains sections titled:

  • Introduction

  • Converting S1 to I1

  • Interpreting Statements that Transfer Control

  • Implementing the Compiler-Interpreter CI1

  • Advantages of Interpreters

  • Problems

  • View full abstract»

  • Full text access may be available. Click article title to sign in or learn about subscription options.

    Bottom-up Parsing

    Compiler Construction Using Java, JavaCC, and Yacc
    Copyright Year: 2012

    Wiley-IEEE Press eBook Chapters

    This chapter contains sections titled:

  • Introduction

  • Principles of Bottom-up parsing

  • Parsing with right- versus left-recursive Grammars

  • Bottom-up parsing with Ambiguous Grammars

  • Do-not-reduce Rule

  • SLR(1) Parsing

  • Shift/Reduce Conflicts

  • Reduce/Reduce Conflicts

  • LR(1) Parsing

  • Problems

  • View full abstract»

  • Full text access may be available. Click article title to sign in or learn about subscription options.

    Yacc

    Compiler Construction Using Java, JavaCC, and Yacc
    Copyright Year: 2012

    Wiley-IEEE Press eBook Chapters

    This chapter contains sections titled:

  • Introduction

  • yacc Input and Output Files

  • A Simple yacc-Generated Parser

  • Passing Values using the Value Stack

  • Using yacc with an Ambiguous Grammar

  • Passing Values Down the Parse Tree

  • Implementing Sly

  • jflex

  • Problems

  • View full abstract»

  • Full text access may be available. Click article title to sign in or learn about subscription options.

    Appendix A: Stack Instruction Set

    Compiler Construction Using Java, JavaCC, and Yacc
    Page(s): 621 - 624
    Copyright Year: 2012

    Wiley-IEEE Press eBook Chapters

    No Abstract. View full abstract»

  • Full text access may be available. Click article title to sign in or learn about subscription options.

    Appendix B: Register Instruction Set

    Compiler Construction Using Java, JavaCC, and Yacc
    Page(s): 625 - 628
    Copyright Year: 2012

    Wiley-IEEE Press eBook Chapters

    No Abstract. View full abstract»

  • Full text access may be available. Click article title to sign in or learn about subscription options.

    References

    Compiler Construction Using Java, JavaCC, and Yacc
    Page(s): 629
    Copyright Year: 2012

    Wiley-IEEE Press eBook Chapters

    No Abstract. View full abstract»

  • Full text access may be available. Click article title to sign in or learn about subscription options.

    Index

    Compiler Construction Using Java, JavaCC, and Yacc
    Page(s): 631 - 635
    Copyright Year: 2012

    Wiley-IEEE Press eBook Chapters

    No Abstract. View full abstract»



  • On This Page

    Recently Published

    Learn More About