pure and declarative syntax definition: paradise lost and regained

194
Pure and Declarative Syntax Definition: Paradise Lost and Regained Lennart Kats Eelco Visser Guido Wachsmuth Delft University of Technology

Upload: guido-wachsmuth

Post on 21-Nov-2014

1.516 views

Category:

Education


0 download

DESCRIPTION

These are the slides from the presentation of our Onward! 2010 essay "Pure and Declarative Syntax Definition: Paradise Lost and Regained" at SPLASH.

TRANSCRIPT

Page 1: Pure and Declarative Syntax Definition: Paradise Lost and Regained

Pure and Declarative Syntax Definition:

Paradise Lost and Regained

Lennart Kats Eelco Visser Guido Wachsmuth

Delft University of Technology

Page 2: Pure and Declarative Syntax Definition: Paradise Lost and Regained
Page 3: Pure and Declarative Syntax Definition: Paradise Lost and Regained

PARADISE

Page 4: Pure and Declarative Syntax Definition: Paradise Lost and Regained

PARADISE LOST

Page 5: Pure and Declarative Syntax Definition: Paradise Lost and Regained

PARADISE REGAINED

Page 6: Pure and Declarative Syntax Definition: Paradise Lost and Regained

PARADISE DENIED

Page 7: Pure and Declarative Syntax Definition: Paradise Lost and Regained

PARADISE

Page 8: Pure and Declarative Syntax Definition: Paradise Lost and Regained

WORDS

Page 9: Pure and Declarative Syntax Definition: Paradise Lost and Regained

TREES

Page 10: Pure and Declarative Syntax Definition: Paradise Lost and Regained

GRAMMARS

Page 11: Pure and Declarative Syntax Definition: Paradise Lost and Regained

LANGUAGE ENGINEERS

Page 12: Pure and Declarative Syntax Definition: Paradise Lost and Regained

LANGUAGES

Page 13: Pure and Declarative Syntax Definition: Paradise Lost and Regained

GRAMMARS

Page 14: Pure and Declarative Syntax Definition: Paradise Lost and Regained

NATURAL

Page 15: Pure and Declarative Syntax Definition: Paradise Lost and Regained

PURE

Page 16: Pure and Declarative Syntax Definition: Paradise Lost and Regained

BEAUTIFUL

Page 17: Pure and Declarative Syntax Definition: Paradise Lost and Regained

SOFTWARE ENGINEERS

Page 18: Pure and Declarative Syntax Definition: Paradise Lost and Regained

LANGUAGE SOFTWARE

Page 19: Pure and Declarative Syntax Definition: Paradise Lost and Regained

NATURAL

NOT

Page 20: Pure and Declarative Syntax Definition: Paradise Lost and Regained

PURE

NOT

Page 21: Pure and Declarative Syntax Definition: Paradise Lost and Regained

BEAUTIFUL

NOT

Page 22: Pure and Declarative Syntax Definition: Paradise Lost and Regained

SYNTAX DEFINITIONS

Page 23: Pure and Declarative Syntax Definition: Paradise Lost and Regained

NATURAL

Page 24: Pure and Declarative Syntax Definition: Paradise Lost and Regained

PURE

Page 25: Pure and Declarative Syntax Definition: Paradise Lost and Regained

BEAUTIFUL

Page 26: Pure and Declarative Syntax Definition: Paradise Lost and Regained

THE FALL

Page 27: Pure and Declarative Syntax Definition: Paradise Lost and Regained

PARSER DEFINITIONS

Page 28: Pure and Declarative Syntax Definition: Paradise Lost and Regained

PARADISE LOST

Page 29: Pure and Declarative Syntax Definition: Paradise Lost and Regained

PAIN

Page 30: Pure and Declarative Syntax Definition: Paradise Lost and Regained

SWEAT

Page 31: Pure and Declarative Syntax Definition: Paradise Lost and Regained

NATURAL

NOT

Page 32: Pure and Declarative Syntax Definition: Paradise Lost and Regained

PURE

NOT

Page 33: Pure and Declarative Syntax Definition: Paradise Lost and Regained

BEAUTIFUL

NOT

Page 34: Pure and Declarative Syntax Definition: Paradise Lost and Regained

THE PLAGUES

Page 35: Pure and Declarative Syntax Definition: Paradise Lost and Regained

context-free grammars

LR(k)

LR(1)

LALR(1)

SLR

LR(0)

LL(k)

LL(1)

LL(0)

GRAMMAR CLASSES

Page 36: Pure and Declarative Syntax Definition: Paradise Lost and Regained

DISAMBIGUATION

Page 37: Pure and Declarative Syntax Definition: Paradise Lost and Regained

LEXICAL SYNTAX

Page 38: Pure and Declarative Syntax Definition: Paradise Lost and Regained

TREE CONSTRUCTION

Page 39: Pure and Declarative Syntax Definition: Paradise Lost and Regained

EVOLUTION

Page 40: Pure and Declarative Syntax Definition: Paradise Lost and Regained

COMPOSITION

Page 41: Pure and Declarative Syntax Definition: Paradise Lost and Regained

RESTRICTION TO PARSERS

Page 42: Pure and Declarative Syntax Definition: Paradise Lost and Regained
Page 43: Pure and Declarative Syntax Definition: Paradise Lost and Regained

PARADISE

Page 44: Pure and Declarative Syntax Definition: Paradise Lost and Regained

WORDS WERE MADE THROUGH

GRAMMARS

Page 45: Pure and Declarative Syntax Definition: Paradise Lost and Regained

GRAMMARS

Page 46: Pure and Declarative Syntax Definition: Paradise Lost and Regained

Num ➝ Digit NumNum ➝ DigitDigit ➝ “0”Digit ➝ “1”

Page 47: Pure and Declarative Syntax Definition: Paradise Lost and Regained

Num ➝ Digit NumNum ➝ DigitDigit ➝ “0”Digit ➝ “1”

production rules

Page 48: Pure and Declarative Syntax Definition: Paradise Lost and Regained

Num ➝ Digit NumNum ➝ DigitDigit ➝ “0”Digit ➝ “1”

terminal symbolsproduction rules

Page 49: Pure and Declarative Syntax Definition: Paradise Lost and Regained

Num ➝ Digit NumNum ➝ DigitDigit ➝ “0”Digit ➝ “1”

nonterminal symbolsterminal symbolsproduction rules

Page 50: Pure and Declarative Syntax Definition: Paradise Lost and Regained

Num ➝ Digit NumNum ➝ DigitDigit ➝ “0”Digit ➝ “1”

nonterminal symbolsterminal symbolsproduction rules

start symbol

Page 51: Pure and Declarative Syntax Definition: Paradise Lost and Regained

WORDS

Page 52: Pure and Declarative Syntax Definition: Paradise Lost and Regained

Num

Page 53: Pure and Declarative Syntax Definition: Paradise Lost and Regained

NumDigit Num

Num ➝ Digit Num

Page 54: Pure and Declarative Syntax Definition: Paradise Lost and Regained

NumDigit NumDigit Digit

Num ➝ Digit NumNum ➝ Digit

Page 55: Pure and Declarative Syntax Definition: Paradise Lost and Regained

NumDigit NumDigit DigitDigit 0

Num ➝ Digit NumNum ➝ DigitDigit ➝ “0”

Page 56: Pure and Declarative Syntax Definition: Paradise Lost and Regained

NumDigit NumDigit DigitDigit 01 0

Num ➝ Digit NumNum ➝ DigitDigit ➝ “0”Digit ➝ “1”

Page 57: Pure and Declarative Syntax Definition: Paradise Lost and Regained

SENTENCES

Page 58: Pure and Declarative Syntax Definition: Paradise Lost and Regained

Exp ➝ Exp “+” ExpExp ➝ Exp “*” ExpExp ➝ Num

production rules

Page 59: Pure and Declarative Syntax Definition: Paradise Lost and Regained

Exp ➝ Exp “+” ExpExp ➝ Exp “*” ExpExp ➝ Num

terminal symbolsproduction rules

Page 60: Pure and Declarative Syntax Definition: Paradise Lost and Regained

Exp ➝ Exp “+” ExpExp ➝ Exp “*” ExpExp ➝ Num

nonterminal symbolsterminal symbolsproduction rules

Page 61: Pure and Declarative Syntax Definition: Paradise Lost and Regained

Exp ➝ Exp “+” ExpExp ➝ Exp “*” ExpExp ➝ Num

nonterminal symbolsterminal symbolsproduction rules

start symbol

Page 62: Pure and Declarative Syntax Definition: Paradise Lost and Regained

Exp

Page 63: Pure and Declarative Syntax Definition: Paradise Lost and Regained

ExpExp + Exp

Exp ➝ Exp “+” Exp

Page 64: Pure and Declarative Syntax Definition: Paradise Lost and Regained

ExpExp + ExpExp * Exp + Exp

Exp ➝ Exp “+” ExpExp ➝ Exp “*” Exp

Page 65: Pure and Declarative Syntax Definition: Paradise Lost and Regained

ExpExp + ExpExp * Exp + Exp3 * Exp + Exp

Exp ➝ Exp “+” ExpExp ➝ Exp “*” ExpExp ➝ Num

Page 66: Pure and Declarative Syntax Definition: Paradise Lost and Regained

ExpExp + ExpExp * Exp + Exp3 * Exp + Exp3 * 7 + Exp

Exp ➝ Exp “+” ExpExp ➝ Exp “*” ExpExp ➝ NumExp ➝ Num

Page 67: Pure and Declarative Syntax Definition: Paradise Lost and Regained

ExpExp + ExpExp * Exp + Exp3 * Exp + Exp3 * 7 + Exp3 * 7 + 21

Exp ➝ Exp “+” ExpExp ➝ Exp “*” ExpExp ➝ NumExp ➝ NumExp ➝ Num

Page 68: Pure and Declarative Syntax Definition: Paradise Lost and Regained

THEY MADE LANGUAGESBY MAKING GRAMMARS

Page 69: Pure and Declarative Syntax Definition: Paradise Lost and Regained

GRAMMAR

Page 70: Pure and Declarative Syntax Definition: Paradise Lost and Regained

LANGUAGE

Page 71: Pure and Declarative Syntax Definition: Paradise Lost and Regained

TRUTH

Page 72: Pure and Declarative Syntax Definition: Paradise Lost and Regained

Exp ➝ Exp “+” ExpExp ➝ Exp “*” ExpExp ➝ Num

Exp “+” Exp ➝ ExpExp “*” Exp ➝ Exp

Num ➝ Exp

productive reductive

Page 73: Pure and Declarative Syntax Definition: Paradise Lost and Regained

3 * 7 + 21

Page 74: Pure and Declarative Syntax Definition: Paradise Lost and Regained

3 * 7 + 21 3 * 7 + Exp

Num ➝ Exp

Page 75: Pure and Declarative Syntax Definition: Paradise Lost and Regained

3 * 7 + 21 3 * 7 + Exp 3 * Exp + Exp

Num ➝ ExpNum ➝ Exp

Page 76: Pure and Declarative Syntax Definition: Paradise Lost and Regained

3 * 7 + 21 3 * 7 + Exp 3 * Exp + Exp Exp * Exp + Exp

Num ➝ ExpNum ➝ ExpNum ➝ Exp

Page 77: Pure and Declarative Syntax Definition: Paradise Lost and Regained

3 * 7 + 21 3 * 7 + Exp 3 * Exp + Exp Exp * Exp + ExpExp + Exp

Num ➝ ExpNum ➝ ExpNum ➝ Exp

Exp “*” Exp ➝ Exp

Page 78: Pure and Declarative Syntax Definition: Paradise Lost and Regained

3 * 7 + 21 3 * 7 + Exp 3 * Exp + Exp Exp * Exp + ExpExp + Exp Exp

Num ➝ ExpNum ➝ ExpNum ➝ Exp

Exp “*” Exp ➝ ExpExp “+” Exp ➝ Exp

Page 79: Pure and Declarative Syntax Definition: Paradise Lost and Regained

THEY TURNED WORDS INTO

TREES

Page 80: Pure and Declarative Syntax Definition: Paradise Lost and Regained

SENTENCES

Page 81: Pure and Declarative Syntax Definition: Paradise Lost and Regained

STRUCTURE

Page 82: Pure and Declarative Syntax Definition: Paradise Lost and Regained

Exp ➝ Exp “+” ExpExp ➝ Exp “*” ExpExp ➝ Num

Exp “+” Exp ➝ ExpExp “*” Exp ➝ Exp

Num ➝ Exp

productive reductive

Page 83: Pure and Declarative Syntax Definition: Paradise Lost and Regained

Exp

Num

Exp

+Exp Exp

Exp

*Exp Exp

tree construction

Page 84: Pure and Declarative Syntax Definition: Paradise Lost and Regained

3 * +7 21

Page 85: Pure and Declarative Syntax Definition: Paradise Lost and Regained

Exp Exp

3 * +7 21

Exp

Exp

Num

Page 86: Pure and Declarative Syntax Definition: Paradise Lost and Regained

Exp

Exp

Exp

3 * +7 21

Exp

Exp

+Exp Exp

Exp

*Exp Exp

Page 87: Pure and Declarative Syntax Definition: Paradise Lost and Regained

Exp

Exp

Exp

3 * +7 21

Exp

Exp

Exp

+Exp Exp

Page 88: Pure and Declarative Syntax Definition: Paradise Lost and Regained

ONE FORMALISM

Page 89: Pure and Declarative Syntax Definition: Paradise Lost and Regained

THREE READINGS

Page 90: Pure and Declarative Syntax Definition: Paradise Lost and Regained

PURE

Page 91: Pure and Declarative Syntax Definition: Paradise Lost and Regained

DECLARATIVE

Page 92: Pure and Declarative Syntax Definition: Paradise Lost and Regained

BEAUTIFUL

Page 93: Pure and Declarative Syntax Definition: Paradise Lost and Regained

PARADISE LOST

Page 94: Pure and Declarative Syntax Definition: Paradise Lost and Regained

EFFICIENCY

Page 95: Pure and Declarative Syntax Definition: Paradise Lost and Regained

THE FIRST PLAGUE WERE

GRAMMAR CLASSES

Page 96: Pure and Declarative Syntax Definition: Paradise Lost and Regained

context-free grammars

Page 97: Pure and Declarative Syntax Definition: Paradise Lost and Regained

context-free grammars

LL(0)

Page 98: Pure and Declarative Syntax Definition: Paradise Lost and Regained

context-free grammars

LL(1)

LL(0)

Page 99: Pure and Declarative Syntax Definition: Paradise Lost and Regained

context-free grammars

LL(k)

LL(1)

LL(0)

Page 100: Pure and Declarative Syntax Definition: Paradise Lost and Regained

context-free grammars

LR(0)

LL(k)

LL(1)

LL(0)

Page 101: Pure and Declarative Syntax Definition: Paradise Lost and Regained

context-free grammars

LR(1)

LR(0)

LL(k)

LL(1)

LL(0)

Page 102: Pure and Declarative Syntax Definition: Paradise Lost and Regained

context-free grammars

LR(k)

LR(1)

LR(0)

LL(k)

LL(1)

LL(0)

Page 103: Pure and Declarative Syntax Definition: Paradise Lost and Regained

context-free grammars

LR(k)

LR(1)

SLR

LR(0)

LL(k)

LL(1)

LL(0)

Page 104: Pure and Declarative Syntax Definition: Paradise Lost and Regained

context-free grammars

LR(k)

LR(1)

LALR(1)

SLR

LR(0)

LL(k)

LL(1)

LL(0)

Page 105: Pure and Declarative Syntax Definition: Paradise Lost and Regained

Exp “+” Exp ➝ ExpExp “*” Exp ➝ Exp

Num ➝ Exp

Term (“+” Term)* ➝ ExpFact (“*” Fact)* ➝ Term

Num ➝ Fact

paradise grammar classes

Page 106: Pure and Declarative Syntax Definition: Paradise Lost and Regained

Exp

Exp

Exp

3 + +7 21

Exp

Exp

paradise grammar classes

Fact Fact

3 + +7 21

Fact

*

Exp

Term Term Term

*

Page 107: Pure and Declarative Syntax Definition: Paradise Lost and Regained

THE SECOND PLAGUE WAS

DISAMBIGUATION

Page 108: Pure and Declarative Syntax Definition: Paradise Lost and Regained

Exp

Exp

Exp

3 * +7 21

Exp

Exp

Exp

Exp

Exp

3 * +7 21

Exp

Exp

Page 109: Pure and Declarative Syntax Definition: Paradise Lost and Regained

text books

precedence operators associativity

1 ( ), [ ] non-associative

2 new non-associative

3 . left-associative

4 ++, -- non-associative

5 -, +, !, ~, ++, --, (type) right-associative

6 *, /, % left-associative

7 +, - left-associative

… … …

Page 110: Pure and Declarative Syntax Definition: Paradise Lost and Regained

context-free grammars

LR(k)

LR(1)

LALR(1)

SLR

LR(0)

LL(k)

LL(1)

LL(0)

Page 111: Pure and Declarative Syntax Definition: Paradise Lost and Regained

context-free grammars

unambigous

LR(k)

LR(1)

LALR(1)

SLR

LR(0)

LL(k)

LL(1)

LL(0)

Page 112: Pure and Declarative Syntax Definition: Paradise Lost and Regained

Exp “+” Term ➝ ExpTerm ➝ Exp

Term “*” Fact ➝ Term Fact ➝ TermNum ➝ Fact

grammar classes

Page 113: Pure and Declarative Syntax Definition: Paradise Lost and Regained

FALSE PROPHETS

Page 114: Pure and Declarative Syntax Definition: Paradise Lost and Regained

“a” “b” ➝ A“a” ➝ A

“a” “b” / “a” ➝ A

paradise PEGs

L = {ab, a} L = {ab, a}

Page 115: Pure and Declarative Syntax Definition: Paradise Lost and Regained

“a” ➝ A “a” “b” ➝ A

“a” / “a” “b” ➝ A

paradise PEGs

L = {ab, a} L = {a}

Page 116: Pure and Declarative Syntax Definition: Paradise Lost and Regained

if c1 then if c2 then s1 else s2

dangling else

Page 117: Pure and Declarative Syntax Definition: Paradise Lost and Regained

“if ” E “then” S “else” S / “if ” E “then” S ➝ S

“if ” E “then” S / “if ” E “then” S “else” S ➝ S

PEGs

Page 118: Pure and Declarative Syntax Definition: Paradise Lost and Regained

THE THIRD PLAGUE WAS

LEXICAL SYNTAX

Page 119: Pure and Declarative Syntax Definition: Paradise Lost and Regained

morphology & syntax

Page 120: Pure and Declarative Syntax Definition: Paradise Lost and Regained

limited look-ahead

LR(k)

LR(1)

LALR(1)

SLR

LR(0)

LL(k)

LL(1)

LL(0)

Page 121: Pure and Declarative Syntax Definition: Paradise Lost and Regained

scanners

Page 122: Pure and Declarative Syntax Definition: Paradise Lost and Regained

3 * +7 21

Page 123: Pure and Declarative Syntax Definition: Paradise Lost and Regained

3 * +7 21

Page 124: Pure and Declarative Syntax Definition: Paradise Lost and Regained

parsers

Page 125: Pure and Declarative Syntax Definition: Paradise Lost and Regained

3 * +7 21

Page 126: Pure and Declarative Syntax Definition: Paradise Lost and Regained

Exp

Exp

Exp

3 * +7 21

Exp

Exp

Page 127: Pure and Declarative Syntax Definition: Paradise Lost and Regained

array [ ..1 10 ] integerof

x = *1. .10

y :

Page 128: Pure and Declarative Syntax Definition: Paradise Lost and Regained

array [ ..1 10 ] integerof

x = *1. .10

y :

Page 129: Pure and Declarative Syntax Definition: Paradise Lost and Regained

array [ 1. .10 ] integerof

x = *1. .10

y :

Page 130: Pure and Declarative Syntax Definition: Paradise Lost and Regained

THE FOURTH PLAGUE WAS

TREE CONSTRUCTION

Page 131: Pure and Declarative Syntax Definition: Paradise Lost and Regained

Exp

Exp

Exp

3 + +7 21

Exp

Exp

Const

Add

Const

3 7 21

Const

Add

paradise

Page 132: Pure and Declarative Syntax Definition: Paradise Lost and Regained

Const

Add

Const

3 7 21

Const

Add

Fact Fact

3 + +7 21

Fact

*

Exp

Term Term Term

*

grammar classes

Page 133: Pure and Declarative Syntax Definition: Paradise Lost and Regained

expr: INTEGER { $$ = con($1); }| expr '+' expr { $$ = opr('+', 2, $1, $3);}| expr '*' expr { $$ = opr('*', 2, $1, $3);};

semantic actions

Page 134: Pure and Declarative Syntax Definition: Paradise Lost and Regained

THE FIFTH PLAGUE WAS

EVOLUTION

Page 135: Pure and Declarative Syntax Definition: Paradise Lost and Regained

Exp “+” Exp ➝ ExpExp “*” Exp ➝ Exp

Num ➝ Exp

Exp “+” Term ➝ ExpTerm ➝ Exp

Term “*” Fact ➝ Term Fact ➝ TermNum ➝ Fact

paradise grammar classes

Page 136: Pure and Declarative Syntax Definition: Paradise Lost and Regained

Exp “+” Exp ➝ ExpExp “*” Exp ➝ Exp

Num ➝ Exp

Exp “=” Exp ➝ ExpExp “<” Exp ➝ ExpExp “>” Exp ➝ Exp

CExp “+” Term ➝ CExpTerm ➝ CExp

Term “*” Fact ➝ Term Fact ➝ TermNum ➝ Fact

Exp “=” CExp ➝ ExpExp “<” CExp ➝ ExpExp “>” CExp ➝ Exp

CExp ➝ Exp

paradise grammar classes

Page 137: Pure and Declarative Syntax Definition: Paradise Lost and Regained

THE SIXTH PLAGUE WAS

COMPOSITION

Page 138: Pure and Declarative Syntax Definition: Paradise Lost and Regained

parsers

Page 139: Pure and Declarative Syntax Definition: Paradise Lost and Regained

context-free grammars

LR(k)

LR(1)

LALR(1)

SLR

LR(0)

LL(k)

LL(1)

LL(0)

Page 140: Pure and Declarative Syntax Definition: Paradise Lost and Regained

context-free grammars

LR(k)

LR(1)

LALR(1)

SLR

LR(0)

LL(k)

LL(1)

LL(0)

Page 141: Pure and Declarative Syntax Definition: Paradise Lost and Regained

context-free grammars

LR(k)

LR(1)

LALR(1)

SLR

LR(0)

LL(k)

LL(1)

LL(0)

Page 142: Pure and Declarative Syntax Definition: Paradise Lost and Regained

context-free grammars

LR(k)

LR(1)

LALR(1)

SLR

LR(0)

LL(k)

LL(1)

LL(0)

Page 143: Pure and Declarative Syntax Definition: Paradise Lost and Regained

scanners

Page 144: Pure and Declarative Syntax Definition: Paradise Lost and Regained

public boolean authenticate(String user, String pw) {

SQL stm = <| SELECT id FROM Users WHERE name = ${user} AND password = ${pw} |>;

return executeQuery(stm).size() != 0;}

Page 145: Pure and Declarative Syntax Definition: Paradise Lost and Regained

THE SEVENTH PLAGUE WAS

RESTRICTION TO

PARSERS

Page 146: Pure and Declarative Syntax Definition: Paradise Lost and Regained

PRETTY PRINTERS

Page 147: Pure and Declarative Syntax Definition: Paradise Lost and Regained

SENTENCE GENERATORS

Page 148: Pure and Declarative Syntax Definition: Paradise Lost and Regained

AST ACCESS

Page 149: Pure and Declarative Syntax Definition: Paradise Lost and Regained

IDE SUPPORT

Page 150: Pure and Declarative Syntax Definition: Paradise Lost and Regained

PARADISE REGAINED

Page 151: Pure and Declarative Syntax Definition: Paradise Lost and Regained

GENERALISED

PARSING

Page 152: Pure and Declarative Syntax Definition: Paradise Lost and Regained

context-free grammars

LR(k)

LR(1)

LALR(1)

SLR

LR(0)

LL(k)

LL(1)

LL(0)

Page 153: Pure and Declarative Syntax Definition: Paradise Lost and Regained

context-free grammars

Page 154: Pure and Declarative Syntax Definition: Paradise Lost and Regained

paradise SDF

context-free syntax

Exp "+" Exp -> Exp Exp "*" Exp -> Exp NUM -> Exp

Exp “+” Exp ➝ ExpExp “*” Exp ➝ Exp

Num ➝ Exp

Page 155: Pure and Declarative Syntax Definition: Paradise Lost and Regained

DECLARATIVE

DISAMBIGUATION

Page 156: Pure and Declarative Syntax Definition: Paradise Lost and Regained

context-free grammars

unambigous

LR(k)

LR(1)

LALR(1)

SLR

LR(0)

LL(k)

LL(1)

LL(0)

Page 157: Pure and Declarative Syntax Definition: Paradise Lost and Regained

context-free grammars

unambigous

Page 158: Pure and Declarative Syntax Definition: Paradise Lost and Regained

context-free grammars

Page 159: Pure and Declarative Syntax Definition: Paradise Lost and Regained

text books

precedence operators associativity

1 ( ), [ ] non-associative

2 new non-associative

3 . left-associative

4 ++, -- non-associative

5 -, +, !, ~, ++, --, (type) right-associative

6 *, /, % left-associative

7 +, - left-associative

… … …

Page 160: Pure and Declarative Syntax Definition: Paradise Lost and Regained

context-free priorities Exp "*" Exp -> Exp {left}> Exp "+" Exp -> Exp {left}

Page 161: Pure and Declarative Syntax Definition: Paradise Lost and Regained

context-free syntax "if" E "then" S -> S {prefer} "if" E "then" S "else" S -> S

Page 162: Pure and Declarative Syntax Definition: Paradise Lost and Regained

SCANNERLESS

PARSING

Page 163: Pure and Declarative Syntax Definition: Paradise Lost and Regained

morphology & syntax

Page 164: Pure and Declarative Syntax Definition: Paradise Lost and Regained

lexical syntax [0-9]+ -> NUM

[\ \t\n] -> LAYOUT "//" ~[\n]* [\n] -> LAYOUT

Page 165: Pure and Declarative Syntax Definition: Paradise Lost and Regained

parser

Page 166: Pure and Declarative Syntax Definition: Paradise Lost and Regained

parser

Page 167: Pure and Declarative Syntax Definition: Paradise Lost and Regained

DECLARATIVE

TREE CONSTRUCTION

Page 168: Pure and Declarative Syntax Definition: Paradise Lost and Regained

Exp

Exp

Exp

3 + +7 21

Exp

Exp

Const

Add

Const

3 7 21

Const

Add

paradise

Page 169: Pure and Declarative Syntax Definition: Paradise Lost and Regained

SDF

context-free syntax Exp "+" Exp -> Exp {cons("Add")} Exp "*" Exp -> Exp {cons("Mul")} NUM -> Exp {cons("Const")}

Page 170: Pure and Declarative Syntax Definition: Paradise Lost and Regained

Const

Add

Const

3 7 21

Const

Add

paradise SDF

Add( Add( Const("3"), Const("7") ), Const("21"))

Page 171: Pure and Declarative Syntax Definition: Paradise Lost and Regained

SEAMLESS

EVOLUTION

Page 172: Pure and Declarative Syntax Definition: Paradise Lost and Regained

context-free syntax Exp "+" Exp -> Exp {cons("Add")} Exp "*" Exp -> Exp {cons("Mul")} NUM -> Exp {cons("Const")} Exp "=" Exp -> Exp {cons("Eq")} Exp ">" Exp -> Exp {cons("Gt")} Exp "<" Exp -> Exp {cons("Lt")}

Page 173: Pure and Declarative Syntax Definition: Paradise Lost and Regained

MODULAR

COMPOSITION

Page 174: Pure and Declarative Syntax Definition: Paradise Lost and Regained

context-free grammars

LR(k)

LR(1)

LALR(1)

SLR

LR(0)

LL(k)

LL(1)

LL(0)

Page 175: Pure and Declarative Syntax Definition: Paradise Lost and Regained

context-free grammars

Page 176: Pure and Declarative Syntax Definition: Paradise Lost and Regained

public boolean authenticate(String user, String pw) {

SQL stm = <| SELECT id FROM Users WHERE name = ${user} AND password = ${pw} |>;

return executeQuery(stm).size() != 0;}

Page 177: Pure and Declarative Syntax Definition: Paradise Lost and Regained

module Java-SQL imports Java SQL

exports context-free syntax

"<|" Query "|>" -> Exp {cons("ToSQL")} "${" Exp "}" -> SqlExp {cons("FromSQL")}

Page 178: Pure and Declarative Syntax Definition: Paradise Lost and Regained

BEYOND

PARSERS

Page 179: Pure and Declarative Syntax Definition: Paradise Lost and Regained

PRETTY PRINTERS

Page 180: Pure and Declarative Syntax Definition: Paradise Lost and Regained

SENTENCEGENERATORS

Page 181: Pure and Declarative Syntax Definition: Paradise Lost and Regained

AST ACCESS

Page 182: Pure and Declarative Syntax Definition: Paradise Lost and Regained

IDE SUPPORT

Page 183: Pure and Declarative Syntax Definition: Paradise Lost and Regained

PARADISE DENIED

Page 184: Pure and Declarative Syntax Definition: Paradise Lost and Regained

still around

Page 185: Pure and Declarative Syntax Definition: Paradise Lost and Regained

still around

Page 186: Pure and Declarative Syntax Definition: Paradise Lost and Regained

still have to use it

Page 187: Pure and Declarative Syntax Definition: Paradise Lost and Regained

still have to learnLL, LR, SLR, LALR

Page 188: Pure and Declarative Syntax Definition: Paradise Lost and Regained

still think using parser generators is hard

Page 189: Pure and Declarative Syntax Definition: Paradise Lost and Regained

modern parser generator

Page 190: Pure and Declarative Syntax Definition: Paradise Lost and Regained

modern parser generator

Page 191: Pure and Declarative Syntax Definition: Paradise Lost and Regained

PARADISE OPEN

Page 192: Pure and Declarative Syntax Definition: Paradise Lost and Regained
Page 193: Pure and Declarative Syntax Definition: Paradise Lost and Regained

slides title author copyright

1, 2, 42 Jeremiah lamenting Rembrandt public domain

3, 7, 14-16, 19-21, 23-25, 31-33, 43, 88-92

Adam and Eve in the Garden of Eden Wenzel Peterphoto: Jonathan Linczak some rights reserved

4, 28, 93 Expulsion from the Garden of Eden Thomas Cole public domain

5, 138, 175 Livres d'heures des Étienne Chevalier Jean Fouquet public domain

6, 167 The Adoration of the Golden Calf Nicolas Poussin public domain

8, 51, 112, 131, 150 Thesaurus Enoch Lau some rights reserved

9, 79, 81 The Burmis Tree Monsieur david some rights reserved

10, 13, 22, 45, 69 Latin Grammar Anthony Nelzin some rights reserved

11, 17, 176 The Garden of Earthly Delights (centre panel) Hieronymus Bosch public domain

12, 18, 68 Programming language textbooks K.lee public domain

26 The Fall of Man Jacob Jordaens public domain

27 Illustration d'après un Bison naturalisé d'Eulalie en Margeride F Lamiot some rights reserved

29 Can't Concentrate Sasha Wolff some rights reserved

30 Cold Sweat Eric Tastad some rights reserved

34 The Fifth Plague of Egypt Joseph M. W. Turner public domain

36 Managed Destruction Harley Kingston some rights reserved

Page 194: Pure and Declarative Syntax Definition: Paradise Lost and Regained

slides title author copyright

37 Book Scanner Ben Woosley some rights reserved

38 Dead trees in the clay pan of the Deadvlei Harald Süpfle some rights reserved

39 Charles Robert Darwin John Maler Collier public domain

40 Black Lego Wallpaper monohex some rights reserved

41 Four - Nova Prospekt (Restricted) |Digressive| some rights reserved

44, 110, 148 Noam Chomsky Fellowsisters some rights reserved

57, 80, 115, 129, 151 Minuscule 798 f.41v - f.42r unknown public domain

70 Latin Bible Gerard Brilsphoto: Adrian Pingstone public domain

71 Themis and Aegeus Kodros Painterphoto: Bibi Saint-Pol public domain

94 IBM System/3 Jonathunder some rights reserved

104 Destruction of the Beast and the False Prophet Benjamin West public domain

168 lex & yacc O’Reilly all rights reserved

169 flex & bison O’Reilly all rights reserved

170-172 Students TU Delft Media Services all rights reserved

173 ANTLR The Pragmatic Bookshelf all rights reserved

174 Xtext all rights reserved