Wonderful Tutorial For Writing Interpreters/Compilers - Page 1
Forum section: electronics / general

author: Omega Glory
author_rank: Regular Contributor
timestamp: December 12, 2021, 03:38:24 pm
content: I've been trying to learn how to write a compiler for a custom CPU I made, when I came across this incredible series of blog posts on creating a Pascal interpreter from scratch. It covers lexing, parsing, semantic analysis, scope resolution, and much more. The code is written in Python, and everything is much more readable than similar tutorials I've seen online. This was too good not to share:https://ruslanspivak.com/lsbasi-part1/

author: bobcat2000
author_rank: Regular Contributor
timestamp: December 22, 2021, 07:51:21 am
content: Oh This is good. So much memory taking this class in school. I think I got an A on this class.My first calculator program written in C using a Stack... Good Time!!!https://www.amazon.com/Compilers-Principles-Techniques-Alfred-Aho/dp/0201100886/ref=sr_1_1?crid=3MH2S7KFSSXMN&keywords=%E2%80%8E+978-0201100884&qid=1640159400&s=books&sprefix=978-0201100884%2Cstripbooks%2C265&sr=1-1

author: DiTBho
author_rank: Super Contributor
timestamp: December 22, 2021, 12:36:31 pm
content: Quote from: Omega Glory on December 12, 2021, 03:38:24 pmAssembly compiler?For a "C--" or "C" compiler, the best reference (in my opinion) is LCC.It has a good book, and good sources.

author: SiliconWizard
author_rank: Super Contributor
timestamp: December 22, 2021, 06:54:53 pm
content: It's hard not to mention Wirth's "Compiler construction":https://people.inf.ethz.ch/wirth/CompilerConstruction/index.html

author: Omega Glory
author_rank: Regular Contributor
timestamp: December 23, 2021, 03:20:35 pm
content: Quote from: DiTBho on December 22, 2021, 12:36:31 pmWell I've written an assembler for my CPU, so I'm planning on having my compiler generate assembly. That way it might be a little easier to debug instead of going straight to hex. Hmm, I've heard of the Tiny C Compiler, but not the Little C Compiler. I'll check that out. My idea is to come up with a very simple high level language, but it will probably be similar to C.Quote from: bobcat2000 on December 22, 2021, 07:51:21 amAh yes, the Dragon book. I have heard a lot of good things about that. I don't own a copy now because of the price, but maybe I should bite the bullet. (edit: I should have looked harder. There are a few used ones for a good price).Quote from: SiliconWizard on December 22, 2021, 06:54:53 pmThank you very much! That looks very good!

author: rstofer
author_rank: Super Contributor
timestamp: December 29, 2021, 07:16:19 pm
content: Quote from: SiliconWizard on December 22, 2021, 06:54:53 pmAnd we should mention the syntax diagrams used to create the Pascal compilers. It is a straightforward translation from syntax to code. BNF is fine but I like the diagrams.

author: cfbsoftware
author_rank: Regular Contributor
timestamp: January 15, 2022, 09:54:34 pm
content: Quote from: rstofer on December 29, 2021, 07:16:19 pmI agree! When I first saw these in the 1970's I immediately understood the Pascal syntax. Consequently I have produced a set for the Oberon language:https://www.astrobe.com/OberonSyntax/html/OberonSyntax.htmThe diagrams were generated using 'EBNF Visualiser' which you can download from:http://dotnet.jku.at/applications/Visualizer/index.htmlYou just feed it the EBNF text definitions and it creates the diagrams for you.

author: Cerebus
author_rank: Super Contributor
timestamp: January 15, 2022, 11:44:28 pm
content: Quote from: rstofer on December 29, 2021, 07:16:19 pm"Railroad diagrams" as I was introduced to them. Their existence predates their use in the Pascal User Manual. I first saw them in Burroughs' manuals from well before when the Pascal User Manual was published. Quite where and when they were first used is unclear to me. They definitely have their place and I'd say they are probably the best form for a programmer's reference manual. For a language implementor nothing can replace a formal grammar in BNF (or whatever other formalism for grammars one chooses/is best fitted to one's implementation method).