9. Representation of Grammar
• A grammar G can be formally written as a 4-tuple (N, T, S, P)
where −
N is a set of variables or non-terminal symbols.{1,2,3..E,T,F,V...}
T is a set of terminal symbols.{x,y,z...,+,-,*,/...}
S is a special variable called the Start symbol
P is Production rules for Terminals and Non-terminals. A
production rule has the form α → β
9
10. Example
• Grammar G1 −({S, A, B}, {a, b}, S, {S → AB, A → a, B → b})
S, A, and B are Non-terminal symbols.
a and b are Terminal symbols.
S is the Start symbol.
Productions, P : S → AB, A → a, B → b
10
11. Example
• Grammar G2 −({A, B}, {a, b, c}, B, {A → B, A → a, A→c,
B → b, B→A})
A, and B are Non-terminal symbols.
a , b and c are Terminal symbols.
B is the Start symbol.
Productions, P : A → B, A → a, A→c,B → b, B→A
11
12. Example
• Grammar G2 −({A, B}, {a, b, c}, P, {A → B, A → a, A→c,
B → b, B→A})
Wrong Grammar
12
13. Derivations Strings from a Grammar
Example
• Let us consider the grammar −
G2 = ({S, A}, {a, b}, S, {S → aAb, aA → aaAb, A → b } )
Some of the strings that can be derived are −
S ⇒ aAb (S → aAb)
⇒ aaAbb (aA → aAb)
⇒ aabbb (A → b) Accepted Strings
13
14. Derivations Strings from a Grammar
Example
G={S → aS , S → B, B → b and B → bB} where S is Start
symbol.
S → B → b (Accepted)
S → B → bB → bb (Accepted)
S → aS → aB → ab (Accepted)
S → aS → aaS → aaB → aab(Accepted)
S → aS → aB → abB → abb (Accepted)
14
15. Derivations Tree
• A derivation tree is an ordered rooted tree that graphically
represents the semantic information a string derived from
grammar.
15
16. Derivations Tree
Representation Technique
• Root vertex
• Vertex
• Leaves vertex
The root node is always a node indicating start symbols.
The leaf node is always terminal nodes.
The interior nodes are always the non-terminal nodes.
16
20. Derivations Tree
Example1:
Let a G1 {N,T,P,S} be
N = {S}, T = {b,c,d}, Starting symbol = S, P = {S → AA
,A→bc,A→d}
One derivation tree from the above string is “bcd”
S → AA
→ bcA (A→bc)
→ bcd (A→d)
→ bcd Accepted
20
26. Derivations Tree
Example:
Let a G1 {N,T,P,S} be
N = {S}, T = {a, b}, Starting symbol = S, P = S → SS | aSb | c
One derivation from the above string is “acbc”
S → SS
→ aSbS (S→aSb)
→ acbS (S→c)
→ acbc (S→c)
26
27. Automata
• The term "Automata" is derived from the Greek word "αὐτόματα" which
means "self-acting".
• An automaton (Automata in plural) is an abstract computing device
which follows a predetermined sequence of operations automatically.
27