740 likes | 975 Views
Context-Free Languages. Regular Languages. Context-Free Languages. Regular Languages. stack. automaton. Context-Free Languages. Context-Free Grammars. Pushdown Automata. Context-Free Grammars. Grammars. Grammars express languages Example: the English language.
E N D
Context-Free Languages Regular Languages
stack automaton Context-Free Languages Context-Free Grammars Pushdown Automata
Grammars • Grammars express languages • Example: the English language
Language of the grammar: L = { “a cat runs”, “a cat walks”, “the cat runs”, “the cat walks”, “a dog runs”, “a dog walks”, “the dog runs”, “the dog walks” }
Notation Production Rules Variable Terminal
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:
Example A context-free grammar : A derivation:
A context-free grammar : Another derivation:
(((( )))) Describes parentheses:
Example A context-free grammar : A derivation:
A context-free grammar : Another derivation:
Example A context-free grammar : A derivation:
A context-free grammar : A derivation:
Describes matched parentheses: () ((( ))) (( ))
Definition: Context-Free Grammars Grammar Variables Terminal symbols Start variable Productions of the form: Variable String of variables and terminals
Definition: Context-Free Languages • A language is context-free • if and only if • there is a context-freegrammar • with
Leftmost derivation: Rightmost derivation: Derivation Order
Leftmost derivation: Rightmost derivation:
Derivation Tree yield
Partial Derivation Trees Partial derivation tree