赛派号

空气能采暖十大名牌排名派沃空气能采暖排名弟几 Owl: Parser generator for visibly pushdown languages

What kind of language was it, and what was ambiguous about it? Do you control the language or is it an existing language?

FWIW here is a small, self-contained recursive-descent parser I recently wrote in Python (that recognizes certain C data definitions).

https://github.com/oilshell/oil/blob/master/build/cpython_de...

I think your structure is bit odd because Nodes are "smart". That is, the style is more object oriented than functional.

If you clearly separate out the input data (lexer), code for the parser, and the resulting data it will be better. Pretty much all compilers and interpreters follow this structure, even ones in Ja (e.g. in Terrence Parr's books). AST nodes should be dumb (no methods related except trivial ones for pretty printing).

I think you might be getting confused between clauses of the grammar and nodes in an AST. They are similar but they don't he a one-to-one correspondence. (Generating a heterogeneous AST is generally more useful than generating a homogeneous parse tree.)

In my case I return tuples; in bigger projects I use Zephyr ASDL. (https://news.ycombinator.com/item?id=17852049)

Parser() is a class because it holds the state of the current token. That is necessary for LL(1) parser. It feels a bit redundant sometimes, but it is a straightforward and useful structure once you get used to it.

Writing an LL(1) recursive descent parser by hand is a good exercise even if you plan to use a parser generator eventually. IME it helps to write out the grammar in comments next to the code.

On the other hand, I he found that what parsing technique works best is very closely related to the actual language. It could be that something like Owl works for you language, but it's not obvious and would require some justification IMO.

版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容, 请发送邮件至lsinopec@gmail.com举报,一经查实,本站将立刻删除。

上一篇 没有了

下一篇没有了