0% found this document useful (0 votes)
8 views5 pages

Automata

The document provides an overview of Context-Free Grammar (CFG), including definitions of terminals, non-terminals, and production rules that generate strings in a language. It explains Context-Free Languages (CFL) and gives examples of CFG productions, such as generating strings of 'a' and palindromes. Additionally, it discusses derivation trees and the concept of ambiguity in CFGs, highlighting the difference between ambiguous and unambiguous grammars.

Uploaded by

zaryabamjad89
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
8 views5 pages

Automata

The document provides an overview of Context-Free Grammar (CFG), including definitions of terminals, non-terminals, and production rules that generate strings in a language. It explains Context-Free Languages (CFL) and gives examples of CFG productions, such as generating strings of 'a' and palindromes. Additionally, it discusses derivation trees and the concept of ambiguity in CFGs, highlighting the difference between ambiguous and unambiguous grammars.

Uploaded by

zaryabamjad89
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 5

CONTEXT-FREE

GRAMMAR (CFG)
THEORY OF AUTOMATA
INSTRUCTOR: SIR SHAHZAD
ZARYAB AMJAD (04)
Introduction to Context-Free Grammar
(CFG)
- Terminals: These are the basic symbols of a
language that appear in the final output and
cannot be broken down or replaced further.

- Non-Terminals: These are placeholders or


variables that can be substituted by one or
more terminals or other non-terminals.

- CFG Terminologies: CFGs consist of a set of


terminals, non-terminals, a start symbol, and a
set of production rules. These rules define how
strings in a language can be generated.
Productions in CFG
- Production rules are the
backbone of a CFG.

- They describe how non-terminal


symbols can be expanded into
terminal and/or other non-
terminal symbols.

- A rule is usually written in the


form: A → α, where A is a non-
terminal and α is a combination
of terminals and/or non-
terminals.

- Example: S → aS | b
Context-Free Language
(CFL)
- A CFL is a language generated
using a context-free grammar.

- Examples:
- S → aS | Λ produces all strings
of ‘a’ (i.e., a*).
- S → aSa | bSb | Λ generates all
palindromes (strings that read the
same forward and backward).
Derivation Trees and Ambiguity in CFG
- Derivation Tree: Also called a parse
tree, it shows the step-by-step
application of rules to derive a string
from the start symbol.

- Ambiguity in CFG: A CFG is ambiguous


if a single string can be generated in
multiple ways (i.e., different parse
trees).

- Example: S → aS | Sa | a can derive the


string ‘aaa’ in multiple distinct ways.

- Unambiguous CFG: Produces only one


parse tree for each valid string.
E.g., the palindrome grammar mentioned
earlier.

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy