formal grammars
TRANSCRIPT
![Page 1: Formal Grammars](https://reader031.vdocument.in/reader031/viewer/2022021918/588856841a28ab951c8b6d1d/html5/thumbnails/1.jpg)
IN4303 2016-2017 Compiler Construction
Formal Grammars language specification
Guido Wachsmuth, Eelco Visser
![Page 2: Formal Grammars](https://reader031.vdocument.in/reader031/viewer/2022021918/588856841a28ab951c8b6d1d/html5/thumbnails/2.jpg)
Formal Grammars 2
3 * +7 21
3 * +7 21
Exp ExpExp
Exp
Exp
parser
![Page 3: Formal Grammars](https://reader031.vdocument.in/reader031/viewer/2022021918/588856841a28ab951c8b6d1d/html5/thumbnails/3.jpg)
Formal Grammars 3
syntax definition
errors
parse generate
check
parse table
generic parser
![Page 4: Formal Grammars](https://reader031.vdocument.in/reader031/viewer/2022021918/588856841a28ab951c8b6d1d/html5/thumbnails/4.jpg)
Formal Grammars
StrategoDynSem
NaBL2
SDF3
ESVeditor
SPTtests
4
syntax definition
concrete syntax
abstract syntax
static semantics
name binding
type system
dynamic semantics
translation
interpretation
![Page 5: Formal Grammars](https://reader031.vdocument.in/reader031/viewer/2022021918/588856841a28ab951c8b6d1d/html5/thumbnails/5.jpg)
Formal Grammars
StrategoDynSem
NaBL2
SDF3
ESVeditor
SPTtests
5
syntax definition
concrete syntax
abstract syntax
static semantics
name binding
type system
dynamic semantics
translation
interpretation
![Page 6: Formal Grammars](https://reader031.vdocument.in/reader031/viewer/2022021918/588856841a28ab951c8b6d1d/html5/thumbnails/6.jpg)
Formal Grammars
StrategoDynSem
NaBL2
SDF3
ESVeditor
SPTtests
6
syntax definition
concrete syntax
abstract syntax
static semantics
name binding
type system
dynamic semantics
translation
interpretation
![Page 7: Formal Grammars](https://reader031.vdocument.in/reader031/viewer/2022021918/588856841a28ab951c8b6d1d/html5/thumbnails/7.jpg)
Formal Grammars 7
P A R E N T A L
ADVISORYTHEORETICAL CONTENT
![Page 8: Formal Grammars](https://reader031.vdocument.in/reader031/viewer/2022021918/588856841a28ab951c8b6d1d/html5/thumbnails/8.jpg)
Formal Grammars 8
formal languages
![Page 9: Formal Grammars](https://reader031.vdocument.in/reader031/viewer/2022021918/588856841a28ab951c8b6d1d/html5/thumbnails/9.jpg)
Formal Grammars 9
infinite productivity
![Page 10: Formal Grammars](https://reader031.vdocument.in/reader031/viewer/2022021918/588856841a28ab951c8b6d1d/html5/thumbnails/10.jpg)
Formal Grammars 10
finite models
![Page 11: Formal Grammars](https://reader031.vdocument.in/reader031/viewer/2022021918/588856841a28ab951c8b6d1d/html5/thumbnails/11.jpg)
Formal Grammars 11
Philosophy
Linguistics
lexicology
grammar
morphology
syntax
phonology
semantics
Interdisciplinary
Computer Science
syntax
semantics
![Page 12: Formal Grammars](https://reader031.vdocument.in/reader031/viewer/2022021918/588856841a28ab951c8b6d1d/html5/thumbnails/12.jpg)
Formal Grammars 12
Philosophy
Linguistics
lexicology
grammar
morphology
syntax
phonology
semantics
Interdisciplinary
Computer Science
syntax
semantics
![Page 13: Formal Grammars](https://reader031.vdocument.in/reader031/viewer/2022021918/588856841a28ab951c8b6d1d/html5/thumbnails/13.jpg)
Formal Grammars 13
![Page 14: Formal Grammars](https://reader031.vdocument.in/reader031/viewer/2022021918/588856841a28ab951c8b6d1d/html5/thumbnails/14.jpg)
Formal Grammars 13
vocabulary Σ
finite, nonempty set of elements (words, letters)
alphabet
![Page 15: Formal Grammars](https://reader031.vdocument.in/reader031/viewer/2022021918/588856841a28ab951c8b6d1d/html5/thumbnails/15.jpg)
Formal Grammars 13
vocabulary Σ
finite, nonempty set of elements (words, letters)
alphabet
string over Σ
finite sequence of elements chosen from Σ
word, sentence, utterance
![Page 16: Formal Grammars](https://reader031.vdocument.in/reader031/viewer/2022021918/588856841a28ab951c8b6d1d/html5/thumbnails/16.jpg)
Formal Grammars 13
vocabulary Σ
finite, nonempty set of elements (words, letters)
alphabet
string over Σ
finite sequence of elements chosen from Σ
word, sentence, utterance
formal language λ
set of strings over a vocabulary Σ
λ ⊆ Σ*
![Page 17: Formal Grammars](https://reader031.vdocument.in/reader031/viewer/2022021918/588856841a28ab951c8b6d1d/html5/thumbnails/17.jpg)
Formal Grammars 14
formal grammars
![Page 18: Formal Grammars](https://reader031.vdocument.in/reader031/viewer/2022021918/588856841a28ab951c8b6d1d/html5/thumbnails/18.jpg)
Formal Grammars 15
formal grammar G
derivation relation ⇒G
formal language L(G) ⊆ Σ*
L(G) = {w∈Σ* | S ⇒G* w}
![Page 19: Formal Grammars](https://reader031.vdocument.in/reader031/viewer/2022021918/588856841a28ab951c8b6d1d/html5/thumbnails/19.jpg)
Formal Grammars 16
G = (N, Σ, P, S)
Num → Digit Num Num → Digit Digit → “0” Digit → “1” Digit → “2” Digit → “3” Digit → “4” Digit → “5” Digit → “6” Digit → “7” Digit → “8” Digit → “9”
decimal numbers morphology
![Page 20: Formal Grammars](https://reader031.vdocument.in/reader031/viewer/2022021918/588856841a28ab951c8b6d1d/html5/thumbnails/20.jpg)
Formal Grammars 17
G = (N, Σ, P, S)
Num → Digit Num Num → Digit Digit → “0” Digit → “1” Digit → “2” Digit → “3” Digit → “4” Digit → “5” Digit → “6” Digit → “7” Digit → “8” Digit → “9”
decimal numbers morphology
Σ: finite set of terminal symbols
![Page 21: Formal Grammars](https://reader031.vdocument.in/reader031/viewer/2022021918/588856841a28ab951c8b6d1d/html5/thumbnails/21.jpg)
Formal Grammars 18
G = (N, Σ, P, S)
Num → Digit Num Num → Digit Digit → “0” Digit → “1” Digit → “2” Digit → “3” Digit → “4” Digit → “5” Digit → “6” Digit → “7” Digit → “8” Digit → “9”
decimal numbers morphology
Σ: finite set of terminal symbols
N: finite set of non-terminal symbols
![Page 22: Formal Grammars](https://reader031.vdocument.in/reader031/viewer/2022021918/588856841a28ab951c8b6d1d/html5/thumbnails/22.jpg)
Formal Grammars 19
G = (N, Σ, P, S)
Num → Digit Num Num → Digit Digit → “0” Digit → “1” Digit → “2” Digit → “3” Digit → “4” Digit → “5” Digit → “6” Digit → “7” Digit → “8” Digit → “9”
decimal numbers morphology
Σ: finite set of terminal symbols
N: finite set of non-terminal symbols
S∈N: start symbol
![Page 23: Formal Grammars](https://reader031.vdocument.in/reader031/viewer/2022021918/588856841a28ab951c8b6d1d/html5/thumbnails/23.jpg)
Formal Grammars 20
G = (N, Σ, P, S)
Num → Digit Num Num → Digit Digit → “0” Digit → “1” Digit → “2” Digit → “3” Digit → “4” Digit → “5” Digit → “6” Digit → “7” Digit → “8” Digit → “9”
decimal numbers morphology
Σ: finite set of terminal symbols
N: finite set of non-terminal symbols
S∈N: start symbol
P⊆N×(N∪Σ)*: set of production rules
![Page 24: Formal Grammars](https://reader031.vdocument.in/reader031/viewer/2022021918/588856841a28ab951c8b6d1d/html5/thumbnails/24.jpg)
Formal Grammars 21
Num ⇒
Digit Num ⇒
4 Num ⇒
4 Digit Num ⇒
4 3 Num ⇒
4 3 Digit Num ⇒
4 3 0 Num ⇒
4 3 0 Digit ⇒
4 3 0 3
Num → Digit Num ⇒
Digit → “4” ⇒
Num → Digit Num ⇒
Digit → “3” ⇒
Num → Digit Num ⇒
Digit → “0” ⇒
Num → Digit ⇒
Digit → “3” ⇒
decimal numbers production
![Page 25: Formal Grammars](https://reader031.vdocument.in/reader031/viewer/2022021918/588856841a28ab951c8b6d1d/html5/thumbnails/25.jpg)
Formal Grammars 21
Num ⇒
Digit Num ⇒
4 Num ⇒
4 Digit Num ⇒
4 3 Num ⇒
4 3 Digit Num ⇒
4 3 0 Num ⇒
4 3 0 Digit ⇒
4 3 0 3
Num → Digit Num ⇒
Digit → “4” ⇒
Num → Digit Num ⇒
Digit → “3” ⇒
Num → Digit Num ⇒
Digit → “0” ⇒
Num → Digit ⇒
Digit → “3” ⇒
decimal numbers production
leftmost derivation
![Page 26: Formal Grammars](https://reader031.vdocument.in/reader031/viewer/2022021918/588856841a28ab951c8b6d1d/html5/thumbnails/26.jpg)
Formal Grammars 22
Num ⇒
Digit Num ⇒
Digit Digit Num ⇒
Digit Digit Digit Num ⇒
Digit Digit Digit Digit ⇒
Digit Digit Digit 3 ⇒
Digit Digit 0 3 ⇒
Digit 3 0 3 ⇒
4 3 0 3
Num → Digit Num ⇒
Num → Digit Num ⇒
Num → Digit Num ⇒
Num → Digit ⇒
Digit → “3” ⇒ ⇒
Digit → “0” ⇒ ⇒
Digit → “3” ⇒
Digit → “4” ⇒ ⇒
decimal numbers production
![Page 27: Formal Grammars](https://reader031.vdocument.in/reader031/viewer/2022021918/588856841a28ab951c8b6d1d/html5/thumbnails/27.jpg)
Formal Grammars 22
Num ⇒
Digit Num ⇒
Digit Digit Num ⇒
Digit Digit Digit Num ⇒
Digit Digit Digit Digit ⇒
Digit Digit Digit 3 ⇒
Digit Digit 0 3 ⇒
Digit 3 0 3 ⇒
4 3 0 3
Num → Digit Num ⇒
Num → Digit Num ⇒
Num → Digit Num ⇒
Num → Digit ⇒
Digit → “3” ⇒ ⇒
Digit → “0” ⇒ ⇒
Digit → “3” ⇒
Digit → “4” ⇒ ⇒
decimal numbers production
rightmost derivation
![Page 28: Formal Grammars](https://reader031.vdocument.in/reader031/viewer/2022021918/588856841a28ab951c8b6d1d/html5/thumbnails/28.jpg)
Formal Grammars 23
G = (N, Σ, P, S)
Exp → Num Exp → Exp “+” Exp Exp → Exp “−” Exp Exp → Exp “*” Exp Exp → Exp “/” Exp Exp → “(” Exp “)”
binary expressions syntax
![Page 29: Formal Grammars](https://reader031.vdocument.in/reader031/viewer/2022021918/588856841a28ab951c8b6d1d/html5/thumbnails/29.jpg)
Formal Grammars 24
G = (N, Σ, P, S)
Exp → Num Exp → Exp “+” Exp Exp → Exp “−” Exp Exp → Exp “*” Exp Exp → Exp “/” Exp Exp → “(” Exp “)”
binary expressions syntax
Σ: finite set of terminal symbols
![Page 30: Formal Grammars](https://reader031.vdocument.in/reader031/viewer/2022021918/588856841a28ab951c8b6d1d/html5/thumbnails/30.jpg)
Formal Grammars 25
G = (N, Σ, P, S)
Exp → Num Exp → Exp “+” Exp Exp → Exp “−” Exp Exp → Exp “*” Exp Exp → Exp “/” Exp Exp → “(” Exp “)”
binary expressions syntax
Σ: finite set of terminal symbols
N: finite set of non-terminal symbols
![Page 31: Formal Grammars](https://reader031.vdocument.in/reader031/viewer/2022021918/588856841a28ab951c8b6d1d/html5/thumbnails/31.jpg)
Formal Grammars 26
G = (N, Σ, P, S)
Exp → Num Exp → Exp “+” Exp Exp → Exp “−” Exp Exp → Exp “*” Exp Exp → Exp “/” Exp Exp → “(” Exp “)”
binary expressions syntax
Σ: finite set of terminal symbols
N: finite set of non-terminal symbols
S∈N: start symbol
![Page 32: Formal Grammars](https://reader031.vdocument.in/reader031/viewer/2022021918/588856841a28ab951c8b6d1d/html5/thumbnails/32.jpg)
Formal Grammars 27
G = (N, Σ, P, S)
Exp → Num Exp → Exp “+” Exp Exp → Exp “−” Exp Exp → Exp “*” Exp Exp → Exp “/” Exp Exp → “(” Exp “)”
binary expressions syntax
Σ: finite set of terminal symbols
N: finite set of non-terminal symbols
S∈N: start symbol
P⊆N×(N∪Σ)*: set of production rules
![Page 33: Formal Grammars](https://reader031.vdocument.in/reader031/viewer/2022021918/588856841a28ab951c8b6d1d/html5/thumbnails/33.jpg)
Formal Grammars 28
Exp ⇒
Exp + Exp ⇒
Exp + Exp * Exp ⇒
3 + Exp * Exp ⇒
3 + 4 * Exp ⇒
3 + 4 * 5
Exp → Exp “+” Exp ⇒
Exp → Exp “*” Exp ⇒
Exp → Num ⇒
Exp → Num ⇒
Exp → Num ⇒
binary expressions production
![Page 34: Formal Grammars](https://reader031.vdocument.in/reader031/viewer/2022021918/588856841a28ab951c8b6d1d/html5/thumbnails/34.jpg)
Formal Grammars 29
formal grammar G = (N, Σ, P, S)
nonterminal symbols N
terminal symbols Σ
production rules P ⊆ (N∪Σ)* N (N∪Σ)* × (N∪Σ)*
start symbol S∈N
![Page 35: Formal Grammars](https://reader031.vdocument.in/reader031/viewer/2022021918/588856841a28ab951c8b6d1d/html5/thumbnails/35.jpg)
Formal Grammars 29
formal grammar G = (N, Σ, P, S)
nonterminal symbols N
terminal symbols Σ
production rules P ⊆ (N∪Σ)* N (N∪Σ)* × (N∪Σ)*
start symbol S∈N
nonterminal symbol
![Page 36: Formal Grammars](https://reader031.vdocument.in/reader031/viewer/2022021918/588856841a28ab951c8b6d1d/html5/thumbnails/36.jpg)
Formal Grammars 29
formal grammar G = (N, Σ, P, S)
nonterminal symbols N
terminal symbols Σ
production rules P ⊆ (N∪Σ)* N (N∪Σ)* × (N∪Σ)*
start symbol S∈N
context
![Page 37: Formal Grammars](https://reader031.vdocument.in/reader031/viewer/2022021918/588856841a28ab951c8b6d1d/html5/thumbnails/37.jpg)
Formal Grammars 29
formal grammar G = (N, Σ, P, S)
nonterminal symbols N
terminal symbols Σ
production rules P ⊆ (N∪Σ)* N (N∪Σ)* × (N∪Σ)*
start symbol S∈N
replacement
![Page 38: Formal Grammars](https://reader031.vdocument.in/reader031/viewer/2022021918/588856841a28ab951c8b6d1d/html5/thumbnails/38.jpg)
Formal Grammars 29
formal grammar G = (N, Σ, P, S)
nonterminal symbols N
terminal symbols Σ
production rules P ⊆ (N∪Σ)* N (N∪Σ)* × (N∪Σ)*
start symbol S∈N
![Page 39: Formal Grammars](https://reader031.vdocument.in/reader031/viewer/2022021918/588856841a28ab951c8b6d1d/html5/thumbnails/39.jpg)
Formal Grammars 30
type-0, unrestricted: P ⊆ (N∪Σ)* N (N∪Σ)* × (N∪Σ)*
type-1, context-sensitive: (a A c, a b c)
type-2, context-free: P ⊆ N × (N∪Σ)*
type-3, regular: (A, x) or (A, xB)
![Page 40: Formal Grammars](https://reader031.vdocument.in/reader031/viewer/2022021918/588856841a28ab951c8b6d1d/html5/thumbnails/40.jpg)
Formal Grammars 31
formal grammars
context-sensitive
context-free
regular
![Page 41: Formal Grammars](https://reader031.vdocument.in/reader031/viewer/2022021918/588856841a28ab951c8b6d1d/html5/thumbnails/41.jpg)
Formal Grammars 32
formal grammar G
derivation relation ⇒G
formal language L(G) ⊆ Σ*
L(G) = {w∈Σ* | S ⇒G* w}
![Page 42: Formal Grammars](https://reader031.vdocument.in/reader031/viewer/2022021918/588856841a28ab951c8b6d1d/html5/thumbnails/42.jpg)
Formal Grammars 33
formal grammar G = (N, Σ, P, S)
derivation relation ⇒G ⊆ (N∪Σ)* × (N∪Σ)*
w ⇒G w’ ⇔
∃(p, q)∈P: ∃u,v∈(N∪Σ)*:
w=u p v ∧ w’=u q v
formal language L(G) ⊆ Σ*
L(G) = {w∈Σ* | S ⇒G* w}
![Page 43: Formal Grammars](https://reader031.vdocument.in/reader031/viewer/2022021918/588856841a28ab951c8b6d1d/html5/thumbnails/43.jpg)
Formal Grammars 34
formal languages
context-sensitive
context-free
regular
![Page 44: Formal Grammars](https://reader031.vdocument.in/reader031/viewer/2022021918/588856841a28ab951c8b6d1d/html5/thumbnails/44.jpg)
Formal Grammars 35
3 * +7 21
3 * +7 21
Exp ExpExp
Exp
Exp
parser
Derivation is about productivity. But what about parsing?
![Page 45: Formal Grammars](https://reader031.vdocument.in/reader031/viewer/2022021918/588856841a28ab951c8b6d1d/html5/thumbnails/45.jpg)
Formal Grammars 36
word problem
![Page 46: Formal Grammars](https://reader031.vdocument.in/reader031/viewer/2022021918/588856841a28ab951c8b6d1d/html5/thumbnails/46.jpg)
Formal Grammars 37
word problem χL: Σ*→ {0,1}
w → 1, if w∈L
w → 0, else
theoretical computer science decidability & complexity
![Page 47: Formal Grammars](https://reader031.vdocument.in/reader031/viewer/2022021918/588856841a28ab951c8b6d1d/html5/thumbnails/47.jpg)
Formal Grammars 37
word problem χL: Σ*→ {0,1}
w → 1, if w∈L
w → 0, else
decidability
type-0: semi-decidable
type-1, type-2, type-3: decidable
theoretical computer science decidability & complexity
![Page 48: Formal Grammars](https://reader031.vdocument.in/reader031/viewer/2022021918/588856841a28ab951c8b6d1d/html5/thumbnails/48.jpg)
Formal Grammars 37
word problem χL: Σ*→ {0,1}
w → 1, if w∈L
w → 0, else
decidability
type-0: semi-decidable
type-1, type-2, type-3: decidable
complexity
type-1: PSPACE-complete
type-2, type-3: P
theoretical computer science decidability & complexity
![Page 49: Formal Grammars](https://reader031.vdocument.in/reader031/viewer/2022021918/588856841a28ab951c8b6d1d/html5/thumbnails/49.jpg)
Formal Grammars 37
word problem χL: Σ*→ {0,1}
w → 1, if w∈L
w → 0, else
decidability
type-0: semi-decidable
type-1, type-2, type-3: decidable
complexity
type-1: PSPACE-complete
type-2, type-3: P
theoretical computer science decidability & complexity
PSPACE⊇NP⊇P
![Page 50: Formal Grammars](https://reader031.vdocument.in/reader031/viewer/2022021918/588856841a28ab951c8b6d1d/html5/thumbnails/50.jpg)
Formal Grammars 38
formal grammars
context-sensitive
context-free
regular
theoretical computer science decidability & complexity
![Page 51: Formal Grammars](https://reader031.vdocument.in/reader031/viewer/2022021918/588856841a28ab951c8b6d1d/html5/thumbnails/51.jpg)
Formal Grammars 38
formal grammars
context-sensitive
context-free
regular
theoretical computer science decidability & complexity
![Page 52: Formal Grammars](https://reader031.vdocument.in/reader031/viewer/2022021918/588856841a28ab951c8b6d1d/html5/thumbnails/52.jpg)
Formal Grammars 38
formal grammars
context-sensitive
context-free
regular
theoretical computer science decidability & complexity
![Page 53: Formal Grammars](https://reader031.vdocument.in/reader031/viewer/2022021918/588856841a28ab951c8b6d1d/html5/thumbnails/53.jpg)
Formal Grammars 39
Exp → Num Exp → Exp “+” Exp Exp → Exp “−” Exp Exp → Exp “*” Exp Exp → Exp “/” Exp Exp → “(” Exp “)”
context-free grammars production vs. reduction rules
![Page 54: Formal Grammars](https://reader031.vdocument.in/reader031/viewer/2022021918/588856841a28ab951c8b6d1d/html5/thumbnails/54.jpg)
Formal Grammars 39
Exp → Num Exp → Exp “+” Exp Exp → Exp “−” Exp Exp → Exp “*” Exp Exp → Exp “/” Exp Exp → “(” Exp “)”
context-free grammars production vs. reduction rules
productive form
![Page 55: Formal Grammars](https://reader031.vdocument.in/reader031/viewer/2022021918/588856841a28ab951c8b6d1d/html5/thumbnails/55.jpg)
Formal Grammars 39
Exp → Num Exp → Exp “+” Exp Exp → Exp “−” Exp Exp → Exp “*” Exp Exp → Exp “/” Exp Exp → “(” Exp “)”
Num → Exp Exp “+” Exp → Exp Exp “−” Exp → Exp Exp “*” Exp → Exp Exp “/” Exp → Exp “(” Exp “)” → Exp
context-free grammars production vs. reduction rules
productive form
![Page 56: Formal Grammars](https://reader031.vdocument.in/reader031/viewer/2022021918/588856841a28ab951c8b6d1d/html5/thumbnails/56.jpg)
Formal Grammars 39
Exp → Num Exp → Exp “+” Exp Exp → Exp “−” Exp Exp → Exp “*” Exp Exp → Exp “/” Exp Exp → “(” Exp “)”
Num → Exp Exp “+” Exp → Exp Exp “−” Exp → Exp Exp “*” Exp → Exp Exp “/” Exp → Exp “(” Exp “)” → Exp
context-free grammars production vs. reduction rules
productive form reductive form
![Page 57: Formal Grammars](https://reader031.vdocument.in/reader031/viewer/2022021918/588856841a28ab951c8b6d1d/html5/thumbnails/57.jpg)
Formal Grammars 40
3 + 4 * 5 ⇒
Exp + 4 * 5 ⇒
Exp + Exp * 5 ⇒
Exp + Exp * Exp ⇒
Exp + Exp ⇒
Exp
Num → Exp ⇒
Num → Exp ⇒
Num → Exp ⇒
Exp “*” Exp → Exp ⇒
Exp “+” Exp → Exp ⇒⇒
binary expressions reduction
![Page 58: Formal Grammars](https://reader031.vdocument.in/reader031/viewer/2022021918/588856841a28ab951c8b6d1d/html5/thumbnails/58.jpg)
Formal Grammars 41
3 * +7 21
3 * +7 21
Exp ExpExp
Exp
Exp
parser
The word problem is about membership. But what about structure?
![Page 59: Formal Grammars](https://reader031.vdocument.in/reader031/viewer/2022021918/588856841a28ab951c8b6d1d/html5/thumbnails/59.jpg)
Formal Grammars 42
syntax trees
![Page 60: Formal Grammars](https://reader031.vdocument.in/reader031/viewer/2022021918/588856841a28ab951c8b6d1d/html5/thumbnails/60.jpg)
Formal Grammars 43
Exp
Num
Exp
+Exp Exp
Exp
−Exp Exp
Exp
*Exp Exp
Exp
/Exp Exp
Exp
Exp( )
context-free grammars tree construction rules
![Page 61: Formal Grammars](https://reader031.vdocument.in/reader031/viewer/2022021918/588856841a28ab951c8b6d1d/html5/thumbnails/61.jpg)
Formal Grammars 44
binary expressions tree construction
3 + *4 5
![Page 62: Formal Grammars](https://reader031.vdocument.in/reader031/viewer/2022021918/588856841a28ab951c8b6d1d/html5/thumbnails/62.jpg)
Formal Grammars 44
binary expressions tree construction
Exp
3 + *4 5
![Page 63: Formal Grammars](https://reader031.vdocument.in/reader031/viewer/2022021918/588856841a28ab951c8b6d1d/html5/thumbnails/63.jpg)
Formal Grammars 44
binary expressions tree construction
Exp Exp
3 + *4 5
![Page 64: Formal Grammars](https://reader031.vdocument.in/reader031/viewer/2022021918/588856841a28ab951c8b6d1d/html5/thumbnails/64.jpg)
Formal Grammars 44
binary expressions tree construction
Exp Exp
3 + *4 5
Exp
![Page 65: Formal Grammars](https://reader031.vdocument.in/reader031/viewer/2022021918/588856841a28ab951c8b6d1d/html5/thumbnails/65.jpg)
Formal Grammars 44
binary expressions tree construction
Exp
Exp
Exp
3 + *4 5
Exp
![Page 66: Formal Grammars](https://reader031.vdocument.in/reader031/viewer/2022021918/588856841a28ab951c8b6d1d/html5/thumbnails/66.jpg)
Formal Grammars 44
binary expressions tree construction
Exp
Exp
Exp
3 + *4 5
Exp
Exp
![Page 67: Formal Grammars](https://reader031.vdocument.in/reader031/viewer/2022021918/588856841a28ab951c8b6d1d/html5/thumbnails/67.jpg)
Formal Grammars 45
binary expressions ambiguity
Exp
Exp
Exp
3 + *4 5
Exp
Exp
Exp
Exp
Exp
3 + *4 5
Exp
Exp
![Page 68: Formal Grammars](https://reader031.vdocument.in/reader031/viewer/2022021918/588856841a28ab951c8b6d1d/html5/thumbnails/68.jpg)
Formal Grammars 46
syntax trees
different trees for same sentence
derivations
different leftmost derivations for same sentence
different rightmost derivations for same sentence
NOT just different derivations for same sentence
context-free grammars ambiguity
![Page 69: Formal Grammars](https://reader031.vdocument.in/reader031/viewer/2022021918/588856841a28ab951c8b6d1d/html5/thumbnails/69.jpg)
Formal Grammars 47
parse trees
parent node: nonterminal symbol
child nodes: terminal symbols
abstract syntax trees (ASTs)
abstract over terminal symbols
convey information at parent nodes
abstract over injective production rules
syntax trees parse trees & abstract syntax trees
![Page 70: Formal Grammars](https://reader031.vdocument.in/reader031/viewer/2022021918/588856841a28ab951c8b6d1d/html5/thumbnails/70.jpg)
Formal Grammars 48
binary expressions parse tree & abstract syntax tree
Exp
Exp
Exp Exp
Exp
(3 + *4 5 )
Exp
![Page 71: Formal Grammars](https://reader031.vdocument.in/reader031/viewer/2022021918/588856841a28ab951c8b6d1d/html5/thumbnails/71.jpg)
Formal Grammars 48
binary expressions parse tree & abstract syntax tree
Const
Mul
Const
3 4 5
Const
Add
Exp
Exp
Exp Exp
Exp
(3 + *4 5 )
Exp
![Page 72: Formal Grammars](https://reader031.vdocument.in/reader031/viewer/2022021918/588856841a28ab951c8b6d1d/html5/thumbnails/72.jpg)
Formal Grammars 49
Except where otherwise noted, this work is licensed under
![Page 73: Formal Grammars](https://reader031.vdocument.in/reader031/viewer/2022021918/588856841a28ab951c8b6d1d/html5/thumbnails/73.jpg)
Formal Grammars 50
attribution
slide title author license
1 The Pine, Saint Tropez Paul Signac public domain
2, 3, 35, 41 PICOL icons Melih Bilgil CC BY 3.0
9 Writing Caitlin Regan CC BY 2.0
10 Latin Grammar Anthony Nelzin
13, 15, 29-34, 38 Noam Chomsky Fellowsisters CC BY-NC-SA 2.0