SlideShare a Scribd company logo
8
Most read
9
Most read
10
Most read
Vladimir Kozhaev
● Freelancer
● Development of programming
languages and development
tools.
● If you need to develop a domain
specific language, IDE based
on Eclipse or Inellij Idea, parser,
compiler do not heistate to ask
me.
● email:vkozhaev@gmaill.com,
skype:vladimir.kozhaev
blog:http://gamesdevandmath.bl
ogspot.com
● ANTLR 4, DSL development in depth
ANTLR overview
● ANTLR (ANother Tool for Language
Recognition) is a powerful parser generator for
reading, processing, executing, or translating
structured text or binary files. It's widely used to
build languages, tools, and frameworks. From a
grammar, ANTLR generates a parser that can
build and walk parse trees.
● Now avaiable version 4.5.3
● Java, C#, JavaScript, Python2, Python3 targets
● Some alternatives:JFlex,JLex,CookCC,AustenX
Why ANTLR?
● Developed with java
● Actively developing project
● Opensource
● Vide range of the tools and target languages
● Existing community
● Good book: The Definitive ANTLR 4 Reference
by Terence Parr
● A lot of the syntax sugar:left recursion, right
associativity etc
What is ANTLR
● Parsers(for example log files)
● Translators(from JSON to XML,
pseudocode to Java)
● Domain Specific Languages(DSL)
What is ANTLR
What is ANTLR
What Is ANTLR
ANTLR patterns
Lexems vs Fragments where is a
difference?
● A fragment will never be counted as a token, it
only serves to simplify a grammar.
● They need to be referenced from a lexer rule
● Matching a NUMBER will always return a
NUMBER to the lexer, regardless of if it
matched "1234", "0xab12", or "0777"
Priority Rules
Several lexer rules can match the same input
text. In that case, the token type will be chosen
as follows:
● First, select the lexer rule which matches the
longest input
● If several lexer rules match the same input
length, choose the first one, based on definition
order
Error recovery strategies
Error recovering
Visitors,Listeners,Actions
● Example 1, with visitor
● Example 2, with listener
● Example 3, with embeded action
● See https://github.com/vladimirkozhaev/https---
github.com-vladimirkozhaev-calc_antlr
Lexer vs parser rules
● Lexer vs parser, question two steps
with the same sence
● Lexer rules are used to split text on
the tokens
● Parser rules - for higher level parsing
Right associativity
expr : expr '^'<assoc=right> expr // ^ operator is right
associative
| INT
;
Eclipse ANTLR IDE
Eclipse ANTLR IDE
Questions
● Ask me please?

More Related Content

ODP
Using ANTLR on real example - convert "string combined" queries into paramete...
PDF
Linux Hardening
PPTX
Clean Code I - Best Practices
DOCX
Best Practices for Writing and Organizing QA Tests
PDF
Software Testing As a Career Path
PDF
ISTQB Metodolojisi ile Test Planlama ve Tahminleme
PPTX
Istqb foundation level
PPTX
Using ANTLR on real example - convert "string combined" queries into paramete...
Linux Hardening
Clean Code I - Best Practices
Best Practices for Writing and Organizing QA Tests
Software Testing As a Career Path
ISTQB Metodolojisi ile Test Planlama ve Tahminleme
Istqb foundation level

What's hot (16)

PPTX
Manual Testing tutorials and Interview Questions.pptx
PPTX
Clean code
PPTX
Spring Security
PPTX
.NETからActive Directoryデータにアクセス ~ユーザ情報の取得と表示~
PDF
Mitre ATT&CK Kullanarak Etkin Saldırı Tespiti
PDF
Metasploit for Penetration Testing: Beginner Class
PDF
Tawi Nairobi City County License 2015
PPTX
BTRisk - Siber Olay Tespit ve Mudahale Egitimi
PPTX
Security Testing.pptx
PDF
Project Management Tips to Improve Test Planning
PPTX
Secure coding practices
PPTX
Metasploit
PDF
DDOG 2024 Investor Day.pdf - Q4 2024 Datadog
PPTX
Beyaz Şapkalı Hacker CEH Eğitimi - Bölüm 1, 2, 3
PPT
Introduction to Go programming
PPT
Software testing
Manual Testing tutorials and Interview Questions.pptx
Clean code
Spring Security
.NETからActive Directoryデータにアクセス ~ユーザ情報の取得と表示~
Mitre ATT&CK Kullanarak Etkin Saldırı Tespiti
Metasploit for Penetration Testing: Beginner Class
Tawi Nairobi City County License 2015
BTRisk - Siber Olay Tespit ve Mudahale Egitimi
Security Testing.pptx
Project Management Tips to Improve Test Planning
Secure coding practices
Metasploit
DDOG 2024 Investor Day.pdf - Q4 2024 Datadog
Beyaz Şapkalı Hacker CEH Eğitimi - Bölüm 1, 2, 3
Introduction to Go programming
Software testing
Ad

Viewers also liked (12)

KEY
Antlr Conference Drools & Hibernate
PPT
что такое Git и как с ним бороться
ODP
ANTLR4 and its testing
PPTX
Architectures n-tiers
ODP
игровая логика, проблемы и решения
PDF
Automated antlr tree walker
PPT
ньюансы разработки видео для мобильных устройств
PPTX
An Introduction to ANTLR
PDF
Impulsione sua carreira contribuindo para projetos open source
PDF
Introduction à l'approche ADM de l'OMG
PPT
Antlr V3
PDF
20100629 dsl-poitou-charentes-jug
Antlr Conference Drools & Hibernate
что такое Git и как с ним бороться
ANTLR4 and its testing
Architectures n-tiers
игровая логика, проблемы и решения
Automated antlr tree walker
ньюансы разработки видео для мобильных устройств
An Introduction to ANTLR
Impulsione sua carreira contribuindo para projetos open source
Introduction à l'approche ADM de l'OMG
Antlr V3
20100629 dsl-poitou-charentes-jug
Ad

Similar to ANTLR4 in depth (20)

PDF
PDF
Code Generation Cambridge 2013 Introduction to Parsing with ANTLR4
PPT
introduction_to_antlr 3.ppt
PDF
Generative programming (mostly parser generation)
PPTX
ANTLR - Writing Parsers the Easy Way
PPTX
Binary Studio Academy PRO: ANTLR course by Alexander Vasiltsov (lesson 1)
PPTX
Antlr part1 introduction
PPTX
Antlr part3 getting_started_in_c_sharp
PPTX
Binary Studio Academy PRO: ANTLR course by Alexander Vasiltsov (lesson 3)
PPTX
Antlr part2 getting_started_in_java
PPTX
Antlr4 get the right tool for the job
PDF
Generating parsers using Ragel and Lemon
PPTX
2. introduction
PPTX
Binary Studio Academy PRO: ANTLR course by Alexander Vasiltsov (lesson 2)
PPTX
Binary Studio Academy PRO: ANTLR course by Alexander Vasiltsov (lesson 4)
DOCX
PDF
How to create a programming language
PDF
Context free langauges
PPT
Programming_Language_Syntax.ppt
PPTX
chapter4 end.pptx
Code Generation Cambridge 2013 Introduction to Parsing with ANTLR4
introduction_to_antlr 3.ppt
Generative programming (mostly parser generation)
ANTLR - Writing Parsers the Easy Way
Binary Studio Academy PRO: ANTLR course by Alexander Vasiltsov (lesson 1)
Antlr part1 introduction
Antlr part3 getting_started_in_c_sharp
Binary Studio Academy PRO: ANTLR course by Alexander Vasiltsov (lesson 3)
Antlr part2 getting_started_in_java
Antlr4 get the right tool for the job
Generating parsers using Ragel and Lemon
2. introduction
Binary Studio Academy PRO: ANTLR course by Alexander Vasiltsov (lesson 2)
Binary Studio Academy PRO: ANTLR course by Alexander Vasiltsov (lesson 4)
How to create a programming language
Context free langauges
Programming_Language_Syntax.ppt
chapter4 end.pptx

More from Владимир Кожаев (7)

ODP
флеш и сервер
ODP
ньюансы разработки видео для мобильных устройств
PPT
Vladimir kozhayev isometry handmade
PPT
Vladimir kozhayev isometry handmade
флеш и сервер
ньюансы разработки видео для мобильных устройств
Vladimir kozhayev isometry handmade
Vladimir kozhayev isometry handmade

Recently uploaded (20)

PDF
composite construction of structures.pdf
PDF
Evaluating the Democratization of the Turkish Armed Forces from a Normative P...
PDF
SM_6th-Sem__Cse_Internet-of-Things.pdf IOT
PPTX
Construction Project Organization Group 2.pptx
PPTX
OOP with Java - Java Introduction (Basics)
PPT
Project quality management in manufacturing
DOCX
ASol_English-Language-Literature-Set-1-27-02-2023-converted.docx
PDF
Operating System & Kernel Study Guide-1 - converted.pdf
PDF
Mohammad Mahdi Farshadian CV - Prospective PhD Student 2026
PPTX
Sustainable Sites - Green Building Construction
PDF
PPT on Performance Review to get promotions
PPTX
Recipes for Real Time Voice AI WebRTC, SLMs and Open Source Software.pptx
PDF
Model Code of Practice - Construction Work - 21102022 .pdf
PDF
The CXO Playbook 2025 – Future-Ready Strategies for C-Suite Leaders Cerebrai...
PDF
Arduino robotics embedded978-1-4302-3184-4.pdf
PPTX
CYBER-CRIMES AND SECURITY A guide to understanding
PPTX
bas. eng. economics group 4 presentation 1.pptx
PPT
Mechanical Engineering MATERIALS Selection
PPTX
IOT PPTs Week 10 Lecture Material.pptx of NPTEL Smart Cities contd
PPTX
M Tech Sem 1 Civil Engineering Environmental Sciences.pptx
composite construction of structures.pdf
Evaluating the Democratization of the Turkish Armed Forces from a Normative P...
SM_6th-Sem__Cse_Internet-of-Things.pdf IOT
Construction Project Organization Group 2.pptx
OOP with Java - Java Introduction (Basics)
Project quality management in manufacturing
ASol_English-Language-Literature-Set-1-27-02-2023-converted.docx
Operating System & Kernel Study Guide-1 - converted.pdf
Mohammad Mahdi Farshadian CV - Prospective PhD Student 2026
Sustainable Sites - Green Building Construction
PPT on Performance Review to get promotions
Recipes for Real Time Voice AI WebRTC, SLMs and Open Source Software.pptx
Model Code of Practice - Construction Work - 21102022 .pdf
The CXO Playbook 2025 – Future-Ready Strategies for C-Suite Leaders Cerebrai...
Arduino robotics embedded978-1-4302-3184-4.pdf
CYBER-CRIMES AND SECURITY A guide to understanding
bas. eng. economics group 4 presentation 1.pptx
Mechanical Engineering MATERIALS Selection
IOT PPTs Week 10 Lecture Material.pptx of NPTEL Smart Cities contd
M Tech Sem 1 Civil Engineering Environmental Sciences.pptx

ANTLR4 in depth

  • 1. Vladimir Kozhaev ● Freelancer ● Development of programming languages and development tools. ● If you need to develop a domain specific language, IDE based on Eclipse or Inellij Idea, parser, compiler do not heistate to ask me. ● email:vkozhaev@gmaill.com, skype:vladimir.kozhaev blog:http://gamesdevandmath.bl ogspot.com
  • 2. ● ANTLR 4, DSL development in depth
  • 3. ANTLR overview ● ANTLR (ANother Tool for Language Recognition) is a powerful parser generator for reading, processing, executing, or translating structured text or binary files. It's widely used to build languages, tools, and frameworks. From a grammar, ANTLR generates a parser that can build and walk parse trees. ● Now avaiable version 4.5.3 ● Java, C#, JavaScript, Python2, Python3 targets ● Some alternatives:JFlex,JLex,CookCC,AustenX
  • 4. Why ANTLR? ● Developed with java ● Actively developing project ● Opensource ● Vide range of the tools and target languages ● Existing community ● Good book: The Definitive ANTLR 4 Reference by Terence Parr ● A lot of the syntax sugar:left recursion, right associativity etc
  • 5. What is ANTLR ● Parsers(for example log files) ● Translators(from JSON to XML, pseudocode to Java) ● Domain Specific Languages(DSL)
  • 10. Lexems vs Fragments where is a difference? ● A fragment will never be counted as a token, it only serves to simplify a grammar. ● They need to be referenced from a lexer rule ● Matching a NUMBER will always return a NUMBER to the lexer, regardless of if it matched "1234", "0xab12", or "0777"
  • 11. Priority Rules Several lexer rules can match the same input text. In that case, the token type will be chosen as follows: ● First, select the lexer rule which matches the longest input ● If several lexer rules match the same input length, choose the first one, based on definition order
  • 14. Visitors,Listeners,Actions ● Example 1, with visitor ● Example 2, with listener ● Example 3, with embeded action ● See https://github.com/vladimirkozhaev/https--- github.com-vladimirkozhaev-calc_antlr
  • 15. Lexer vs parser rules ● Lexer vs parser, question two steps with the same sence ● Lexer rules are used to split text on the tokens ● Parser rules - for higher level parsing
  • 16. Right associativity expr : expr '^'<assoc=right> expr // ^ operator is right associative | INT ;