Python implementation of Parsec?

后端 未结 6 1382
名媛妹妹
名媛妹妹 2021-02-19 11:17

I recently wrote a parser in Python using Ply (it\'s a python reimplementation of yacc). When I was almost done with the parser I discovered that the grammar I need to parse re

6条回答
  •  伪装坚强ぢ
    2021-02-19 11:18

    Nothing prevents you for diverting your parser from the "context free" path using PLY. You can pass information to the lexer during parsing, and in this way achieve full flexibility. I'm pretty sure that you can parse anything you want with PLY this way.

    For a hands-on example, consider - it is a parser for ANSI C written in Python with PLY. It solves the classic C typedef - identifier problem (that makes C's grammar non context-sensitive) by populating a symbol table in the parser that is being used in the lexer to resolve symbol names as either types or not.

提交回复
热议问题