Best practices for writing a programming language parser

前端 未结 7 1862
故里飘歌
故里飘歌 2020-12-14 16:49

Are there any best practices that I should follow while writing a parser?

相关标签:
7条回答
  • 2020-12-14 17:42
    • Choose the right kind of parser, sometimes a Recursive Descendant will be enough, sometimes you should use an LR parser (also, there are many types of LR parsers).
    • If you have a complex grammar, build an Abstract Syntax Tree.
    • Try to identify very well what goes into the lexer, what is part of the syntax and what is a matter of semantics.
    • Try to make the parser the least coupled to the lexer implementation as possible.
    • Provide a good interface to the user so he is agnostic of the parser implementation.
    0 讨论(0)
提交回复
热议问题