patternMinor
Regular Expression to Context-Free Grammar
Viewed 0 times
expressionfreeregulargrammarcontext
Problem
Anyone knows if there is an algorithm for directly write the context-free grammar that generates a given regular expression?
Solution
I assume you want to get a grammar that generates the same language as the given regular expression.
You can achieve that by the following steps:
Both translations are standard and covered in basic textbooks on formal languages and automata. Note that any regular grammar is also context-free.
You can achieve that by the following steps:
- Translate the regular expression into an NFA.
- Translate the NFA into a (right-)regular grammar.
Both translations are standard and covered in basic textbooks on formal languages and automata. Note that any regular grammar is also context-free.
Context
StackExchange Computer Science Q#9050, answer score: 9
Revisions (0)
No revisions yet.