SlideShare a Scribd company logo
1 of 51
Download to read offline
Getting Rid
of
Backtracking
Jan Köhnlein
itemis
https://youtu.be/h0aXgiL-lws
Agenda
• Understanding The Parser
• Ambiguities
• Debugging a Grammar
• Non-LL(*) Decisions
Agenda
• Understanding The Parser
• Ambiguities
• Debugging a Grammar
• Non-LL(*) Decisions
Parsing in Xtext
• Xtext continuously parses documents in editor
• Parsing needs to be fast
• Parsing needs good error recovery
• Xtext uses ANTLR 3.2
• LL(*) parser generator
LL-Parsing
• Traverse the document from beginning to end
• Each rule becomes a method
• Iterate:
1. Look ahead the minimum number of tokens to
decide on the next path segment
2. Rewind and generate AST along that path
segment
Lookahead: Decision
Class:
... members+=Member* ...;
Member:
Field | Method;
Field:
type=[Type] name=ID;
Method:
return=[Type] name=ID '(' ')';
int foo
double bar()
Lookahead: Syntax Only
Class:
... members+=Member* ...;
Member:
Field | Method;
Field:
type=[Type] name=ID;
Method:
return=[Type] name=ID '(' ')';
int foo
double bar()
Lookahead: Syntax Only!
Class:
... members+=Member* ...;
Member:
Field | Method;
Field:
type=[Type] name=ID;
Method:
return=[Type] name=ID '(' ')';
int foo
double bar()
ID
ID
Lookahead: Common Tokens
Class:
... members+=Member* ...;
Member:
Field | Method;
Field:
type=[Type] name=ID;
Method:
return=[Type] name=ID '(' ')';
int foo
double bar()
ID
ID
Lookahead
k=3
Lookahead: If-Cascade
Class:
... members+=Member* ...;
Member:
Field | Method;
Field:
type=[Type] name=ID;
Method:
return=[Type] name=ID '(' ')';
int foo
double bar()
ID
ID
Lookahead
k=3
Member
ID
ID
yes
error
no
(
yes no
Method
yes
Field
no
Execution
Class:
... members+=Member* ...;
Member:
Field | Method;
Field:
type=[Type] name=ID;
Method:
return=[Type] name=ID '(' ')';
int foo double bar()
Execution
Class:
... members+=Member* ...;
Member:
Field | Method;
Field:
type=[Type] name=ID;
Method:
return=[Type] name=ID '(' ')';ID
ID
Member
ID
ID
yes
error
no
(
yes no
Method
yes
Field
no
int foo double bar()
Execution
Class:
... members+=Member* ...;
Member:
Field | Method;
Field:
type=[Type] name=ID;
Method:
return=[Type] name=ID '(' ')';
int foo double bar()
ID
ID
Member
ID
ID
yes
error
no
(
yes no
Method
yes
Field
no
Execution
Class:
... members+=Member* ...;
Member:
Field | Method;
Field:
type=[Type] name=ID;
Method:
return=[Type] name=ID '(' ')';
int foo double bar()
ID
ID
Member
ID
ID
yes
error
no
(
yes no
Method
yes
Field
no
Execution
Class:
... members+=Member* ...;
Member:
Field | Method;
Field:
type=[Type] name=ID;
Method:
return=[Type] name=ID '(' ')';
int foo double bar()
ID
ID
Member
ID
ID
yes
error
no
(
yes no
Method
yes
Field
no
It’s a Field!
Execution
Class:
... members+=Member* ...;
Member:
Field | Method;
Field:
type=[Type] name=ID;
Method:
return=[Type] name=ID '(' ')';
int foo double bar() Create Field
Execution
Class:
... members+=Member* ...;
Member:
Field | Method;
Field:
type=[Type] name=ID;
Method:
return=[Type] name=ID '(' ')';
int foo double bar() Create Field
Execution
Class:
... members+=Member* ...;
Member:
Field | Method;
Field:
type=[Type] name=ID;
Method:
return=[Type] name=ID '(' ')';
int foo double bar()
Member
ID
ID
yes
error
no
(
yes no
Method
yes
Field
no
Class:
... members+=Member* ...;
Member:
Field | Method;
Field:
type=[Type] name=ID;
Method:
return=[Type] name=ID '(' ')';ID
ID
Execution
Class:
... members+=Member* ...;
Member:
Field | Method;
Field:
type=[Type] name=ID;
Method:
return=[Type] name=ID '(' ')';
int foo double bar()
Member
ID
ID
yes
error
no
(
yes no
Method
yes
Field
no
Class:
... members+=Member* ...;
Member:
Field | Method;
Field:
type=[Type] name=ID;
Method:
return=[Type] name=ID '(' ')';ID
ID
Execution
Class:
... members+=Member* ...;
Member:
Field | Method;
Field:
type=[Type] name=ID;
Method:
return=[Type] name=ID '(' ')';
int foo double bar()
Member
ID
ID
yes
error
no
(
yes no
Method
yes
Field
no
It’s a Method!
Class:
... members+=Member* ...;
Member:
Field | Method;
Field:
type=[Type] name=ID;
Method:
return=[Type] name=ID '(' ')';ID
ID
Execution
Class:
... members+=Member* ...;
Member:
Field | Method;
Field:
type=[Type] name=ID;
Method:
return=[Type] name=ID '(' ')';
int foo double bar() Create Method
Execution
Class:
... members+=Member* ...;
Member:
Field | Method;
Field:
type=[Type] name=ID;
Method:
return=[Type] name=ID '(' ')';
int foo double bar() Create Method
Agenda
• Understanding The Parser
• Ambiguities
• Debugging a Grammar
• Non-LL(*) Decisions
Ambiguities
• Multiple paths in the grammar 

for the same sequence of tokens
• Caused by
• alternatives |
• optional cardinalities ? and *
Simple Example
Class:
... members+=Member* ...;
Member:
Field | Method;
Field:
type=[Type]? name=ID;
Method:
return=[Type] name=ID '(' ')';
int foo
double bar()
baz
Simple Example
Class:
... members+=Member* ...;
Member:
Field | Method;
Field:
type=[Type]? name=ID;
Method:
return=[Type] name=ID '(' ')';
int foo
double bar()
bazwarning(200): ..InternalMyDsl.g:258:2:
Decision can match input such as "RULE_ID" using multiple
alternatives: 1, 2
As a result, alternative(s) 2 were disabled for that input
error(201): ..InternalMyDsl.g:258:2: The following alternatives can
never be matched: 2
Simple Example
Class:
... members+=Member* ...;
Member:
Field | Method;
Field:
type=[Type]? name=ID;
Method:
return=[Type] name=ID '(' ')';
int foo
double bar()
baz
• ID ID matches
• two fields w/o type
• one field w type
➡ Ambiguity
Solution I:
Change Syntax
Class:
... members+=Member* ...;
Member:
Field | Method;
Field:
('val' | type=[Type]) name=ID;
• Add more keywords
• Change order
• etc.
• Really resolves the ambiguity
• Too many keywords make language verbose
• Unfortunately not always possible
New keyword
Solution II:
Backtracking
fragment = parser.antlr.XtextAntlrGeneratorFragment auto-inject {
options = {
backtrack = true
}
}
fragment = parser.antlr.XtextAntlrUiGeneratorFragment auto-inject {
options = {
backtrack = true
}
}
Backtracking: Maze Analogy
https://youtu.be/h0aXgiL-lws
LL(*):
You send a
trained monkey
to look ahead
Backtracking:
You try all paths
yourself
Backside of Backtracking
• Can yield exponential parse time
• Suppresses all ambiguity warnings in the grammar
• Puts syntactic predicates on all first choices
• Language implementor should make decisions
Solution III:
Syntactic Predicate
Class:
... members+=Member* ...;
Member:
Field | Method;
Field:
=>(type=[Type] name=ID)
| name=ID;
Method:
type=[Type] name=ID '(' ')';
int foo
double bar()
baz
• Start local backtracking
• “If the token sequence
matches, go this way!”
Syntactic
Predicate
Solution III:
Syntactic Predicate
Class:
... members+=Member* ...;
Member:
Field | Method;
Field:
=>(type=[Type] name=ID)
| name=ID;
Method:
type=[Type] name=ID '(' ')';
int foo
double bar()
baz
• Start local backtracking
• “If the token sequence
matches, go this way!”
Syntactic
Predicate
Solution III:
Syntactic Predicate
Class:
... members+=Member* ...;
Member:
Field | Method;
Field:
=>(type=[Type] name=ID)
| name=ID;
Method:
type=[Type] name=ID '(' ')';
int foo
double bar()
baz
Syntactic
Predicate
Solution III:
Syntactic Predicate
Class:
... members+=Member* ...;
Member:
Field | Method;
Field:
name=ID
| =>(type=[Type] name=ID);
Method:
type=[Type] name=ID '(' ')';
int foo
double bar()
baz
Wrong
Order
Caveats
• SPs remove all warnings on the local decision
• SPs are executed in the order of alternatives
• Always write tests!
• Apply the SP to a minimum set of tokens only to limit
lookahead
• Prefer first token set syntactic predicates
First Token Set Predicate
XExpressionOrSimpleConstructorCall returns XExpression:
->XbaseConstructorCall | XExpression
;
XbaseConstructorCall returns XConstructorCall:
{xbase::XConstructorCall}
'new' constructor=[types::JvmConstructor|QualifiedName]
(=> ... // further stuff with complicated lookahead
First Token
• “If you find ‘new’, go this way!”
• Shortens lookahead
• Improves performance and error recovery
First Token
Predicate
Agenda
• Understanding The Parser
• Ambiguities
• Debugging a Grammar
• Non-LL(*) Decisions
Detecting Ambiguities
// with Xbase
Model returns XExpression:
XExpression;
XLiteral returns XExpression:
RGBLiteral |
XCollectionLiteral |
XClosure |
XBooleanLiteral |
XNumberLiteral |
XNullLiteral |
XStringLiteral |
XTypeLiteral;
RGBLiteral:
red=INT ':' green=INT ':' blue=INT;
255:10:10 // an RGB literal
Detecting Ambiguities
// with Xbase
Model:
expr=XExpression;
XLiteral returns XExpression:
RGBLiteral |
XCollectionLiteral |
XClosure |
XBooleanLiteral |
XNumberLiteral |
XNullLiteral |
XStringLiteral |
XTypeLiteral;
RGBLiteral:
red=INT ':' green=INT ':' blue=INT;
255:10:10 // an RGB literal
warning(200): ..InternalXbaseExample.g:119:1:
Decision can match input such as "RULE_INT ':' RULE_INT ':'
RULE_INT" using multiple alternatives: 1, 5
As a result, alternative(s) 5 were disabled for that input
Semantic predicates were present but were hidden by actions.
Debugging With ANTLRWorks
fragment =
parser.antlr.DebugAntlrGeneratorFragment
auto-inject {}
ANTLRWorks
Agenda
• Understanding The Parser
• Ambiguities
• Debugging a Grammar
• Non-LL(*) Decisions
Class:
... members+=Member* ...;
Member:
Field | Method;
Field:
mods+=Modifier* type=[Type] name=ID;
Method:
mods+=Modifier* return=[Type] name=ID '(' ')';
enum Modifier:
public | protected | private | final | static;
LL(*) und DFA
private static final int foo
public double bar()
Loop in
Lookahead
s0
Method Field
public...static
s1
ID
s2
ID
( <else>
Non LL(*) Decision
Class:
... members+=Member* ...;
Member:
Field | Method;
Field:
type=TypeRef name=ID;
Method:
return=TypeRef name=ID '(' ')';
TypeRef:
name=[Type] ('<' typeArg=TypeRef '>')?;
Map<String, Set<String>> foo
List<String> bar()
Recursion in
Lookahead
Non LL*
Class:
... members+=Member* ...;
Member:
Field | Method;
Field:
type=TypeRef name=ID;
Method:
return=TypeRef name=ID '(' ')';
TypeRef:
name=[Type] ('<' typeArg=TypeRef '>')?;
Map<String, Set<String>> foo
List<String> bar()
Recursion in
Lookahead
error(211): ..InternalMyDsl.g:119:1:
[fatal] rule ruleMember has non-LL(*) decision due to
recursive rule invocations reachable from alts 1,2.
Resolve by left-factoring or using syntactic predicates or
using backtrack=true option.
Syntactic Predicate
Class:
... members+=Member* ...;
Member:
Field | Method;
Field:
type=TypeRef name=ID;
Method:
=>(returnType=TypeRef name=ID '(') ')';
TypeRef:
name=[Type] ('<' typeArg=TypeRef '>')?;
Map<String, Set<String>> foo
List<String> bar()
Syntactic
Predicate
Syntactic Predicate
Class:
... members+=Member* ...;
Member:
Field | Method;
Field:
type=TypeRef name=ID;
Method:
=>(returnType=TypeRef name=ID '(') ')';
TypeRef:
name=[Type] ('<' typeArg=TypeRef '>')?;
Map<String, Set<String>> foo
List<String> bar()
Syntactic Predicate
Class:
... members+=Member* ...;
Member:
Method | Field;
Field:
type=TypeRef name=ID;
Method:
=>(returnType=TypeRef name=ID '(') ')';
TypeRef:
name=[Type] ('<' typeArg=TypeRef '>')?;
Map<String, Set<String>> foo
List<String> bar()
Syntactic Predicate
Class:
... members+=Member* ...;
Member:
Method | Field;
Field:
type=TypeRef name=ID;
Method:
=>(returnType=TypeRef name=ID '(') ')';
TypeRef:
name=[Type] ('<' typeArg=TypeRef '>')?;
Map<String, Set<String>> foo
List<String> bar()
Left-Factoring Using Actions
Class:
... members+=Member* ...;
Member:
TypeRef (
{Field.type=current} name=ID
| {Method.return=current} name=ID '(' ')');
TypeRef:
name=[Type] ('<' typeArg=TypeRef '>')?;
List<Set<String>> foo
List<String> bar()
Common
Element
Assigned
Actions
Resources
• ANTLRWorks:

http://www.antlr3.org/works/
• The book:

More Related Content

What's hot

C# 7.x What's new and what's coming with C# 8
C# 7.x What's new and what's coming with C# 8C# 7.x What's new and what's coming with C# 8
C# 7.x What's new and what's coming with C# 8Christian Nagel
 
Csharp In Detail Part2
Csharp In Detail Part2Csharp In Detail Part2
Csharp In Detail Part2Mohamed Krar
 
14. Defining Classes
14. Defining Classes14. Defining Classes
14. Defining ClassesIntro C# Book
 
Programming in Scala: Notes
Programming in Scala: NotesProgramming in Scala: Notes
Programming in Scala: NotesRoberto Casadei
 
Lift off with Groovy 2 at JavaOne 2013
Lift off with Groovy 2 at JavaOne 2013Lift off with Groovy 2 at JavaOne 2013
Lift off with Groovy 2 at JavaOne 2013Guillaume Laforge
 
Building DSLs with Xtext - Eclipse Modeling Day 2009
Building DSLs with Xtext - Eclipse Modeling Day 2009Building DSLs with Xtext - Eclipse Modeling Day 2009
Building DSLs with Xtext - Eclipse Modeling Day 2009Heiko Behrens
 
Esoft Metro Campus - Programming with C++
Esoft Metro Campus - Programming with C++Esoft Metro Campus - Programming with C++
Esoft Metro Campus - Programming with C++Rasan Samarasinghe
 
Ti1220 Lecture 2: Names, Bindings, and Scopes
Ti1220 Lecture 2: Names, Bindings, and ScopesTi1220 Lecture 2: Names, Bindings, and Scopes
Ti1220 Lecture 2: Names, Bindings, and ScopesEelco Visser
 
Groovy Ast Transformations (greach)
Groovy Ast Transformations (greach)Groovy Ast Transformations (greach)
Groovy Ast Transformations (greach)HamletDRC
 
Oop2011 actor presentation_stal
Oop2011 actor presentation_stalOop2011 actor presentation_stal
Oop2011 actor presentation_stalMichael Stal
 
DISE - Windows Based Application Development in C#
DISE - Windows Based Application Development in C#DISE - Windows Based Application Development in C#
DISE - Windows Based Application Development in C#Rasan Samarasinghe
 
Variables: names, bindings, type, scope
Variables: names, bindings, type, scopeVariables: names, bindings, type, scope
Variables: names, bindings, type, scopesuthi
 
Java tutorial for Beginners and Entry Level
Java tutorial for Beginners and Entry LevelJava tutorial for Beginners and Entry Level
Java tutorial for Beginners and Entry LevelRamrao Desai
 
Introduction to Programming Bots
Introduction to Programming BotsIntroduction to Programming Bots
Introduction to Programming BotsDmitri Nesteruk
 
STL ALGORITHMS
STL ALGORITHMSSTL ALGORITHMS
STL ALGORITHMSfawzmasood
 

What's hot (20)

C# 7.x What's new and what's coming with C# 8
C# 7.x What's new and what's coming with C# 8C# 7.x What's new and what's coming with C# 8
C# 7.x What's new and what's coming with C# 8
 
Csharp In Detail Part2
Csharp In Detail Part2Csharp In Detail Part2
Csharp In Detail Part2
 
14. Defining Classes
14. Defining Classes14. Defining Classes
14. Defining Classes
 
JAVA OOP
JAVA OOPJAVA OOP
JAVA OOP
 
The Style of C++ 11
The Style of C++ 11The Style of C++ 11
The Style of C++ 11
 
Javascript
JavascriptJavascript
Javascript
 
Programming in Scala: Notes
Programming in Scala: NotesProgramming in Scala: Notes
Programming in Scala: Notes
 
Lift off with Groovy 2 at JavaOne 2013
Lift off with Groovy 2 at JavaOne 2013Lift off with Groovy 2 at JavaOne 2013
Lift off with Groovy 2 at JavaOne 2013
 
Building DSLs with Xtext - Eclipse Modeling Day 2009
Building DSLs with Xtext - Eclipse Modeling Day 2009Building DSLs with Xtext - Eclipse Modeling Day 2009
Building DSLs with Xtext - Eclipse Modeling Day 2009
 
Esoft Metro Campus - Programming with C++
Esoft Metro Campus - Programming with C++Esoft Metro Campus - Programming with C++
Esoft Metro Campus - Programming with C++
 
Ti1220 Lecture 2: Names, Bindings, and Scopes
Ti1220 Lecture 2: Names, Bindings, and ScopesTi1220 Lecture 2: Names, Bindings, and Scopes
Ti1220 Lecture 2: Names, Bindings, and Scopes
 
Groovy Ast Transformations (greach)
Groovy Ast Transformations (greach)Groovy Ast Transformations (greach)
Groovy Ast Transformations (greach)
 
Oop2011 actor presentation_stal
Oop2011 actor presentation_stalOop2011 actor presentation_stal
Oop2011 actor presentation_stal
 
DISE - Windows Based Application Development in C#
DISE - Windows Based Application Development in C#DISE - Windows Based Application Development in C#
DISE - Windows Based Application Development in C#
 
Variables: names, bindings, type, scope
Variables: names, bindings, type, scopeVariables: names, bindings, type, scope
Variables: names, bindings, type, scope
 
Java tutorial for Beginners and Entry Level
Java tutorial for Beginners and Entry LevelJava tutorial for Beginners and Entry Level
Java tutorial for Beginners and Entry Level
 
Introduction to Programming Bots
Introduction to Programming BotsIntroduction to Programming Bots
Introduction to Programming Bots
 
Cheat Sheet java
Cheat Sheet javaCheat Sheet java
Cheat Sheet java
 
Java 5 Features
Java 5 FeaturesJava 5 Features
Java 5 Features
 
STL ALGORITHMS
STL ALGORITHMSSTL ALGORITHMS
STL ALGORITHMS
 

Viewers also liked

Extending the Xbase Typesystem
Extending the Xbase TypesystemExtending the Xbase Typesystem
Extending the Xbase TypesystemSebastian Zarnekow
 
Code retreat @BMW Car IT
Code retreat @BMW Car ITCode retreat @BMW Car IT
Code retreat @BMW Car ITSebastian Benz
 
ARText - Driving Developments with Xtext
ARText - Driving Developments with XtextARText - Driving Developments with Xtext
ARText - Driving Developments with XtextSebastian Benz
 
Parsing Expression With Xtext
Parsing Expression With XtextParsing Expression With Xtext
Parsing Expression With XtextSven Efftinge
 
Xtext's new Formatter API
Xtext's new Formatter APIXtext's new Formatter API
Xtext's new Formatter APImeysholdt
 
Building a Python IDE with Xtext
Building a Python IDE with XtextBuilding a Python IDE with Xtext
Building a Python IDE with XtextSebastian Zarnekow
 
Language Engineering With Xtext
Language Engineering With XtextLanguage Engineering With Xtext
Language Engineering With XtextSven Efftinge
 
Codegeneration Goodies
Codegeneration GoodiesCodegeneration Goodies
Codegeneration Goodiesmeysholdt
 
Pragmatic DSL Design with Xtext, Xbase and Xtend 2
Pragmatic DSL Design with Xtext, Xbase and Xtend 2Pragmatic DSL Design with Xtext, Xbase and Xtend 2
Pragmatic DSL Design with Xtext, Xbase and Xtend 2Dr. Jan Köhnlein
 
Building Your Own DSL with Xtext
Building Your Own DSL with XtextBuilding Your Own DSL with Xtext
Building Your Own DSL with XtextGlobalLogic Ukraine
 
Executable specifications for xtext
Executable specifications for xtextExecutable specifications for xtext
Executable specifications for xtextmeysholdt
 

Viewers also liked (20)

Extending the Xbase Typesystem
Extending the Xbase TypesystemExtending the Xbase Typesystem
Extending the Xbase Typesystem
 
Scoping Tips and Tricks
Scoping Tips and TricksScoping Tips and Tricks
Scoping Tips and Tricks
 
Scoping
ScopingScoping
Scoping
 
Xtext Best Practices
Xtext Best PracticesXtext Best Practices
Xtext Best Practices
 
Code retreat @BMW Car IT
Code retreat @BMW Car ITCode retreat @BMW Car IT
Code retreat @BMW Car IT
 
ARText - Driving Developments with Xtext
ARText - Driving Developments with XtextARText - Driving Developments with Xtext
ARText - Driving Developments with Xtext
 
Parsing Expression With Xtext
Parsing Expression With XtextParsing Expression With Xtext
Parsing Expression With Xtext
 
Responsiveness
ResponsivenessResponsiveness
Responsiveness
 
XRobots
XRobotsXRobots
XRobots
 
Code Generation With Xtend
Code Generation With XtendCode Generation With Xtend
Code Generation With Xtend
 
Xtext's new Formatter API
Xtext's new Formatter APIXtext's new Formatter API
Xtext's new Formatter API
 
Building a Python IDE with Xtext
Building a Python IDE with XtextBuilding a Python IDE with Xtext
Building a Python IDE with Xtext
 
What's Cooking in Xtext 2.0
What's Cooking in Xtext 2.0What's Cooking in Xtext 2.0
What's Cooking in Xtext 2.0
 
Language Engineering With Xtext
Language Engineering With XtextLanguage Engineering With Xtext
Language Engineering With Xtext
 
Codegeneration Goodies
Codegeneration GoodiesCodegeneration Goodies
Codegeneration Goodies
 
Pragmatic DSL Design with Xtext, Xbase and Xtend 2
Pragmatic DSL Design with Xtext, Xbase and Xtend 2Pragmatic DSL Design with Xtext, Xbase and Xtend 2
Pragmatic DSL Design with Xtext, Xbase and Xtend 2
 
Building Your Own DSL with Xtext
Building Your Own DSL with XtextBuilding Your Own DSL with Xtext
Building Your Own DSL with Xtext
 
Executable specifications for xtext
Executable specifications for xtextExecutable specifications for xtext
Executable specifications for xtext
 
Future of Xtext
Future of XtextFuture of Xtext
Future of Xtext
 
Java DSLs with Xtext
Java DSLs with XtextJava DSLs with Xtext
Java DSLs with Xtext
 

Similar to Getting rid of backtracking

JavaScript in 2016 (Codemotion Rome)
JavaScript in 2016 (Codemotion Rome)JavaScript in 2016 (Codemotion Rome)
JavaScript in 2016 (Codemotion Rome)Eduard Tomàs
 
JavaScript in 2016
JavaScript in 2016JavaScript in 2016
JavaScript in 2016Codemotion
 
TypeScript Best Practices
TypeScript Best PracticesTypeScript Best Practices
TypeScript Best Practicesfelixbillon
 
Core java complete ppt(note)
Core java  complete  ppt(note)Core java  complete  ppt(note)
Core java complete ppt(note)arvind pandey
 
Python Training v2
Python Training v2Python Training v2
Python Training v2ibaydan
 
Functional programming in kotlin with Arrow [Sunnytech 2018]
Functional programming in kotlin with Arrow [Sunnytech 2018]Functional programming in kotlin with Arrow [Sunnytech 2018]
Functional programming in kotlin with Arrow [Sunnytech 2018]Emmanuel Nhan
 
Object Calisthenics em Go
Object Calisthenics em GoObject Calisthenics em Go
Object Calisthenics em GoElton Minetto
 
Introduction to Python for Plone developers
Introduction to Python for Plone developersIntroduction to Python for Plone developers
Introduction to Python for Plone developersJim Roepcke
 
Type Profiler: Ambitious Type Inference for Ruby 3
Type Profiler: Ambitious Type Inference for Ruby 3Type Profiler: Ambitious Type Inference for Ruby 3
Type Profiler: Ambitious Type Inference for Ruby 3mametter
 
Pharo, an innovative and open-source Smalltalk
Pharo, an innovative and open-source SmalltalkPharo, an innovative and open-source Smalltalk
Pharo, an innovative and open-source SmalltalkSerge Stinckwich
 
SenchaCon 2016: Modernizing the Ext JS Class System - Don Griffin
SenchaCon 2016: Modernizing the Ext JS Class System - Don GriffinSenchaCon 2016: Modernizing the Ext JS Class System - Don Griffin
SenchaCon 2016: Modernizing the Ext JS Class System - Don GriffinSencha
 
Php 5.4: New Language Features You Will Find Useful
Php 5.4: New Language Features You Will Find UsefulPhp 5.4: New Language Features You Will Find Useful
Php 5.4: New Language Features You Will Find UsefulDavid Engel
 
Type Profiler: An Analysis to guess type signatures
Type Profiler: An Analysis to guess type signaturesType Profiler: An Analysis to guess type signatures
Type Profiler: An Analysis to guess type signaturesmametter
 
gdscWorkShopJavascriptintroductions.pptx
gdscWorkShopJavascriptintroductions.pptxgdscWorkShopJavascriptintroductions.pptx
gdscWorkShopJavascriptintroductions.pptxsandeshshahapur
 
Introduction to web programming for java and c# programmers by @drpicox
Introduction to web programming for java and c# programmers by @drpicoxIntroduction to web programming for java and c# programmers by @drpicox
Introduction to web programming for java and c# programmers by @drpicoxDavid Rodenas
 

Similar to Getting rid of backtracking (20)

JavaScript in 2016 (Codemotion Rome)
JavaScript in 2016 (Codemotion Rome)JavaScript in 2016 (Codemotion Rome)
JavaScript in 2016 (Codemotion Rome)
 
JavaScript in 2016
JavaScript in 2016JavaScript in 2016
JavaScript in 2016
 
TypeScript Best Practices
TypeScript Best PracticesTypeScript Best Practices
TypeScript Best Practices
 
Core java complete ppt(note)
Core java  complete  ppt(note)Core java  complete  ppt(note)
Core java complete ppt(note)
 
Intro to Python
Intro to PythonIntro to Python
Intro to Python
 
Python Training v2
Python Training v2Python Training v2
Python Training v2
 
Functional programming in kotlin with Arrow [Sunnytech 2018]
Functional programming in kotlin with Arrow [Sunnytech 2018]Functional programming in kotlin with Arrow [Sunnytech 2018]
Functional programming in kotlin with Arrow [Sunnytech 2018]
 
Object Calisthenics em Go
Object Calisthenics em GoObject Calisthenics em Go
Object Calisthenics em Go
 
Introduction to Python for Plone developers
Introduction to Python for Plone developersIntroduction to Python for Plone developers
Introduction to Python for Plone developers
 
Type Profiler: Ambitious Type Inference for Ruby 3
Type Profiler: Ambitious Type Inference for Ruby 3Type Profiler: Ambitious Type Inference for Ruby 3
Type Profiler: Ambitious Type Inference for Ruby 3
 
Pharo, an innovative and open-source Smalltalk
Pharo, an innovative and open-source SmalltalkPharo, an innovative and open-source Smalltalk
Pharo, an innovative and open-source Smalltalk
 
Intro
IntroIntro
Intro
 
SenchaCon 2016: Modernizing the Ext JS Class System - Don Griffin
SenchaCon 2016: Modernizing the Ext JS Class System - Don GriffinSenchaCon 2016: Modernizing the Ext JS Class System - Don Griffin
SenchaCon 2016: Modernizing the Ext JS Class System - Don Griffin
 
Php 5.4: New Language Features You Will Find Useful
Php 5.4: New Language Features You Will Find UsefulPhp 5.4: New Language Features You Will Find Useful
Php 5.4: New Language Features You Will Find Useful
 
Type Profiler: An Analysis to guess type signatures
Type Profiler: An Analysis to guess type signaturesType Profiler: An Analysis to guess type signatures
Type Profiler: An Analysis to guess type signatures
 
Object Oriented Programming using C++ - Part 4
Object Oriented Programming using C++ - Part 4Object Oriented Programming using C++ - Part 4
Object Oriented Programming using C++ - Part 4
 
gdscWorkShopJavascriptintroductions.pptx
gdscWorkShopJavascriptintroductions.pptxgdscWorkShopJavascriptintroductions.pptx
gdscWorkShopJavascriptintroductions.pptx
 
Introduction to web programming for java and c# programmers by @drpicox
Introduction to web programming for java and c# programmers by @drpicoxIntroduction to web programming for java and c# programmers by @drpicox
Introduction to web programming for java and c# programmers by @drpicox
 
Python course
Python coursePython course
Python course
 
Learning python
Learning pythonLearning python
Learning python
 

More from Dr. Jan Köhnlein

The Eclipse Layout Kernel sirius con 2017
The Eclipse Layout Kernel   sirius con 2017The Eclipse Layout Kernel   sirius con 2017
The Eclipse Layout Kernel sirius con 2017Dr. Jan Köhnlein
 
A New Approach Towards Web-based IDEs
A New Approach Towards Web-based IDEsA New Approach Towards Web-based IDEs
A New Approach Towards Web-based IDEsDr. Jan Köhnlein
 
Graphical Views For Xtext With FXDiagram
Graphical Views For Xtext With FXDiagramGraphical Views For Xtext With FXDiagram
Graphical Views For Xtext With FXDiagramDr. Jan Köhnlein
 
Diagram Editors - The FXed Generation
Diagram Editors - The FXed GenerationDiagram Editors - The FXed Generation
Diagram Editors - The FXed GenerationDr. Jan Köhnlein
 
Eclipse Diagram Editors - An Endangered Species
Eclipse Diagram Editors - An Endangered SpeciesEclipse Diagram Editors - An Endangered Species
Eclipse Diagram Editors - An Endangered SpeciesDr. Jan Köhnlein
 
A fresh look at graphical editing
A fresh look at graphical editingA fresh look at graphical editing
A fresh look at graphical editingDr. Jan Köhnlein
 
A fresh look at graphical editing
A fresh look at graphical editingA fresh look at graphical editing
A fresh look at graphical editingDr. Jan Köhnlein
 
A fresh look at graphical editing
A fresh look at graphical editingA fresh look at graphical editing
A fresh look at graphical editingDr. Jan Köhnlein
 
Android tutorial - Xtext slides
Android tutorial - Xtext slidesAndroid tutorial - Xtext slides
Android tutorial - Xtext slidesDr. Jan Köhnlein
 
Combining Text and Graphics in Eclipse-based Modeling Tools
Combining Text and Graphics in Eclipse-based Modeling ToolsCombining Text and Graphics in Eclipse-based Modeling Tools
Combining Text and Graphics in Eclipse-based Modeling ToolsDr. Jan Köhnlein
 
Combining Graphical and Textual
Combining Graphical and TextualCombining Graphical and Textual
Combining Graphical and TextualDr. Jan Köhnlein
 
Domain Specific Languages With Eclipse Modeling
Domain Specific Languages With Eclipse ModelingDomain Specific Languages With Eclipse Modeling
Domain Specific Languages With Eclipse ModelingDr. Jan Köhnlein
 
Domänenspezifische Sprachen mit Xtext
Domänenspezifische Sprachen mit XtextDomänenspezifische Sprachen mit Xtext
Domänenspezifische Sprachen mit XtextDr. Jan Köhnlein
 

More from Dr. Jan Köhnlein (20)

The Eclipse Layout Kernel sirius con 2017
The Eclipse Layout Kernel   sirius con 2017The Eclipse Layout Kernel   sirius con 2017
The Eclipse Layout Kernel sirius con 2017
 
A New Approach Towards Web-based IDEs
A New Approach Towards Web-based IDEsA New Approach Towards Web-based IDEs
A New Approach Towards Web-based IDEs
 
Graphical Views For Xtext With FXDiagram
Graphical Views For Xtext With FXDiagramGraphical Views For Xtext With FXDiagram
Graphical Views For Xtext With FXDiagram
 
Diagrams, Xtext and UX
Diagrams, Xtext and UXDiagrams, Xtext and UX
Diagrams, Xtext and UX
 
Xtext, diagrams and ux
Xtext, diagrams and uxXtext, diagrams and ux
Xtext, diagrams and ux
 
Diagram Editors - The FXed Generation
Diagram Editors - The FXed GenerationDiagram Editors - The FXed Generation
Diagram Editors - The FXed Generation
 
Graphical Views For Xtext
Graphical Views For XtextGraphical Views For Xtext
Graphical Views For Xtext
 
The Xtext Grammar Language
The Xtext Grammar LanguageThe Xtext Grammar Language
The Xtext Grammar Language
 
Eclipse Diagram Editors - An Endangered Species
Eclipse Diagram Editors - An Endangered SpeciesEclipse Diagram Editors - An Endangered Species
Eclipse Diagram Editors - An Endangered Species
 
DSLs for Java Developers
DSLs for Java DevelopersDSLs for Java Developers
DSLs for Java Developers
 
A fresh look at graphical editing
A fresh look at graphical editingA fresh look at graphical editing
A fresh look at graphical editing
 
A fresh look at graphical editing
A fresh look at graphical editingA fresh look at graphical editing
A fresh look at graphical editing
 
A fresh look at graphical editing
A fresh look at graphical editingA fresh look at graphical editing
A fresh look at graphical editing
 
Android tutorial - Xtext slides
Android tutorial - Xtext slidesAndroid tutorial - Xtext slides
Android tutorial - Xtext slides
 
Eclipse meets e4
Eclipse meets e4Eclipse meets e4
Eclipse meets e4
 
Combining Text and Graphics in Eclipse-based Modeling Tools
Combining Text and Graphics in Eclipse-based Modeling ToolsCombining Text and Graphics in Eclipse-based Modeling Tools
Combining Text and Graphics in Eclipse-based Modeling Tools
 
Combining Graphical and Textual
Combining Graphical and TextualCombining Graphical and Textual
Combining Graphical and Textual
 
Domain Specific Languages With Eclipse Modeling
Domain Specific Languages With Eclipse ModelingDomain Specific Languages With Eclipse Modeling
Domain Specific Languages With Eclipse Modeling
 
Domänenspezifische Sprachen mit Xtext
Domänenspezifische Sprachen mit XtextDomänenspezifische Sprachen mit Xtext
Domänenspezifische Sprachen mit Xtext
 
Workshop On Xtext
Workshop On XtextWorkshop On Xtext
Workshop On Xtext
 

Recently uploaded

The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...ICS
 
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...Health
 
Chinsurah Escorts ☎️8617697112 Starting From 5K to 15K High Profile Escorts ...
Chinsurah Escorts ☎️8617697112  Starting From 5K to 15K High Profile Escorts ...Chinsurah Escorts ☎️8617697112  Starting From 5K to 15K High Profile Escorts ...
Chinsurah Escorts ☎️8617697112 Starting From 5K to 15K High Profile Escorts ...Nitya salvi
 
BUS PASS MANGEMENT SYSTEM USING PHP.pptx
BUS PASS MANGEMENT SYSTEM USING PHP.pptxBUS PASS MANGEMENT SYSTEM USING PHP.pptx
BUS PASS MANGEMENT SYSTEM USING PHP.pptxalwaysnagaraju26
 
The Guide to Integrating Generative AI into Unified Continuous Testing Platfo...
The Guide to Integrating Generative AI into Unified Continuous Testing Platfo...The Guide to Integrating Generative AI into Unified Continuous Testing Platfo...
The Guide to Integrating Generative AI into Unified Continuous Testing Platfo...kalichargn70th171
 
Payment Gateway Testing Simplified_ A Step-by-Step Guide for Beginners.pdf
Payment Gateway Testing Simplified_ A Step-by-Step Guide for Beginners.pdfPayment Gateway Testing Simplified_ A Step-by-Step Guide for Beginners.pdf
Payment Gateway Testing Simplified_ A Step-by-Step Guide for Beginners.pdfkalichargn70th171
 
Azure_Native_Qumulo_High_Performance_Compute_Benchmarks.pdf
Azure_Native_Qumulo_High_Performance_Compute_Benchmarks.pdfAzure_Native_Qumulo_High_Performance_Compute_Benchmarks.pdf
Azure_Native_Qumulo_High_Performance_Compute_Benchmarks.pdfryanfarris8
 
Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...
Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...
Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...Steffen Staab
 
Crypto Cloud Review - How To Earn Up To $500 Per DAY Of Bitcoin 100% On AutoP...
Crypto Cloud Review - How To Earn Up To $500 Per DAY Of Bitcoin 100% On AutoP...Crypto Cloud Review - How To Earn Up To $500 Per DAY Of Bitcoin 100% On AutoP...
Crypto Cloud Review - How To Earn Up To $500 Per DAY Of Bitcoin 100% On AutoP...SelfMade bd
 
%in tembisa+277-882-255-28 abortion pills for sale in tembisa
%in tembisa+277-882-255-28 abortion pills for sale in tembisa%in tembisa+277-882-255-28 abortion pills for sale in tembisa
%in tembisa+277-882-255-28 abortion pills for sale in tembisamasabamasaba
 
Direct Style Effect Systems - The Print[A] Example - A Comprehension Aid
Direct Style Effect Systems -The Print[A] Example- A Comprehension AidDirect Style Effect Systems -The Print[A] Example- A Comprehension Aid
Direct Style Effect Systems - The Print[A] Example - A Comprehension AidPhilip Schwarz
 
ManageIQ - Sprint 236 Review - Slide Deck
ManageIQ - Sprint 236 Review - Slide DeckManageIQ - Sprint 236 Review - Slide Deck
ManageIQ - Sprint 236 Review - Slide DeckManageIQ
 
How To Troubleshoot Collaboration Apps for the Modern Connected Worker
How To Troubleshoot Collaboration Apps for the Modern Connected WorkerHow To Troubleshoot Collaboration Apps for the Modern Connected Worker
How To Troubleshoot Collaboration Apps for the Modern Connected WorkerThousandEyes
 
introduction-to-automotive Andoid os-csimmonds-ndctechtown-2021.pdf
introduction-to-automotive Andoid os-csimmonds-ndctechtown-2021.pdfintroduction-to-automotive Andoid os-csimmonds-ndctechtown-2021.pdf
introduction-to-automotive Andoid os-csimmonds-ndctechtown-2021.pdfVishalKumarJha10
 
MarTech Trend 2024 Book : Marketing Technology Trends (2024 Edition) How Data...
MarTech Trend 2024 Book : Marketing Technology Trends (2024 Edition) How Data...MarTech Trend 2024 Book : Marketing Technology Trends (2024 Edition) How Data...
MarTech Trend 2024 Book : Marketing Technology Trends (2024 Edition) How Data...Jittipong Loespradit
 
AI Mastery 201: Elevating Your Workflow with Advanced LLM Techniques
AI Mastery 201: Elevating Your Workflow with Advanced LLM TechniquesAI Mastery 201: Elevating Your Workflow with Advanced LLM Techniques
AI Mastery 201: Elevating Your Workflow with Advanced LLM TechniquesVictorSzoltysek
 
%in Midrand+277-882-255-28 abortion pills for sale in midrand
%in Midrand+277-882-255-28 abortion pills for sale in midrand%in Midrand+277-882-255-28 abortion pills for sale in midrand
%in Midrand+277-882-255-28 abortion pills for sale in midrandmasabamasaba
 
%in kaalfontein+277-882-255-28 abortion pills for sale in kaalfontein
%in kaalfontein+277-882-255-28 abortion pills for sale in kaalfontein%in kaalfontein+277-882-255-28 abortion pills for sale in kaalfontein
%in kaalfontein+277-882-255-28 abortion pills for sale in kaalfonteinmasabamasaba
 

Recently uploaded (20)

Microsoft AI Transformation Partner Playbook.pdf
Microsoft AI Transformation Partner Playbook.pdfMicrosoft AI Transformation Partner Playbook.pdf
Microsoft AI Transformation Partner Playbook.pdf
 
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...
 
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
 
Chinsurah Escorts ☎️8617697112 Starting From 5K to 15K High Profile Escorts ...
Chinsurah Escorts ☎️8617697112  Starting From 5K to 15K High Profile Escorts ...Chinsurah Escorts ☎️8617697112  Starting From 5K to 15K High Profile Escorts ...
Chinsurah Escorts ☎️8617697112 Starting From 5K to 15K High Profile Escorts ...
 
BUS PASS MANGEMENT SYSTEM USING PHP.pptx
BUS PASS MANGEMENT SYSTEM USING PHP.pptxBUS PASS MANGEMENT SYSTEM USING PHP.pptx
BUS PASS MANGEMENT SYSTEM USING PHP.pptx
 
The Guide to Integrating Generative AI into Unified Continuous Testing Platfo...
The Guide to Integrating Generative AI into Unified Continuous Testing Platfo...The Guide to Integrating Generative AI into Unified Continuous Testing Platfo...
The Guide to Integrating Generative AI into Unified Continuous Testing Platfo...
 
CHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
CHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICECHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
CHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
 
Payment Gateway Testing Simplified_ A Step-by-Step Guide for Beginners.pdf
Payment Gateway Testing Simplified_ A Step-by-Step Guide for Beginners.pdfPayment Gateway Testing Simplified_ A Step-by-Step Guide for Beginners.pdf
Payment Gateway Testing Simplified_ A Step-by-Step Guide for Beginners.pdf
 
Azure_Native_Qumulo_High_Performance_Compute_Benchmarks.pdf
Azure_Native_Qumulo_High_Performance_Compute_Benchmarks.pdfAzure_Native_Qumulo_High_Performance_Compute_Benchmarks.pdf
Azure_Native_Qumulo_High_Performance_Compute_Benchmarks.pdf
 
Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...
Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...
Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...
 
Crypto Cloud Review - How To Earn Up To $500 Per DAY Of Bitcoin 100% On AutoP...
Crypto Cloud Review - How To Earn Up To $500 Per DAY Of Bitcoin 100% On AutoP...Crypto Cloud Review - How To Earn Up To $500 Per DAY Of Bitcoin 100% On AutoP...
Crypto Cloud Review - How To Earn Up To $500 Per DAY Of Bitcoin 100% On AutoP...
 
%in tembisa+277-882-255-28 abortion pills for sale in tembisa
%in tembisa+277-882-255-28 abortion pills for sale in tembisa%in tembisa+277-882-255-28 abortion pills for sale in tembisa
%in tembisa+277-882-255-28 abortion pills for sale in tembisa
 
Direct Style Effect Systems - The Print[A] Example - A Comprehension Aid
Direct Style Effect Systems -The Print[A] Example- A Comprehension AidDirect Style Effect Systems -The Print[A] Example- A Comprehension Aid
Direct Style Effect Systems - The Print[A] Example - A Comprehension Aid
 
ManageIQ - Sprint 236 Review - Slide Deck
ManageIQ - Sprint 236 Review - Slide DeckManageIQ - Sprint 236 Review - Slide Deck
ManageIQ - Sprint 236 Review - Slide Deck
 
How To Troubleshoot Collaboration Apps for the Modern Connected Worker
How To Troubleshoot Collaboration Apps for the Modern Connected WorkerHow To Troubleshoot Collaboration Apps for the Modern Connected Worker
How To Troubleshoot Collaboration Apps for the Modern Connected Worker
 
introduction-to-automotive Andoid os-csimmonds-ndctechtown-2021.pdf
introduction-to-automotive Andoid os-csimmonds-ndctechtown-2021.pdfintroduction-to-automotive Andoid os-csimmonds-ndctechtown-2021.pdf
introduction-to-automotive Andoid os-csimmonds-ndctechtown-2021.pdf
 
MarTech Trend 2024 Book : Marketing Technology Trends (2024 Edition) How Data...
MarTech Trend 2024 Book : Marketing Technology Trends (2024 Edition) How Data...MarTech Trend 2024 Book : Marketing Technology Trends (2024 Edition) How Data...
MarTech Trend 2024 Book : Marketing Technology Trends (2024 Edition) How Data...
 
AI Mastery 201: Elevating Your Workflow with Advanced LLM Techniques
AI Mastery 201: Elevating Your Workflow with Advanced LLM TechniquesAI Mastery 201: Elevating Your Workflow with Advanced LLM Techniques
AI Mastery 201: Elevating Your Workflow with Advanced LLM Techniques
 
%in Midrand+277-882-255-28 abortion pills for sale in midrand
%in Midrand+277-882-255-28 abortion pills for sale in midrand%in Midrand+277-882-255-28 abortion pills for sale in midrand
%in Midrand+277-882-255-28 abortion pills for sale in midrand
 
%in kaalfontein+277-882-255-28 abortion pills for sale in kaalfontein
%in kaalfontein+277-882-255-28 abortion pills for sale in kaalfontein%in kaalfontein+277-882-255-28 abortion pills for sale in kaalfontein
%in kaalfontein+277-882-255-28 abortion pills for sale in kaalfontein
 

Getting rid of backtracking

  • 2. Agenda • Understanding The Parser • Ambiguities • Debugging a Grammar • Non-LL(*) Decisions
  • 3. Agenda • Understanding The Parser • Ambiguities • Debugging a Grammar • Non-LL(*) Decisions
  • 4. Parsing in Xtext • Xtext continuously parses documents in editor • Parsing needs to be fast • Parsing needs good error recovery • Xtext uses ANTLR 3.2 • LL(*) parser generator
  • 5. LL-Parsing • Traverse the document from beginning to end • Each rule becomes a method • Iterate: 1. Look ahead the minimum number of tokens to decide on the next path segment 2. Rewind and generate AST along that path segment
  • 6. Lookahead: Decision Class: ... members+=Member* ...; Member: Field | Method; Field: type=[Type] name=ID; Method: return=[Type] name=ID '(' ')'; int foo double bar()
  • 7. Lookahead: Syntax Only Class: ... members+=Member* ...; Member: Field | Method; Field: type=[Type] name=ID; Method: return=[Type] name=ID '(' ')'; int foo double bar()
  • 8. Lookahead: Syntax Only! Class: ... members+=Member* ...; Member: Field | Method; Field: type=[Type] name=ID; Method: return=[Type] name=ID '(' ')'; int foo double bar() ID ID
  • 9. Lookahead: Common Tokens Class: ... members+=Member* ...; Member: Field | Method; Field: type=[Type] name=ID; Method: return=[Type] name=ID '(' ')'; int foo double bar() ID ID Lookahead k=3
  • 10. Lookahead: If-Cascade Class: ... members+=Member* ...; Member: Field | Method; Field: type=[Type] name=ID; Method: return=[Type] name=ID '(' ')'; int foo double bar() ID ID Lookahead k=3 Member ID ID yes error no ( yes no Method yes Field no
  • 11. Execution Class: ... members+=Member* ...; Member: Field | Method; Field: type=[Type] name=ID; Method: return=[Type] name=ID '(' ')'; int foo double bar()
  • 12. Execution Class: ... members+=Member* ...; Member: Field | Method; Field: type=[Type] name=ID; Method: return=[Type] name=ID '(' ')';ID ID Member ID ID yes error no ( yes no Method yes Field no int foo double bar()
  • 13. Execution Class: ... members+=Member* ...; Member: Field | Method; Field: type=[Type] name=ID; Method: return=[Type] name=ID '(' ')'; int foo double bar() ID ID Member ID ID yes error no ( yes no Method yes Field no
  • 14. Execution Class: ... members+=Member* ...; Member: Field | Method; Field: type=[Type] name=ID; Method: return=[Type] name=ID '(' ')'; int foo double bar() ID ID Member ID ID yes error no ( yes no Method yes Field no
  • 15. Execution Class: ... members+=Member* ...; Member: Field | Method; Field: type=[Type] name=ID; Method: return=[Type] name=ID '(' ')'; int foo double bar() ID ID Member ID ID yes error no ( yes no Method yes Field no It’s a Field!
  • 16. Execution Class: ... members+=Member* ...; Member: Field | Method; Field: type=[Type] name=ID; Method: return=[Type] name=ID '(' ')'; int foo double bar() Create Field
  • 17. Execution Class: ... members+=Member* ...; Member: Field | Method; Field: type=[Type] name=ID; Method: return=[Type] name=ID '(' ')'; int foo double bar() Create Field
  • 18. Execution Class: ... members+=Member* ...; Member: Field | Method; Field: type=[Type] name=ID; Method: return=[Type] name=ID '(' ')'; int foo double bar() Member ID ID yes error no ( yes no Method yes Field no Class: ... members+=Member* ...; Member: Field | Method; Field: type=[Type] name=ID; Method: return=[Type] name=ID '(' ')';ID ID
  • 19. Execution Class: ... members+=Member* ...; Member: Field | Method; Field: type=[Type] name=ID; Method: return=[Type] name=ID '(' ')'; int foo double bar() Member ID ID yes error no ( yes no Method yes Field no Class: ... members+=Member* ...; Member: Field | Method; Field: type=[Type] name=ID; Method: return=[Type] name=ID '(' ')';ID ID
  • 20. Execution Class: ... members+=Member* ...; Member: Field | Method; Field: type=[Type] name=ID; Method: return=[Type] name=ID '(' ')'; int foo double bar() Member ID ID yes error no ( yes no Method yes Field no It’s a Method! Class: ... members+=Member* ...; Member: Field | Method; Field: type=[Type] name=ID; Method: return=[Type] name=ID '(' ')';ID ID
  • 21. Execution Class: ... members+=Member* ...; Member: Field | Method; Field: type=[Type] name=ID; Method: return=[Type] name=ID '(' ')'; int foo double bar() Create Method
  • 22. Execution Class: ... members+=Member* ...; Member: Field | Method; Field: type=[Type] name=ID; Method: return=[Type] name=ID '(' ')'; int foo double bar() Create Method
  • 23. Agenda • Understanding The Parser • Ambiguities • Debugging a Grammar • Non-LL(*) Decisions
  • 24. Ambiguities • Multiple paths in the grammar 
 for the same sequence of tokens • Caused by • alternatives | • optional cardinalities ? and *
  • 25. Simple Example Class: ... members+=Member* ...; Member: Field | Method; Field: type=[Type]? name=ID; Method: return=[Type] name=ID '(' ')'; int foo double bar() baz
  • 26. Simple Example Class: ... members+=Member* ...; Member: Field | Method; Field: type=[Type]? name=ID; Method: return=[Type] name=ID '(' ')'; int foo double bar() bazwarning(200): ..InternalMyDsl.g:258:2: Decision can match input such as "RULE_ID" using multiple alternatives: 1, 2 As a result, alternative(s) 2 were disabled for that input error(201): ..InternalMyDsl.g:258:2: The following alternatives can never be matched: 2
  • 27. Simple Example Class: ... members+=Member* ...; Member: Field | Method; Field: type=[Type]? name=ID; Method: return=[Type] name=ID '(' ')'; int foo double bar() baz • ID ID matches • two fields w/o type • one field w type ➡ Ambiguity
  • 28. Solution I: Change Syntax Class: ... members+=Member* ...; Member: Field | Method; Field: ('val' | type=[Type]) name=ID; • Add more keywords • Change order • etc. • Really resolves the ambiguity • Too many keywords make language verbose • Unfortunately not always possible New keyword
  • 29. Solution II: Backtracking fragment = parser.antlr.XtextAntlrGeneratorFragment auto-inject { options = { backtrack = true } } fragment = parser.antlr.XtextAntlrUiGeneratorFragment auto-inject { options = { backtrack = true } }
  • 30. Backtracking: Maze Analogy https://youtu.be/h0aXgiL-lws LL(*): You send a trained monkey to look ahead Backtracking: You try all paths yourself
  • 31. Backside of Backtracking • Can yield exponential parse time • Suppresses all ambiguity warnings in the grammar • Puts syntactic predicates on all first choices • Language implementor should make decisions
  • 32. Solution III: Syntactic Predicate Class: ... members+=Member* ...; Member: Field | Method; Field: =>(type=[Type] name=ID) | name=ID; Method: type=[Type] name=ID '(' ')'; int foo double bar() baz • Start local backtracking • “If the token sequence matches, go this way!” Syntactic Predicate
  • 33. Solution III: Syntactic Predicate Class: ... members+=Member* ...; Member: Field | Method; Field: =>(type=[Type] name=ID) | name=ID; Method: type=[Type] name=ID '(' ')'; int foo double bar() baz • Start local backtracking • “If the token sequence matches, go this way!” Syntactic Predicate
  • 34. Solution III: Syntactic Predicate Class: ... members+=Member* ...; Member: Field | Method; Field: =>(type=[Type] name=ID) | name=ID; Method: type=[Type] name=ID '(' ')'; int foo double bar() baz Syntactic Predicate
  • 35. Solution III: Syntactic Predicate Class: ... members+=Member* ...; Member: Field | Method; Field: name=ID | =>(type=[Type] name=ID); Method: type=[Type] name=ID '(' ')'; int foo double bar() baz Wrong Order
  • 36. Caveats • SPs remove all warnings on the local decision • SPs are executed in the order of alternatives • Always write tests! • Apply the SP to a minimum set of tokens only to limit lookahead • Prefer first token set syntactic predicates
  • 37. First Token Set Predicate XExpressionOrSimpleConstructorCall returns XExpression: ->XbaseConstructorCall | XExpression ; XbaseConstructorCall returns XConstructorCall: {xbase::XConstructorCall} 'new' constructor=[types::JvmConstructor|QualifiedName] (=> ... // further stuff with complicated lookahead First Token • “If you find ‘new’, go this way!” • Shortens lookahead • Improves performance and error recovery First Token Predicate
  • 38. Agenda • Understanding The Parser • Ambiguities • Debugging a Grammar • Non-LL(*) Decisions
  • 39. Detecting Ambiguities // with Xbase Model returns XExpression: XExpression; XLiteral returns XExpression: RGBLiteral | XCollectionLiteral | XClosure | XBooleanLiteral | XNumberLiteral | XNullLiteral | XStringLiteral | XTypeLiteral; RGBLiteral: red=INT ':' green=INT ':' blue=INT; 255:10:10 // an RGB literal
  • 40. Detecting Ambiguities // with Xbase Model: expr=XExpression; XLiteral returns XExpression: RGBLiteral | XCollectionLiteral | XClosure | XBooleanLiteral | XNumberLiteral | XNullLiteral | XStringLiteral | XTypeLiteral; RGBLiteral: red=INT ':' green=INT ':' blue=INT; 255:10:10 // an RGB literal warning(200): ..InternalXbaseExample.g:119:1: Decision can match input such as "RULE_INT ':' RULE_INT ':' RULE_INT" using multiple alternatives: 1, 5 As a result, alternative(s) 5 were disabled for that input Semantic predicates were present but were hidden by actions.
  • 41. Debugging With ANTLRWorks fragment = parser.antlr.DebugAntlrGeneratorFragment auto-inject {} ANTLRWorks
  • 42. Agenda • Understanding The Parser • Ambiguities • Debugging a Grammar • Non-LL(*) Decisions
  • 43. Class: ... members+=Member* ...; Member: Field | Method; Field: mods+=Modifier* type=[Type] name=ID; Method: mods+=Modifier* return=[Type] name=ID '(' ')'; enum Modifier: public | protected | private | final | static; LL(*) und DFA private static final int foo public double bar() Loop in Lookahead s0 Method Field public...static s1 ID s2 ID ( <else>
  • 44. Non LL(*) Decision Class: ... members+=Member* ...; Member: Field | Method; Field: type=TypeRef name=ID; Method: return=TypeRef name=ID '(' ')'; TypeRef: name=[Type] ('<' typeArg=TypeRef '>')?; Map<String, Set<String>> foo List<String> bar() Recursion in Lookahead
  • 45. Non LL* Class: ... members+=Member* ...; Member: Field | Method; Field: type=TypeRef name=ID; Method: return=TypeRef name=ID '(' ')'; TypeRef: name=[Type] ('<' typeArg=TypeRef '>')?; Map<String, Set<String>> foo List<String> bar() Recursion in Lookahead error(211): ..InternalMyDsl.g:119:1: [fatal] rule ruleMember has non-LL(*) decision due to recursive rule invocations reachable from alts 1,2. Resolve by left-factoring or using syntactic predicates or using backtrack=true option.
  • 46. Syntactic Predicate Class: ... members+=Member* ...; Member: Field | Method; Field: type=TypeRef name=ID; Method: =>(returnType=TypeRef name=ID '(') ')'; TypeRef: name=[Type] ('<' typeArg=TypeRef '>')?; Map<String, Set<String>> foo List<String> bar() Syntactic Predicate
  • 47. Syntactic Predicate Class: ... members+=Member* ...; Member: Field | Method; Field: type=TypeRef name=ID; Method: =>(returnType=TypeRef name=ID '(') ')'; TypeRef: name=[Type] ('<' typeArg=TypeRef '>')?; Map<String, Set<String>> foo List<String> bar()
  • 48. Syntactic Predicate Class: ... members+=Member* ...; Member: Method | Field; Field: type=TypeRef name=ID; Method: =>(returnType=TypeRef name=ID '(') ')'; TypeRef: name=[Type] ('<' typeArg=TypeRef '>')?; Map<String, Set<String>> foo List<String> bar()
  • 49. Syntactic Predicate Class: ... members+=Member* ...; Member: Method | Field; Field: type=TypeRef name=ID; Method: =>(returnType=TypeRef name=ID '(') ')'; TypeRef: name=[Type] ('<' typeArg=TypeRef '>')?; Map<String, Set<String>> foo List<String> bar()
  • 50. Left-Factoring Using Actions Class: ... members+=Member* ...; Member: TypeRef ( {Field.type=current} name=ID | {Method.return=current} name=ID '(' ')'); TypeRef: name=[Type] ('<' typeArg=TypeRef '>')?; List<Set<String>> foo List<String> bar() Common Element Assigned Actions