OSDev.org

The Place to Start for Operating System Developers
It is currently Thu Mar 28, 2024 8:03 am

All times are UTC - 6 hours




Post new topic Reply to topic  [ 12 posts ] 
Author Message
 Post subject: "Crafting Interpreters" - early-release version of textbook
PostPosted: Thu Sep 27, 2018 9:55 am 
Offline
Member
Member
User avatar

Joined: Fri Oct 27, 2006 9:42 am
Posts: 1925
Location: Athens, GA, USA
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.


Top
 Profile  
 
 Post subject: Re: "Crafting Interpreters" - early-release version of textb
PostPosted: Sat Sep 29, 2018 1:15 am 
Offline
Member
Member
User avatar

Joined: Sat Mar 31, 2012 3:07 am
Posts: 4591
Location: Chichester, UK
Looks interesting. Thanks for the link.


Top
 Profile  
 
 Post subject: Re: "Crafting Interpreters" - early-release version of textb
PostPosted: Sat Sep 29, 2018 11:27 am 
Offline
Member
Member

Joined: Thu Jul 03, 2014 5:18 am
Posts: 84
Location: The Netherlands
Thanks for sharing! Could probably learn a trick or two for my own project.

_________________
My blog: http://www.rivencove.com/


Top
 Profile  
 
 Post subject: Re: "Crafting Interpreters" - early-release version of textb
PostPosted: Mon Oct 01, 2018 3:12 am 
Offline
Member
Member

Joined: Thu Jul 05, 2012 5:12 am
Posts: 923
Location: Finland
I read the first chapter and liked his writing style so far. Thanks for the link.

_________________
Undefined behavior since 2012


Top
 Profile  
 
 Post subject: Re: "Crafting Interpreters" - early-release version of textb
PostPosted: Mon Oct 01, 2018 4:06 am 
Offline
Member
Member

Joined: Wed Mar 30, 2011 12:31 am
Posts: 676
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.

_________________
toaruos on github | toaruos.org | gitlab | twitter | bim - a text editor


Top
 Profile  
 
 Post subject: Re: "Crafting Interpreters" - early-release version of textb
PostPosted: Mon Oct 01, 2018 9:05 am 
Offline
Member
Member
User avatar

Joined: Mon Sep 03, 2018 2:25 am
Posts: 66
Could this be handy for creating an AML interpreter?


Top
 Profile  
 
 Post subject: Re: "Crafting Interpreters" - early-release version of textb
PostPosted: Mon Oct 01, 2018 12:24 pm 
Offline
Member
Member
User avatar

Joined: Fri Oct 27, 2006 9:42 am
Posts: 1925
Location: Athens, GA, USA
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.


Top
 Profile  
 
 Post subject: Re: "Crafting Interpreters" - early-release version of textb
PostPosted: Sun Oct 14, 2018 6:08 pm 
Offline
Member
Member

Joined: Tue Mar 04, 2014 5:27 am
Posts: 1108
Looks good and quite clear/clean.


Top
 Profile  
 
 Post subject: Re: "Crafting Interpreters" - early-release version of textb
PostPosted: Mon Aug 19, 2019 9:50 am 
Offline
Member
Member
User avatar

Joined: Tue Mar 06, 2007 11:17 am
Posts: 1225
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...

_________________
Live PC 1: Image Live PC 2: Image

YouTube:
http://youtube.com/@AltComp126/streams
http://youtube.com/@proyectos/streams

http://master.dl.sourceforge.net/projec ... 7z?viasf=1


Last edited by ~ on Mon Aug 19, 2019 11:00 am, edited 1 time in total.

Top
 Profile  
 
 Post subject: Re: "Crafting Interpreters" - early-release version of textb
PostPosted: Mon Aug 19, 2019 10:58 am 
Offline
Member
Member
User avatar

Joined: Fri Oct 27, 2006 9:42 am
Posts: 1925
Location: Athens, GA, USA
~ 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.


Top
 Profile  
 
 Post subject: Re: "Crafting Interpreters" - early-release version of textb
PostPosted: Tue Aug 20, 2019 1:13 am 
Offline
Member
Member
User avatar

Joined: Sat Mar 31, 2012 3:07 am
Posts: 4591
Location: Chichester, UK
~ 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.


Top
 Profile  
 
 Post subject: Re: "Crafting Interpreters" - early-release version of textb
PostPosted: Tue Aug 20, 2019 1:56 am 
Offline
Member
Member
User avatar

Joined: Thu Nov 16, 2006 12:01 pm
Posts: 7612
Location: Germany
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.


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 12 posts ] 

All times are UTC - 6 hours


Who is online

Users browsing this forum: No registered users and 33 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group