10

Does anyone know if there is an existing existing ANTLR or IRONY grammar for R?

Many thanks.

Bart Kiers
  • 166,582
  • 36
  • 299
  • 288
Jonno
  • 789
  • 9
  • 26
  • 2
    Did you already find the [Bison/Flex grammar](http://svn.r-project.org/R/trunk/src/main/gram.y) in their SVN repository? If no one posts an ANTLR- or IRONY grammar, you could convert the Bison/Flex to either of those. – Bart Kiers Apr 18 '11 at 16:22
  • 3
    What do you intend to do with it? Usually having just a parser doesn't buy you much; you typically need an AST, ways to traverse/analyze/modify the AST, etc. – Ira Baxter Apr 18 '11 at 17:15
  • @Bart Kiers - thanks! I'll certainly look into it! – Jonno Apr 19 '11 at 09:50
  • @Ira Baxter - Apologies if my terms/understanding is incorrect, currently I'm using irony for a small DSL that converts to .net - based on that I've been asked to look at a way to interpret R – Jonno Apr 19 '11 at 09:51
  • 2
    "a way to interpret R". This implies you need an AST, means to walk over it program execution order (fun when hit a goto:where is the target in the tree?) and symbol tables (which can answer the "target" question I just asked) as a minimum. – Ira Baxter Apr 19 '11 at 13:55
  • @Jonno can I ask you if you ever resolved this matter? I need similar R parser but RCC site is not providing download link anymore. Can you share your experience please? – Tae-Sung Shin Nov 17 '11 at 18:23
  • @Charles, please leave the tag `antlr4` there. The question does not mention that antlr4 cannot be used, and by adding this tag, it will be more easily found. Besides, Terence asked me to create a tag (since he didn't have enough rep to do so at that time) and this being the only question with the antlr4 tag, you removing it caused the "wiki/info" of this tag to be removed as well. Thanks for your consideration. – Bart Kiers Apr 15 '12 at 18:40
  • @BartKiers, I will honor your request, however I still object to the tag needing to exist. Tags are for questions, *not* for answers; there is nothing at all in the *question* that seems version-specific whatsoever. Perhaps you can find some other questions that could also be tagged with `antlr4`? This question alone seems like a bad starting point. – Charles Apr 16 '12 at 01:11

2 Answers2

7

I've built an R grammar for the early access "Honey Badger" ANTLR v4 release, if you'd like to give it a look. See the ANTLR v4 Examples page. Source for v4 is https://github.com/antlr/antlr4. binary jar here: http://antlr.org/download/antlr-4.0ea-complete.jar For R you want http://www.antlr.org/wiki/download/attachments/28049418/R.g4

Terence Parr
  • 5,912
  • 26
  • 32
  • I haven't *really* looked at v4 yet, but I will do so soon after seeing how ridiculously short that [R grammar](https://github.com/antlr/antlr4/blob/master/tool/playground/R.g4) is. Nice! – Bart Kiers Feb 01 '12 at 20:43
  • Some of the links no longer work - any chance of updated ones? Thanks – mchen Dec 10 '13 at 23:43
3

I'd guess a good place to look would be R to C Compiler (RCC) that was developed by John Garvin at Rice

Ira Baxter
  • 93,541
  • 22
  • 172
  • 341
  • Thanks Ira - I will check it out and mark your answer accepted if nothing else appears, many thanks. – Jonno Apr 19 '11 at 09:51