Building a parser (Part I)

前端 未结 4 560
轻奢々
轻奢々 2020-12-12 16:24

I\'m making my own javascript-based programming language (yeah, it is crazy, but it\'s for learn only... maybe?). Well, I\'m reading about parsers and the first pas

4条回答
  •  失恋的感觉
    2020-12-12 17:12

    Is my way better or worse that the original way? Note that my code will be read and compiled (translated to another language, like PHP), instead of interpreted all the time.

    What's the original way ? There are many different ways to implement languages. I think yours is fine actually, I once tried to build a language myself that translated to C#, the hack programming language. Many language compilers translate to an intermediate language, it's quite common.

    After I tokenizer, what I need do exactly? I'm really lost on this pass!

    After tokenizing, you need to parse it. Use some good lexer / parser framework, such as the Boost.Spirit, or Coco, or whatever. There are hundreds of them. Or you can implement your own lexer, but that takes time and resources. There are many ways to parse code, I generally rely on recursive descent parsing.

    Next you need to do Code Generation. That's the most difficult part in my opinion. There are tools for that too, but you can do it manually if you want to, I tried to do it in my project, but it was pretty basic and buggy, there's some helpful code here and here.

    There are some good tutorial to learn how I can do it?

    As I suggested earlier, use tools to do it. There are a lot of pretty good well-documented parser frameworks. For further information, you can try asking some people who know about this stuff. @DeadMG , over at the Lounge C++ is building a programming language called "Wide". You may try consulting him.

提交回复
热议问题