Confusing parser warning

Currently when a comma is missing in the arguments to a function call the Stan parser throws a confusing warning: ‘PARSER EXPECTED: “(”’, could we make it say ‘PARSER EXPECTED: “,”’ instead? Didn’t file an issue b/c I’m not sure how hard this is.

--- Translating Stan model to C++ code ---
Model name=delay_model_l1_model
Input file=/Users/krzysztof/projekty/delay-analysis-thailand-build/models/delay-model-l1.stan
Output file=/Users/krzysztof/projekty/delay-analysis-thailand-build/models/delay-model-l1.hpp

SYNTAX ERROR, MESSAGE(S) FROM PARSER:


ERROR at line 292

 290:        province_index, district_index, subdistrict_index, delivery_index);
 291:    
 292:      vector[n_obs] delta = construct(1, 0, n_obs, 
                                          ^
 293:        scaling[4], delta_0 + offset[4]

PARSER EXPECTED: "("

make[3]: *** [/Users/krzysztof/projekty/delay-analysis-thailand-build/models/delay-model-l1.hpp] Error 253
make[2]: *** [models/delay-model-l1] Error 2
make[1]: *** [models/CMakeFiles/compiled-delay-model.dir/all] Error 2
make: *** [all] Error 2

Please don’t let difficulty of solving something hold you back from filing an issue.

We can fix this if we have a minimal reproducible example (preferably less than 300 lines long). I couldn’t actually tell where you thought the comma was missing from in this example.

1 Like

This misleading error message is still around.
Here is a reproducible example:

functions{     
 
  
  real fun_mre(real x, real y, real z ){ 
    return(x + y + z);
                      }          
  
  
  real fun_mre1( real x, real y, real z ){ 
       real total;
       total = fun_mre(x,
                        y;
                        z); 
        return(total);
    }
  }
  data{}
  model{}

When I try to parse it I get:

SYNTAX ERROR, MESSAGE(S) FROM PARSER:

  error in 'model2892f772215_mre' at line 11, column 23
  -------------------------------------------------
     9:   real fun_mre1( real x, real y, real z ){ 
    10:        real total;
    11:        total = fun_mre(x,
                              ^
    12:                         y;
  -------------------------------------------------

PARSER EXPECTED: "("
Error in stanc(filename, allow_undefined = TRUE) : 
  failed to parse Stan model 'mre' due to the above error.

I am pleased to say that putting this example together enabled to find what was causing the rouble in my own code.

Thanks. Here’s an even simpler example:

transformed data {
  real x = atan2(2 ; 3);
}

I’m opening an issue and we’ll clean this up. Right now, GitHub seems to be down, so it’s queued up.

Hey all. Just to let you know I observed this same error just now when I mistakenly included an extra , in the function call.

E.g.

functions{     
 
  
  real fun_mre(real x, real y, real z ){ 
    return(x + y + z);
                      }          
  
  
  real fun_mre1( real x, real y, real z ){ 
       real total;
       total = fun_mre(x,
                        y,,
                        z); 
        return(total);
    }
  }
  data{}
  model{}

Thanks. Here’s the issue.

I’ll link it back to here to make sure it all gets cleaned up for our next release.

1 Like

Hi all, I have got a similar error message in my code:
data{
int LENGTH;
matrix[LENGTH,2] RT;
int NUM_CHOICES;
}

SYNTAX ERROR, MESSAGE(S) FROM PARSER:
error in ‘model2e9c650056b_1053d37b0166cc5129477f51c56f5e3f’ at line 151, column 0

149: }
150:
151: data{
^
152:

PARSER EXPECTED: “}”

@Erandi: Which version of Stan are you using?

This model compiles without error in the latest version of RStan (old compiler) and the latest version of CmdStan (new compiler).

@Bob_Carpenter

R version 4.0.2
Stan version 2.19.3

Then I installed rstan 2.21.1 and run my code, why am I getting this error message?

Compilation ERROR, function(s)/method(s) not created! C:/rtools40/mingw64/bin/…/lib/gcc/x86_64-w64-mingw32/8.3.0/…/…/…/…/x86_64-w64-mingw32/bin/ld.exe: file22a8da71e8b.o:file22a8da71e8b.cpp:(.text+0x9ac): undefined reference to tbb::internal::task_scheduler_observer_v3::observe(bool)' C:/rtools40/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/8.3.0/../../../../x86_64-w64-mingw32/bin/ld.exe: file22a8da71e8b.o:file22a8da71e8b.cpp:(.text+0x18b7): undefined reference to rstan::stan_fit::stan_fit(SEXPREC*, int)’
C:/rtools40/mingw64/bin/…/lib/gcc/x86_64-w64-mingw32/8.3.0/…/…/…/…/x86_64-w64-mingw32/bin/ld.exe: file22a8da71e8b.o:file22a8da71e8b.cpp:(.text+0x9ee): undefined reference to `tbb::internal::task_scheduler_observer_v3::observe(bool)’
C:/rtools40/mingw64/bin/…/lib/gcc/x86_64-w64-mingw32/8.3.0/…/…/…/…/x86_64-w64-mingw32/bin/ld.exe: file22a8da71e8b.o:file22a8da71e8b.cpp:(.text$_ZN3tbb8internal26task_scheduler_observer_v3D1Ev[_ZN3tbb8internal26task_scheduler_observe
In addition: Warning message:
In file.remove(c(unprocessed, processed)) :
cannot remove file ‘C:\Users\erandi\AppData\Local\Temp\RtmpmE49kQ\file22a8bbc54de.stan’, reason ‘No such file or directory’
Error in sink(type = “output”) : invalid connection

Unfortunately, because you’re on Windows it’s probably because of this current mess we’re dealing with:

To run Stan from R without the hassles of RStan on Windows I recommend our new CmdStanR interface. Here are some nice instructions from @Max_Mantei:

Your data block compiles fine for me with the latest CmdStanR:

library(cmdstanr)
file <- write_stan_tempfile(
"
data{
  int LENGTH;
  matrix[LENGTH,2] RT;
  int NUM_CHOICES;
}
"
)

# compiles with no error
mod <- cmdstan_model(file)

For more info on CmdStanR we have some tutorials at https://mc-stan.org/cmdstanr/articles/.

Oh…no luck for me on windows, I changed the version because of I was unable to get the output with rstan version 2.19.3 and then got the suggestion to change it. So then, better option is to install CmdStanR interface on windows, not in Linux?

I am confused. Thanks a lot

Oh, linux is fine too! Sorry if I confused you.

Not you, I am confused myself. I haven’t installed linux in my laptop, but as you recommend it is possible to install CmdStanR interface on windows 10.

Now I am trying for that.

Thanks in advance

No problem. Yeah it should be possible to use CmdStanR with Windows10.

That said, if you want to give RStan on Windows another try I just saw that @bgoodri just edited this post Rstan on Windows with new links to install a potentially fixed version RStan. I’m not sure if it will be fixed for you, but it might be.

erandi@DESKTOP-O9FUKUT MSYS ~
$ pacman -Sy mingw-w64-x86_64-make
:: Synchronizing package databases…
mingw32 is up to date
mingw64 is up to date
warning: mingw-w64-x86_64-make-4.2.1-2 is up to date – reinstalling
resolving dependencies…
looking for conflicting packages…

Packages (1) mingw-w64-x86_64-make-4.2.1-2

Total Installed Size: 1.33 MiB
Net Upgrade Size: 0.00 MiB

:: Proceed with installation? [Y/n] Y
(1/1) checking keys in keyring [####################################################################] 100%
(1/1) checking package integrity [####################################################################] 100%
(1/1) loading package files [####################################################################] 100%
(1/1) checking for file conflicts [####################################################################] 100%
(1/1) checking available disk space [####################################################################] 100%
:: Processing package changes…
(1/1) reinstalling mingw-w64-x86_64-make [####################################################################] 100%

erandi@DESKTOP-O9FUKUT MSYS ~
$

Then I tried to given three lines on cmd, but it gave me the error of
‘g++’ is not recognized as an internal or external command, operable program or batch file

Please kindly guide me in this regard. I wanna give a try for CmdStanR as I am having earlier mentioned an error with rstan 2.21.0.

One more thing, I failed when running with more than one chain, do you have an idea for that?

Thanks in advance

Hi,

a few things you can try here.

  • make sure to restart the cmd, powershell and any open R sessions or RStudio after installing mingw32-make
  • check that
C:\RTools\RTools40\usr\bin
C:\RTools\RTools40\mingw64\bin

are defined in your PATH environment variable.

  • See more detailed instructions for Windows here.

Can you provide more info on how you tried to run with more than 1 chain.

Hi, Thanks for the comment here, I will try for CmdStanR with your suggestions. It will take some time for me.

For my second issue answer would be (if my understanding is correct)

n_chains <- 4
options(mc.cores = parallel::detectCores())
fit<-stan(model_code , data , iter = 1000, warmup = 500, chains = n_chains, control= list(max_treedepth=10)

Thanks