[英]Is this a LL(1) grammar?
Considering the following grammar for propositional logic: 考虑以下命题逻辑语法:
<A> ::= <B> <-> <A> | <B>
<B> ::= <C> -> <B> | <C>
<C> ::= <D> \/ <C> | <D>
<D> ::= <E> /\ <D> | <E>
<E> ::= <F> | -<F>
<F> ::= <G> | <H>
<G> ::= (<A>)
<H> ::= p | q | r | ... | z
Precedence for conectives is: -, /\\, /, ->, <->. 连词的优先顺序是:-,/ \\,/,->,<->。
Associativity is also considered, for example p\\/q\\/r
should be the same as p\\/(q\\/r)
. 还考虑了关联性,例如
p\\/q\\/r
应该与p\\/(q\\/r)
。 The same for the other conectives. 其他猜想者也一样。
I pretend to make a predictive top-down parser in java. 我假装用Java做一个预测性的自上而下的解析器。 I dont see here ambiguity or direct left recursion, but not sure if thats all i need to consider this a LL(1) grammar.
我在这里看不到歧义或直接左递归,但是不确定这是否就是我需要考虑的LL(1)语法。 Maybe undirect left recursion?
也许是非直接的左递归?
If this is not a LL(1) grammar, what would be the steps required to transform it for my intentions? 如果这不是LL(1)语法,那么出于我的意图将其转换需要采取哪些步骤?
It's not LL(1). 不是LL(1)。 Here's why:
原因如下:
The first rule of an LL(1) grammar is: LL(1)语法的第一条规则是:
A grammar G is LL(1) if and only if whenever A --> C | D
只有当
A --> C | D
时,语法G才是LL(1) A --> C | D
A --> C | D
are two distinct productions of G, the following conditions hold: A --> C | D
是G的两个截然不同的产生,满足以下条件:
a
, do both C and D derive strings beginning with a
. a
,C和D都不能得出以a
开头的字符串。 This rule is, so that there are no conflicts while parsing this code. 此规则是为了使在解析此代码时没有冲突。 When the parser encounters a
(
, it won't know which production to use. 当解析器遇到
(
,它将不知道使用哪个生产。
Your grammar violates this first rule. 您的语法违反了第一条规则。 All your non-terminals on the right hand of the same production , that is, all your Cs and Ds, eventually reduce to G and H, so all of them derive at least one string beginning with
(
. 同一生产右手边的所有非终结符,即所有C和D最终都归结为G和H,因此它们全部派生至少一个以
(
开头的字符串。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.