DEV Community

Discussion on: ELI5: How does someone write a new computer language?

Collapse
 
karataev profile image
Eugene Karataev
  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?

Collapse
 
mortoray profile image
edA‑qa mort‑ora‑y
  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.

Thread Thread
 
karataev profile image
Eugene Karataev

Thanks!