• Paper: Developing a Modular Compiler for a Subset of a C-like Language

    From John R Levine@21:1/5 to All on Thu Jan 9 09:18:08 2025
    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

    Regards,
    John Levine, [email protected], Taughannock Networks, Trumansburg NY
    Please consider the environment before reading this e-mail. https://jl.ly

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From OrangeFish@21:1/5 to John R Levine on Sat Jan 11 09:15:48 2025
    On 2025-01-09 09:18, John R Levine 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 wish that they had proofread the pdf before posting. Various pieces
    of yacc/lex code are missing.

    OF.
    [It's just a draft and the authors' actual contact addresses are on that
    web page. How about writing to them and asking them to put in the
    missing code? People update arXiv papers all the time. -John]

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From OrangeFish@21:1/5 to All on Sun Jan 12 16:15:00 2025
    On 2025-01-11 09:15, Our Moderator suggested:

    [It's just a draft and the authors' actual contact addresses are on that
    web page. How about writing to them and asking them to put in the
    missing code? People update arXiv papers all the time. -John]

    Thank you for the suggestion. As I double-checked the pages, I
    discovered that it was my Lexmark at fault. So I converted from PDF 1.7
    to PDF 1.3 and it printed in its entirety.

    OF.
    [That's strange. They try not to do anything clever when generating the PDFs. -John]

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From [email protected]@21:1/5 to John R Levine on Thu Jan 16 13:46:20 2025
    John R Levine <[email protected]> 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.
    --
    Waldek Hebisch

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Salvador Mirzo@21:1/5 to [email protected] on Mon Jan 20 08:38:42 2025
    [email protected] writes:

    John R Levine <[email protected]> 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]

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From [email protected]@21:1/5 to Salvador Mirzo on Tue Jan 21 12:01:02 2025
    Salvador Mirzo <[email protected]> wrote:
    [email protected] writes:

    John R Levine <[email protected]> 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

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From OrangeFish@21:1/5 to Salvador Mirzo on Mon Jan 20 11:17:21 2025
    On 2025-01-20 06:38, Salvador Mirzo wrote:
    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]

    What are expert opinions on Wirth's book Compilerbau (German
    notwithstanding)? There seem to love-it or hate-it opinions without
    much substance.

    (Another question is where to look for how to add debugging information
    to the output.)

    OF.

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From [email protected]@21:1/5 to [email protected] on Tue Jan 21 18:45:12 2025
    [email protected] wrote:
    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

    Oops, I should give a link instead of a filname:

    http://fricas.org/~p-wyk4/kompi2015/pr

    --
    Waldek Hebisch

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From George Neuner@21:1/5 to [email protected] on Tue Jan 21 19:44:55 2025
    On Mon, 20 Jan 2025 11:17:21 -0500, OrangeFish
    <[email protected]d> wrote:

    What are expert opinions on Wirth's book Compilerbau (German >notwithstanding)? There seem to love-it or hate-it opinions without
    much substance.

    (Another question is where to look for how to add debugging information
    to the output.)

    OF.

    The English version is fairly simplistic - an undergrad intro course
    at best. I haven't seen the German version.

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From George Neuner@21:1/5 to [email protected] on Tue Jan 21 19:54:45 2025
    On Mon, 20 Jan 2025 08:38:42 -0300, Salvador Mirzo
    <[email protected]> wrote:

    [email protected] writes:

    John R Levine <[email protected]> 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]

    The Racket lanaguage (which is a Scheme variant) has a framework
    called nanopass designed deliberately for teaching compilers. https://docs.racket-lang.org/nanopass/index.html


    I don't have URLs for papers (sorry!), but over the years, some groups
    have written about using nanopass in compiler courses.

    If Scheme(-like) is not to your liking, the ideas of nanopass have
    been adopted and implemented in some other languages. Search engines
    are your friend.

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From OrangeFish@21:1/5 to George Neuner on Thu Jan 23 20:49:51 2025
    On 2025-01-21 19:44, George Neuner wrote:
    On Mon, 20 Jan 2025 11:17:21 -0500, OrangeFish
    <[email protected]d> wrote:

    What are expert opinions on Wirth's book Compilerbau (German
    notwithstanding)? There seem to love-it or hate-it opinions without
    much substance.

    (Another question is where to look for how to add debugging information
    to the output.)

    OF.

    The English version is fairly simplistic - an undergrad intro course
    at best. I haven't seen the German version.

    I was suggesting Wirth to answer Salvador Misro's request for "Would you recommend an equivalent paper or book that addresses these short-comings
    but maintains the educational spirit of the paper?".

    Is Wirth (in any version) suitable?

    OF.

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From George Neuner@21:1/5 to [email protected] on Sat Jan 25 19:07:44 2025
    On Thu, 23 Jan 2025 20:49:51 -0500, OrangeFish
    <[email protected]d> wrote:

    I was suggesting Wirth to answer Salvador Misro's request for "Would you >recommend an equivalent paper or book that addresses these short-comings
    but maintains the educational spirit of the paper?".

    Is Wirth (in any version) suitable?

    Wirth's books are fine for dipping your toes in the ocean of language implementation. They are pretty well written and they cover the
    entire compiler from parsing to code generation.

    However, they are undergrad level at best - I have yet to see Wirth demonstrates any significant optimizations [middle or back end], or
    any attempt at implementing a functional language. SFAIHS, everything
    he has written has been about either procedural or OO implementation.

    [My impression is that the largest difference between old compiler books
    and the state of the art is that optimization and the analysis that enables
    it has gotten vastly more sophisticated. Back when the Dragon Book was first written, compilers often had to fit in 64K and if you wanted to keep the intermediate code in memory, you couldn't compile very big programs. -John]

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)