Congrats on at least having an emitter, but I'm still searching for an article that shows how to emit assembly of any kind.
My favorite was always context-sensitive, interprocedural points-to analysis. And dataflow analysis in the presence of higher-order controlflow constructs.
so instead of
self.emitter.emitLine("printf(\"" + self.curToken.text + "\\n\");")
you do something like self.emitter.emitLine("STRING DB " + self.curToken.text + "', '$'")
...
self.emitter.emitLine("LEA DX,STRING")
self.emitter.emitLine("MOV AH,09H")
self.emitter.emitLine("INT 21H")I guess that's why we have things like LLVM that allow you to generate intermediate representations that get converted to a bunch of different instruction sets
You said in your other post that this can be done with minor modifications, but I can already foresee a few modifications that would need to be made which aren't minor.
And then there's the problem that you may want to target more than one architecture. We can write two completely different code generators, but it would be nice if there were an architecture that could share some of the code.
> You said in your other post that this can be done with minor modifications
And it probably can, depending on the flavor of assembly you want to use, there are dozens (hundreds?) of them, i'm sure some will allow you to inline the string declaration. The example I gave probably doesn't even work since I haven't programmed in 8086 in close to 20 years, and I don't even remember how to set up data blocks and code blocks in it any more.
> And then there's the problem that you may want to target more than one architecture.
This is a toy compiler written by a professor of computer science meant to teach you the basics of building a compiler (lexing, parsing, emitting). This isn't a tutorial on building the next GCC.
That's a fair criticism.
I'm frustrated with the lack of material on emitting assembly, but it wasn't right of me to take that out on the author of this post. I apologized in a different post.
> And it probably can, depending on the flavor of assembly you want to use, there are dozens (hundreds?) of them
How about one I can run on my machine? There are maybe 5 that are useful targets I can think of:
* x86 or ARM (depending your machine)
* LLVM
* GCC RTL
* Web assembly
* Parrot? Maybe the JVM has some low-level bytecode?The real barriers to me at this point are targeting a pragmatic real-world architecture.