在使用Prolog DCG解析输入时,配有语法BNF的说明会很方便。
例如:
BNF
<Sentence> ::= <Noun_phrase> <Verb_phrase>
<Noun_phrase> ::= <Determiner> <Noun>
<Verb_phrase> ::= <Verb> <Phrase>
<Determiner> ::= a
<Determiner> ::= the
<Noun> ::= cat
<Noun> ::= mouse
<Verb> ::= scares
<Verb> ::= hates
作为Prolog DCG
sentence --> noun_phrase, verb_phrase.
verb_phrase --> verb, noun_phrase.
noun_phrase --> determiner, noun.
determiner --> [a].
determiner --> [the].
noun --> [cat].
noun --> [mouse].
verb --> [scares].
verb --> [hates].
然而,Prolog DCG 也可以有参数,例如在这个例子中,
Number
可以是 singular
或者 plural
。sentence(Number) --> noun_phrase(Number), verb_phrase(Number).
verb_phrase(Number) --> verb(Number), noun_phrase(Number).
noun_phrase(Number) --> determiner(Number), noun(Number).
determiner(singular) --> [a].
determiner(singular) --> [the].
determiner(plural) --> [the].
noun(singular) --> [cat].
noun(plural) --> [cats].
noun(singular) --> [mouse].
noun(plural) --> [mice].
verb(singular) --> [scares].
verb(plural) --> [scare].
verb(singular) --> [hates].
verb(plural) --> [hate].
是否有一种标准或被接受的BNF扩展,其中包括用于非终结符的参数?
如果是这样,我需要一个链接。
我怀疑ATN(增强转换网络)与此相关,并且可能是唯一的标准答案,但我希望有一些线性文本形式而不是某种形式的顶点/边图。