[flagged]
That is not a compiler. That is called a wrapper script. But funny none the less.
GCC does basically the same thing even today,
11–20 of 114 posts
[flagged]
That is not a compiler. That is called a wrapper script. But funny none the less.
GCC does basically the same thing even today,
Now write a Python compiler in 500 lines of C.
Note that most of what makes python great isn't the language, it is the library. I believe that large parts of the python library are also written in C (for speed), and thus you won't be able to use my 500 line python compiler for anything useful because you won't have any useful libraries.
Earlier quoted context omitted.
That is not a compiler. That is called a wrapper script. But funny none the less.
The original cc was just a wrapper like this Python example around a bunch of external programs, calling c00, c01, until something could be fed to as and then linked using ld. GCC does basically the same thing even today,
Now write a Python compiler in 500 lines of C.
That said, I guess technically you could make something that compiles python to an executable? This is hacker news after all
Earlier quoted context omitted.
The original cc was just a wrapper like this Python example around a bunch of external programs, calling c00, c01, until something could be fed to as and then linked using ld. GCC does basically the same thing even today,
yeah but c00 and c01 actually do stuff
Still a really cool article and an impressive project, though. I especially like the StringPool technique; I'll have to keep it in mind if I ever write a compiler!
Now write a Python compiler in 500 lines of C.
I find it surprising that a single-pass compiler is easier to implement than a traditional lexer->parser->AST->emitter. (I'm not a compiler expert, though.) I'd have expected that generating an AST would be at least as simple, if not simpler. Plus by generating an AST, doing some simple optimization is a lot easier: one can pattern-match parts of the AST and replace them with more efficient equivalents. Maybe I'm ove…
This article breaks it down well enough to make me feel like I could write my own C compiler targeting AVR. (I probably could... but it would not be easy.) Never actually looked into how compilers work before, it's surprisingly similar/related to linguistics.
Since compilers transform languages with a clearly defined grammar ... the connection to linguistics is maybe not so surprising after all.