-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.html
271 lines (228 loc) · 11.9 KB
/
index.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>ANTLR4 - Overview</title>
<meta name="description" content="A framework for easily creating beautiful presentations using HTML">
<meta name="author" content="Hakim El Hattab">
<meta name="apple-mobile-web-app-capable" content="yes" />
<meta name="apple-mobile-web-app-status-bar-style" content="black-translucent" />
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no">
<link rel="stylesheet" href="css/reveal.min.css">
<link rel="stylesheet" href="css/theme/beige.css" id="theme">
<!-- For syntax highlighting -->
<link rel="stylesheet" href="lib/css/zenburn.css">
<!-- If the query includes 'print-pdf', include the PDF print sheet -->
<script>
if( window.location.search.match( /print-pdf/gi ) ) {
var link = document.createElement( 'link' );
link.rel = 'stylesheet';
link.type = 'text/css';
link.href = 'css/print/pdf.css';
document.getElementsByTagName( 'head' )[0].appendChild( link );
}
</script>
<!--[if lt IE 9]>
<script src="lib/js/html5shiv.js"></script>
<![endif]-->
</head>
<body>
<div class="reveal">
<!-- Any section element inside of this container is displayed as a slide -->
<div class="slides">
<section data-markdown>
# ANTLR 4
### A (rather simple) Overview
By *Duarte Duarte*, *Luís Cleto*, *Miguel Marques* and *Ruben Cordeiro*
COMP/MIEIC/FEUP - 2013/2014
</section>
<section>
<section data-markdown>
## What's ANTLR 4?
</section>
<section data-markdown>
## What's ANTLR 4?
**ANTLR 4** is a parser generator, generating parse trees automatically from a given **grammar**.
It's a **parser generator** and a **language tool**.
</section>
<section data-markdown>
## Design Goals
* Ease-of-use over performance
* Simplicity over complexity
</section>
<section data-markdown>
## Industry adoption
* **Twitter** search uses ANTLR for query parsing.
* **Oracle** uses ANTLR within the SQL Developer IDE.
* The **NetBeans** IDE parses C++ with ANTLR.
</section>
</section>
<section>
<section data-markdown>
## What does parsing with ANTLR4 mean?
</section>
<section data-markdown>
### What does parsing with ANTLR4 mean?
* Structure is described as a **grammar**.
* Recognizer is divided into **lexer** and **parser**.
* **Parse tree** can be auto generated.
<!-- ![An image was supposed to be here..](parseMeaning.png) -->
</section>
<section data-markdown>
### What does parsing with ANTLR4 mean?
![An image was supposed to be here..](images/parseMeaning.png)
</section>
</section>
<section>
<section data-markdown>
## ANTLR4 ALL(*)
</section>
<section data-markdown>
## ANTLR4 ALL(*)
* Generates recursive descent parser
* like what you would build by hand
* Does dynamic grammar analysis while parsing
* saves results like a JIT does
* Allows for direct left recursion
* indirect left recursion not supported
* Parsing time typically near-linear
</section>
<section data-markdown>
## ANTLR4 ALL(*)
By moving grammar analysis to parse-time, it's possible to avoid the common pitfalls of ambiguity and left-recursion.
</section>
</section>
<section>
<section data-markdown>
## Grammar specification
</section>
<section data-markdown>
## Grammar specification
``` javascript
grammar assignment;
stat: ID '=' expr ';' // match an assignment; can match "f();"
| ID '=' expr ';' // oops! an exact duplicate of previous alternative
| expr ';' // expression statement
;
expr: ID '(' ')'
| INT
;
ID : [a-z]+ ; // match one or more of any lowercase letter
INT : [0-9]+ ; // match integers
```
The ANTLR tool generates recursive-descent parsers from grammar rules such as the ones above.
</section>
<section>
<h2> Generated Parse Tree </h2>
<img src="images/parseTree.png"></img>
<aside class="notes">
These are called context objects because they record everything we know about the recognition of a phrase by a rule. Each context object knows the
start and stop tokens for the recognized phrase and provides access to all of
the elements of that phrase. For example, AssignContext provides methods ID()
and expr() to access the identifier node and expression subtree.
</aside>
</section>
<section>
<h3> Parse-Tree Listeners and Visitors </h3>
Given this concrete structure, we can use the tree-walking mechanisms that ANTLR generates automatically, rather than writing the same tree-walking boilerplate code for each application.
</section>
<section data-markdown>
## Parse-Tree Listeners and Visitors
Options for separation of actions from grammars in ANTLR4:
* Listeners (SAX style)
* Visitors (DOM style)
</section>
<section data-markdown>
## Listeners
![An image was supposed to be here..](images/listenerDepthWalking.png)
Tree traversal.
</section>
<section data-markdown>
## Listeners
![An image was supposed to be here..](images/visitorCallSequence.png)
*ParseTreeWalker* call sequence.
</section>
<section data-markdown>
## Visitors
![An image was supposed to be here..](images/visitorCallSequence2.png)
</section>
</section>
<section>
<section data-markdown>
## Practical Example
### Building a Calculator Using a Visitor
</section>
<section>
<h2> Practical Example </h2>
<ul>
<li><a href="calcGrammar.html" target="blank">Grammar</a></li>
<li><a href="evalVisitor.html" target="blank">Visitor Implementation</a></li>
<li><a href="calcJava.html" target="blank"> Application </a></li>
</ul>
</section>
<section>
<h2> Pratical Example </h2>
We built a calculator without having to insert raw <i>Java</i> actions into the grammar.
The grammar is kept application independent and programming language neutral.
</section>
</section>
<section>
<section data-markdown>
## Summary
</section>
<section data-markdown>
## Summary
ANTLR4 is:
* Modular.
* Powerful.
</section>
<section data-markdown>
## Summary
ANTLR4's release codename is *Honey Badger*.
It was named after the extremely resilient animal since ANTLR4 takes whatever you give it: it just doesn't give a damn!
</section>
<section data-markdown>
## Summary
![An image was supposed to be here..](images/honeyBadger.jpg)
</section>
</section>
<section data-markdown>
## References
* ANTLR4-Website
* http://www.antlr.org
* Book (it's actually worth reading)
* http://pragprog.com/book/tpantlr2/the-definitive-antlr-4-reference
</section>
<section data-markdown>
## Questions?
</section>
</div>
</div>
<script src="lib/js/head.min.js"></script>
<script src="js/reveal.min.js"></script>
<script>
// Full list of configuration options available here:
// https://github.com/hakimel/reveal.js#configuration
Reveal.initialize({
controls: true,
progress: true,
history: true,
center: true,
theme: Reveal.getQueryHash().theme, // available themes are in /css/theme
transition: Reveal.getQueryHash().transition || 'default', // default/cube/page/concave/zoom/linear/fade/none
// Parallax scrolling
// parallaxBackgroundImage: 'https://s3.amazonaws.com/hakim-static/reveal-js/reveal-parallax-1.jpg',
// parallaxBackgroundSize: '2100px 900px',
// Optional libraries used to extend on reveal.js
dependencies: [
{ src: 'lib/js/classList.js', condition: function() { return !document.body.classList; } },
{ src: 'plugin/markdown/marked.js', condition: function() { return !!document.querySelector( '[data-markdown]' ); } },
{ src: 'plugin/markdown/markdown.js', condition: function() { return !!document.querySelector( '[data-markdown]' ); } },
{ src: 'plugin/highlight/highlight.js', async: true, callback: function() { hljs.initHighlightingOnLoad(); } },
{ src: 'plugin/zoom-js/zoom.js', async: true, condition: function() { return !!document.body.classList; } },
{ src: 'plugin/notes/notes.js', async: true, condition: function() { return !!document.body.classList; } }
]
});
</script>
</body>
</html>