"Crafting Interpreters" - early-release version of textbook

All off topic discussions go here. Everything from the funny thing your cat did to your favorite tv shows. Non-programming computer questions are ok too.
Post Reply
User avatar
Schol-R-LEA
Member
Member
Posts: 1925
Joined: Fri Oct 27, 2006 9:42 am
Location: Athens, GA, USA

"Crafting Interpreters" - early-release version of textbook

Post by Schol-R-LEA »

Crafting Interpreters is a book on developing programming language translators - focusing on interpreters, but also covering compilers - which is being written by one Bob Nystrom. Nystrom has been releasing the early drafts of the chapters on this web site as they are written, hoping to get feedback and error checking from the community. Those here who have an interest in language translators might want to go over it.
Rev. First Speaker Schol-R-LEA;2 LCF ELF JAM POEE KoR KCO PPWMTF
Ordo OS Project
Lisp programmers tend to seem very odd to outsiders, just like anyone else who has had a religious experience they can't quite explain to others.
User avatar
iansjack
Member
Member
Posts: 4688
Joined: Sat Mar 31, 2012 3:07 am
Location: Chichester, UK

Re: "Crafting Interpreters" - early-release version of textb

Post by iansjack »

Looks interesting. Thanks for the link.
dseller
Member
Member
Posts: 84
Joined: Thu Jul 03, 2014 5:18 am
Location: The Netherlands
Contact:

Re: "Crafting Interpreters" - early-release version of textb

Post by dseller »

Thanks for sharing! Could probably learn a trick or two for my own project.
Antti
Member
Member
Posts: 923
Joined: Thu Jul 05, 2012 5:12 am
Location: Finland

Re: "Crafting Interpreters" - early-release version of textb

Post by Antti »

I read the first chapter and liked his writing style so far. Thanks for the link.
klange
Member
Member
Posts: 679
Joined: Wed Mar 30, 2011 12:31 am
Libera.chat IRC: klange
Discord: klange

Re: "Crafting Interpreters" - early-release version of textb

Post by klange »

Coincidentally, I started reading this a few days before Schol-R-LEA posted it here... I've forgotten so much from my uni compiler courses, but I want to get something cooked up to ship with my OS so the second half on building a byecode-based interpreter in C really intrigues me.
User avatar
thomtl
Member
Member
Posts: 66
Joined: Mon Sep 03, 2018 2:25 am

Re: "Crafting Interpreters" - early-release version of textb

Post by thomtl »

Could this be handy for creating an AML interpreter?
User avatar
Schol-R-LEA
Member
Member
Posts: 1925
Joined: Fri Oct 27, 2006 9:42 am
Location: Athens, GA, USA

Re: "Crafting Interpreters" - early-release version of textb

Post by Schol-R-LEA »

thomtl wrote:Could this be handy for creating an AML interpreter?
The sections on lexical analysis, parsing, and general code-generation methods, almost certainly.
Rev. First Speaker Schol-R-LEA;2 LCF ELF JAM POEE KoR KCO PPWMTF
Ordo OS Project
Lisp programmers tend to seem very odd to outsiders, just like anyone else who has had a religious experience they can't quite explain to others.
alexfru
Member
Member
Posts: 1111
Joined: Tue Mar 04, 2014 5:27 am

Re: "Crafting Interpreters" - early-release version of textb

Post by alexfru »

Looks good and quite clear/clean.
User avatar
~
Member
Member
Posts: 1226
Joined: Tue Mar 06, 2007 11:17 am
Libera.chat IRC: ArcheFire

Re: "Crafting Interpreters" - early-release version of textb

Post by ~ »

The hardest part of a compiler is calculating expressions constructing instructions for the right precedence, variable/function types, intermediate results.

I'm thinking to develop a method of listing elements in a stack and depending on the precedence, pop them to calculate or keep them if the precedence still says to wait for calculating what I haev listed in the stack, in a single pass, just like when I read formulas to calculate.

I think that expression parsers actually do a single pass to the expression as it's read in, they don't need to complicate themselves with nesting of operations, just wait or go ahead to calculate according to the current precedence of the last operator, parenthesis...
Last edited by ~ on Mon Aug 19, 2019 11:00 am, edited 1 time in total.
YouTube:
http://youtube.com/@AltComp126

My x86 emulator/kernel project and software tools/documentation:
http://master.dl.sourceforge.net/projec ... 7z?viasf=1
User avatar
Schol-R-LEA
Member
Member
Posts: 1925
Joined: Fri Oct 27, 2006 9:42 am
Location: Athens, GA, USA

Re: "Crafting Interpreters" - early-release version of textb

Post by Schol-R-LEA »

~ wrote:The hardest part of a compiler is calculating expressions constructing instructions for the right precedence, variable/function types, intermediate results.

I'm thinking to develop a method of listing elements in a stack and depending on the precedence, pop them to calculate or keep them if the precedence still says to wait for calculating what I haev listed in the stack.
This comment tells me that you still haven't read any existing textbooks or other literature on compiler design. Precedence is a solved problem, solved at a completely different level (with most of it done in the grammar and the parser for same) and in a vastly easier manner than what you are attempting.

IOW, you are reinventing a square wheel made from cardboard in an era when steel-belted radials are the norm.

READ THAT DAMN BOOK. NOW. STOP TRYING TO HALF-@$$ THIS! Even as a pre-release beta, that book is a million times better than what you are trying to accomplish with your 'stone knives and bear skins' approach.

I, and others such as Solar, have given you links to a small library of books and other information sources on several occasions, and yet you still persist in acting as if this is something no one has ever attempted before. This is shooting yourself in the head, never mind in the foot.

Do you even have a grammar for the source language (which I assume is C or - Eris help you - C++) to design your parser from? Because without one, you have a snowball's chance in hell of getting anywhere with your compiler project. It isn't as if grammars for most major languages aren't readily available, either - the grammar for C11, along with the publicly released C11 draft standard update from 2014, is free from the OpenStandards website, as is the entire suite of draft C++ standards from 1998 to 2017, and while they aren't the final standards they are at least usable for your purposes - so there's no reason not to apply one to your lexer and your parser.
Rev. First Speaker Schol-R-LEA;2 LCF ELF JAM POEE KoR KCO PPWMTF
Ordo OS Project
Lisp programmers tend to seem very odd to outsiders, just like anyone else who has had a religious experience they can't quite explain to others.
User avatar
iansjack
Member
Member
Posts: 4688
Joined: Sat Mar 31, 2012 3:07 am
Location: Chichester, UK

Re: "Crafting Interpreters" - early-release version of textb

Post by iansjack »

~ wrote:The hardest part of a compiler is calculating expressions constructing instructions for the right precedence, variable/function types, intermediate results.
In other words - the hardest part of a compiler is compiling the source language to the final instructions?

Can't argue with that.
User avatar
Solar
Member
Member
Posts: 7615
Joined: Thu Nov 16, 2006 12:01 pm
Location: Germany
Contact:

Re: "Crafting Interpreters" - early-release version of textb

Post by Solar »

Schol-R-LEA wrote:
~ wrote:The hardest part of a compiler...
This comment tells me that you still haven't read any existing textbooks or other literature on compiler design.
Which is twice as sad as the website / book we're talking about in this thread is an excellent, hands-on (instead of theoretical) introduction to the subject...

Crafting Interpreters, by Bob Nystrom of Game Programming Patterns fame. Do give it a try.

The first part does it all in Java / tree-walk interpreter, the second part in C / bytecode VM. If I find the time, I'd like to re-do the second part in C++... but several other projects rank a bit higher at the moment.
Every good solution is obvious once you've found it.
Post Reply