How best to parse a simple grammar?

前端 未结 5 1129
礼貌的吻别
礼貌的吻别 2020-12-07 15:13

Ok, so I\'ve asked a bunch of smaller questions about this project, but I still don\'t have much confidence in the designs I\'m coming up with, so I\'m going to ask a questi

5条回答
  •  余生分开走
    2020-12-07 15:36

    For simple grammars I really like Parsing Expression Grammars (PEGs), which amount to a disciplined, structured way of writing a recursive-descent parser. In a dynamically typed language like Python you can do useful things without having a separate "parser generator". That means no nonsense with reduce-reduce conflicts or other arcana of LR parsing.

    I did a little searching and pyPEG appears to be a nice library for Python.

提交回复
热议问题