[英]Creating a regular grammar out of a regular expression
Could anyone please step me through the process of obtaining a regular grammar from a regular expression? 任何人都可以引导我完成从正则表达式获得常规语法的过程吗? I found few 'tutorials', but I am still unable to turn a more complicated regular expression into a grammar.
我发现很少'教程',但我仍然无法将更复杂的正则表达式转换成语法。
How would you tackle ((a+b)*(c|d))+a?
你会如何解决
((a+b)*(c|d))+a?
? ?
I though of 我虽然
A -> aB
A -> aA
B -> bA
A -> cC
A -> dC
C -> cA
C -> dA
C -> a
C -> epsilon
But it's obviously incorrect. 但这显然不正确。
Just work from inside out. 从内到外工作。 Each operator introduces a new non-terminal
每个运营商都引入了一个新的非终端
Operator Grammar Operator Grammar
-------- ------- -------- -------
R|S A->R R* A->
A->S A->AR
R? A-> R+ A->R
A->R A->AR
(Most expositions will also introduce new nonterminals for concatenation; here, I didn't bother. I hope it's not confusing.) (大多数论述也将引入新的非终结用于连接;在这里,我没有打扰。我希望它不会混淆。)
Example: 例:
((a+b)*(c|d))+a?
Sub- Rewritten with Rules for
expression new nonterminal new nonterminal
---------- --------------- -----------
a+ A A->a A->Aa
a+b Ab
(a+b)* (Ab)* B-> B->BAb
c|d C C->c C->d
(a+b)*(c|d) BC
(a+b)*(c|d)+ (BC)+ D->BC D->DBC
a? E E-> E->a
(a+b)*(c|d)+ DE S->DE
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.