Write a compiler for brainfunk
$7.99
Minimum price
$9.99
Suggested price

Write a compiler for brainfunk

About the Book

This book covers writing all the usual tools we use as software developers for a tiny language named brainfuck (sorry for the typo in the main title).

Presenting all the tools and keep the book small was possible because of the few features of the language.

The downside is that writing a program using this language is something I do not recommend to any of you.

But if you want to know what involves writing programming tools for developers, then brainfuck is a great language.

  • Share this book

  • Categories

    • Computers and Programming
    • Ruby
    • JavaScript
    • Automated Software Testing
  • Feedback

    You must own a copy of this Book to access the forums.

    Email the Author(s)

About the Author

Jean Lazarou
Jean Lazarou

Developer of applications for 30 years now, creating tools to make life easier, read more and more and publishing articles.

We should be able to explain what we really understand...

Table of Contents

  • 1. Preface
  • 2. Introduction
  • 3. The language definition
    • 3.1. Syntax
    • 3.2. Semantics
    • 3.3. Language extensions
    • 3.4. Example
  • 4. The language implementation
    • 4.1. The Tokenizer
    • 4.2. The Compiler
    • 4.3. The Virtual Machine
  • 5. More robust, more complex…
    • 5.1. Running all the tests
    • 5.2. The Tokenizer
    • 5.3. The Compiler
  • 6. Optimizer
    • 6.1. Tests covering the optimization cases
    • 6.2. Implementation of the optimizer
    • 6.3. Edge cases
  • 7. Running optimized code
    • 7.1. Tests for the new instructions
    • 7.2. Optimized code benchmarking
  • 8. JIT compilation
    • 8.1. Manual JIT compilation
      • 8.1.1. Step 1: Replace instructions
      • 8.1.2. Step 2: Replace constants
      • 8.1.3. Step 3: Merge items
      • 8.1.4. Step 4: Handle the gotos
      • 8.1.5. Step 5: Do not use runtime class
      • 8.1.6. Conclusion
    • 8.2. JIT compiler
      • 8.2.1. Implementation
      • 8.2.2. Testing the JIT compiler
    • 8.3. JIT compiled code benchmarking
  • 9. Command line interface
    • 9.1. Command line options
    • 9.2. Compile a program (rbfc)
    • 9.3. Run a program (rbfr)
  • 10. Bytecode verifier
    • 10.1. Valid bytecodes
    • 10.2. Valid arguments for bytecodes
    • 10.3. Valid indexes for jump bytecodes
    • 10.4. Valid bytecodes sequence
  • 11. Development tools
    • 11.1. The debug instruction
      • 11.1.1. The Runtime class
      • 11.1.2. The Debugger class
    • 11.2. Code mapping
      • 11.2.1. Additional APIs
      • 11.2.2. Note
    • 11.3. A debugger
      • 11.3.1. Running the debugger
      • 11.3.2. The debugger shell
  • 12. Let’s get really funky
    • 12.1. Transpile the source code
    • 12.2. Browser dev-tools integration
      • 12.2.1. Mappings to the JavaScript code
      • 12.2.2. Numbers encoding in the MAP files
      • 12.2.3. Implementation of the numbers encoding
      • 12.2.4. MAP file generation
  • 13. Check all tests pass…
  • 14. Last word
    • 14.1. The project’s structure
    • 14.2. The Ruby version
  • 15. Links
    • 15.1. The brainfuck language
    • 15.2. Machine code, machine instructions
    • 15.3. JavaScript
      • 15.3.1. Generator functions
      • 15.3.2. Map files
      • 15.3.3. Ecosystem of JavaScript
      • 15.3.4. Project repository
  • 16. Examples
    • 16.1. A simple echo one characater program
    • 16.2. A real echo program
    • 16.3. The cat program
    • 16.4. The Hello world program

The Leanpub 60 Day 100% Happiness Guarantee

Within 60 days of purchase you can get a 100% refund on any Leanpub purchase, in two clicks.

Now, this is technically risky for us, since you'll have the book or course files either way. But we're so confident in our products and services, and in our authors and readers, that we're happy to offer a full money back guarantee for everything we sell.

You can only find out how good something is by trying it, and because of our 100% money back guarantee there's literally no risk to do so!

So, there's no reason not to click the Add to Cart button, is there?

See full terms...

Earn $8 on a $10 Purchase, and $16 on a $20 Purchase

We pay 80% royalties on purchases of $7.99 or more, and 80% royalties minus a 50 cent flat fee on purchases between $0.99 and $7.98. You earn $8 on a $10 sale, and $16 on a $20 sale. So, if we sell 5000 non-refunded copies of your book for $20, you'll earn $80,000.

(Yes, some authors have already earned much more than that on Leanpub.)

In fact, authors have earnedover $13 millionwriting, publishing and selling on Leanpub.

Learn more about writing on Leanpub

Free Updates. DRM Free.

If you buy a Leanpub book, you get free updates for as long as the author updates the book! Many authors use Leanpub to publish their books in-progress, while they are writing them. All readers get free updates, regardless of when they bought the book or how much they paid (including free).

Most Leanpub books are available in PDF (for computers) and EPUB (for phones, tablets and Kindle). The formats that a book includes are shown at the top right corner of this page.

Finally, Leanpub books don't have any DRM copy-protection nonsense, so you can easily read them on any supported device.

Learn more about Leanpub's ebook formats and where to read them

Write and Publish on Leanpub

You can use Leanpub to easily write, publish and sell in-progress and completed ebooks and online courses!

Leanpub is a powerful platform for serious authors, combining a simple, elegant writing and publishing workflow with a store focused on selling in-progress ebooks.

Leanpub is a magical typewriter for authors: just write in plain text, and to publish your ebook, just click a button. (Or, if you are producing your ebook your own way, you can even upload your own PDF and/or EPUB files and then publish with one click!) It really is that easy.

Learn more about writing on Leanpub