Writing a compiler for a DSL in python

前端 未结 8 1800
囚心锁ツ
囚心锁ツ 2021-02-02 03:51

I am writing a game in python and have decided to create a DSL for the map data files. I know I could write my own parser with regex, but I am wondering if there are existing py

8条回答
  •  鱼传尺愫
    2021-02-02 04:24

    Yes, there are many -- too many -- parsing tools, but none in the standard library.

    From what what I saw PLY and SPARK are popular. PLY is like yacc, but you do everything in Python because you write your grammar in docstrings.

    Personally, I like the concept of parser combinators (taken from functional programming), and I quite like pyparsing: you write your grammar and actions directly in python and it is easy to start with. I ended up producing my own tree node types with actions though, instead of using their default ParserElement type.

    Otherwise, you can also use existing declarative language like YAML.

提交回复
热议问题