780 likes | 1.17k Views
Reverse of a Regular Language. Proof idea:. Construct NFA that accepts :. invert the transitions of the NFA that accepts. Theorem:. The reverse of a regular language is a regular language. Proof. Since is regular, there is NFA that accepts. Example:.
E N D
Proof idea: Construct NFA that accepts : invert the transitions of the NFA that accepts Theorem: The reverse of a regular language is a regular language
Proof Since is regular, there is NFA that accepts Example:
Resulting machine accepts is regular
Grammars • Grammars express languages • Example: the English language
Language of the grammar: L = { “a boy runs”, “a boy walks”, “the boy runs”, “the boy walks”, “a dog runs”, “a dog walks”, “the dog runs”, “the dog walks” }
Notation Variable or Non-terminal Terminal Production rule
Another Example • Grammar: • Derivation of sentence :
Grammar: • Derivation of sentence :
More Notation • Grammar Set of variables Set of terminal symbols Start variable Set of Production rules
Example • Grammar :
More Notation • Sentential Form: • A sentence that contains • variables and terminals • Example: Sentential Forms sentence
We write: • Instead of:
In general we write: • If:
Example Grammar Derivations
Example Grammar Derivations
Another Grammar Example • Grammar : Derivations:
Language of a Grammar • For a grammar • with start variable : String of terminals
Example • For grammar : Since:
Linear Grammars • Grammars with • at most one variable at the right side • of a production • Examples:
A Non-Linear Grammar Grammar :
Another Linear Grammar • Grammar :
Right-Linear Grammars • All productions have form: • Example: or
Left-Linear Grammars • All productions have form: • Example: or
Regular Grammars • A regular grammaris any • right-linear or left-linear grammar • Examples:
Observation • Regular grammars generate regular languages • Examples:
Theorem Languages Generated by Regular Grammars Regular Languages
Theorem - Part 1 Languages Generated by Regular Grammars Regular Languages Any regular grammar generates a regular language
Theorem - Part 2 Languages Generated by Regular Grammars Regular Languages Any regular language is generated by a regular grammar
Proof – Part 1 Languages Generated by Regular Grammars Regular Languages The language generated by any regular grammar is regular
The case of Right-Linear Grammars • Let be a right-linear grammar • We will prove: is regular • Proof idea: We will construct NFA • with
Grammar is right-linear Example:
Construct NFA such that • every state is a grammar variable: special final state