From p.dalgaard@biostat.ku.dk  Tue Jan  6 10:11:56 1998
From: p.dalgaard@biostat.ku.dk (Peter Dalgaard BSA)
Date: 06 Jan 1998 11:11:56 +0100
Subject: Error in parse
In-Reply-To: Paul Gilbert's message of Mon, 5 Jan 1998 17:23:01 -0500
References: <98Jan5.172327est.13453@mailgate.bank-banque-canada.ca>
Message-ID: <x24t3hkj2r.fsf@blueberry.kubism.ku.dk>

Paul Gilbert <pgilbert@bank-banque-canada.ca> writes:

> Error in parse(file, n, text, prompt) : syntax error on line 23
...
> 
> ARMA <- function(model)
> {
> if (0 !=m) if (p != dim(C)[2]) stop("dimension of model parameters do not
> conform!")
> if (fortran)  if (m==0) C <- array(0,c(1,p,1))
> else
>   {for (Time in 1:sampleT)
>       {if (b >= 2) for (l in 2:b)
>           if (l<=Time) vt <- vt - c(B[l,,] %*% prederror[Time+1-l,])
>        if (m!=0) for (l in 1:dim(C)[1])
>           if (l<=Time) vt <- vt - c(C[l,,] %*% u[Time+1-l,])
>        prederror[Time,] <- vt
>        if (any(0!=error.weights))
>         {
>          if (length(error.weights)>1)
>            {for (h in 2:length(error.weights))
>             if ( (Time+h-1) <= sampleT)
>               {vt    <-  rep(0,p)
>      }  }  }  }
>   }
> 1
> }
> 
> KF <- function(model)
> {2}


What is happening here is that the lexical analyser reads the "KF"
token on the penultimate line, but the parser never sees it. 

This must be related to the token-lookahead code in main/src/gram.[yc]
(the token() function). The R_ParseFile function works by repeated
calls to R_Parse1File, which parses single expressions in the file and
R_Parse1File starts with ParseInit(), which as one of its first duties
sets SavedToken = 0. So if a token is saved and not used at the end of
one expression, it gets discarded.

So the bug is one of two (or both):

1) There's a bug in the readahead logic (this essentially works by
counting if's, else's, braces and newlines, so it would be no wonder
if your code tickled it)

2) It is wrong to assume that there's no initial saved token when
parsing 2nd and subsequent expressions in a file.

I think #1 is certainly present, because there should be no reason
to read past the terminating brace in your ARMA() function to detect
the end of it, but I'm not sure that you can't get other examples
where readahead will happen legally.

<better hand this over to Ross now>

-- 
   O__  ---- Peter Dalgaard             Blegdamsvej 3  
  c/ /'_ --- Dept. of Biostatistics     2200 Cph. N   
 (*) \(*) -- University of Copenhagen   Denmark      Ph: (+45) 35327918
~~~~~~~~~~ - (p.dalgaard@biostat.ku.dk)             FAX: (+45) 35327907

-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
r-devel mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html
Send "info", "help", or "[un]subscribe"
(in the "body", not the subject !)  To: r-devel-request@stat.math.ethz.ch
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._


Error in parse
Peter Dalgaard BSA