SlideShare una empresa de Scribd logo
1 de 73
Descargar para leer sin conexión
IN4303 2015/16
Compiler Construction
Language Specification
formal grammars
Guido Wachsmuth
Formal Grammars 2
3 * +7 21
3 * +7 21
Exp ExpExp
Exp
Exp
parser
Formal Grammars 3
syntax
definition
errors
parse generate
check
parse
table
generic
parser
Formal Grammars
Stratego
NaBL
TS
SDF3
ESV
editor
SPT
tests
4
syntax definition
concrete syntax
abstract syntax
static semantics
name binding
type system
dynamic semantics
translation
interpretation
Formal Grammars
Stratego
NaBL
TS
SDF3
ESV
editor
SPT
tests
5
syntax definition
concrete syntax
abstract syntax
static semantics
name binding
type system
dynamic semantics
translation
interpretation
Formal Grammars
Stratego
NaBL
TS
SDF3
ESV
editor
SPT
tests
6
syntax definition
concrete syntax
abstract syntax
static semantics
name binding
type system
dynamic semantics
translation
interpretation
Formal Grammars 7
P A R E N T A L
ADVISORY
THEORETICAL CONTENT
Formal Grammars 8
formal languages
Formal Grammars 9
infinite productivity
Formal Grammars 10
finite models
Formal Grammars 11
Philosophy
Linguistics
lexicology
grammar
morphology
syntax
phonology
semantics
Interdisciplinary
Computer Science
syntax
semantics
Formal Grammars 12
Philosophy
Linguistics
lexicology
grammar
morphology
syntax
phonology
semantics
Interdisciplinary
Computer Science
syntax
semantics
Formal Grammars 13
Formal Grammars 13
vocabulary Σ
finite, nonempty set of elements (words, letters)
alphabet
Formal Grammars 13
vocabulary Σ
finite, nonempty set of elements (words, letters)
alphabet
string over Σ
finite sequence of elements chosen from Σ
word, sentence, utterance
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 Σ
λ ⊆ Σ*
Formal Grammars 14
formal grammars
Formal Grammars 15
formal grammar G
derivation relation G
formal language L(G) ⊆ Σ*
L(G) = {w∈Σ*
| S G
*
w}
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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)
Formal Grammars 31
formal grammars
context-sensitive
context-free
regular
Formal Grammars 32
formal grammar G
derivation relation G
formal language L(G) ⊆ Σ*
L(G) = {w∈Σ*
| S G
*
w}
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}
Formal Grammars 34
formal languages
context-sensitive
context-free
regular
Formal Grammars 35
3 * +7 21
3 * +7 21
Exp ExpExp
Exp
Exp
parser
Derivation is about productivity.
But what about parsing?
Formal Grammars 36
word problem
Formal Grammars 37
word problem χL: Σ*
→ {0,1}
w → 1, if w∈L
w → 0, else
theoretical computer science
decidability & complexity
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
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
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
Formal Grammars 38
formal grammars
context-sensitive
context-free
regular
theoretical computer science
decidability & complexity
Formal Grammars 38
formal grammars
context-sensitive
context-free
regular
theoretical computer science
decidability & complexity
Formal Grammars 38
formal grammars
context-sensitive
context-free
regular
theoretical computer science
decidability & complexity
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
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
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
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
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
Formal Grammars 41
3 * +7 21
3 * +7 21
Exp ExpExp
Exp
Exp
parser
The word problem is about membership.
But what about structure?
Formal Grammars 42
syntax trees
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
Formal Grammars 44
binary expressions
tree construction
3 + *4 5
Formal Grammars 44
binary expressions
tree construction
Exp
3 + *4 5
Formal Grammars 44
binary expressions
tree construction
Exp Exp
3 + *4 5
Formal Grammars 44
binary expressions
tree construction
Exp Exp
3 + *4 5
Exp
Formal Grammars 44
binary expressions
tree construction
Exp
Exp
Exp
3 + *4 5
Exp
Formal Grammars 44
binary expressions
tree construction
Exp
Exp
Exp
3 + *4 5
Exp
Exp
Formal Grammars 45
binary expressions
ambiguity
Exp
Exp
Exp
3 + *4 5
Exp
Exp
Exp
Exp
Exp
3 + *4 5
Exp
Exp
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
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
Formal Grammars 48
binary expressions
parse tree & abstract syntax tree
Exp
Exp
Exp Exp
Exp
(3 + *4 5 )
Exp
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
Formal Grammars 49
Except where otherwise noted, this work is licensed under
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

Más contenido relacionado

La actualidad más candente

Compiler Components and their Generators - Lexical Analysis
Compiler Components and their Generators - Lexical AnalysisCompiler Components and their Generators - Lexical Analysis
Compiler Components and their Generators - Lexical AnalysisGuido Wachsmuth
 
Declarative Semantics Definition - Term Rewriting
Declarative Semantics Definition - Term RewritingDeclarative Semantics Definition - Term Rewriting
Declarative Semantics Definition - Term RewritingGuido Wachsmuth
 
Introduction - Imperative and Object-Oriented Languages
Introduction - Imperative and Object-Oriented LanguagesIntroduction - Imperative and Object-Oriented Languages
Introduction - Imperative and Object-Oriented LanguagesGuido Wachsmuth
 
Static name resolution
Static name resolutionStatic name resolution
Static name resolutionEelco Visser
 
Declare Your Language: Syntactic (Editor) Services
Declare Your Language: Syntactic (Editor) ServicesDeclare Your Language: Syntactic (Editor) Services
Declare Your Language: Syntactic (Editor) ServicesEelco Visser
 
Declare Your Language: Type Checking
Declare Your Language: Type CheckingDeclare Your Language: Type Checking
Declare Your Language: Type CheckingEelco Visser
 
Parsing in Compiler Design
Parsing in Compiler DesignParsing in Compiler Design
Parsing in Compiler DesignAkhil Kaushik
 
Dynamic Semantics Specification and Interpreter Generation
Dynamic Semantics Specification and Interpreter GenerationDynamic Semantics Specification and Interpreter Generation
Dynamic Semantics Specification and Interpreter GenerationEelco Visser
 
Regex Presentation
Regex PresentationRegex Presentation
Regex Presentationarnolambert
 
regular expressions (Regex)
regular expressions (Regex)regular expressions (Regex)
regular expressions (Regex)Rebaz Najeeb
 
5 top-down-parsers
5  top-down-parsers 5  top-down-parsers
5 top-down-parsers Saeed Parsa
 

La actualidad más candente (20)

Compiler Components and their Generators - Lexical Analysis
Compiler Components and their Generators - Lexical AnalysisCompiler Components and their Generators - Lexical Analysis
Compiler Components and their Generators - Lexical Analysis
 
Static Analysis
Static AnalysisStatic Analysis
Static Analysis
 
Term Rewriting
Term RewritingTerm Rewriting
Term Rewriting
 
Declarative Semantics Definition - Term Rewriting
Declarative Semantics Definition - Term RewritingDeclarative Semantics Definition - Term Rewriting
Declarative Semantics Definition - Term Rewriting
 
Introduction - Imperative and Object-Oriented Languages
Introduction - Imperative and Object-Oriented LanguagesIntroduction - Imperative and Object-Oriented Languages
Introduction - Imperative and Object-Oriented Languages
 
Static name resolution
Static name resolutionStatic name resolution
Static name resolution
 
Declare Your Language: Syntactic (Editor) Services
Declare Your Language: Syntactic (Editor) ServicesDeclare Your Language: Syntactic (Editor) Services
Declare Your Language: Syntactic (Editor) Services
 
Dynamic Semantics
Dynamic SemanticsDynamic Semantics
Dynamic Semantics
 
Type analysis
Type analysisType analysis
Type analysis
 
Ch04
Ch04Ch04
Ch04
 
Ch03
Ch03Ch03
Ch03
 
Declare Your Language: Type Checking
Declare Your Language: Type CheckingDeclare Your Language: Type Checking
Declare Your Language: Type Checking
 
Parsing in Compiler Design
Parsing in Compiler DesignParsing in Compiler Design
Parsing in Compiler Design
 
Dynamic Semantics Specification and Interpreter Generation
Dynamic Semantics Specification and Interpreter GenerationDynamic Semantics Specification and Interpreter Generation
Dynamic Semantics Specification and Interpreter Generation
 
Regular expression examples
Regular expression examplesRegular expression examples
Regular expression examples
 
Ch06
Ch06Ch06
Ch06
 
Regex Presentation
Regex PresentationRegex Presentation
Regex Presentation
 
regular expressions (Regex)
regular expressions (Regex)regular expressions (Regex)
regular expressions (Regex)
 
5 top-down-parsers
5  top-down-parsers 5  top-down-parsers
5 top-down-parsers
 
Ch4a
Ch4aCh4a
Ch4a
 

Destacado

Climbing the Abstract Syntax Tree (Bulgaria PHP 2016)
Climbing the Abstract Syntax Tree (Bulgaria PHP 2016)Climbing the Abstract Syntax Tree (Bulgaria PHP 2016)
Climbing the Abstract Syntax Tree (Bulgaria PHP 2016)James Titcumb
 
Hugging Abstract Syntax Trees: A Pythonic Love Story (OSDC 2010)
Hugging Abstract Syntax Trees: A Pythonic Love Story (OSDC 2010)Hugging Abstract Syntax Trees: A Pythonic Love Story (OSDC 2010)
Hugging Abstract Syntax Trees: A Pythonic Love Story (OSDC 2010)Tom Lee
 
The organs of speech
The organs of speechThe organs of speech
The organs of speechMonir Hossen
 
Lexical pragmatics presentation
Lexical pragmatics presentationLexical pragmatics presentation
Lexical pragmatics presentationGul Shair
 
Pragmatics presentation chapter five from the book of peter grundy Doing Prag...
Pragmatics presentation chapter five from the book of peter grundy Doing Prag...Pragmatics presentation chapter five from the book of peter grundy Doing Prag...
Pragmatics presentation chapter five from the book of peter grundy Doing Prag...Ijaz Ahmed
 
A Few of My Favorite (Python) Things
A Few of My Favorite (Python) ThingsA Few of My Favorite (Python) Things
A Few of My Favorite (Python) ThingsMichael Pirnat
 
Discourse analysis
Discourse analysisDiscourse analysis
Discourse analysisAlicia Ruiz
 
Syntax powerpoint
Syntax powerpointSyntax powerpoint
Syntax powerpointcswstyle
 
AST - the only true tool for building JavaScript
AST - the only true tool for building JavaScriptAST - the only true tool for building JavaScript
AST - the only true tool for building JavaScriptIngvar Stepanyan
 
English Pronunciation Speech Organs
English Pronunciation Speech OrgansEnglish Pronunciation Speech Organs
English Pronunciation Speech Organsvictorgaogao
 
Compiler vs interpreter
Compiler vs interpreterCompiler vs interpreter
Compiler vs interpreterParas Patel
 
Ed2 constructivist bruner. report
Ed2 constructivist bruner. reportEd2 constructivist bruner. report
Ed2 constructivist bruner. reportEddie Abug
 
Language translator
Language translatorLanguage translator
Language translatorasmakh89
 

Destacado (20)

ENGLISH SYNTAX
ENGLISH SYNTAXENGLISH SYNTAX
ENGLISH SYNTAX
 
Syntax (Part 1)
Syntax (Part 1)Syntax (Part 1)
Syntax (Part 1)
 
Syntax
SyntaxSyntax
Syntax
 
MySQL Cursors
MySQL CursorsMySQL Cursors
MySQL Cursors
 
Climbing the Abstract Syntax Tree (Bulgaria PHP 2016)
Climbing the Abstract Syntax Tree (Bulgaria PHP 2016)Climbing the Abstract Syntax Tree (Bulgaria PHP 2016)
Climbing the Abstract Syntax Tree (Bulgaria PHP 2016)
 
Hugging Abstract Syntax Trees: A Pythonic Love Story (OSDC 2010)
Hugging Abstract Syntax Trees: A Pythonic Love Story (OSDC 2010)Hugging Abstract Syntax Trees: A Pythonic Love Story (OSDC 2010)
Hugging Abstract Syntax Trees: A Pythonic Love Story (OSDC 2010)
 
The organs of speech
The organs of speechThe organs of speech
The organs of speech
 
Lexical pragmatics presentation
Lexical pragmatics presentationLexical pragmatics presentation
Lexical pragmatics presentation
 
Pragmatics presentation chapter five from the book of peter grundy Doing Prag...
Pragmatics presentation chapter five from the book of peter grundy Doing Prag...Pragmatics presentation chapter five from the book of peter grundy Doing Prag...
Pragmatics presentation chapter five from the book of peter grundy Doing Prag...
 
A Few of My Favorite (Python) Things
A Few of My Favorite (Python) ThingsA Few of My Favorite (Python) Things
A Few of My Favorite (Python) Things
 
Discourse analysis
Discourse analysisDiscourse analysis
Discourse analysis
 
Syntax powerpoint
Syntax powerpointSyntax powerpoint
Syntax powerpoint
 
AST - the only true tool for building JavaScript
AST - the only true tool for building JavaScriptAST - the only true tool for building JavaScript
AST - the only true tool for building JavaScript
 
English Pronunciation Speech Organs
English Pronunciation Speech OrgansEnglish Pronunciation Speech Organs
English Pronunciation Speech Organs
 
Speech organs
Speech organsSpeech organs
Speech organs
 
Syntax
SyntaxSyntax
Syntax
 
Compiler vs interpreter
Compiler vs interpreterCompiler vs interpreter
Compiler vs interpreter
 
Ed2 constructivist bruner. report
Ed2 constructivist bruner. reportEd2 constructivist bruner. report
Ed2 constructivist bruner. report
 
Language translator
Language translatorLanguage translator
Language translator
 
(1) lexical semantics 1
(1) lexical semantics 1(1) lexical semantics 1
(1) lexical semantics 1
 

Similar a Declarative Syntax Definition - Grammars and Trees

Declarative Syntax Definition - Pretty Printing
Declarative Syntax Definition - Pretty PrintingDeclarative Syntax Definition - Pretty Printing
Declarative Syntax Definition - Pretty PrintingGuido Wachsmuth
 
Class_Powerpoint_Sequences_Arithmetic_and_Geometric_with_Series_Finite_and_In...
Class_Powerpoint_Sequences_Arithmetic_and_Geometric_with_Series_Finite_and_In...Class_Powerpoint_Sequences_Arithmetic_and_Geometric_with_Series_Finite_and_In...
Class_Powerpoint_Sequences_Arithmetic_and_Geometric_with_Series_Finite_and_In...MargieCDeSagun
 
Geometric Sequence and Series.pdf
Geometric Sequence and Series.pdfGeometric Sequence and Series.pdf
Geometric Sequence and Series.pdfVnDr
 
Compiler components and their generators traditional parsing algorithms
Compiler components and their generators  traditional parsing algorithmsCompiler components and their generators  traditional parsing algorithms
Compiler components and their generators traditional parsing algorithmsPeshrowKareem1
 
Section 11-2 Algebra 2
Section 11-2 Algebra 2Section 11-2 Algebra 2
Section 11-2 Algebra 2Jimbo Lamb
 
Arithmetic Sequences and Series.ppt
Arithmetic Sequences and Series.pptArithmetic Sequences and Series.ppt
Arithmetic Sequences and Series.pptJohn Marvin Canaria
 
Scope Graphs: A fresh look at name binding in programming languages
Scope Graphs: A fresh look at name binding in programming languagesScope Graphs: A fresh look at name binding in programming languages
Scope Graphs: A fresh look at name binding in programming languagesEelco Visser
 
Arithmetic Sequences and Series-Boger.ppt
Arithmetic Sequences and Series-Boger.pptArithmetic Sequences and Series-Boger.ppt
Arithmetic Sequences and Series-Boger.pptAngelle Pantig
 
Scala as a Declarative Language
Scala as a Declarative LanguageScala as a Declarative Language
Scala as a Declarative Languagevsssuresh
 
Arithmetic Sequences and Series-Boger.ppt
Arithmetic Sequences and Series-Boger.pptArithmetic Sequences and Series-Boger.ppt
Arithmetic Sequences and Series-Boger.pptGIDEONPAUL13
 
Arithmetic Sequences and Series-Boger.ppt
Arithmetic Sequences and Series-Boger.pptArithmetic Sequences and Series-Boger.ppt
Arithmetic Sequences and Series-Boger.pptJosephMuez2
 
Arithmetic Sequences and Series-Boger.ppt
Arithmetic Sequences and Series-Boger.pptArithmetic Sequences and Series-Boger.ppt
Arithmetic Sequences and Series-Boger.pptreboy_arroyo
 
The probability of non-confluent systems
The probability of non-confluent systemsThe probability of non-confluent systems
The probability of non-confluent systemsAlejandro Díaz-Caro
 
Syntax Analysis.pdf
Syntax Analysis.pdfSyntax Analysis.pdf
Syntax Analysis.pdfShivang70701
 
Perl6 for-beginners
Perl6 for-beginnersPerl6 for-beginners
Perl6 for-beginnersJens Rehsack
 
Arithmetic and geometric_sequences
Arithmetic and geometric_sequencesArithmetic and geometric_sequences
Arithmetic and geometric_sequencesDreams4school
 
Applied Math 40S June 2 AM, 2008
Applied Math 40S June 2 AM, 2008Applied Math 40S June 2 AM, 2008
Applied Math 40S June 2 AM, 2008Darren Kuropatwa
 
Declarative Language Definition
Declarative Language DefinitionDeclarative Language Definition
Declarative Language DefinitionEelco Visser
 

Similar a Declarative Syntax Definition - Grammars and Trees (20)

Ch2 (1).ppt
Ch2 (1).pptCh2 (1).ppt
Ch2 (1).ppt
 
Declarative Syntax Definition - Pretty Printing
Declarative Syntax Definition - Pretty PrintingDeclarative Syntax Definition - Pretty Printing
Declarative Syntax Definition - Pretty Printing
 
Class_Powerpoint_Sequences_Arithmetic_and_Geometric_with_Series_Finite_and_In...
Class_Powerpoint_Sequences_Arithmetic_and_Geometric_with_Series_Finite_and_In...Class_Powerpoint_Sequences_Arithmetic_and_Geometric_with_Series_Finite_and_In...
Class_Powerpoint_Sequences_Arithmetic_and_Geometric_with_Series_Finite_and_In...
 
Geometric Sequence and Series.pdf
Geometric Sequence and Series.pdfGeometric Sequence and Series.pdf
Geometric Sequence and Series.pdf
 
Compiler components and their generators traditional parsing algorithms
Compiler components and their generators  traditional parsing algorithmsCompiler components and their generators  traditional parsing algorithms
Compiler components and their generators traditional parsing algorithms
 
Section 11-2 Algebra 2
Section 11-2 Algebra 2Section 11-2 Algebra 2
Section 11-2 Algebra 2
 
Ch2
Ch2Ch2
Ch2
 
Arithmetic Sequences and Series.ppt
Arithmetic Sequences and Series.pptArithmetic Sequences and Series.ppt
Arithmetic Sequences and Series.ppt
 
Scope Graphs: A fresh look at name binding in programming languages
Scope Graphs: A fresh look at name binding in programming languagesScope Graphs: A fresh look at name binding in programming languages
Scope Graphs: A fresh look at name binding in programming languages
 
Arithmetic Sequences and Series-Boger.ppt
Arithmetic Sequences and Series-Boger.pptArithmetic Sequences and Series-Boger.ppt
Arithmetic Sequences and Series-Boger.ppt
 
Scala as a Declarative Language
Scala as a Declarative LanguageScala as a Declarative Language
Scala as a Declarative Language
 
Arithmetic Sequences and Series-Boger.ppt
Arithmetic Sequences and Series-Boger.pptArithmetic Sequences and Series-Boger.ppt
Arithmetic Sequences and Series-Boger.ppt
 
Arithmetic Sequences and Series-Boger.ppt
Arithmetic Sequences and Series-Boger.pptArithmetic Sequences and Series-Boger.ppt
Arithmetic Sequences and Series-Boger.ppt
 
Arithmetic Sequences and Series-Boger.ppt
Arithmetic Sequences and Series-Boger.pptArithmetic Sequences and Series-Boger.ppt
Arithmetic Sequences and Series-Boger.ppt
 
The probability of non-confluent systems
The probability of non-confluent systemsThe probability of non-confluent systems
The probability of non-confluent systems
 
Syntax Analysis.pdf
Syntax Analysis.pdfSyntax Analysis.pdf
Syntax Analysis.pdf
 
Perl6 for-beginners
Perl6 for-beginnersPerl6 for-beginners
Perl6 for-beginners
 
Arithmetic and geometric_sequences
Arithmetic and geometric_sequencesArithmetic and geometric_sequences
Arithmetic and geometric_sequences
 
Applied Math 40S June 2 AM, 2008
Applied Math 40S June 2 AM, 2008Applied Math 40S June 2 AM, 2008
Applied Math 40S June 2 AM, 2008
 
Declarative Language Definition
Declarative Language DefinitionDeclarative Language Definition
Declarative Language Definition
 

Más de Guido Wachsmuth

Domain-Specific Type Systems
Domain-Specific Type SystemsDomain-Specific Type Systems
Domain-Specific Type SystemsGuido Wachsmuth
 
Compiler Components and their Generators - LR Parsing
Compiler Components and their Generators - LR ParsingCompiler Components and their Generators - LR Parsing
Compiler Components and their Generators - LR ParsingGuido Wachsmuth
 
Compiling Imperative and Object-Oriented Languages - Garbage Collection
Compiling Imperative and Object-Oriented Languages - Garbage CollectionCompiling Imperative and Object-Oriented Languages - Garbage Collection
Compiling Imperative and Object-Oriented Languages - Garbage CollectionGuido Wachsmuth
 
Compiling Imperative and Object-Oriented Languages - Register Allocation
Compiling Imperative and Object-Oriented Languages - Register AllocationCompiling Imperative and Object-Oriented Languages - Register Allocation
Compiling Imperative and Object-Oriented Languages - Register AllocationGuido Wachsmuth
 
Compiling Imperative and Object-Oriented Languages - Dataflow Analysis
Compiling Imperative and Object-Oriented Languages - Dataflow AnalysisCompiling Imperative and Object-Oriented Languages - Dataflow Analysis
Compiling Imperative and Object-Oriented Languages - Dataflow AnalysisGuido Wachsmuth
 
Compiling Imperative and Object-Oriented Languages - Activation Records
Compiling Imperative and Object-Oriented Languages - Activation RecordsCompiling Imperative and Object-Oriented Languages - Activation Records
Compiling Imperative and Object-Oriented Languages - Activation RecordsGuido Wachsmuth
 
Declarative Semantics Definition - Code Generation
Declarative Semantics Definition - Code Generation Declarative Semantics Definition - Code Generation
Declarative Semantics Definition - Code Generation Guido Wachsmuth
 

Más de Guido Wachsmuth (9)

Language
LanguageLanguage
Language
 
Domain-Specific Type Systems
Domain-Specific Type SystemsDomain-Specific Type Systems
Domain-Specific Type Systems
 
Compiler Components and their Generators - LR Parsing
Compiler Components and their Generators - LR ParsingCompiler Components and their Generators - LR Parsing
Compiler Components and their Generators - LR Parsing
 
Compiling Imperative and Object-Oriented Languages - Garbage Collection
Compiling Imperative and Object-Oriented Languages - Garbage CollectionCompiling Imperative and Object-Oriented Languages - Garbage Collection
Compiling Imperative and Object-Oriented Languages - Garbage Collection
 
Compiling Imperative and Object-Oriented Languages - Register Allocation
Compiling Imperative and Object-Oriented Languages - Register AllocationCompiling Imperative and Object-Oriented Languages - Register Allocation
Compiling Imperative and Object-Oriented Languages - Register Allocation
 
Compiling Imperative and Object-Oriented Languages - Dataflow Analysis
Compiling Imperative and Object-Oriented Languages - Dataflow AnalysisCompiling Imperative and Object-Oriented Languages - Dataflow Analysis
Compiling Imperative and Object-Oriented Languages - Dataflow Analysis
 
Compiling Imperative and Object-Oriented Languages - Activation Records
Compiling Imperative and Object-Oriented Languages - Activation RecordsCompiling Imperative and Object-Oriented Languages - Activation Records
Compiling Imperative and Object-Oriented Languages - Activation Records
 
Declarative Semantics Definition - Code Generation
Declarative Semantics Definition - Code Generation Declarative Semantics Definition - Code Generation
Declarative Semantics Definition - Code Generation
 
Software Languages
Software LanguagesSoftware Languages
Software Languages
 

Último

Introduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The BasicsIntroduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The BasicsTechSoup
 
Seal of Good Local Governance (SGLG) 2024Final.pptx
Seal of Good Local Governance (SGLG) 2024Final.pptxSeal of Good Local Governance (SGLG) 2024Final.pptx
Seal of Good Local Governance (SGLG) 2024Final.pptxnegromaestrong
 
Spellings Wk 3 English CAPS CARES Please Practise
Spellings Wk 3 English CAPS CARES Please PractiseSpellings Wk 3 English CAPS CARES Please Practise
Spellings Wk 3 English CAPS CARES Please PractiseAnaAcapella
 
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in DelhiRussian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhikauryashika82
 
Magic bus Group work1and 2 (Team 3).pptx
Magic bus Group work1and 2 (Team 3).pptxMagic bus Group work1and 2 (Team 3).pptx
Magic bus Group work1and 2 (Team 3).pptxdhanalakshmis0310
 
Micro-Scholarship, What it is, How can it help me.pdf
Micro-Scholarship, What it is, How can it help me.pdfMicro-Scholarship, What it is, How can it help me.pdf
Micro-Scholarship, What it is, How can it help me.pdfPoh-Sun Goh
 
How to Create and Manage Wizard in Odoo 17
How to Create and Manage Wizard in Odoo 17How to Create and Manage Wizard in Odoo 17
How to Create and Manage Wizard in Odoo 17Celine George
 
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...Nguyen Thanh Tu Collection
 
Grant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy ConsultingGrant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy ConsultingTechSoup
 
1029 - Danh muc Sach Giao Khoa 10 . pdf
1029 -  Danh muc Sach Giao Khoa 10 . pdf1029 -  Danh muc Sach Giao Khoa 10 . pdf
1029 - Danh muc Sach Giao Khoa 10 . pdfQucHHunhnh
 
PROCESS RECORDING FORMAT.docx
PROCESS      RECORDING        FORMAT.docxPROCESS      RECORDING        FORMAT.docx
PROCESS RECORDING FORMAT.docxPoojaSen20
 
SKILL OF INTRODUCING THE LESSON MICRO SKILLS.pptx
SKILL OF INTRODUCING THE LESSON MICRO SKILLS.pptxSKILL OF INTRODUCING THE LESSON MICRO SKILLS.pptx
SKILL OF INTRODUCING THE LESSON MICRO SKILLS.pptxAmanpreet Kaur
 
The basics of sentences session 3pptx.pptx
The basics of sentences session 3pptx.pptxThe basics of sentences session 3pptx.pptx
The basics of sentences session 3pptx.pptxheathfieldcps1
 
Key note speaker Neum_Admir Softic_ENG.pdf
Key note speaker Neum_Admir Softic_ENG.pdfKey note speaker Neum_Admir Softic_ENG.pdf
Key note speaker Neum_Admir Softic_ENG.pdfAdmir Softic
 
Mixin Classes in Odoo 17 How to Extend Models Using Mixin Classes
Mixin Classes in Odoo 17  How to Extend Models Using Mixin ClassesMixin Classes in Odoo 17  How to Extend Models Using Mixin Classes
Mixin Classes in Odoo 17 How to Extend Models Using Mixin ClassesCeline George
 
Food safety_Challenges food safety laboratories_.pdf
Food safety_Challenges food safety laboratories_.pdfFood safety_Challenges food safety laboratories_.pdf
Food safety_Challenges food safety laboratories_.pdfSherif Taha
 
How to Give a Domain for a Field in Odoo 17
How to Give a Domain for a Field in Odoo 17How to Give a Domain for a Field in Odoo 17
How to Give a Domain for a Field in Odoo 17Celine George
 
Activity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdfActivity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdfciinovamais
 
SOC 101 Demonstration of Learning Presentation
SOC 101 Demonstration of Learning PresentationSOC 101 Demonstration of Learning Presentation
SOC 101 Demonstration of Learning Presentationcamerronhm
 

Último (20)

Introduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The BasicsIntroduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The Basics
 
Seal of Good Local Governance (SGLG) 2024Final.pptx
Seal of Good Local Governance (SGLG) 2024Final.pptxSeal of Good Local Governance (SGLG) 2024Final.pptx
Seal of Good Local Governance (SGLG) 2024Final.pptx
 
Spellings Wk 3 English CAPS CARES Please Practise
Spellings Wk 3 English CAPS CARES Please PractiseSpellings Wk 3 English CAPS CARES Please Practise
Spellings Wk 3 English CAPS CARES Please Practise
 
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in DelhiRussian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
 
Magic bus Group work1and 2 (Team 3).pptx
Magic bus Group work1and 2 (Team 3).pptxMagic bus Group work1and 2 (Team 3).pptx
Magic bus Group work1and 2 (Team 3).pptx
 
Micro-Scholarship, What it is, How can it help me.pdf
Micro-Scholarship, What it is, How can it help me.pdfMicro-Scholarship, What it is, How can it help me.pdf
Micro-Scholarship, What it is, How can it help me.pdf
 
How to Create and Manage Wizard in Odoo 17
How to Create and Manage Wizard in Odoo 17How to Create and Manage Wizard in Odoo 17
How to Create and Manage Wizard in Odoo 17
 
Spatium Project Simulation student brief
Spatium Project Simulation student briefSpatium Project Simulation student brief
Spatium Project Simulation student brief
 
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...
 
Grant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy ConsultingGrant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy Consulting
 
1029 - Danh muc Sach Giao Khoa 10 . pdf
1029 -  Danh muc Sach Giao Khoa 10 . pdf1029 -  Danh muc Sach Giao Khoa 10 . pdf
1029 - Danh muc Sach Giao Khoa 10 . pdf
 
PROCESS RECORDING FORMAT.docx
PROCESS      RECORDING        FORMAT.docxPROCESS      RECORDING        FORMAT.docx
PROCESS RECORDING FORMAT.docx
 
SKILL OF INTRODUCING THE LESSON MICRO SKILLS.pptx
SKILL OF INTRODUCING THE LESSON MICRO SKILLS.pptxSKILL OF INTRODUCING THE LESSON MICRO SKILLS.pptx
SKILL OF INTRODUCING THE LESSON MICRO SKILLS.pptx
 
The basics of sentences session 3pptx.pptx
The basics of sentences session 3pptx.pptxThe basics of sentences session 3pptx.pptx
The basics of sentences session 3pptx.pptx
 
Key note speaker Neum_Admir Softic_ENG.pdf
Key note speaker Neum_Admir Softic_ENG.pdfKey note speaker Neum_Admir Softic_ENG.pdf
Key note speaker Neum_Admir Softic_ENG.pdf
 
Mixin Classes in Odoo 17 How to Extend Models Using Mixin Classes
Mixin Classes in Odoo 17  How to Extend Models Using Mixin ClassesMixin Classes in Odoo 17  How to Extend Models Using Mixin Classes
Mixin Classes in Odoo 17 How to Extend Models Using Mixin Classes
 
Food safety_Challenges food safety laboratories_.pdf
Food safety_Challenges food safety laboratories_.pdfFood safety_Challenges food safety laboratories_.pdf
Food safety_Challenges food safety laboratories_.pdf
 
How to Give a Domain for a Field in Odoo 17
How to Give a Domain for a Field in Odoo 17How to Give a Domain for a Field in Odoo 17
How to Give a Domain for a Field in Odoo 17
 
Activity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdfActivity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdf
 
SOC 101 Demonstration of Learning Presentation
SOC 101 Demonstration of Learning PresentationSOC 101 Demonstration of Learning Presentation
SOC 101 Demonstration of Learning Presentation
 

Declarative Syntax Definition - Grammars and Trees

  • 1. IN4303 2015/16 Compiler Construction Language Specification formal grammars Guido Wachsmuth
  • 2. Formal Grammars 2 3 * +7 21 3 * +7 21 Exp ExpExp Exp Exp parser
  • 3. Formal Grammars 3 syntax definition errors parse generate check parse table generic parser
  • 4. Formal Grammars Stratego NaBL TS SDF3 ESV editor SPT tests 4 syntax definition concrete syntax abstract syntax static semantics name binding type system dynamic semantics translation interpretation
  • 5. Formal Grammars Stratego NaBL TS SDF3 ESV editor SPT tests 5 syntax definition concrete syntax abstract syntax static semantics name binding type system dynamic semantics translation interpretation
  • 6. Formal Grammars Stratego NaBL TS SDF3 ESV editor SPT tests 6 syntax definition concrete syntax abstract syntax static semantics name binding type system dynamic semantics translation interpretation
  • 7. Formal Grammars 7 P A R E N T A L ADVISORY THEORETICAL CONTENT
  • 14. Formal Grammars 13 vocabulary Σ finite, nonempty set of elements (words, letters) alphabet
  • 15. Formal Grammars 13 vocabulary Σ finite, nonempty set of elements (words, letters) alphabet string over Σ finite sequence of elements chosen from Σ word, sentence, utterance
  • 16. 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 Σ λ ⊆ Σ*
  • 18. Formal Grammars 15 formal grammar G derivation relation G formal language L(G) ⊆ Σ* L(G) = {w∈Σ* | S G * w}
  • 19. 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
  • 20. 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
  • 21. 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
  • 22. 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
  • 23. 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
  • 24. 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
  • 25. 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
  • 26. 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
  • 27. 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
  • 28. 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
  • 29. 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
  • 30. 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
  • 31. 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
  • 32. 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
  • 33. 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
  • 34. 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
  • 35. 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
  • 36. 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
  • 37. 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
  • 38. 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
  • 39. 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)
  • 40. Formal Grammars 31 formal grammars context-sensitive context-free regular
  • 41. Formal Grammars 32 formal grammar G derivation relation G formal language L(G) ⊆ Σ* L(G) = {w∈Σ* | S G * w}
  • 42. 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}
  • 43. Formal Grammars 34 formal languages context-sensitive context-free regular
  • 44. Formal Grammars 35 3 * +7 21 3 * +7 21 Exp ExpExp Exp Exp parser Derivation is about productivity. But what about parsing?
  • 46. Formal Grammars 37 word problem χL: Σ* → {0,1} w → 1, if w∈L w → 0, else theoretical computer science decidability & complexity
  • 47. 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
  • 48. 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
  • 49. 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
  • 50. Formal Grammars 38 formal grammars context-sensitive context-free regular theoretical computer science decidability & complexity
  • 51. Formal Grammars 38 formal grammars context-sensitive context-free regular theoretical computer science decidability & complexity
  • 52. Formal Grammars 38 formal grammars context-sensitive context-free regular theoretical computer science decidability & complexity
  • 53. 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
  • 54. 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
  • 55. 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
  • 56. 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
  • 57. 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
  • 58. Formal Grammars 41 3 * +7 21 3 * +7 21 Exp ExpExp Exp Exp parser The word problem is about membership. But what about structure?
  • 60. 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
  • 61. Formal Grammars 44 binary expressions tree construction 3 + *4 5
  • 62. Formal Grammars 44 binary expressions tree construction Exp 3 + *4 5
  • 63. Formal Grammars 44 binary expressions tree construction Exp Exp 3 + *4 5
  • 64. Formal Grammars 44 binary expressions tree construction Exp Exp 3 + *4 5 Exp
  • 65. Formal Grammars 44 binary expressions tree construction Exp Exp Exp 3 + *4 5 Exp
  • 66. Formal Grammars 44 binary expressions tree construction Exp Exp Exp 3 + *4 5 Exp Exp
  • 67. Formal Grammars 45 binary expressions ambiguity Exp Exp Exp 3 + *4 5 Exp Exp Exp Exp Exp 3 + *4 5 Exp Exp
  • 68. 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
  • 69. 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
  • 70. Formal Grammars 48 binary expressions parse tree & abstract syntax tree Exp Exp Exp Exp Exp (3 + *4 5 ) Exp
  • 71. 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
  • 72. Formal Grammars 49 Except where otherwise noted, this work is licensed under
  • 73. 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

Notas del editor

  1. \n
  2. \n
  3. \n
  4. \n
  5. \n
  6. \n
  7. \n
  8. \n
  9. \n
  10. \n
  11. \n
  12. expressions: binary expressions, method calls\n\nobject-orientation: classes, single inheritance, methods, no overloading\n
  13. \n
  14. \n
  15. \n
  16. \n
  17. \n
  18. \n
  19. \n
  20. \n
  21. \n
  22. \n
  23. \n
  24. \n
  25. \n
  26. property of language\n\nsay what no-one said before\n\nholds for software languages as well\n
  27. scientific challenge\n
  28. \n
  29. linguistic theory\n\nNoam Chomsky\n
  30. linguistic theory\n\nNoam Chomsky\n
  31. linguistic theory\n\nNoam Chomsky\n
  32. restrictions on production rules => grammar classes\n
  33. restrictions on production rules => grammar classes\n
  34. restrictions on production rules => grammar classes\n
  35. restrictions on production rules => grammar classes\n
  36. restrictions on production rules => grammar classes\n
  37. restrictions on production rules => grammar classes\n
  38. restrictions on production rules => grammar classes\n
  39. restrictions on production rules => grammar classes\n
  40. computer science: lexical syntax\n\ncan write this as a regular grammar\n
  41. computer science: lexical syntax\n\ncan write this as a regular grammar\n
  42. computer science: lexical syntax\n\ncan write this as a regular grammar\n
  43. computer science: lexical syntax\n\ncan write this as a regular grammar\n
  44. computer science: lexical syntax\n\ncan write this as a regular grammar\n
  45. computer science: lexical syntax\n\ncan write this as a regular grammar\n
  46. computer science: lexical syntax\n\ncan write this as a regular grammar\n
  47. computer science: lexical syntax\n\ncan write this as a regular grammar\n
  48. computer science: lexical syntax\n\ncan write this as a regular grammar\n
  49. computer science: lexical syntax\n\ncan write this as a regular grammar\n
  50. computer science: lexical syntax\n\ncan write this as a regular grammar\n
  51. computer science: lexical syntax\n\ncan write this as a regular grammar\n
  52. generative device\n
  53. generative device\n
  54. generative device\n
  55. generative device\n
  56. generative device\n
  57. generative device\n
  58. generative device\n
  59. generative device\n
  60. generative device\n
  61. generative device\n
  62. generative device\n
  63. generative device\n
  64. generative device\n
  65. generative device\n
  66. generative device\n
  67. generative device\n
  68. generative device\n
  69. generative device\n
  70. generative device\n
  71. generative device\n
  72. generative device\n
  73. generative device\n
  74. generative device\n
  75. generative device\n
  76. generative device\n
  77. generative device\n
  78. generative device\n
  79. generative device\n
  80. generative device\n
  81. generative device\n
  82. generative device\n
  83. generative device\n
  84. generative device\n
  85. other derivations possible\n
  86. other derivations possible\n
  87. other derivations possible\n
  88. other derivations possible\n
  89. other derivations possible\n
  90. other derivations possible\n
  91. other derivations possible\n
  92. other derivations possible\n
  93. other derivations possible\n
  94. other derivations possible\n
  95. other derivations possible\n
  96. other derivations possible\n
  97. other derivations possible\n
  98. other derivations possible\n
  99. other derivations possible\n
  100. other derivations possible\n
  101. other derivations possible\n
  102. other derivations possible\n
  103. other derivations possible\n
  104. other derivations possible\n
  105. other derivations possible\n
  106. other derivations possible\n
  107. other derivations possible\n
  108. other derivations possible\n
  109. other derivations possible\n
  110. other derivations possible\n
  111. other derivations possible\n
  112. other derivations possible\n
  113. other derivations possible\n
  114. other derivations possible\n
  115. other derivations possible\n
  116. other derivations possible\n
  117. other derivations possible\n
  118. \n
  119. \n
  120. \n
  121. \n
  122. \n
  123. \n
  124. \n
  125. \n
  126. \n
  127. \n
  128. \n
  129. \n
  130. \n
  131. \n
  132. \n
  133. \n
  134. \n
  135. \n
  136. \n
  137. \n
  138. \n
  139. \n
  140. \n
  141. \n
  142. \n
  143. \n
  144. \n
  145. \n
  146. \n
  147. \n
  148. \n
  149. \n
  150. \n
  151. \n
  152. \n
  153. \n
  154. \n
  155. \n
  156. \n
  157. \n
  158. \n
  159. \n
  160. \n
  161. \n
  162. \n
  163. \n
  164. \n
  165. \n
  166. \n
  167. \n
  168. \n
  169. \n
  170. \n
  171. \n
  172. \n
  173. \n
  174. \n
  175. \n
  176. \n
  177. \n
  178. \n
  179. \n
  180. \n
  181. \n
  182. \n
  183. \n
  184. \n
  185. \n
  186. \n
  187. \n
  188. \n
  189. \n
  190. \n
  191. \n
  192. \n
  193. \n
  194. \n
  195. \n
  196. \n
  197. \n
  198. \n
  199. \n
  200. \n
  201. \n
  202. \n
  203. \n
  204. \n
  205. \n
  206. \n
  207. \n
  208. \n
  209. \n
  210. \n
  211. \n
  212. \n
  213. \n
  214. \n
  215. \n
  216. \n
  217. \n
  218. \n
  219. \n
  220. \n
  221. \n
  222. \n
  223. \n
  224. \n
  225. X* for zero or more X\n\nempty word\n\nbut no construct for separated repetition\n
  226. \n
  227. \n
  228. \n
  229. \n
  230. \n
  231. \n
  232. \n
  233. \n
  234. \n
  235. \n
  236. \n
  237. \n
  238. \n
  239. \n
  240. \n
  241. \n
  242. \n
  243. \n
  244. \n
  245. \n
  246. \n
  247. \n
  248. \n
  249. \n
  250. \n
  251. \n
  252. \n
  253. \n
  254. \n
  255. \n
  256. All actual, detailed work on assignments must be individual work. \nYou are encouraged to discuss assignments, programming languages used to solve the assignments, their libraries, and general solution techniques in these languages with each other. \nBut if you do so, then you must acknowledge the people with whom you discussed at the top of your submission. \nYou should not look for assignment solutions elsewhere; but if material is taken from elsewhere, then you must acknowledge it. \n\nYou are not permitted to provide or receive any kind of solutions of assignments. \nThis includes partial, incomplete, or erroneous solutions. \nYou are also not permitted to provide or receive programming help from people other than the teaching assistants or the instructor of the course.\n\n
  257. any kind of solution: an algorithm, code, intermediate solutions\nplagiarism: copying from others, from the web, mimic another ones solution \n\nAny violation of these rules will be reported as a suspected case of fraud to the Board of Examiners and handled according to the EEMCS Faculty's fraud procedure. \nIf the case is proven, a penalty will be imposed: a minimum of exclusion from the course for the duration of one academic year up to a maximum of a one-year exclusion form all courses at TU Delft. \nFor details on the procedure, see Section 2.1.26 in the faculty's Study Guide for MSc Programmes.\n
  258. \n
  259. \n
  260. \n
  261. \n
  262. \n
  263. \n
  264. \n
  265. \n
  266. \n
  267. round-up on every lecture\n\nwhat to take with you\n\ncheck yourself, pre- and post-paration\n
  268. \n
  269. \n