A RecognitionBased Syntactic Foundationvganesh/TEACHING/S2014/ECE351/lectures... · Designing a...
Transcript of A RecognitionBased Syntactic Foundationvganesh/TEACHING/S2014/ECE351/lectures... · Designing a...
![Page 1: A RecognitionBased Syntactic Foundationvganesh/TEACHING/S2014/ECE351/lectures... · Designing a Language Syntax 1.Formalize syntax via contextfree grammar 2.Write a YACC parser specification](https://reader031.fdocuments.us/reader031/viewer/2022022017/5b7fc73a7f8b9ad9778c8a1e/html5/thumbnails/1.jpg)
Parsing Expression Grammars:A RecognitionBased Syntactic Foundation
Bryan FordMassachusetts Institute of Technology
January 14, 2004
![Page 2: A RecognitionBased Syntactic Foundationvganesh/TEACHING/S2014/ECE351/lectures... · Designing a Language Syntax 1.Formalize syntax via contextfree grammar 2.Write a YACC parser specification](https://reader031.fdocuments.us/reader031/viewer/2022022017/5b7fc73a7f8b9ad9778c8a1e/html5/thumbnails/2.jpg)
Designing a Language Syntax
![Page 3: A RecognitionBased Syntactic Foundationvganesh/TEACHING/S2014/ECE351/lectures... · Designing a Language Syntax 1.Formalize syntax via contextfree grammar 2.Write a YACC parser specification](https://reader031.fdocuments.us/reader031/viewer/2022022017/5b7fc73a7f8b9ad9778c8a1e/html5/thumbnails/3.jpg)
Designing a Language Syntax
1.Formalize syntax via contextfree grammar
2.Write a YACC parser specification
3.Hack on grammar until “ nearLALR(1)”
4.Use generated parser
Textbook Method
![Page 4: A RecognitionBased Syntactic Foundationvganesh/TEACHING/S2014/ECE351/lectures... · Designing a Language Syntax 1.Formalize syntax via contextfree grammar 2.Write a YACC parser specification](https://reader031.fdocuments.us/reader031/viewer/2022022017/5b7fc73a7f8b9ad9778c8a1e/html5/thumbnails/4.jpg)
Designing a Language Syntax
1.Formalize syntax via contextfree grammar
2.Write a YACC parser specification
3.Hack on grammar until “ nearLALR(1)”
4.Use generated parser
1.Specify syntax informally
2.Write a recursive descent parser
Textbook Method Pragmatic Method
![Page 5: A RecognitionBased Syntactic Foundationvganesh/TEACHING/S2014/ECE351/lectures... · Designing a Language Syntax 1.Formalize syntax via contextfree grammar 2.Write a YACC parser specification](https://reader031.fdocuments.us/reader031/viewer/2022022017/5b7fc73a7f8b9ad9778c8a1e/html5/thumbnails/5.jpg)
What exactly does a CFG describe?
Short answer:a rule system to generate language strings
Example CFG:
S aaSS
S
aaS
aa aaaaS
...aaaa
![Page 6: A RecognitionBased Syntactic Foundationvganesh/TEACHING/S2014/ECE351/lectures... · Designing a Language Syntax 1.Formalize syntax via contextfree grammar 2.Write a YACC parser specification](https://reader031.fdocuments.us/reader031/viewer/2022022017/5b7fc73a7f8b9ad9778c8a1e/html5/thumbnails/6.jpg)
What exactly does a CFG describe?
Short answer:a rule system to generate language strings
Example CFG:
S aaSS
S
aaS
aa aaaaS
...aaaa
Start symbol
![Page 7: A RecognitionBased Syntactic Foundationvganesh/TEACHING/S2014/ECE351/lectures... · Designing a Language Syntax 1.Formalize syntax via contextfree grammar 2.Write a YACC parser specification](https://reader031.fdocuments.us/reader031/viewer/2022022017/5b7fc73a7f8b9ad9778c8a1e/html5/thumbnails/7.jpg)
What exactly does a CFG describe?
Short answer:a rule system to generate language strings
Example CFG:
S aaSS
S
aaS
aa aaaaS
...aaaa
Start symbol
Output strings
![Page 8: A RecognitionBased Syntactic Foundationvganesh/TEACHING/S2014/ECE351/lectures... · Designing a Language Syntax 1.Formalize syntax via contextfree grammar 2.Write a YACC parser specification](https://reader031.fdocuments.us/reader031/viewer/2022022017/5b7fc73a7f8b9ad9778c8a1e/html5/thumbnails/8.jpg)
What exatly do we want to describe?
Proposed answer:a rule system to recognize language strings
Parsing Expression Grammar (PEG)models recursive descent parsing practice
Example PEG:
S aaS /
a a a a
SS
Sa a
a a
![Page 9: A RecognitionBased Syntactic Foundationvganesh/TEACHING/S2014/ECE351/lectures... · Designing a Language Syntax 1.Formalize syntax via contextfree grammar 2.Write a YACC parser specification](https://reader031.fdocuments.us/reader031/viewer/2022022017/5b7fc73a7f8b9ad9778c8a1e/html5/thumbnails/9.jpg)
What exatly do we want to describe?
Proposed answer:a rule system to recognize language strings
Parsing Expression Grammar (PEG)models recursive descent parsing practice
Example PEG:
S aaS /
a a a a
SS
Sa a
a a
Inputstring
![Page 10: A RecognitionBased Syntactic Foundationvganesh/TEACHING/S2014/ECE351/lectures... · Designing a Language Syntax 1.Formalize syntax via contextfree grammar 2.Write a YACC parser specification](https://reader031.fdocuments.us/reader031/viewer/2022022017/5b7fc73a7f8b9ad9778c8a1e/html5/thumbnails/10.jpg)
What exatly do we want to describe?
Proposed answer:a rule system to recognize language strings
Parsing Expression Grammar (PEG)models recursive descent parsing practice
Example PEG:
S aaS /
a a a a
SS
Sa a
a a
Inputstring
Derivestructure
![Page 11: A RecognitionBased Syntactic Foundationvganesh/TEACHING/S2014/ECE351/lectures... · Designing a Language Syntax 1.Formalize syntax via contextfree grammar 2.Write a YACC parser specification](https://reader031.fdocuments.us/reader031/viewer/2022022017/5b7fc73a7f8b9ad9778c8a1e/html5/thumbnails/11.jpg)
TakeHome Points
Key benefits of PEGs:
● Simplicity, formalism, analyzability of CFGs
● Closer match to syntax practices
– More expressive than deterministic CFGs (LL/LR)– More of the “ right kind” of expressiveness:
prioritized choice, greedy rules, syntactic predicates
– Unlimited lookahead, backtracking
● Lineartime parsing for any PEG
![Page 12: A RecognitionBased Syntactic Foundationvganesh/TEACHING/S2014/ECE351/lectures... · Designing a Language Syntax 1.Formalize syntax via contextfree grammar 2.Write a YACC parser specification](https://reader031.fdocuments.us/reader031/viewer/2022022017/5b7fc73a7f8b9ad9778c8a1e/html5/thumbnails/12.jpg)
What kind ofrecursive descent parsing?
Key assumptions:
● Parsing functions are stateless:depend only on input string
● Parsing functions make decisions locally:return at most one result (success/failure)
![Page 13: A RecognitionBased Syntactic Foundationvganesh/TEACHING/S2014/ECE351/lectures... · Designing a Language Syntax 1.Formalize syntax via contextfree grammar 2.Write a YACC parser specification](https://reader031.fdocuments.us/reader031/viewer/2022022017/5b7fc73a7f8b9ad9778c8a1e/html5/thumbnails/13.jpg)
Parsing Expression Grammars
Consists of: (∑, N, R, eS)
– ∑: finite set of terminals (character set)– N: finite set of nonterminals
– R: finite set of rules of the form “ A e” ,where A ∈ N, e is a parsing expression.
– eS: a parsing expression called the start expression.
![Page 14: A RecognitionBased Syntactic Foundationvganesh/TEACHING/S2014/ECE351/lectures... · Designing a Language Syntax 1.Formalize syntax via contextfree grammar 2.Write a YACC parser specification](https://reader031.fdocuments.us/reader031/viewer/2022022017/5b7fc73a7f8b9ad9778c8a1e/html5/thumbnails/14.jpg)
Parsing Expressions
the empty string
a terminal (a ∈ ∑)
A nonterminal (A ∈ N)
e1 e2 a sequence of parsing expressions
e1 / e2 prioritized choice between alternatives
e?, e*, e+ optional, zeroormore, oneormore
&e, !e syntactic predicates
![Page 15: A RecognitionBased Syntactic Foundationvganesh/TEACHING/S2014/ECE351/lectures... · Designing a Language Syntax 1.Formalize syntax via contextfree grammar 2.Write a YACC parser specification](https://reader031.fdocuments.us/reader031/viewer/2022022017/5b7fc73a7f8b9ad9778c8a1e/html5/thumbnails/15.jpg)
How PEGs Express Languages
Given input string s, a parsing expression either:– Matches and consumes a prefix s' of s.
– Fails on s.
Example:
S badS matches “badder”S matches “baddest”S fails on “abad”S fails on “babe”
![Page 16: A RecognitionBased Syntactic Foundationvganesh/TEACHING/S2014/ECE351/lectures... · Designing a Language Syntax 1.Formalize syntax via contextfree grammar 2.Write a YACC parser specification](https://reader031.fdocuments.us/reader031/viewer/2022022017/5b7fc73a7f8b9ad9778c8a1e/html5/thumbnails/16.jpg)
Prioritized Choice with Backtracking
S A / B means:
“ To parse an S, first try to parse an A.If A fails, then backtrack and try to parse a B.”
Example:S if C then S else S /
if C then S
S matches “if C then S foo”S matches “if C then S 1 else S 2”S fails on “if C else S”
![Page 17: A RecognitionBased Syntactic Foundationvganesh/TEACHING/S2014/ECE351/lectures... · Designing a Language Syntax 1.Formalize syntax via contextfree grammar 2.Write a YACC parser specification](https://reader031.fdocuments.us/reader031/viewer/2022022017/5b7fc73a7f8b9ad9778c8a1e/html5/thumbnails/17.jpg)
Prioritized Choice with Backtracking
S A / B means:
“ To parse an S, first try to parse an A.If A fails, then backtrack and try to parse a B.”
Example from the C++ standard:
“ An expressionstatement ... can be indistinguishable from a declaration ... In those cases the statement is a declaration.”
statement declaration /expressionstatement
![Page 18: A RecognitionBased Syntactic Foundationvganesh/TEACHING/S2014/ECE351/lectures... · Designing a Language Syntax 1.Formalize syntax via contextfree grammar 2.Write a YACC parser specification](https://reader031.fdocuments.us/reader031/viewer/2022022017/5b7fc73a7f8b9ad9778c8a1e/html5/thumbnails/18.jpg)
Greedy Option and Repetition
A e? equivalent to A e /
A e* equivalent to A e A /
A e+ equivalent to A e e*
Example:
I L+
L a / b / c / ...
I matches “foobar”I matches “foo(bar)”I fails on “123”
![Page 19: A RecognitionBased Syntactic Foundationvganesh/TEACHING/S2014/ECE351/lectures... · Designing a Language Syntax 1.Formalize syntax via contextfree grammar 2.Write a YACC parser specification](https://reader031.fdocuments.us/reader031/viewer/2022022017/5b7fc73a7f8b9ad9778c8a1e/html5/thumbnails/19.jpg)
Syntactic Predicates
Andpredicate: &e succeeds whenever e does,but consumes no input [Parr '94, '95]
Notpredicate: !e succeeds whenever e fails
Example:
A foo &(bar)B foo !(bar)
A matches “foobar”A fails on “foobie”B matches “foobie”B fails on “foobar”
![Page 20: A RecognitionBased Syntactic Foundationvganesh/TEACHING/S2014/ECE351/lectures... · Designing a Language Syntax 1.Formalize syntax via contextfree grammar 2.Write a YACC parser specification](https://reader031.fdocuments.us/reader031/viewer/2022022017/5b7fc73a7f8b9ad9778c8a1e/html5/thumbnails/20.jpg)
Syntactic Predicates
Andpredicate: &e succeeds whenever e does,but consumes no input [Parr '94, '95]
Notpredicate: !e succeeds whenever e fails
Example:C B I* EI !E (C / T)B (*E *)T [any terminal]
C matches “(*ab*)cd”C matches “(*a(*b*)c*)”C fails on “(*a(*b*)”
![Page 21: A RecognitionBased Syntactic Foundationvganesh/TEACHING/S2014/ECE351/lectures... · Designing a Language Syntax 1.Formalize syntax via contextfree grammar 2.Write a YACC parser specification](https://reader031.fdocuments.us/reader031/viewer/2022022017/5b7fc73a7f8b9ad9778c8a1e/html5/thumbnails/21.jpg)
Syntactic Predicates
Andpredicate: &e succeeds whenever e does,but consumes no input [Parr '94, '95]
Notpredicate: !e succeeds whenever e fails
Example:C B I* EI !E (C / T)B (*E *)T [any terminal]
C matches “(*ab*)cd”C matches “(*a(*b*)c*)”C fails on “(*a(*b*)”
Begin marker
![Page 22: A RecognitionBased Syntactic Foundationvganesh/TEACHING/S2014/ECE351/lectures... · Designing a Language Syntax 1.Formalize syntax via contextfree grammar 2.Write a YACC parser specification](https://reader031.fdocuments.us/reader031/viewer/2022022017/5b7fc73a7f8b9ad9778c8a1e/html5/thumbnails/22.jpg)
Syntactic Predicates
Andpredicate: &e succeeds whenever e does,but consumes no input [Parr '94, '95]
Notpredicate: !e succeeds whenever e fails
Example:C B I* EI !E (C / T)B (*E *)T [any terminal]
C matches “(*ab*)cd”C matches “(*a(*b*)c*)”C fails on “(*a(*b*)”
Internal elements
![Page 23: A RecognitionBased Syntactic Foundationvganesh/TEACHING/S2014/ECE351/lectures... · Designing a Language Syntax 1.Formalize syntax via contextfree grammar 2.Write a YACC parser specification](https://reader031.fdocuments.us/reader031/viewer/2022022017/5b7fc73a7f8b9ad9778c8a1e/html5/thumbnails/23.jpg)
Syntactic Predicates
Andpredicate: &e succeeds whenever e does,but consumes no input [Parr '94, '95]
Notpredicate: !e succeeds whenever e fails
Example:C B I* EI !E (C / T)B (*E *)T [any terminal]
C matches “(*ab*)cd”C matches “(*a(*b*)c*)”C fails on “(*a(*b*)”
End marker
![Page 24: A RecognitionBased Syntactic Foundationvganesh/TEACHING/S2014/ECE351/lectures... · Designing a Language Syntax 1.Formalize syntax via contextfree grammar 2.Write a YACC parser specification](https://reader031.fdocuments.us/reader031/viewer/2022022017/5b7fc73a7f8b9ad9778c8a1e/html5/thumbnails/24.jpg)
Syntactic Predicates
Andpredicate: &e succeeds whenever e does,but consumes no input [Parr '94, '95]
Notpredicate: !e succeeds whenever e fails
Example:C B I* EI !E (C / T)B (*E *)T [any terminal]
C matches “(*ab*)cd”C matches “(*a(*b*)c*)”C fails on “(*a(*b*)”
➔
![Page 25: A RecognitionBased Syntactic Foundationvganesh/TEACHING/S2014/ECE351/lectures... · Designing a Language Syntax 1.Formalize syntax via contextfree grammar 2.Write a YACC parser specification](https://reader031.fdocuments.us/reader031/viewer/2022022017/5b7fc73a7f8b9ad9778c8a1e/html5/thumbnails/25.jpg)
Syntactic Predicates
Andpredicate: &e succeeds whenever e does,but consumes no input [Parr '94, '95]
Notpredicate: !e succeeds whenever e fails
Example:C B I* EI !E (C / T)B (*E *)T [any terminal]
C matches “(*ab*)cd”C matches “(*a(*b*)c*)”C fails on “(*a(*b*)”
Only if an end marker doesn't start here...
➔
![Page 26: A RecognitionBased Syntactic Foundationvganesh/TEACHING/S2014/ECE351/lectures... · Designing a Language Syntax 1.Formalize syntax via contextfree grammar 2.Write a YACC parser specification](https://reader031.fdocuments.us/reader031/viewer/2022022017/5b7fc73a7f8b9ad9778c8a1e/html5/thumbnails/26.jpg)
Syntactic Predicates
Andpredicate: &e succeeds whenever e does,but consumes no input [Parr '94, '95]
Notpredicate: !e succeeds whenever e fails
Example:C B I* EI !E (C / T)B (*E *)T [any terminal]
C matches “(*ab*)cd”C matches “(*a(*b*)c*)”C fails on “(*a(*b*)”
Only if an end marker doesn't start here...
...consume a nested comment,or else consume any single character.
➔
![Page 27: A RecognitionBased Syntactic Foundationvganesh/TEACHING/S2014/ECE351/lectures... · Designing a Language Syntax 1.Formalize syntax via contextfree grammar 2.Write a YACC parser specification](https://reader031.fdocuments.us/reader031/viewer/2022022017/5b7fc73a7f8b9ad9778c8a1e/html5/thumbnails/27.jpg)
Syntactic Predicates
Andpredicate: &e succeeds whenever e does,but consumes no input [Parr '94, '95]
Notpredicate: !e succeeds whenever e fails
Example:C B I* EI !E (C / T)B (*E *)T [any terminal]
C matches “(*ab*)cd”C matches “(*a(*b*)c*)”C fails on “(*a(*b*)”
![Page 28: A RecognitionBased Syntactic Foundationvganesh/TEACHING/S2014/ECE351/lectures... · Designing a Language Syntax 1.Formalize syntax via contextfree grammar 2.Write a YACC parser specification](https://reader031.fdocuments.us/reader031/viewer/2022022017/5b7fc73a7f8b9ad9778c8a1e/html5/thumbnails/28.jpg)
Unified Grammars
PEGs can express both lexical and hierarchical syntax of realistic languages in one grammar
● Example (in paper):Complete selfdescribing PEG in 2/3 column
● Example (on web):Unified PEG for Java language
![Page 29: A RecognitionBased Syntactic Foundationvganesh/TEACHING/S2014/ECE351/lectures... · Designing a Language Syntax 1.Formalize syntax via contextfree grammar 2.Write a YACC parser specification](https://reader031.fdocuments.us/reader031/viewer/2022022017/5b7fc73a7f8b9ad9778c8a1e/html5/thumbnails/29.jpg)
Lexical/Hierarchical Interplay
Unified grammars create new design opportunities
Example:
To get Unicode “∀”,instead of “\u2200”,write“\(0x2200)”or “\(8704)”or “\(FOR_ALL)”
E S / ( E ) / ...S “ C* “C \( E ) /
!“ !\ TT [any terminal]
![Page 30: A RecognitionBased Syntactic Foundationvganesh/TEACHING/S2014/ECE351/lectures... · Designing a Language Syntax 1.Formalize syntax via contextfree grammar 2.Write a YACC parser specification](https://reader031.fdocuments.us/reader031/viewer/2022022017/5b7fc73a7f8b9ad9778c8a1e/html5/thumbnails/30.jpg)
Lexical/Hierarchical Interplay
Unified grammars create new design opportunities
Example:
To get Unicode “∀”,instead of “\u2200”,write“\(0x2200)”or “\(8704)”or “\(FOR_ALL)”
E S / ( E ) / ...S “ C* “C \( E ) /
!“ !\ TT [any terminal]
Generalpurpose expression syntax
![Page 31: A RecognitionBased Syntactic Foundationvganesh/TEACHING/S2014/ECE351/lectures... · Designing a Language Syntax 1.Formalize syntax via contextfree grammar 2.Write a YACC parser specification](https://reader031.fdocuments.us/reader031/viewer/2022022017/5b7fc73a7f8b9ad9778c8a1e/html5/thumbnails/31.jpg)
Lexical/Hierarchical Interplay
Unified grammars create new design opportunities
Example:
To get Unicode “∀”,instead of “\u2200”,write“\(0x2200)”or “\(8704)”or “\(FOR_ALL)”
E S / ( E ) / ...S “ C* “C \( E ) /
!“ !\ TT [any terminal]
String literals
![Page 32: A RecognitionBased Syntactic Foundationvganesh/TEACHING/S2014/ECE351/lectures... · Designing a Language Syntax 1.Formalize syntax via contextfree grammar 2.Write a YACC parser specification](https://reader031.fdocuments.us/reader031/viewer/2022022017/5b7fc73a7f8b9ad9778c8a1e/html5/thumbnails/32.jpg)
Lexical/Hierarchical Interplay
Unified grammars create new design opportunities
Example:
To get Unicode “∀”,instead of “\u2200”,write“\(0x2200)”or “\(8704)”or “\(FOR_ALL)”
E S / ( E ) / ...S “ C* “C \( E ) /
!“ !\ TT [any terminal]
Quotable characters
![Page 33: A RecognitionBased Syntactic Foundationvganesh/TEACHING/S2014/ECE351/lectures... · Designing a Language Syntax 1.Formalize syntax via contextfree grammar 2.Write a YACC parser specification](https://reader031.fdocuments.us/reader031/viewer/2022022017/5b7fc73a7f8b9ad9778c8a1e/html5/thumbnails/33.jpg)
Lexical/Hierarchical Interplay
Unified grammars create new design opportunities
Example:
To get Unicode “∀”,instead of “\u2200”,write“\(0x2200)”or “\(8704)”or “\(FOR_ALL)”
E S / ( E ) / ...S “ C* “C \( E ) /
!“ !\ TT [any terminal]
![Page 34: A RecognitionBased Syntactic Foundationvganesh/TEACHING/S2014/ECE351/lectures... · Designing a Language Syntax 1.Formalize syntax via contextfree grammar 2.Write a YACC parser specification](https://reader031.fdocuments.us/reader031/viewer/2022022017/5b7fc73a7f8b9ad9778c8a1e/html5/thumbnails/34.jpg)
Formal Properties of PEGs
● Express all deterministic languages LR(k)● Closed under union, intersection, complement
● Some noncontext free languages, e.g., anbncn
● Undecidable whether L(G) = ∅● Predicate operators can be eliminated
– ...but the process is nontrivial!
![Page 35: A RecognitionBased Syntactic Foundationvganesh/TEACHING/S2014/ECE351/lectures... · Designing a Language Syntax 1.Formalize syntax via contextfree grammar 2.Write a YACC parser specification](https://reader031.fdocuments.us/reader031/viewer/2022022017/5b7fc73a7f8b9ad9778c8a1e/html5/thumbnails/35.jpg)
Minimalist Forms
Predicatefree PEG⇩
TS [Birman '70/'73]
TDPL [Aho '72]
Any PEG⇩
gTS [Birman '70/'73]
GTDPL [Aho '72]
A A aA fA BC / D
A A aA fA B[C, D]
⇦⇨
![Page 36: A RecognitionBased Syntactic Foundationvganesh/TEACHING/S2014/ECE351/lectures... · Designing a Language Syntax 1.Formalize syntax via contextfree grammar 2.Write a YACC parser specification](https://reader031.fdocuments.us/reader031/viewer/2022022017/5b7fc73a7f8b9ad9778c8a1e/html5/thumbnails/36.jpg)
Formal Contributions
● Generalize TDPL/GTDPL with more expressivestructured parsing expression syntax
● Negative syntactic predicate !e ● Predicate elimination transformation
– Intermediate stages depend ongeneralized parsing expressions
● Proof of equivalence of TDPL and GTDPL
![Page 37: A RecognitionBased Syntactic Foundationvganesh/TEACHING/S2014/ECE351/lectures... · Designing a Language Syntax 1.Formalize syntax via contextfree grammar 2.Write a YACC parser specification](https://reader031.fdocuments.us/reader031/viewer/2022022017/5b7fc73a7f8b9ad9778c8a1e/html5/thumbnails/37.jpg)
What can't PEGs express directly?
● Ambiguous languages
That's what CFGs were designed for!
● Globally disambiguated languages?– {a,b}n a {a,b}n ?
● State or semanticdependent syntax– C, C++ typedef symbol tables– Python, Haskell, ML layout
![Page 38: A RecognitionBased Syntactic Foundationvganesh/TEACHING/S2014/ECE351/lectures... · Designing a Language Syntax 1.Formalize syntax via contextfree grammar 2.Write a YACC parser specification](https://reader031.fdocuments.us/reader031/viewer/2022022017/5b7fc73a7f8b9ad9778c8a1e/html5/thumbnails/38.jpg)
Generating Parsers from PEGs
Recursivedescent parsing☞Simple & direct, but exponentialtime if not careful
Packrat parsing [Birman '70/'73, Ford '02]☞Lineartime, but can consume substantial storage
Classic LL/LR algorithms?☞Grammar restrictions, but both time & spaceefficient
![Page 39: A RecognitionBased Syntactic Foundationvganesh/TEACHING/S2014/ECE351/lectures... · Designing a Language Syntax 1.Formalize syntax via contextfree grammar 2.Write a YACC parser specification](https://reader031.fdocuments.us/reader031/viewer/2022022017/5b7fc73a7f8b9ad9778c8a1e/html5/thumbnails/39.jpg)
Conclusion
PEGs model common parsing practices– Prioritized choice, greedy rules, syntactic predicates
PEGs naturally complement CFGs– CFG: generative system, for ambiguous languages– PEG: recognitionbased, for unambiguous languages
For more info:http://pdos.lcs.mit.edu/~baford/packrat(or GGooooggllee for “ Packrat Parsing”)