Whenever a script is not completely linear (like if () {}, while () {}, etc), error messages tend to give wrong line numbers.
The simplest way to find the offending script line is to spread empty lines into the script, starting from the back, until the reported line number increases. Or put in a lot of debug output.
I understand it's not exactly trivial to get a correct number, as code blocks only get read once, and the error might occur only later. Would it be possible to store the actual line number while reading the script from the file for every new command, and report that in case of an error?
That wouldn't help within commands spread over several lines using the backslash, but it's at least an improvement.
Same as Bug 2238
https://sourceforge.net/p/gnuplot/bugs/2238/