LR 系列解析器,无论是 LR、LALR(k)、LALR(1)、GLR 还是其他的解析器都太“奇怪”了,无法记住。如果您尝试编写其中之一,那么您通常最终会实现一个解析器生成器无论如何,只是为了保持理智。
I would go with either a recursive descent parser or maybe a tail-recursive descent parser (i.e. LL) or a top-down operator precedence parser.
The LR family of parsers, whether that be LR, LALR(k), LALR(1), GLR or whatever are just too "weird" to keep in your head. If you try to write one of those, you generally end up implementing a parser generator anyway, just to stay sane.
The simplest type of parser to write by hand is a recursive descent parser, which is in the family of LL parsers. most other types of parser are either difficult to write by hand (LALR parsers, which use large state transition tables) or are for parsing complex languages (such as Earley parsers for parsing natural languages).
wikipedia has some good information on recursive descent parsing.
发布评论
评论(4)
我会使用递归下降解析器或尾递归下降解析器(即 LL)或自上而下的运算符优先级解析器。
LR 系列解析器,无论是 LR、LALR(k)、LALR(1)、GLR 还是其他的解析器都太“奇怪”了,无法记住。如果您尝试编写其中之一,那么您通常最终会实现一个解析器生成器无论如何,只是为了保持理智。
I would go with either a recursive descent parser or maybe a tail-recursive descent parser (i.e. LL) or a top-down operator precedence parser.
The LR family of parsers, whether that be LR, LALR(k), LALR(1), GLR or whatever are just too "weird" to keep in your head. If you try to write one of those, you generally end up implementing a parser generator anyway, just to stay sane.
手动编写的最简单的解析器类型是递归下降解析器,它属于 LL 解析器系列。大多数其他类型的解析器要么难以手工编写(LALR 解析器,使用大型状态转换表),要么用于解析复杂语言(例如用于解析自然语言的 Earley 解析器)。
wikipedia 有一些关于递归下降解析的好信息。
The simplest type of parser to write by hand is a recursive descent parser, which is in the family of LL parsers. most other types of parser are either difficult to write by hand (LALR parsers, which use large state transition tables) or are for parsing complex languages (such as Earley parsers for parsing natural languages).
wikipedia has some good information on recursive descent parsing.
这取决于您尝试使用的语法。 LL 在语法的不确定性方面存在一些问题(你必须使所有的东西都没有左递归)。
如果您无法决定,请选择 LR(1) 或 LALR。甚至可能是 GLR。
This depends on the grammar you try to use. LL has some troubles with uncertainities in grammars (you'll have to make everything left-recursion free).
If you cannot decide, go with LR(1) or LALR. Maybe even GLR.
尝试 XText。这是给你的。快速、轻松地创建您的语言、解析器和编辑器
Try XText. It is for you. Create your language, parser and editor fast and easy