Hi, Is there any parser generator like www.antlr.org? Moreover, how does simple code assistance work currently in R? By 'simple code assistance' I meant things like: Object$M<TAB> --> Object$Method
>>>>> "A-" == Ali - <saveez at hotmail.com> >>>>> on Sat, 18 Aug 2007 00:40:52 +0100 writes:A-> Hi, A-> Is there any parser generator like www.antlr.org? Moreover, how does simple A-> code assistance work currently in R? By 'simple code assistance' I meant A-> things like: A-> Object$M<TAB> --> Object$Method If you really meant a list with components or an S4 object with slots, such code completion works at least since R 2.5.1, because of the recent 'rcompletion' extensions of Deepayan Sarkar, and of course in ESS (Emacs Speaks Statistics), and I think in several other GUI/Environments as well. But if you are thinking OOP as in Java or C++ (and I think you *are* thinking along that way), then rather learn that S (and hence R) do OOP in a function-centric rather than class-centric way; something which seems to be quite hard to grasp for many who have been brought up in Java-like schools.... If you are still interested in R, look out for documents with "S4" (or "formal methods and classes") and "R" in the title ;-) Regards, Martin
> A-> Hi,> A-> Is there any parser generator like www.antlr.org? Moreover, how does simple > A-> code assistance work currently in R? By 'simple code assistance' I meant > A-> things like:> > A-> Object$M<TAB> --> Object$Method> > If you really meant a list with components> or an S4 object with slots,> such code completion works at least since R 2.5.1, because of> the recent 'rcompletion' extensions of Deepayan Sarkar,> and of course in ESS (Emacs Speaks Statistics),> and I think in several other GUI/Environments as well.> > But if you are thinking OOP as in Java or C++ (and I think you> *are* thinking along that way), then rather learn> that S (and hence R) do OOP in a function-centric rather than class-centric> way; something which seems to be quite hard to grasp for many> who have been brought up in Java-like schools....> If you are still interested in R, look out for documents with> "S4" (or "formal methods and classes") and "R" in the title ;-)I am looking for an implemented parser generator of 'R', not only S4 classes or OOP style. By 'R', I mean 'R', it's that simple. I am not a big fan of the inconsistency in R grammer for the price of freedom in bringing new inventions such as S4. I understand this is a controversial subject and that many claim that in this way more options are brought to R. However, this makes R to look like a 'confused' language to me which is undecided between function-centric and object-oriented. We have the OOP package, the methods package and now the S4 classes which are very different to S3 and my understanding is that the S3-based packages are not automatically upgradable to S4. What if in 7 years or so the authors decide to have a S5 class scheme which is very different to both S3 and S4? In this way, it seems to me that there is no 'standard' in R. You may choose a flavour for R like R-S4 or R-S3 or R-this or R-that, and then develop your package based on that flavour. However, it looks like R-this and R-that flavours are actually different languages sharing some syntax. Here is a good demonstration for this problem: can we have one 'universal' parser for R? Or do we need an R-this-parser and R-that-parser for each flavour? It seems that Martin said yes to the second question. Moreover, my question is still somehow un-answered: Is there any existing ANTLR-based parser for R? I understand that in omegahat.org project, people used ANTLR for RSJava, but i am not sure if that had anything to do with an R-parser. _________________________________________________________________ [[alternative HTML version deleted]]
Gabor Grothendieck
2007-Aug-21 02:56 UTC
[R] Any parser generator / code assistance for R?
On 8/17/07, Ali - <saveez at hotmail.com> wrote:> Hi, > > Is there any parser generator like www.antlr.org? Moreover, how does simpleGiven the response, it looks like no one has come up with an antlr parser for R but there are some facilities within R itself. showTree() in the R codetools package which can generate a Lisp style expression for any R expression:> library(codetools) > showTree(quote(for(i in myvec[1:3]) print(i+88*2+3*4)))(for i ([ myvec (: 1 3)) (print (+ (+ i (* 88 2)) (* 3 4)))) Looking at the source of showTree would show you how to walk an R parse tree. The Ryacas R package has a recursive descent R parser that is used to process R code translating it to yacas and it also can translate OpenMath XML code generated by yacas to R. See: http://ryacas.googlecode.com