LL解析器“一个或多个”

时间:2016-02-28 19:26:35

标签: algorithm parsing grammar ll

让我说我的语法是:

file = line, {line}
line = ..., "\n"

如果我想为该语法构建LL解析器,我该如何实现“一行或多行”?

我正在考虑将语法改为:

file = line
line = ..., "\n", nl
nl = line
   | <end of file>

我的线将嵌套。这是解决问题最优雅/最有效的方法吗?

1 个答案:

答案 0 :(得分:1)

关闭。通常就像这样:

file = line, morelines
morelines = e | line, morelines
line = ..., "\n"

其中e是epsilon或空符号