Related articles |
---|
From: | antispam@fricas.org |
Newsgroups: | comp.compilers |
Date: | Tue, 21 Jan 2025 12:01:02 -0000 |
Organization: | Compilers Central |
References: | 25-01-004 25-01-010 25-01-012 |
Injection-Info: | gal.iecc.com; posting-host="news.iecc.com:2001:470:1f07:1126:0:676f:7373:6970"; logging-data="76706"; mail-complaints-to="abuse@iecc.com" |
Keywords: | books |
Posted-Date: | 21 Jan 2025 10:30:24 EST |
Salvador Mirzo <smirzo@antartida.xyz> wrote:
> antispam@fricas.org writes:
>
>> John R Levine <johnl@taugh.com> wrote:
>>> The authors developed a compiler for a toy language targeting Raspberry Pi
>>> using lex and yacc. Nothing very new but it shows how you build a
>>> compiler incremntally expanding the source language.
>>>
>>> https://arxiv.org/abs/2501.04503
>>
>> I am affraid that the best use of this paper is to forget it.
>> On one hand presentation is very naive and their "final"
>> compiler apparently does not handle things handled in ususal toy
>> compilers. On the other hand their presentation has a lot of
>> gaps and mistakes, so that a newbie is unlikely to be able to
>> follow them.
>
> Would you recommend an equivalent paper or book that addresses these
> short-comings but maintains the educational spirit of the paper? (It's
> okay if the architecture is not a popular one.)
> [Good question. There's the old Let's Build a Compiler which you can find
> on my web site and some books. Alan Holub wrote a well known book but the
> code in the book is incredibly buggy so I wouldn't recommend it. -John]
I like very much old presentation of PL/0 in Wirth book "Algoritms
+ Data Structures = Programs". Unfortunately, it is available in
old edition of the book but missing in newer ones. Presentation is
in Pascal which seem to be unknown to current students. Wirth uses
hand coded LL parser (unlike texts depending on parser generators).
Code generator covers only imaginary stack machine which is
interpreted (one cound instead generate machine code, but Wirth does
not explain this). PL/0 compiler does not cover type-checking, but
there is PL/S which is similar, but shows more realistic language
including types.
Wirth "Compiler Construction" book available on the net contains
examples of Oberon-like compiler, about 20 pages. This is
written in Oberon, which may be a problem.
For compiler course that I gave in the past I developed my own
examples. One is variation on Wirth PL/0, but using flex and
bison for syntax and generating code for x86_64. If interested
see:
/zaj/public_html/kompi2015/pr
and look for links to subdirectories of 'pl0'. Version 1
is just lexical analyzer for 'flex', version 2 contains bison
grammar, version 3 builds a parse tree, version 4 builds
simplified parse tree, version 5 adds a code generator.
There are comments inside, but course was in Polish, so comments
and variable names are in Polish too.
Note: this is phase-by-phase approach. Enlarging language
may be tricky, unless one is subsetting compiler for bigger
language. And even when subsetting, there can be unexpected
dependence: code for expressions may need intermediate variables,
so general expressions and variables naturally appear together
in code generator.
I also made somewhat simpler example 'sk' (reachable from the
URL I gave above). This one trivializes syntax, using one letter
variable names and precedence based parser, but contains
"retargetable" code generator (one version generates normal C,
one i386 code, one multiprecision C).
In the past I fetched several compiler books from the net.
"Compiler Construction; A Practical Approach" by F.J.F. Benders
J.W. Haaring, T.H. Janssen, D. Meffert and A.C. van Oostenrijk
contains simple compiler for toy language called "Inger".
--
Waldek Hebisch
Return to the
comp.compilers page.
Search the
comp.compilers archives again.