4 ms·
I second all this. Reading the blogpost I was wondering how the author will do with this parser to actually build an AST rather than just validating syntax. Th
by p4bl0 5y ago
I second all this. Reading the blogpost I was wondering how the author will do with this parser to actually build an AST rather than just validating syntax.
The thing is that building an AST is typically the kind of thing where "do it with some hacks which build the structure procedurally using global variables" as kazinator said is a sure way to have horrible bugs. The inherently recursive nature of an AST doesn't mix very well with procedural manipulation of a global state.
- Someone 5y agoI don’t think there will be an AST. https://briancallahan.net/blog/20210814.html https://briancallahan.net/blog/20210814.html: “We will be writing a single-pass compiler for a simple language and immediately output our final output code as soon as our compiler has enough information to do so” That “as soon as” implies code will be generated before the entire program has been parsed. Also, for me single-pass implies “no AST”, as you would need at least one pass to construct one, and iterating over an AST counts as another pass for me.
- pwdisswordfish8 5y agoSingle-pass to me also implies a code generator that writes the object file directly, rather than compiling to C or assembly (or some other language) as an intermediate format. But words don't mean anything anymore, so long as people can plausibly convince others that making them feel bad by calling out improper use means that they should be allowed to use words however they want, like a child owed the opportunity to exercise their unbridled spirit.
- kazinator 5y agoNote that loading the program into memory is also a pass. Producing an installation image is also a pass, as is installing the program into the target. When we are talking about compiler passes, we don't count these, because they are outside the compiler. When we consider a compiler that puts out assembly language, if that works without producing an AST, just by generating assembly in a syntax-directed way as it followed the phrase structure of the code, then we call that a one-pass compiler. What it makes is assembly language, and it does that in one pass. Producing executable code from the assembly requires another pass, but that pass belongs to the assembler. The compiler is not even running, and so it can't be a pass of that compiler.
- pwdisswordfish8 5y agoHN's capacity for intellectual dishonesty knows no bounds. That's a dishonest attempt to bankrupt the term "single-pass compiler", and remove its value to communicate something meaningful. By that token, the Amsterdam Compiler Kit, notable for being an example of the classic multi-pass compilation strategy, is apparently not a multi-pass compiler at all! It's just a bunch of single-pass compilers. https://en.wikipedia.org/wiki/One-pass_compiler https://en.wikipedia.org/wiki/One-pass_compiler "a one-pass compiler is a compiler that passes through the parts of each compilation unit only once, immediately translating each part into its final machine code" Even if you want to raise the "That's just Wikipedia! Anyone can edit it!" argument, rational thought is still not on your side. Unlike a program that has been compiled into object code, there is no value in a program that has been compiled into assembly except to run it through an assembler and turn it into a binary. The only accurate description for this would be a two-pass compiler (not single-pass). The assembly is an intermediate representation, and the "compiler" is the union of the language frontend that outputs assembly + the assembler itself. (It does not matter that the assembler runs in a separate process and is developed independently.)