Building Your Own Programming Language Generation & Babel generate
Transcript from the "Generation & Babel generate" Lesson
>> Steve Kinney: We'll talk a little bit about generation. And generation is effectively parsing in reverse, right? You have taken your syntax, you've figured out all the tokens, you've figured out it's semantic meaning and all of those things, and now you want to do a thing with it. We evaluated it, but if we wanted to turn it into some other compile time target, this is where that would happen.
[00:00:23] And there's a lot of options, you can write your own low level CPU instruction compiler. That's a great idea. You can use a compiler framework like LLVM, which is even what like Rust target, Swift, I think of Objective C these days. With LLVM you can actually target web assembly with a target as well, right?
[00:01:43] Maybe it's targeting, maybe you are trying to output CPU or Bash, or something along those lines. Those are options and things you can absolutely do. The other option that you have is, and we kinda talked about this a little bit earlier, is that you can traverse that tree and manipulate it, and get into the point where it becomes a tree that some other generator that exists how to use.
[00:02:37] And those are super useful for things like source maps, and stuff along those lines. But, the actual amount that you need to able to be truly generate stuff is a lot smaller. We also I mentioned earlier made some like purposeful choices to kind of already be kind of close here to the Babel specs.
[00:02:59] All we have to do is kind of massage it the rest of the way, and kind of get a taste of that. So the Babel generator, right? And there's a lot of tools, Babel has not only just Babel thing that we use, but it's got a lot of tools to it through traversing trees and stuff along those lines.
[00:03:19] We're gonna write some more about ourselves and rely too much on Babel for that. But the generator is super useful because joining arrays of arguments with commas is fun, but I'd rather not. It takes effectively three options. The code is kind of important for the source maps. So really, as long as we give it an abstract syntax tree, which guess what?
[00:03:41] We have, right? As long as we get an abstract syntax tree, then we should be able to spit out that code, right? So, what we need to do, is we need to figure out a way to transform our existing abstract syntax tree into one that Babel can understand, right?
[00:04:01] We kind of a taste for that, right? And you can kind of like take it to its natural conclusion as well.