toc mod3
toc mod3
toc mod3
Where:
• V (Variables or Non-terminals): A finite set of non-terminal symbols. These symbols can be replaced or
expanded using production rules. They are also referred to as syntactic variables.
• T (Terminals): A finite set of terminal symbols, which form the actual content of the strings generated by the
grammar. Terminal symbols are the alphabet of the language and appear in the final output strings.
• P (Productions or Rules): A finite set of production rules. Each rule is of the form: A→α
Where:
A is a non-terminal symbol from V.
α is a string of symbols from (V∪T) (i.e., a combination of terminals and/or non-
terminals).
• S (Start Symbol): A special non-terminal symbol from VVV that denotes the starting point for generating
strings. It is the symbol from which production begins.
Consider a simple grammar G defined as:
G=(V,T,P,S) With the following components:
•V={S,A} (Set of non-terminals)
•T={a,b} (Set of terminals)
•P={S→aA,A→b} (Set of productions)
•S (Start symbol)
This grammar generates strings starting with a and followed by b.
P- Production Rules Represented
LHS----------------------------------------> RHS
Single Non Terminal---------------- E | String of terminal & Non terminals.
A--------------- aB
B--------------E
________________________________________________________________________
A--------------- aB c
B--------------E
C-------------b
REGULAR GRAMMER
A Regular Grammar is a formal grammar that is used to generate
regular languages. It is a subset of context-free grammars and
consists of rules that have specific constraints. Regular grammars are
closely related to Regular Expressions and Finite Automata, making
them useful for defining patterns in lexical analysis, programming
languages, and text processing.
1. Right-Linear Grammar
2. Left-Linear Grammar
1. Right-Linear Grammar
In a Right-Linear Grammar, each production rule must satisfy one of
the following forms:
A → aB
A→a
A→ε
Where:
A → Ba
A→a
A→ε
Where:
S
/\
A B
/ \
a b
\
A
\
a
2. Rightmost Derivation
In a rightmost derivation, at each step, the rightmost non-terminal is
replaced first. This means that if a string contains multiple non-terminals,
you always expand the one farthest to the right before expanding any
others.
Example
S
/\
A B
/ \
a b
\
A
\
a
Key Points
• Leftmost derivation: Always expand the leftmost non-terminal.
• Rightmost derivation: Always expand the rightmost non-terminal.
• Both derivations will produce the same final string but differ in the
order of rule applications.
• Derivation trees can be constructed from both types of derivations
and will look the same regardless of the derivation type; only the
order of applying rules differs.
Applications of Context Free Grammar
CFGs are fundamental tools for defining and analyzing structured languages, from
programming languages to human languages and complex workflows. Their versatility
and expressive power make them essential in applications that involve parsing,
structure validation, and syntax analysis across many fields.
Context-Free Grammars (CFGs) have a wide range of applications, particularly in fields related to
computer science, linguistics, and formal language theory. Here are some of the main applications:
S AB | a
Useful Symbol: {a,b,S,A}
A BC | b
B aB | C
C aC | B
Removing E (Null Production)
Steps to Remove Null Productions
To eliminate null productions while preserving the language generated by the grammar (except
possibly removing the empty string if it’s part of the language), follow these steps:
PUSH DOWN AUTOMATA
FA + Memory/ Stack
Types of Pushdown Automata
1.Deterministic PDA (DPDA): A PDA with a unique transition
for each state and input symbol combination.
2.Non-deterministic PDA (NPDA): A PDA that may have
multiple possible transitions for a state and input symbol,
allowing it to explore different computation paths.
Construct a PDA for L(O^n 1^n) |n> 1