Asked By : frank
Answered By : Luke Mathieson
- $emptyset$ is a regular expression
- $varepsilon$ is a regular expression
- $a$ is a regular expression for every $a in Sigma$
- if $A$ and $B$ are regular expressions then
- $Acdot B$ is a regular expression (concatentation)
- $A mid B$ is a regular expression (alternation)
- $A^{ast}$ is a regular expression (Kleene star)
Along with some semantics (i.e. how we interpret the operators to get a string), we get a way of generating strings from a regular language. Regular Grammars Regular grammars consist of a four tuple $(N,Sigma, P, S in N)$ where $N$ is the set of non-terminals, $Sigma$ is the set of terminals, $S$ is the start non-terminal and $P$ is the set of productions which tell us how to change the start symbol, step by step, into a string in $Sigma^{ast}$. $P$ can have its productions drawn from one of two types (not both though): Right Linear Grammars For non-terminals $B$, $C$, terminal $a$ and the empty string $varepsilon$, all rules are of the form:
- $B rightarrow a$
- $B rightarrow aC$
- $B rightarrow varepsilon$
Left Linear Grammars Left linear grammars are the same, but rule #2 is $B rightarrow Ca$. Things to Ponder So looking at these definitions and playing with them, we can see that regular expressions look like matching rules, or ways of dealing with strings a bit at a time. Grammars seem to “label” sections of the string, and group labels under new labels to validate the string (i.e. if we can get from $S$ to the string, or vice versa, we’re happy). However these are really doing the same fundamental thing, and how you view the metaphor of their function is really up to you.
Best Answer from StackOverflow
Question Source : http://cs.stackexchange.com/questions/45755