Live data from Hacker News

Resources for Amateur Compiler Writers

c9x.me

51–60 of 75 posts

Re: Resources for Amateur Compiler Writers

#51
post #9
post #6

Earlier quoted context omitted.

"frankly in 2016 I am afraid the average undergrad compiler course is part of the problem as much as the solution." What do you mean by that?

I'm not the OP, but I sympathize. The specific details covered in a "classical" compilers course are heavy weight and not super-relevant right now. These days you don't have to understand LR parsing or touch a parser-generator, you don't have to worry about register coloring... etc. Courses still use the Dragon Book which is older than I am and covers a bunch of stuff only relevant to writing compilers for C on resou…

> These days you don't have to understand LR parsing or touch a parser-generator

What would a modern parser use instead?

Or is it just that for most compiler work the parser has already been written?

Re: Resources for Amateur Compiler Writers

#52
post #26

IMHO, compiler construction as an advanced excercise for amateurs is at topic that has been beaten to death (as OP suggests, there's tons of available materials and projects ranging from high quality not-so-amateur to quick or fun hacks - I'm guilty of one myself). On the other hand, I would love to see "HTML5 and CSS parsing and rendering for amateurs". Given the state of modern HTML5 and CSS standards, and ignoring…

I agree. It's a topic that should die outside maybe posting that one link that aggregates many useful resources on the topic. You probably know the one. Re HTML5/CSS Excellent idea! These slways need more work in some way plus have widedpread impact. Amateurs stumbling on improved algorithms might similarly see their work have great impact.

Why should this topic die exactly? I don't understand the hostility. Do you want to keep a fun topic secret?

Re: Resources for Amateur Compiler Writers

#53
post #51
post #9

Earlier quoted context omitted.

I'm not the OP, but I sympathize. The specific details covered in a "classical" compilers course are heavy weight and not super-relevant right now. These days you don't have to understand LR parsing or touch a parser-generator, you don't have to worry about register coloring... etc. Courses still use the Dragon Book which is older than I am and covers a bunch of stuff only relevant to writing compilers for C on resou…

> These days you don't have to understand LR parsing or touch a parser-generator What would a modern parser use instead? Or is it just that for most compiler work the parser has already been written?

LL parsing library, or better yet, library for PEG grammars. You know, to add another dependency to already bloated program and not to care about having O(n) parsing time/memory.

Re: Resources for Amateur Compiler Writers

#54
post #41

Earlier quoted context omitted.

Thank you. I wasn't sure if he understood that I was implementing it.

I did, and I think my comment still makes sense in that context. If I give you a list of requirements for a programming language that I want you to implement and it includes 'a function must be able to call any function' then you have recursion. You don't need additional separate requirement for 'and that function may be itself', as long as you've fully implemented the first requirement. In fact you'd need an extra r…

The fact is, its easier to implement a language without recursion. See early programming languages that didn't. In such a case, you can simply treat the local variables as if they are global variables in the implementation. You've got to do something more complicated if you are going to handle local variables in a recursive case.

The fact it is not an additional requirement to allow recursion is irrealevent, what matter is that its extra complexity to handle that case correctly.

Re: Resources for Amateur Compiler Writers

#55
post #49

Earlier quoted context omitted.

I did, and I think my comment still makes sense in that context. If I give you a list of requirements for a programming language that I want you to implement and it includes 'a function must be able to call any function' then you have recursion. You don't need additional separate requirement for 'and that function may be itself', as long as you've fully implemented the first requirement. In fact you'd need an extra r…

That's a great point. I think there is fundamental flaw in my virtual machine because recursion does not work, but calling other functions from within a function do work.

[deleted]

Re: Resources for Amateur Compiler Writers

#56
post #42

Earlier quoted context omitted.

That's an excellent question! :) In my language, there is no special global scope for variables; every program is basically one giant (extended and sugared) lambda calculus expression. I do use lambda-lifting so that in the C code I generate, there is a C function in the global C namespace that is called to execute an object-language function but object-language functions also have closure environments so any kind of…

> Of course, the recursion among methods in those languages arises in a way that's very similar to passing a callee as a hidden argument. In OO languages, the hidden argument is "self" or "this"! Self or this allows you to refer to the same object. You don't need to refer to the same object to wind up calling the same method. You could have two different objects that just have the same method. Maybe they share a clas…

Yes, I think I see your point. If I may put it in my own words, I think you are talking about "dynamic recursive activation" throughout this thread.

I don't mean to disagree with the point you are making! It's a valid point.

However, I would like to emphasize that some languages have syntactic properties that complicate things a bit and I feel that a comment about how things "should" be really ought to be qualified by something like, "in a mainstream Java-like language".

Consider the simply-typed lambda calculus, or Martin-Löf type theory. These languages don't allow general recursion but it's not because they are always poorly implemented!

Re: Resources for Amateur Compiler Writers

#57

Earlier quoted context omitted.

I agree. It's a topic that should die outside maybe posting that one link that aggregates many useful resources on the topic. You probably know the one. Re HTML5/CSS Excellent idea! These slways need more work in some way plus have widedpread impact. Amateurs stumbling on improved algorithms might similarly see their work have great impact.

Why should this topic die exactly? I don't understand the hostility. Do you want to keep a fun topic secret?

Not necessarily. It just comes up a whole lot despite mostly not teaching them what they need to know to improve compilers as another commenter pointed out. So, redundant and a bit self-defeating. Other, related topics or an improved version of this one could lead to more real-world results whether hobbyists or professionals pick them up.

Re: Resources for Amateur Compiler Writers

#58
post #10

Earlier quoted context omitted.

So, the TAPL ? :) https://www.cis.upenn.edu/~bcpierce/tapl/

Not really. TAPL is a very useful book, but it won't teach you how to write a compiler, unless the only part of a compiler you actually care about is the type checker. The interpreters it describes (in the chapters titled “An ML implementation of ”) are ridiculously inefficient.

A good amount of new toy-ish languages compile to another language (typically javascript), and introduce new semantics and new type rules. As parent said, small DSLs.

You don't really need more than a typechecker and ast tranformations for that.

Re: Resources for Amateur Compiler Writers

#59
post #19

I wrote a VM, I still can't get recursion to work. It's hard.

I never understood why recursion causes anyone any problems, because recursion is the absence of a special case limitation. If I tell you that a function may call any function, then you already know everything you need to know for recursion. If we didn't have recursion, only then would I need to qualify what I just told you with the restriction that a function can only be active once. When I show students recursion I…

It may interest you to know that some older programming languages didn't originally support recursion, although they did support function calls (early FORTRAN being one example). The return address for a function call was typically stored in a fixed location associated with the target. So if you called that function once, you wouldn't be able to call it a second time until the first call had returned, otherwise you'd end up overwriting the first return address.

Not that I think that is the OP's problem - just a bit of interesting history. Support for recursion may seem obvious in hindsight, but there was a time where that wasn't the case.

Re: Resources for Amateur Compiler Writers

#60
post #16

Earlier quoted context omitted.

There are 3 languages you have to understand to write a compiler: * The language you are using to write the compiler. You have to know it well enough to write a complex application. * The language you are compiling. You have to completely understand it. * The language you are compiling to: x86, JVM, etc. You have to understand it well enough to write every complex application.

I agree, except for the last point. Unless you are writing an optimizing compiler, you just have to understand the target language well enough to write snippets that resemble the operations of your source or intermediate language, which can be pretty little. See: http://t3x.org/subc/cg386.c.html Anecdotally: I have once written an AXP21164 back-end without any prior knowledge, only based on the reference manual. It w…

Nils has an extraordinary amount of compiler related projects and books, http://www.t3x.org/
Post reply on HN