Skip to content
Prev 33792 / 398513 Next

Execution of R code

Prof Brian Ripley <ripley at stats.ox.ac.uk> writes:
One might add that although we don't byte-compile like in Java and
emacs-lisp, the parse tree storage that we use is somewhat more
pre-cooked than the tokenized storage of the ROM BASIC found on early
PCs and their precursors. 

One often considers the parsing stage as two processes: Lexical
analysis (the tokenizer) which recognises elementary items such as
keywords, operators, variable names, and constants; and the actual
code tree generation which knows about syntactical structures like for
loops, functions, and compound expressions. 

A code tree for a simple expression like

while ( i < 10 ) i <- i + 1

could be represented as

      while 
     /     \
    <       <-
   / \     /  \
  i   10  i    +
              / \
             i   1

(apologies to those with proportional screen fonts...) In this
representation, everything is basically functions and arguments: "while"
has two arguments: the loop condition and the body, and those are
calls to a comparison and an assignment function respectively, and so
forth. 

In compiled languages, parsing is followed by a step that converts the
code tree to machine instructions, but in languages like R it is
easier to interpret the tree directly. One particular aspect of R-like
languages is that you can replace or modify functions programmatically
in between running them, which means that you won't get the gain of an
up-front optimization effort unless you impose special restrictions.