SlideShare une entreprise Scribd logo
1  sur  32
ANTLR v3 Overview (for ANTLR v2 users) Terence Parr University of San Francisco
Topics ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
Block Info Flow Diagram
Grammar Syntax header {…} /** doc comment */ kind  grammar  name ; options {…} tokens {…} scopes… action rules … /** doc comment */ rule[String s, int z]   returns [int x, int y]   throws  E   options {…}   scopes   init {…}    :     |     ;   exceptions ^(root child1 … childN) Trees Note: No inheritance
Grammar improvements ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
Example Grammar grammar SimpleParser; program : variable* method+ ; variable: "int" ID (‘=‘ expr)? ';’ ; method  : "method" ID '(' ')' '{' variable* statement+ '}' ; statement : ID ‘=‘ expr ';' | "return" expr ';' ; expr  : ID | INT ; ID  : ('a'..'z'|'A'..'Z')+ ; INT  : '0'..'9'+ ; WS  : (' '|''|'')+ {channel=99;} ;
Using the parser CharStream in = new ANTLRFileStream(“inputfile”); SimpleParserLexer lexer = new SimpleParserLexer(in); CommonTokenStream tokens = new CommonTokenStream(lexer); SimpleParser p = new SimpleParser(tokens); p.program(); // invoke start rule
Improved grammar warnings ,[object Object],[object Object],[object Object],[object Object]
Recursion Warnings a : a A | B ; t.g:2:5: Alternative 1 discovers infinite left-recursion to a from a t.g:2:5: Alternative 1: after matching input such as B decision cannot predict what comes next due to recursion overflow to c from b // with -Im 0 (secret internal parameter) a : b | B ; b : c ; c : B b ;
Nondeterminisms ,[object Object],[object Object],[object Object],a : (A B|A B) C ; a : (A+ B|A+ B) C ; t.g:2:5: Decision can match input such as "A B" using multiple   alternatives: 1, 2
Runtime Objects of Interest ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
Error Recovery ,[object Object],[object Object],[object Object],[object Object],[object Object]
Example Error Recovery int i = 0; method foo( { int j = i; i = 4 } [program, method]: line 2:12 mismatched token: [@14,23:23='{',<14>,2:12]; expecting type ')' [program, method, statement]: line 5:0 mismatched token: [@31,46:46='}',<15>,5:0]; expecting type ';' int i = 0; method foo() ) { int j = i; i = = 4; } [program, method]: line 2:13 mismatched token: [@15,24:24=')',<13>,2:13]; expecting type '{' [program, method, statement, expr]: line 4:6 mismatched token: [@32,47:47='=',<6>,4:6]; expecting set null Note: I put in two errors each so you’ll see it continues properly One token  insertion One token  deletion
Attributes ,[object Object],[object Object],[object Object],a[String s] returns [float y] : id=ID f=field (ids+=ID)+   {$s, $y, $id, $id.text, $f.z; $ids.size();} ; field returns [int x, int z] : … ;
Label properties ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
Rule Scope Attributes ,[object Object],[object Object],method scope { String name; } : &quot;method&quot; ID '(' ')' {$name=$ID.text;} body   ; body: '{' stat* '}’ ; … atom init {… $ method .name …} : ID | INT ;
Global Scope Attributes ,[object Object],scope Symbols { List names; } {int level=0;} globals scope Symbols; init { level++; $Symbols.names = new ArrayList(); } : decl* {level--;} ; block scope Symbols; init { level++; $Symbols.names = new ArrayList(); } :  '{' decl* stat* '}’ {level--;} ; decl :  &quot;int&quot; ID ';' {$Symbols.names.add($ID);} ; *What if we want to keep the symbol tables around after parsing?
Tree Support ,[object Object],[object Object],[object Object],[object Object],[object Object]
Tree Construction ,[object Object],[object Object],[object Object],[object Object],[object Object]
Tree Rewrite Rules ,[object Object],variable :  type declarator ';' -> ^(VAR_DEF type declarator) ; functionHeader :  type ID '(' ( formalParameter ( ',' formalParameter )* )? ')' -> ^(FUNC_HDR type ID formalParameter+) ; atom : … |  '(' expr ')' -> expr ;
Mixed Rewrite/Auto Trees ,[object Object],b : ID INT -> INT ID | INT // implies -> INT ;
Rewrites and labels ,[object Object],[object Object],forStat :  &quot;for&quot; '(' start=assignStat ';' expr ';' next=assignStat ')' block -> ^(&quot;for&quot; $start expr $next block) ; block :  lc='{' variable* stat* '}’ -> ^(BLOCK[$lc] variable* stat*) ; /** match string representation of tree and build tree in memory */ tree : ‘^’ ‘(‘ root=atom (children+=tree)+ ‘)’ -> ^($root $children) |  atom ;
Loops in Rewrites ,[object Object],[object Object],[object Object],[object Object]
Preventing cyclic structures ,[object Object],[object Object],[object Object],[object Object],*Just noticed a bug in this one ;)
Predicated rewrites ,[object Object],a : ID INT -> {p1}? ID -> {p2}? INT -> ;
Misc Rewrite Elements ,[object Object],[object Object],[object Object],b : &quot;int&quot; ( ID -> ^(TYPE &quot;int&quot; ID) | ID '=' INT -> ^(TYPE &quot;int&quot; ID INT) ) ; a : (atom -> atom) (op='+' r=atom -> ^($op $a $r) )* ;
Tree Grammars ,[object Object],[object Object],variable :  ^(VAR_DEF type ID) |  ^(VAR_DEF type ID ^(INIT expr)) ;
Code Generation ,[object Object],[object Object],[object Object]
Sample code gen templates /** Dump the elements one per line and stick in debugging *  location() trigger in front. */ element() ::= << <if(debug)> dbg.location(<it.line>,<it.pos>);<> <endif> <it.el><> >> /** match a token optionally with a label in front */ tokenRef(token,label,elementIndex) ::= << <if(label)> <label>=input.LT(1);<> <endif> match(input,<token>,FOLLOW_<token>_in_<ruleName><elementIndex>); >>
Internationalization ,[object Object],[object Object],[object Object],RULE_REDEFINITION(file,line,col,arg) ::= &quot;<loc()>rule <arg> redefinition” /* This factors out file location formatting; file,line,col inherited from * enclosing template; don't manually pass stuff in. */ loc() ::= &quot;<file>:<line>:<col>: &quot;
Runtime Support ,[object Object],[object Object],[object Object]
Summary ,[object Object],[object Object],[object Object],[object Object]

Contenu connexe

Tendances

Compiler Construction | Lecture 5 | Transformation by Term Rewriting
Compiler Construction | Lecture 5 | Transformation by Term RewritingCompiler Construction | Lecture 5 | Transformation by Term Rewriting
Compiler Construction | Lecture 5 | Transformation by Term RewritingEelco Visser
 
Compiler Construction | Lecture 4 | Parsing
Compiler Construction | Lecture 4 | Parsing Compiler Construction | Lecture 4 | Parsing
Compiler Construction | Lecture 4 | Parsing Eelco Visser
 
An Annotation Framework for Statically-Typed Syntax Trees
An Annotation Framework for Statically-Typed Syntax TreesAn Annotation Framework for Statically-Typed Syntax Trees
An Annotation Framework for Statically-Typed Syntax TreesRay Toal
 
Introduction to Python - Part Three
Introduction to Python - Part ThreeIntroduction to Python - Part Three
Introduction to Python - Part Threeamiable_indian
 
Declare Your Language: Syntax Definition
Declare Your Language: Syntax DefinitionDeclare Your Language: Syntax Definition
Declare Your Language: Syntax DefinitionEelco Visser
 
Introduction to Python - Part Two
Introduction to Python - Part TwoIntroduction to Python - Part Two
Introduction to Python - Part Twoamiable_indian
 
Syntax-Directed Translation into Three Address Code
Syntax-Directed Translation into Three Address CodeSyntax-Directed Translation into Three Address Code
Syntax-Directed Translation into Three Address Codesanchi29
 
Regular expressions in Python
Regular expressions in PythonRegular expressions in Python
Regular expressions in PythonSujith Kumar
 
Core csharp and net quick reference
Core csharp and net quick referenceCore csharp and net quick reference
Core csharp and net quick referenceilesh raval
 
Top Down Parsing, Predictive Parsing
Top Down Parsing, Predictive ParsingTop Down Parsing, Predictive Parsing
Top Down Parsing, Predictive ParsingTanzeela_Hussain
 
Chapter Eight(2)
Chapter Eight(2)Chapter Eight(2)
Chapter Eight(2)bolovv
 
C# Cheat Sheet
C# Cheat SheetC# Cheat Sheet
C# Cheat SheetGlowTouch
 
Declarative Thinking, Declarative Practice
Declarative Thinking, Declarative PracticeDeclarative Thinking, Declarative Practice
Declarative Thinking, Declarative PracticeKevlin Henney
 

Tendances (20)

C tutorial
C tutorialC tutorial
C tutorial
 
Compiler Construction | Lecture 5 | Transformation by Term Rewriting
Compiler Construction | Lecture 5 | Transformation by Term RewritingCompiler Construction | Lecture 5 | Transformation by Term Rewriting
Compiler Construction | Lecture 5 | Transformation by Term Rewriting
 
Compiler Construction | Lecture 4 | Parsing
Compiler Construction | Lecture 4 | Parsing Compiler Construction | Lecture 4 | Parsing
Compiler Construction | Lecture 4 | Parsing
 
An Annotation Framework for Statically-Typed Syntax Trees
An Annotation Framework for Statically-Typed Syntax TreesAn Annotation Framework for Statically-Typed Syntax Trees
An Annotation Framework for Statically-Typed Syntax Trees
 
Introduction to Python - Part Three
Introduction to Python - Part ThreeIntroduction to Python - Part Three
Introduction to Python - Part Three
 
Declare Your Language: Syntax Definition
Declare Your Language: Syntax DefinitionDeclare Your Language: Syntax Definition
Declare Your Language: Syntax Definition
 
Syntax analysis
Syntax analysisSyntax analysis
Syntax analysis
 
Module 11
Module 11Module 11
Module 11
 
Left factor put
Left factor putLeft factor put
Left factor put
 
Introduction to Python - Part Two
Introduction to Python - Part TwoIntroduction to Python - Part Two
Introduction to Python - Part Two
 
Syntax-Directed Translation into Three Address Code
Syntax-Directed Translation into Three Address CodeSyntax-Directed Translation into Three Address Code
Syntax-Directed Translation into Three Address Code
 
LEX & YACC TOOL
LEX & YACC TOOLLEX & YACC TOOL
LEX & YACC TOOL
 
Regular expressions in Python
Regular expressions in PythonRegular expressions in Python
Regular expressions in Python
 
Core csharp and net quick reference
Core csharp and net quick referenceCore csharp and net quick reference
Core csharp and net quick reference
 
Top Down Parsing, Predictive Parsing
Top Down Parsing, Predictive ParsingTop Down Parsing, Predictive Parsing
Top Down Parsing, Predictive Parsing
 
Chapter Eight(2)
Chapter Eight(2)Chapter Eight(2)
Chapter Eight(2)
 
C# Cheat Sheet
C# Cheat SheetC# Cheat Sheet
C# Cheat Sheet
 
Programming with Python
Programming with PythonProgramming with Python
Programming with Python
 
Declarative Thinking, Declarative Practice
Declarative Thinking, Declarative PracticeDeclarative Thinking, Declarative Practice
Declarative Thinking, Declarative Practice
 
Amusing C#
Amusing C#Amusing C#
Amusing C#
 

En vedette

Automated antlr tree walker
Automated antlr tree walkerAutomated antlr tree walker
Automated antlr tree walkergeeksec80
 
An Introduction to ANTLR
An Introduction to ANTLRAn Introduction to ANTLR
An Introduction to ANTLRMorteza Zakeri
 
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...
Using ANTLR on real example - convert "string combined" queries into paramete...Alexey Diyan
 
Antlr Conference Drools & Hibernate
Antlr Conference   Drools & HibernateAntlr Conference   Drools & Hibernate
Antlr Conference Drools & HibernateAlexandre Porcelli
 
White Paper Indirect Distribution
White Paper   Indirect DistributionWhite Paper   Indirect Distribution
White Paper Indirect DistributionDarrelb
 
Falcon Stor Changing The Rules Of Backup
Falcon Stor   Changing The Rules Of BackupFalcon Stor   Changing The Rules Of Backup
Falcon Stor Changing The Rules Of BackupPaul Skach
 
Cut Costs, Not Benefits.
Cut Costs, Not Benefits.Cut Costs, Not Benefits.
Cut Costs, Not Benefits.vickor
 
Latvia - Presentation from Veronika
Latvia - Presentation from VeronikaLatvia - Presentation from Veronika
Latvia - Presentation from Veronikabrixi1
 
College Preparation Journey
College Preparation JourneyCollege Preparation Journey
College Preparation Journeygmills01
 
Social Bookmarking Introduction To Diigo
Social Bookmarking Introduction To DiigoSocial Bookmarking Introduction To Diigo
Social Bookmarking Introduction To Diigobrosenthal
 
2016 artigo wireless control
2016 artigo wireless control2016 artigo wireless control
2016 artigo wireless controlFabricio Schlag
 
Innerwealth Living Inspired Magazine August Issue
Innerwealth Living Inspired Magazine August IssueInnerwealth Living Inspired Magazine August Issue
Innerwealth Living Inspired Magazine August IssueChris Walker
 
LinkedIn for College Students
LinkedIn for College Students LinkedIn for College Students
LinkedIn for College Students Rob Humphrey
 
4088 Norris Road Energy Profile
4088 Norris Road Energy Profile4088 Norris Road Energy Profile
4088 Norris Road Energy Profilesingman
 
Las tres hojitas
Las tres hojitasLas tres hojitas
Las tres hojitashonelius
 
Theming Your Views
Theming Your ViewsTheming Your Views
Theming Your ViewsMark Jarrell
 

En vedette (20)

Automated antlr tree walker
Automated antlr tree walkerAutomated antlr tree walker
Automated antlr tree walker
 
An Introduction to ANTLR
An Introduction to ANTLRAn Introduction to ANTLR
An Introduction to ANTLR
 
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...
Using ANTLR on real example - convert "string combined" queries into paramete...
 
Antlr Conference Drools & Hibernate
Antlr Conference   Drools & HibernateAntlr Conference   Drools & Hibernate
Antlr Conference Drools & Hibernate
 
ANTLR4 in depth
ANTLR4 in depthANTLR4 in depth
ANTLR4 in depth
 
White Paper Indirect Distribution
White Paper   Indirect DistributionWhite Paper   Indirect Distribution
White Paper Indirect Distribution
 
Itb Chap 08
Itb Chap 08Itb Chap 08
Itb Chap 08
 
Falcon Stor Changing The Rules Of Backup
Falcon Stor   Changing The Rules Of BackupFalcon Stor   Changing The Rules Of Backup
Falcon Stor Changing The Rules Of Backup
 
Cut Costs, Not Benefits.
Cut Costs, Not Benefits.Cut Costs, Not Benefits.
Cut Costs, Not Benefits.
 
Networking, czy ma sens?
Networking, czy ma sens?Networking, czy ma sens?
Networking, czy ma sens?
 
Latvia - Presentation from Veronika
Latvia - Presentation from VeronikaLatvia - Presentation from Veronika
Latvia - Presentation from Veronika
 
College Preparation Journey
College Preparation JourneyCollege Preparation Journey
College Preparation Journey
 
Social Bookmarking Introduction To Diigo
Social Bookmarking Introduction To DiigoSocial Bookmarking Introduction To Diigo
Social Bookmarking Introduction To Diigo
 
SocialMedia4SmallBiz_SpotOn
SocialMedia4SmallBiz_SpotOnSocialMedia4SmallBiz_SpotOn
SocialMedia4SmallBiz_SpotOn
 
2016 artigo wireless control
2016 artigo wireless control2016 artigo wireless control
2016 artigo wireless control
 
Innerwealth Living Inspired Magazine August Issue
Innerwealth Living Inspired Magazine August IssueInnerwealth Living Inspired Magazine August Issue
Innerwealth Living Inspired Magazine August Issue
 
LinkedIn for College Students
LinkedIn for College Students LinkedIn for College Students
LinkedIn for College Students
 
4088 Norris Road Energy Profile
4088 Norris Road Energy Profile4088 Norris Road Energy Profile
4088 Norris Road Energy Profile
 
Las tres hojitas
Las tres hojitasLas tres hojitas
Las tres hojitas
 
Theming Your Views
Theming Your ViewsTheming Your Views
Theming Your Views
 

Similaire à Antlr V3

The Java Script Programming Language
The  Java Script  Programming  LanguageThe  Java Script  Programming  Language
The Java Script Programming Languagezone
 
Javascript by Yahoo
Javascript by YahooJavascript by Yahoo
Javascript by Yahoobirbal
 
The JavaScript Programming Language
The JavaScript Programming LanguageThe JavaScript Programming Language
The JavaScript Programming LanguageRaghavan Mohan
 
Les origines de Javascript
Les origines de JavascriptLes origines de Javascript
Les origines de JavascriptBernard Loire
 
C++ Advanced
C++ AdvancedC++ Advanced
C++ AdvancedVivek Das
 
Python - Getting to the Essence - Points.com - Dave Park
Python - Getting to the Essence - Points.com - Dave ParkPython - Getting to the Essence - Points.com - Dave Park
Python - Getting to the Essence - Points.com - Dave Parkpointstechgeeks
 
Os Vanrossum
Os VanrossumOs Vanrossum
Os Vanrossumoscon2007
 
The Kotlin Programming Language
The Kotlin Programming LanguageThe Kotlin Programming Language
The Kotlin Programming Languageintelliyole
 
Hacking Parse.y with ujihisa
Hacking Parse.y with ujihisaHacking Parse.y with ujihisa
Hacking Parse.y with ujihisaujihisa
 

Similaire à Antlr V3 (20)

C to perl binding
C to perl bindingC to perl binding
C to perl binding
 
The Java Script Programming Language
The  Java Script  Programming  LanguageThe  Java Script  Programming  Language
The Java Script Programming Language
 
Javascript by Yahoo
Javascript by YahooJavascript by Yahoo
Javascript by Yahoo
 
The JavaScript Programming Language
The JavaScript Programming LanguageThe JavaScript Programming Language
The JavaScript Programming Language
 
Javascript
JavascriptJavascript
Javascript
 
Les origines de Javascript
Les origines de JavascriptLes origines de Javascript
Les origines de Javascript
 
Javascript
JavascriptJavascript
Javascript
 
C++ Advanced
C++ AdvancedC++ Advanced
C++ Advanced
 
Python 3000
Python 3000Python 3000
Python 3000
 
Linq intro
Linq introLinq intro
Linq intro
 
C programming
C programmingC programming
C programming
 
Python - Getting to the Essence - Points.com - Dave Park
Python - Getting to the Essence - Points.com - Dave ParkPython - Getting to the Essence - Points.com - Dave Park
Python - Getting to the Essence - Points.com - Dave Park
 
Pointers and arrays
Pointers and arraysPointers and arrays
Pointers and arrays
 
Scala 2 + 2 > 4
Scala 2 + 2 > 4Scala 2 + 2 > 4
Scala 2 + 2 > 4
 
Os Vanrossum
Os VanrossumOs Vanrossum
Os Vanrossum
 
Scala introduction
Scala introductionScala introduction
Scala introduction
 
PostThis
PostThisPostThis
PostThis
 
The Kotlin Programming Language
The Kotlin Programming LanguageThe Kotlin Programming Language
The Kotlin Programming Language
 
Perl Presentation
Perl PresentationPerl Presentation
Perl Presentation
 
Hacking Parse.y with ujihisa
Hacking Parse.y with ujihisaHacking Parse.y with ujihisa
Hacking Parse.y with ujihisa
 

Dernier

The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptxThe Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptxLoriGlavin3
 
unit 4 immunoblotting technique complete.pptx
unit 4 immunoblotting technique complete.pptxunit 4 immunoblotting technique complete.pptx
unit 4 immunoblotting technique complete.pptxBkGupta21
 
DevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache MavenDevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache MavenHervé Boutemy
 
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptx
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptxUse of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptx
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptxLoriGlavin3
 
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptxMerck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptxLoriGlavin3
 
Digital Identity is Under Attack: FIDO Paris Seminar.pptx
Digital Identity is Under Attack: FIDO Paris Seminar.pptxDigital Identity is Under Attack: FIDO Paris Seminar.pptx
Digital Identity is Under Attack: FIDO Paris Seminar.pptxLoriGlavin3
 
TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024Lonnie McRorey
 
Advanced Computer Architecture – An Introduction
Advanced Computer Architecture – An IntroductionAdvanced Computer Architecture – An Introduction
Advanced Computer Architecture – An IntroductionDilum Bandara
 
Commit 2024 - Secret Management made easy
Commit 2024 - Secret Management made easyCommit 2024 - Secret Management made easy
Commit 2024 - Secret Management made easyAlfredo García Lavilla
 
Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!Commit University
 
A Deep Dive on Passkeys: FIDO Paris Seminar.pptx
A Deep Dive on Passkeys: FIDO Paris Seminar.pptxA Deep Dive on Passkeys: FIDO Paris Seminar.pptx
A Deep Dive on Passkeys: FIDO Paris Seminar.pptxLoriGlavin3
 
SAP Build Work Zone - Overview L2-L3.pptx
SAP Build Work Zone - Overview L2-L3.pptxSAP Build Work Zone - Overview L2-L3.pptx
SAP Build Work Zone - Overview L2-L3.pptxNavinnSomaal
 
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptx
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptxPasskey Providers and Enabling Portability: FIDO Paris Seminar.pptx
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptxLoriGlavin3
 
SALESFORCE EDUCATION CLOUD | FEXLE SERVICES
SALESFORCE EDUCATION CLOUD | FEXLE SERVICESSALESFORCE EDUCATION CLOUD | FEXLE SERVICES
SALESFORCE EDUCATION CLOUD | FEXLE SERVICESmohitsingh558521
 
The Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and ConsThe Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and ConsPixlogix Infotech
 
What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024Stephanie Beckett
 
Generative AI for Technical Writer or Information Developers
Generative AI for Technical Writer or Information DevelopersGenerative AI for Technical Writer or Information Developers
Generative AI for Technical Writer or Information DevelopersRaghuram Pandurangan
 
Take control of your SAP testing with UiPath Test Suite
Take control of your SAP testing with UiPath Test SuiteTake control of your SAP testing with UiPath Test Suite
Take control of your SAP testing with UiPath Test SuiteDianaGray10
 
How to write a Business Continuity Plan
How to write a Business Continuity PlanHow to write a Business Continuity Plan
How to write a Business Continuity PlanDatabarracks
 

Dernier (20)

The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptxThe Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
 
unit 4 immunoblotting technique complete.pptx
unit 4 immunoblotting technique complete.pptxunit 4 immunoblotting technique complete.pptx
unit 4 immunoblotting technique complete.pptx
 
DevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache MavenDevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache Maven
 
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptx
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptxUse of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptx
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptx
 
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptxMerck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptx
 
Digital Identity is Under Attack: FIDO Paris Seminar.pptx
Digital Identity is Under Attack: FIDO Paris Seminar.pptxDigital Identity is Under Attack: FIDO Paris Seminar.pptx
Digital Identity is Under Attack: FIDO Paris Seminar.pptx
 
TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024
 
Advanced Computer Architecture – An Introduction
Advanced Computer Architecture – An IntroductionAdvanced Computer Architecture – An Introduction
Advanced Computer Architecture – An Introduction
 
Commit 2024 - Secret Management made easy
Commit 2024 - Secret Management made easyCommit 2024 - Secret Management made easy
Commit 2024 - Secret Management made easy
 
DMCC Future of Trade Web3 - Special Edition
DMCC Future of Trade Web3 - Special EditionDMCC Future of Trade Web3 - Special Edition
DMCC Future of Trade Web3 - Special Edition
 
Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!
 
A Deep Dive on Passkeys: FIDO Paris Seminar.pptx
A Deep Dive on Passkeys: FIDO Paris Seminar.pptxA Deep Dive on Passkeys: FIDO Paris Seminar.pptx
A Deep Dive on Passkeys: FIDO Paris Seminar.pptx
 
SAP Build Work Zone - Overview L2-L3.pptx
SAP Build Work Zone - Overview L2-L3.pptxSAP Build Work Zone - Overview L2-L3.pptx
SAP Build Work Zone - Overview L2-L3.pptx
 
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptx
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptxPasskey Providers and Enabling Portability: FIDO Paris Seminar.pptx
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptx
 
SALESFORCE EDUCATION CLOUD | FEXLE SERVICES
SALESFORCE EDUCATION CLOUD | FEXLE SERVICESSALESFORCE EDUCATION CLOUD | FEXLE SERVICES
SALESFORCE EDUCATION CLOUD | FEXLE SERVICES
 
The Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and ConsThe Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and Cons
 
What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024
 
Generative AI for Technical Writer or Information Developers
Generative AI for Technical Writer or Information DevelopersGenerative AI for Technical Writer or Information Developers
Generative AI for Technical Writer or Information Developers
 
Take control of your SAP testing with UiPath Test Suite
Take control of your SAP testing with UiPath Test SuiteTake control of your SAP testing with UiPath Test Suite
Take control of your SAP testing with UiPath Test Suite
 
How to write a Business Continuity Plan
How to write a Business Continuity PlanHow to write a Business Continuity Plan
How to write a Business Continuity Plan
 

Antlr V3

  • 1. ANTLR v3 Overview (for ANTLR v2 users) Terence Parr University of San Francisco
  • 2.
  • 3. Block Info Flow Diagram
  • 4. Grammar Syntax header {…} /** doc comment */ kind grammar name ; options {…} tokens {…} scopes… action rules … /** doc comment */ rule[String s, int z] returns [int x, int y] throws E options {…} scopes init {…} :  |  ; exceptions ^(root child1 … childN) Trees Note: No inheritance
  • 5.
  • 6. Example Grammar grammar SimpleParser; program : variable* method+ ; variable: &quot;int&quot; ID (‘=‘ expr)? ';’ ; method : &quot;method&quot; ID '(' ')' '{' variable* statement+ '}' ; statement : ID ‘=‘ expr ';' | &quot;return&quot; expr ';' ; expr : ID | INT ; ID : ('a'..'z'|'A'..'Z')+ ; INT : '0'..'9'+ ; WS : (' '|''|'')+ {channel=99;} ;
  • 7. Using the parser CharStream in = new ANTLRFileStream(“inputfile”); SimpleParserLexer lexer = new SimpleParserLexer(in); CommonTokenStream tokens = new CommonTokenStream(lexer); SimpleParser p = new SimpleParser(tokens); p.program(); // invoke start rule
  • 8.
  • 9. Recursion Warnings a : a A | B ; t.g:2:5: Alternative 1 discovers infinite left-recursion to a from a t.g:2:5: Alternative 1: after matching input such as B decision cannot predict what comes next due to recursion overflow to c from b // with -Im 0 (secret internal parameter) a : b | B ; b : c ; c : B b ;
  • 10.
  • 11.
  • 12.
  • 13. Example Error Recovery int i = 0; method foo( { int j = i; i = 4 } [program, method]: line 2:12 mismatched token: [@14,23:23='{',<14>,2:12]; expecting type ')' [program, method, statement]: line 5:0 mismatched token: [@31,46:46='}',<15>,5:0]; expecting type ';' int i = 0; method foo() ) { int j = i; i = = 4; } [program, method]: line 2:13 mismatched token: [@15,24:24=')',<13>,2:13]; expecting type '{' [program, method, statement, expr]: line 4:6 mismatched token: [@32,47:47='=',<6>,4:6]; expecting set null Note: I put in two errors each so you’ll see it continues properly One token insertion One token deletion
  • 14.
  • 15.
  • 16.
  • 17.
  • 18.
  • 19.
  • 20.
  • 21.
  • 22.
  • 23.
  • 24.
  • 25.
  • 26.
  • 27.
  • 28.
  • 29. Sample code gen templates /** Dump the elements one per line and stick in debugging * location() trigger in front. */ element() ::= << <if(debug)> dbg.location(<it.line>,<it.pos>);<> <endif> <it.el><> >> /** match a token optionally with a label in front */ tokenRef(token,label,elementIndex) ::= << <if(label)> <label>=input.LT(1);<> <endif> match(input,<token>,FOLLOW_<token>_in_<ruleName><elementIndex>); >>
  • 30.
  • 31.
  • 32.