Is it beneficial for a programmer to learn how to build a compiler?

前端 未结 17 1140
难免孤独
难免孤独 2021-02-07 01:10

There is a lot of variety when it comes to the different types of programmers. In general, is beneficial for a programmer to learn how to build a compiler? In what cases would

17条回答
  •  野的像风
    2021-02-07 01:58

    In some ways, this question is a lot like "Should I learn C?"

    As others have pointed out, some elements of a compiler — lexical analysis, parsing — can be used in many other applications. You'll learn some useful techniques even if you never have to implement a compiler.

    In addition, the code generation phase will give you a better understanding of how the computer works. You'll see how the algorithms and data structures from higher-level languages actually get processed when they get to the CPU (or to the VM, as the case may be). This should help you write better algorithms in your day to day programming.

    If you're designing your own language too, then you'll learn a lot through the process of thinking through the details of how it should work, what control flow elements you need, how expressions should be parsed, which order function paramaters should be read, etc. This should give you a better understanding of languages in general, which ought to make you a better programmer in whichever language you use.

    Finally, there's always a chance you'll find yourself stuck with a legacy application in an old language that is no longer supported, and the easiest way to add new features will be to build your own compiler to extend the language.

提交回复
热议问题