How to create a language these days?

后端 未结 19 1801
青春惊慌失措
青春惊慌失措 2020-12-28 11:24

I need to get around to writing that programming language I\'ve been meaning to write. How do you kids do it these days? I\'ve been out of the loop for over a decade; are yo

相关标签:
19条回答
  • 2020-12-28 11:48

    Real coders still code in C. Just that it's a litte sharper.
    Hmmm... language design? or writing a compiler? If you want to write a compiler, you'd use Flex + Bison. (google)

    0 讨论(0)
  • 2020-12-28 11:48

    Of course older techniques are still common (e.g. using Flex and Bison) many newer language implementations combine the lexing and parsing phase, by using a parser based on a parsing expression grammar (PEG). This works for recursive descent parsers created using combinators, or memoizing Packrat parsers. Many compilers are built using the Antlr framework also.

    0 讨论(0)
  • 2020-12-28 11:49

    Speaking as someone who just built a very simple assembly like language and interpreter, I'd start out with the .NET framework or similar. Nothing can beat the powerful syntax of C# + the backing of the entire .NET community when attempting to write most things. From here i designed a simple bytecode format and assembly syntax and proceeeded to write my interpreter + assembler.

    Like i said, it was a very simple language.

    0 讨论(0)
  • 2020-12-28 11:49

    Before you start creating a language you should read this:

    Hanspeter Moessenboeck, The Art of Niklaus Wirth

    ftp://ftp.ssw.uni-linz.ac.at/pub/Papers/Moe00b.pdf

    0 讨论(0)
  • 2020-12-28 11:50

    What has changed considerably but hasn't been mentioned yet is IDE support and interoperability:

    Nowadays we pretty much expect Intellisense, step-by-step execution and state inspection "right in the editor window", new types that tell the debugger how to treat them and rather helpful diagnostic messages. The old "compile .x -> .y" executable is not enough to create a language anymore. The environment is nothing to focus on first, but affects willingness to adopt.

    Also, libraries have become much more powerful, noone wants to implement all that in yet another language. Try to borrow, make it easy to call existing code, and make it easy to be called by other code.

    Targeting a VM - as itowlson suggested - is probably a good way to get started. If that turns out a problem, it can still be replaced by native compilers.

    0 讨论(0)
  • 2020-12-28 11:50

    Not an easy answer, but..

    You essentially want to define a set of rules written in text (tokens) and then some parser that checks these rules and assembles them into fragments.

    http://www.mactech.com/articles/mactech/Vol.16/16.07/UsingFlexandBison/

    People can spend years on this, The above article talks about using two tools (Flex and Bison) That can be used to turn text into code you can feed to a compiler.

    0 讨论(0)
提交回复
热议问题