[英]How can I find regular grammar for L* if we are given a grammar for language L?
Is there any general method to do so? 有什么通用的方法吗? For example, we have a general method to find grammar for L1 U L2 by adding a production S-> S1 |
例如,我们有一种通用的方法,通过添加生产S-> S1 | | | | | | | | | | | | | | | |,来查找L1 U L2的语法。 S2 where S1 and S2 are start symbols for grammars of L1 and L2 respectively.
S2,其中S1和S2分别是L1和L2语法的起始符号。 Thanks in advance..
提前致谢..
In general, given a grammar G
such that L(G) = L'
, there is no algorithm which always produces a regular grammar G'
such that L(G') = (L')*
. 通常,给定语法
G
使得L(G) = L'
,没有算法总是产生规则语法G'
使得L(G') = (L')*
。 For starters, (L')*
may not be a regular language. 对于初学者,
(L')*
可能不是常规语言。 Even if you allow the procedure to recognize this case and print "not a regular language" in such a case, this cannot be generally possible since it would allow us to determine whether arbitrary unrestricted grammars generate particular strings (the construction is not too hard but I won't provide it unless desired). 即使您允许该过程识别这种情况并在这种情况下打印“非常规语言”,这通常也是不可能的,因为这将使我们能够确定任意不受限制的语法是否会生成特定的字符串(这种构造不是很困难,但是除非需要,否则我不会提供。 This is an undecidable problem, so we can't recognize regular languages in unrestricted grammars.
这是一个无法确定的问题,因此我们无法识别无限制语法中的常规语言。
Perhaps your question is whether there is a neat construction to do this if initially given a regular grammar. 也许您的问题是,如果最初使用常规语法,是否有一个整洁的结构可以做到这一点。 In that case, the answer is a definite and clear, "yes!"
在这种情况下,答案是明确明确的“是!” Here is one easily described (though possibly inefficient in practice) procedure for doing just that:
这是一个很容易描述的过程(尽管在实践中可能效率低下),仅用于此操作:
Thus, we can mechanically go from regular grammar for L
to regular grammar for L*
. 因此,我们可以机械地从
L
的常规语法变为L*
常规语法。
If you just want ANY grammar for L*
, the simplest would probably be to introduce a new start state S'
and productions S' := S'S' | S
如果只希望
L*
任何语法,最简单的方法可能是引入一个新的开始状态S'
和产生式S' := S'S' | S
S' := S'S' | S
where S
is the start symbol of your input grammar. S' := S'S' | S
,其中S
是输入语法的开始符号。 This obviously does not give a regular grammar, however - if the input grammar generates a regular language, this one will do so as well. 这显然不能给出规则的语法,但是-如果输入语法生成了规则的语言,则该语法也可以。
Example: given the regular grammar 示例:给出常规语法
S := 0S | 1T
T := 0S | 1T | 1
A construction gives us this nondeterministic finite automaton: 构造为我们提供了这种不确定的有限自动机:
q s q'
- - -
S 0 S
S 1 T
T 0 S
T 1 T
T 1 (H)
A construction gives us the regular expression: 构造为我们提供了正则表达式:
(0*1)(0*1)*1
The Kleene closure of this is: Kleene的闭包为:
((0*1)(0*1)*1)*
We recognize from the standard construction that this automaton is equivalent: 我们从标准构造中认识到此自动机是等效的:
q s q'
- - -
(I) - S
S 0 S
S 1 T
T 0 S
T 1 T
T 1 H
H - (I)
Whence the following regular grammar: 遵循以下常规语法:
I := S | -
S := 0S | 1T
T := 0S | 1T | H
H := I
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.