LVEE 2014: Text parsing with Python and PLY

D
Text parsing with Python and PLY 
Daniil Baturin <daniil@baturin.org> 
LVEE 2014
Formal language 
Set of strings composed of symbols of some alphabet. 
A language can be defined by a formal grammar. 
Two or more grammars may produce the same language. 
Forward problem: given a grammar, generate a string that 
belongs a language (trivial). 
Parsing is the inverse problem: given a string, decide if it 
belongs a language defined by a grammar.
Formal grammar 
Formal grammar is a set of production rules. 
A production rule has a one or more symbols at its left-hand and right-hand sides. 
You need to specify the start symbol. 
Example: 
<sentence> ::= <verb phrase> <noun phrase> 
<noun phrase> ::= <article> <adjective> <noun> 
<verb phrase> ::= <verb> <article> <noun> 
<article> ::= <”a” | “the” | empty> 
... 
“sentence” is the start symbol.
Lexers and tokens 
Lexer—breaks the text into tokens, string 
literals with metadata. 
Tokens are identified by regular expressions. 
Parsers usually operate on tokens rather than 
string literals. E.g. all numbers ([0-9]+) become 
TOKEN(NUMBER, value). 
Lexer can be autogenerated or hand-coded.
Symbols 
Terminal symbols are symbols that can't be 
further reduced (rewritten). 
Non-terminal symbols are composed from 
references to terminals and other non-terminals. 
<article> ::= <”a” | “the” | empty> 
“Article” is a non-terminal; “a”, “the”, empty are 
terminals.
Approaches to parsing 
● Hand-coded ad-hoc parser 
● Autogenerated parser 
● Hand-coded advanced algorithm
Regular grammar 
All production rules are of the following form: 
<some nonterminal> ::= <some terminal> 
<some nonterminal> ::= <some terminal> <another nonterminal> 
<some nonterminal> ::= <empty> 
Equivalent to regular expressions. 
“(a|b)*” regex: 
<start> ::= “a” <start> 
| “b” <start> 
| <empty> 
This is good for a hand-coded parser (or a regex library).
Context-free grammar 
All productions are of the following form: 
<some nonterminal> ::= <some terminals or nonterminals> 
Good for autogenerated parsers. Ad-hoc 
parsers tend to be messy.
More complex grammars 
Context-sensitive: rules may contain terminals 
and nonterminals in both sides. 
Can be conquered with special tools or lexer 
hacks. 
Not even context-sensitive: you are in trouble. ;)
Parser generators 
Usually use LALR(1) method. 
Read a token and push it on stack. 
If some rule is matched, empty the stack and 
proceed (reduce). 
If not, push the token on stack and proceed 
(shift).
PLY Lex—the lexer generator 
Token recognizers are functions. 
Token regexes are in docstrings. 
You should export a tuple of all tokens for use in 
a parser. 
def t_NUMBER(t): 
r'[0­9]+' 
t.value = int(t.value) 
return t
PLY YACC—the parser generator 
Production rule recognizers are functions. 
Rules are in docstrings. 
Rules can refer to other rules and can be recursive. 
You can refer to lexer tokens in rules. 
The argument is the token list. 
def p_expr(p): 
''' expr : NUMBER OPSIGN NUMBER ''' 
p[0] = (p[2], p[1], p[3])
Grammar “patterns” 
The rule form used by YACC doesn't have a 
notation for repetition etc. 
Empty: 
something : 
This or that: 
something : foo | bar 
One or more of something: 
list_of_something : list_of_something something 
| something
Common problems 
Shift-reduce conflict: two or more rules have more than 
one common token at the beginning. 
foo : baz quux xyzzy 
bar : baz quux fgsfds 
Usually can be solved by left factorization: 
foobar_start : baz quux 
foo : foobar_start xyzzy 
bar : foobar_start fgsfds 
Default resolution is shift. 
Reduce-reduce conflict: same string matches more 
than one rule. Often indicates a grammar design error.
What I didn't tell 
Exclusive lexer states. 
Precedence rules. 
Wrapping lexers and parsers into classes. 
Error recovery.
The sample code 
https://github.com/dmbaturin/ply-example
Questions?
1 of 17

Recommended

Computational model language and grammar bnf by
Computational model language and grammar bnfComputational model language and grammar bnf
Computational model language and grammar bnfTaha Shakeel
1.2K views25 slides
Lecture 04 syntax analysis by
Lecture 04 syntax analysisLecture 04 syntax analysis
Lecture 04 syntax analysisIffat Anjum
3.4K views34 slides
Compiler Design by
Compiler Design Compiler Design
Compiler Design waqar ahmed
46 views8 slides
python by
pythonpython
pythonRajendran
266 views7 slides
parser by
parserparser
parserRajendran
229 views6 slides

More Related Content

What's hot

Regular Expressions in PHP by
Regular Expressions in PHPRegular Expressions in PHP
Regular Expressions in PHPAndrew Kandels
3.8K views20 slides
Lesson 03 python statement, indentation and comments by
Lesson 03   python statement, indentation and commentsLesson 03   python statement, indentation and comments
Lesson 03 python statement, indentation and commentsNilimesh Halder
639 views5 slides
The JavaScript Programming Language by
The JavaScript Programming LanguageThe JavaScript Programming Language
The JavaScript Programming LanguageRaghavan Mohan
1.4K views142 slides
The Java Script Programming Language by
The  Java Script  Programming  LanguageThe  Java Script  Programming  Language
The Java Script Programming Languagezone
983 views142 slides
Javascript by
JavascriptJavascript
Javascriptvikram singh
528 views142 slides
Regular Expression in Compiler design by
Regular Expression in Compiler designRegular Expression in Compiler design
Regular Expression in Compiler designRiazul Islam
4.1K views9 slides

What's hot(19)

Regular Expressions in PHP by Andrew Kandels
Regular Expressions in PHPRegular Expressions in PHP
Regular Expressions in PHP
Andrew Kandels3.8K views
Lesson 03 python statement, indentation and comments by Nilimesh Halder
Lesson 03   python statement, indentation and commentsLesson 03   python statement, indentation and comments
Lesson 03 python statement, indentation and comments
Nilimesh Halder639 views
The JavaScript Programming Language by Raghavan Mohan
The JavaScript Programming LanguageThe JavaScript Programming Language
The JavaScript Programming Language
Raghavan Mohan1.4K views
The Java Script Programming Language by zone
The  Java Script  Programming  LanguageThe  Java Script  Programming  Language
The Java Script Programming Language
zone983 views
Regular Expression in Compiler design by Riazul Islam
Regular Expression in Compiler designRegular Expression in Compiler design
Regular Expression in Compiler design
Riazul Islam4.1K views
Chapter Three(2) by bolovv
Chapter Three(2)Chapter Three(2)
Chapter Three(2)
bolovv3.2K views
Convention-Based Syntactic Descriptions by Ray Toal
Convention-Based Syntactic DescriptionsConvention-Based Syntactic Descriptions
Convention-Based Syntactic Descriptions
Ray Toal321 views
Chapter3pptx__2021_12_23_22_52_54.pptx by DrIsikoIsaac
Chapter3pptx__2021_12_23_22_52_54.pptxChapter3pptx__2021_12_23_22_52_54.pptx
Chapter3pptx__2021_12_23_22_52_54.pptx
DrIsikoIsaac131 views
Chapter Two(1) by bolovv
Chapter Two(1)Chapter Two(1)
Chapter Two(1)
bolovv3.2K views
Basic syntax supported by python by Jaya Kumari
Basic syntax supported by pythonBasic syntax supported by python
Basic syntax supported by python
Jaya Kumari29 views
Types of Language in Theory of Computation by Ankur Singh
Types of Language in Theory of ComputationTypes of Language in Theory of Computation
Types of Language in Theory of Computation
Ankur Singh12.5K views

Viewers also liked

Text analysis using python by
Text analysis using pythonText analysis using python
Text analysis using pythonVijay Ramachandran
1.6K views24 slides
Views Unlimited: Unleashing the Power of Drupal's Views Module by
Views Unlimited: Unleashing the Power of Drupal's Views ModuleViews Unlimited: Unleashing the Power of Drupal's Views Module
Views Unlimited: Unleashing the Power of Drupal's Views ModuleRanel Padon
3.8K views72 slides
PyCon PH 2014 - GeoComputation by
PyCon PH 2014 - GeoComputationPyCon PH 2014 - GeoComputation
PyCon PH 2014 - GeoComputationRanel Padon
1.8K views101 slides
An Embedded Error Recovery and Debugging Mechanism for Scripting Language Ext... by
An Embedded Error Recovery and Debugging Mechanism for Scripting Language Ext...An Embedded Error Recovery and Debugging Mechanism for Scripting Language Ext...
An Embedded Error Recovery and Debugging Mechanism for Scripting Language Ext...David Beazley (Dabeaz LLC)
1.2K views36 slides
Generator Tricks for Systems Programmers by
Generator Tricks for Systems ProgrammersGenerator Tricks for Systems Programmers
Generator Tricks for Systems ProgrammersDavid Beazley (Dabeaz LLC)
2.5K views142 slides
WAD : A Module for Converting Fatal Extension Errors into Python Exceptions by
WAD : A Module for Converting Fatal Extension Errors into Python ExceptionsWAD : A Module for Converting Fatal Extension Errors into Python Exceptions
WAD : A Module for Converting Fatal Extension Errors into Python ExceptionsDavid Beazley (Dabeaz LLC)
1K views45 slides

Viewers also liked(20)

Views Unlimited: Unleashing the Power of Drupal's Views Module by Ranel Padon
Views Unlimited: Unleashing the Power of Drupal's Views ModuleViews Unlimited: Unleashing the Power of Drupal's Views Module
Views Unlimited: Unleashing the Power of Drupal's Views Module
Ranel Padon3.8K views
PyCon PH 2014 - GeoComputation by Ranel Padon
PyCon PH 2014 - GeoComputationPyCon PH 2014 - GeoComputation
PyCon PH 2014 - GeoComputation
Ranel Padon1.8K views
An Embedded Error Recovery and Debugging Mechanism for Scripting Language Ext... by David Beazley (Dabeaz LLC)
An Embedded Error Recovery and Debugging Mechanism for Scripting Language Ext...An Embedded Error Recovery and Debugging Mechanism for Scripting Language Ext...
An Embedded Error Recovery and Debugging Mechanism for Scripting Language Ext...
CKEditor Widgets with Drupal by Ranel Padon
CKEditor Widgets with DrupalCKEditor Widgets with Drupal
CKEditor Widgets with Drupal
Ranel Padon4.8K views
SWIG : An Easy to Use Tool for Integrating Scripting Languages with C and C++ by David Beazley (Dabeaz LLC)
SWIG : An Easy to Use Tool for Integrating Scripting Languages with C and C++SWIG : An Easy to Use Tool for Integrating Scripting Languages with C and C++
SWIG : An Easy to Use Tool for Integrating Scripting Languages with C and C++
Why Extension Programmers Should Stop Worrying About Parsing and Start Thinki... by David Beazley (Dabeaz LLC)
Why Extension Programmers Should Stop Worrying About Parsing and Start Thinki...Why Extension Programmers Should Stop Worrying About Parsing and Start Thinki...
Why Extension Programmers Should Stop Worrying About Parsing and Start Thinki...
Python Programming - X. Exception Handling and Assertions by Ranel Padon
Python Programming - X. Exception Handling and AssertionsPython Programming - X. Exception Handling and Assertions
Python Programming - X. Exception Handling and Assertions
Ranel Padon2.4K views
Python for text processing by Xiang Li
Python for text processingPython for text processing
Python for text processing
Xiang Li14.7K views
Python Programming - III. Controlling the Flow by Ranel Padon
Python Programming - III. Controlling the FlowPython Programming - III. Controlling the Flow
Python Programming - III. Controlling the Flow
Ranel Padon3.3K views
The Synergy of Drupal Hooks/APIs (Custom Module Development with ChartJS) by Ranel Padon
The Synergy of Drupal Hooks/APIs (Custom Module Development with ChartJS)The Synergy of Drupal Hooks/APIs (Custom Module Development with ChartJS)
The Synergy of Drupal Hooks/APIs (Custom Module Development with ChartJS)
Ranel Padon1.3K views
Python Programming - VII. Customizing Classes and Operator Overloading by Ranel Padon
Python Programming - VII. Customizing Classes and Operator OverloadingPython Programming - VII. Customizing Classes and Operator Overloading
Python Programming - VII. Customizing Classes and Operator Overloading
Ranel Padon2.2K views
Switchable Map APIs with Drupal by Ranel Padon
Switchable Map APIs with DrupalSwitchable Map APIs with Drupal
Switchable Map APIs with Drupal
Ranel Padon1.7K views
Python Programming - IX. On Randomness by Ranel Padon
Python Programming - IX. On RandomnessPython Programming - IX. On Randomness
Python Programming - IX. On Randomness
Ranel Padon3.4K views
Python Programming - VIII. Inheritance and Polymorphism by Ranel Padon
Python Programming - VIII. Inheritance and PolymorphismPython Programming - VIII. Inheritance and Polymorphism
Python Programming - VIII. Inheritance and Polymorphism
Ranel Padon3.1K views

Similar to LVEE 2014: Text parsing with Python and PLY

Control structure by
Control structureControl structure
Control structurebaran19901990
1.3K views51 slides
Lex and Yacc ppt by
Lex and Yacc pptLex and Yacc ppt
Lex and Yacc pptpssraikar
32.3K views64 slides
Lexical by
LexicalLexical
Lexicalbaran19901990
1.4K views40 slides
Pcd question bank by
Pcd question bank Pcd question bank
Pcd question bank Sumathi Gnanasekaran
135 views35 slides
3a. Context Free Grammar.pdf by
3a. Context Free Grammar.pdf3a. Context Free Grammar.pdf
3a. Context Free Grammar.pdfTANZINTANZINA
19 views18 slides
Syntax analysis by
Syntax analysisSyntax analysis
Syntax analysisAkshaya Arunan
8.5K views58 slides

Similar to LVEE 2014: Text parsing with Python and PLY(20)

Lex and Yacc ppt by pssraikar
Lex and Yacc pptLex and Yacc ppt
Lex and Yacc ppt
pssraikar32.3K views
3a. Context Free Grammar.pdf by TANZINTANZINA
3a. Context Free Grammar.pdf3a. Context Free Grammar.pdf
3a. Context Free Grammar.pdf
TANZINTANZINA19 views
CH 2.pptx by Obsa2
CH 2.pptxCH 2.pptx
CH 2.pptx
Obsa29 views
Lexical analysis - Compiler Design by Kuppusamy P
Lexical analysis - Compiler DesignLexical analysis - Compiler Design
Lexical analysis - Compiler Design
Kuppusamy P475 views
Programming_Language_Syntax.ppt by Amrita Sharma
Programming_Language_Syntax.pptProgramming_Language_Syntax.ppt
Programming_Language_Syntax.ppt
Amrita Sharma13 views
Introduction of bison by vip_du
Introduction of bisonIntroduction of bison
Introduction of bison
vip_du4.4K views
Using ANTLR on real example - convert "string combined" queries into paramete... by Alexey Diyan
Using ANTLR on real example - convert "string combined" queries into paramete...Using ANTLR on real example - convert "string combined" queries into paramete...
Using ANTLR on real example - convert "string combined" queries into paramete...
Alexey Diyan16.4K views

Recently uploaded

Measurecamp Brussels - Synthetic data.pdf by
Measurecamp Brussels - Synthetic data.pdfMeasurecamp Brussels - Synthetic data.pdf
Measurecamp Brussels - Synthetic data.pdfHuman37
27 views14 slides
Measuring User on the web with the core web vitals - by @theafolayan.pptx by
Measuring User on the web with the core web vitals - by @theafolayan.pptxMeasuring User on the web with the core web vitals - by @theafolayan.pptx
Measuring User on the web with the core web vitals - by @theafolayan.pptxOluwaseun Raphael Afolayan
14 views13 slides
Transcript: Redefining the book supply chain: A glimpse into the future - Tec... by
Transcript: Redefining the book supply chain: A glimpse into the future - Tec...Transcript: Redefining the book supply chain: A glimpse into the future - Tec...
Transcript: Redefining the book supply chain: A glimpse into the future - Tec...BookNet Canada
43 views16 slides
"Node.js vs workers — A comparison of two JavaScript runtimes", James M Snell by
"Node.js vs workers — A comparison of two JavaScript runtimes", James M Snell"Node.js vs workers — A comparison of two JavaScript runtimes", James M Snell
"Node.js vs workers — A comparison of two JavaScript runtimes", James M SnellFwdays
14 views30 slides
Discover Aura Workshop (12.5.23).pdf by
Discover Aura Workshop (12.5.23).pdfDiscover Aura Workshop (12.5.23).pdf
Discover Aura Workshop (12.5.23).pdfNeo4j
20 views55 slides
This talk was not generated with ChatGPT: how AI is changing science by
This talk was not generated with ChatGPT: how AI is changing scienceThis talk was not generated with ChatGPT: how AI is changing science
This talk was not generated with ChatGPT: how AI is changing scienceElena Simperl
34 views13 slides

Recently uploaded(20)

Measurecamp Brussels - Synthetic data.pdf by Human37
Measurecamp Brussels - Synthetic data.pdfMeasurecamp Brussels - Synthetic data.pdf
Measurecamp Brussels - Synthetic data.pdf
Human37 27 views
Transcript: Redefining the book supply chain: A glimpse into the future - Tec... by BookNet Canada
Transcript: Redefining the book supply chain: A glimpse into the future - Tec...Transcript: Redefining the book supply chain: A glimpse into the future - Tec...
Transcript: Redefining the book supply chain: A glimpse into the future - Tec...
BookNet Canada43 views
"Node.js vs workers — A comparison of two JavaScript runtimes", James M Snell by Fwdays
"Node.js vs workers — A comparison of two JavaScript runtimes", James M Snell"Node.js vs workers — A comparison of two JavaScript runtimes", James M Snell
"Node.js vs workers — A comparison of two JavaScript runtimes", James M Snell
Fwdays14 views
Discover Aura Workshop (12.5.23).pdf by Neo4j
Discover Aura Workshop (12.5.23).pdfDiscover Aura Workshop (12.5.23).pdf
Discover Aura Workshop (12.5.23).pdf
Neo4j20 views
This talk was not generated with ChatGPT: how AI is changing science by Elena Simperl
This talk was not generated with ChatGPT: how AI is changing scienceThis talk was not generated with ChatGPT: how AI is changing science
This talk was not generated with ChatGPT: how AI is changing science
Elena Simperl34 views
NTGapps NTG LowCode Platform by Mustafa Kuğu
NTGapps NTG LowCode Platform NTGapps NTG LowCode Platform
NTGapps NTG LowCode Platform
Mustafa Kuğu474 views
Don’t Make A Human Do A Robot’s Job! : 6 Reasons Why AI Will Save Us & Not De... by Moses Kemibaro
Don’t Make A Human Do A Robot’s Job! : 6 Reasons Why AI Will Save Us & Not De...Don’t Make A Human Do A Robot’s Job! : 6 Reasons Why AI Will Save Us & Not De...
Don’t Make A Human Do A Robot’s Job! : 6 Reasons Why AI Will Save Us & Not De...
Moses Kemibaro38 views
"Running students' code in isolation. The hard way", Yurii Holiuk by Fwdays
"Running students' code in isolation. The hard way", Yurii Holiuk "Running students' code in isolation. The hard way", Yurii Holiuk
"Running students' code in isolation. The hard way", Yurii Holiuk
Fwdays38 views
Business Analyst Series 2023 - Week 4 Session 7 by DianaGray10
Business Analyst Series 2023 -  Week 4 Session 7Business Analyst Series 2023 -  Week 4 Session 7
Business Analyst Series 2023 - Week 4 Session 7
DianaGray10152 views
AI + Memoori = AIM by Memoori
AI + Memoori = AIMAI + Memoori = AIM
AI + Memoori = AIM
Memoori15 views
Innovation & Entrepreneurship strategies in Dairy Industry by PervaizDar1
Innovation & Entrepreneurship strategies in Dairy IndustryInnovation & Entrepreneurship strategies in Dairy Industry
Innovation & Entrepreneurship strategies in Dairy Industry
PervaizDar139 views
"Node.js Development in 2024: trends and tools", Nikita Galkin by Fwdays
"Node.js Development in 2024: trends and tools", Nikita Galkin "Node.js Development in 2024: trends and tools", Nikita Galkin
"Node.js Development in 2024: trends and tools", Nikita Galkin
Fwdays37 views
"Surviving highload with Node.js", Andrii Shumada by Fwdays
"Surviving highload with Node.js", Andrii Shumada "Surviving highload with Node.js", Andrii Shumada
"Surviving highload with Node.js", Andrii Shumada
Fwdays59 views
Digital Personal Data Protection (DPDP) Practical Approach For CISOs by Priyanka Aash
Digital Personal Data Protection (DPDP) Practical Approach For CISOsDigital Personal Data Protection (DPDP) Practical Approach For CISOs
Digital Personal Data Protection (DPDP) Practical Approach For CISOs
Priyanka Aash171 views
Initiating and Advancing Your Strategic GIS Governance Strategy by Safe Software
Initiating and Advancing Your Strategic GIS Governance StrategyInitiating and Advancing Your Strategic GIS Governance Strategy
Initiating and Advancing Your Strategic GIS Governance Strategy
Safe Software198 views
Future of AR - Facebook Presentation by Rob McCarty
Future of AR - Facebook PresentationFuture of AR - Facebook Presentation
Future of AR - Facebook Presentation
Rob McCarty66 views

LVEE 2014: Text parsing with Python and PLY

  • 1. Text parsing with Python and PLY Daniil Baturin <daniil@baturin.org> LVEE 2014
  • 2. Formal language Set of strings composed of symbols of some alphabet. A language can be defined by a formal grammar. Two or more grammars may produce the same language. Forward problem: given a grammar, generate a string that belongs a language (trivial). Parsing is the inverse problem: given a string, decide if it belongs a language defined by a grammar.
  • 3. Formal grammar Formal grammar is a set of production rules. A production rule has a one or more symbols at its left-hand and right-hand sides. You need to specify the start symbol. Example: <sentence> ::= <verb phrase> <noun phrase> <noun phrase> ::= <article> <adjective> <noun> <verb phrase> ::= <verb> <article> <noun> <article> ::= <”a” | “the” | empty> ... “sentence” is the start symbol.
  • 4. Lexers and tokens Lexer—breaks the text into tokens, string literals with metadata. Tokens are identified by regular expressions. Parsers usually operate on tokens rather than string literals. E.g. all numbers ([0-9]+) become TOKEN(NUMBER, value). Lexer can be autogenerated or hand-coded.
  • 5. Symbols Terminal symbols are symbols that can't be further reduced (rewritten). Non-terminal symbols are composed from references to terminals and other non-terminals. <article> ::= <”a” | “the” | empty> “Article” is a non-terminal; “a”, “the”, empty are terminals.
  • 6. Approaches to parsing ● Hand-coded ad-hoc parser ● Autogenerated parser ● Hand-coded advanced algorithm
  • 7. Regular grammar All production rules are of the following form: <some nonterminal> ::= <some terminal> <some nonterminal> ::= <some terminal> <another nonterminal> <some nonterminal> ::= <empty> Equivalent to regular expressions. “(a|b)*” regex: <start> ::= “a” <start> | “b” <start> | <empty> This is good for a hand-coded parser (or a regex library).
  • 8. Context-free grammar All productions are of the following form: <some nonterminal> ::= <some terminals or nonterminals> Good for autogenerated parsers. Ad-hoc parsers tend to be messy.
  • 9. More complex grammars Context-sensitive: rules may contain terminals and nonterminals in both sides. Can be conquered with special tools or lexer hacks. Not even context-sensitive: you are in trouble. ;)
  • 10. Parser generators Usually use LALR(1) method. Read a token and push it on stack. If some rule is matched, empty the stack and proceed (reduce). If not, push the token on stack and proceed (shift).
  • 11. PLY Lex—the lexer generator Token recognizers are functions. Token regexes are in docstrings. You should export a tuple of all tokens for use in a parser. def t_NUMBER(t): r'[0­9]+' t.value = int(t.value) return t
  • 12. PLY YACC—the parser generator Production rule recognizers are functions. Rules are in docstrings. Rules can refer to other rules and can be recursive. You can refer to lexer tokens in rules. The argument is the token list. def p_expr(p): ''' expr : NUMBER OPSIGN NUMBER ''' p[0] = (p[2], p[1], p[3])
  • 13. Grammar “patterns” The rule form used by YACC doesn't have a notation for repetition etc. Empty: something : This or that: something : foo | bar One or more of something: list_of_something : list_of_something something | something
  • 14. Common problems Shift-reduce conflict: two or more rules have more than one common token at the beginning. foo : baz quux xyzzy bar : baz quux fgsfds Usually can be solved by left factorization: foobar_start : baz quux foo : foobar_start xyzzy bar : foobar_start fgsfds Default resolution is shift. Reduce-reduce conflict: same string matches more than one rule. Often indicates a grammar design error.
  • 15. What I didn't tell Exclusive lexer states. Precedence rules. Wrapping lexers and parsers into classes. Error recovery.
  • 16. The sample code https://github.com/dmbaturin/ply-example