loading...

re: ELI5: How does someone write a new computer language? VIEW POST

TOP OF THREAD FULL DISCUSSION
re: There's no way to truly ELI5 this without obscuring details, so I'll opt for simplifying, yet trying to stay correct. Vocabulary A lang...
 
  1. Do all compilers transform source code to AST? Are there any languages which omit this step?

  2. Let's take python and javascript for example. Their syntax is different, but abstractions (variables, functions, loops, conditions, e.t.c) are almost the same. Do they have similar ASTs? Can we take AST generated by python compiler and convert it to the source code in javascript?

 
  1. Yes. However, here is where we'd need to go into technical details to define what an AST truly is. There are some languages, potentially, where the parse directly results in a usable tree. There are also stream languages where no complete tree is ever created. But there's no avoiding the concept of the AST ever -- the compiler/VM/interpreter needs to understand the source.

  2. The ASTs have similar features, but are different depending on the compiler and language. When I talked about "lowering", it is possible, and quite common, to lower from the AST to another language. Not all languages support enough of the source language to be viable. Others require essentially writing a complete VM in them to do the compilation.

Code of Conduct Report abuse