Parsing state of the art and ANTLR 4 demo using intellij plugin

2,064 views
1,762 views

Published on

Quick discussion of attempts to increase top-down parsing strength and a demo of ANTLR 4 using the Intellij plugin. The demo language is Valgol, derived from "Valley girl" speak from 1980s. Hilarious. Speed comparison of ANTLR to many other tools when parsing Java.

Published in: Technology
0 Comments
3 Likes
Statistics
Notes
  • Be the first to comment

No Downloads
Views
Total views
2,064
On SlideShare
0
From Embeds
0
Number of Embeds
3
Actions
Shares
0
Downloads
21
Comments
0
Likes
3
Embeds 0
No embeds

No notes for slide

Parsing state of the art and ANTLR 4 demo using intellij plugin

  1. 1. Computer Language Design and Implementation meetup March 6, 2014 Latest and greatest parsing stuff Terence Parr University of San Francisco
  2. 2. Believe it or not... ● I think I have built my last parser generator ● ``Why program by hand in 5 days what you can spend 5 years of your life automating?’’ ^ 2
  3. 3. The great struggle ● Top-down (LL), bottom-up (LR,GLR) have duked it out for a long time ● LL(k) much weaker than GLR as GLR can take any grammar ● LL is O(n), GLR is “O(n^3)” ● Some worked on increasing LL strength ● Others worked on optimizing GLR for speed
  4. 4. Increasing LL strength ● ● ● ● All about the lookahead 1990: LL(k) for k>1 1994: limited backtracking (syn. predicates) 2004: PEG: parser expression grammars formalized syn preds. Key addition: memoize partial parsing results to get O(n); ● 2007: ANTLR 3 LL(*) ● 2010: GLL; any grammar but O(n^3)
  5. 5. 2012: ANTLR 4 ALL(*) ● ● ● ● ● Any grammar w/o indirect left-recursion Can tweak grammar to make very fast Auto constructs parse trees Generates listeners and/or visitors Good doc (if you have $25)
  6. 6. ALL(*) vs X speed parsing Java 12,920 Java files, 3.6M lines, size 123M.
  7. 7. Time and space to parse and optionally build trees. Single 3.2M Java file
  8. 8. Listener events
  9. 9. Depth-First Search of parse tree, firing events
  10. 10. Demo: let’s build Valgol From “Valley girls” in 1980s def f(x,y) { code: https://github.com/parrt/antlr4-demo-simple-lang plugin: http://plugins.jetbrains.com/plugin/7358?pr= var z = grody^max gag me with a spoon totally do antlr = like bitchen for i = like 1 to maybe 10 totally do x = fersure tubular }

×