gnudatalanguage / gdl

GDL - GNU Data Language
GNU General Public License v2.0
278 stars 62 forks source link

Interpreter errors using concatenation ("&") #692

Open maynardGK opened 4 years ago

maynardGK commented 4 years ago

Overall I've had little-to-no problems with command concatenation ("&") and line continuation ("$"). However as I recently have transferred scripts to a new computer I discovered this error when an extra "&" slipped into an endif-else-begin statement:

if( !version.os_name eq 'Windows' ) then begin &$
     dst = "D:/f/"  & Pathsep=";" & print,' Windows' & endif & else begin & $
     dst ="/d/f/" & Pathsep=":" & print,'Whoops!' &endelse

This is a valid statement in GDL, but it shouldn't be, just as "else begin" by itself is not. To see this in a linux system one would reverse the logic:

if( !version.os_name ne 'Windows' ) then begin &$
     dst ="/d/f/" & Pathsep=":" & print,'Not Windows'  & endif & else begin & $
     dst = "D:/f/"  & Pathsep=";" & print,' Windows'&endelse
maynardGK commented 4 years ago

Another odd behavior of concatenation: "&&" should be interpreted(?) as just "&" but is not:

GDL>  resu2a=FILE_WHICH('../src/', filetest) & print,resu2a
../src/gdl
GDL> resu2a=FILE_WHICH('../src/', filetest) & & print,resu2a
../src/gdl
GDL> resu2a=FILE_WHICH('../src/', filetest) && print,resu2a
% Variable is undefined: PRINT
% Execution halted at: $MAIN$
GillesDuvert commented 3 years ago

concerning the second point

IDL> resu2a=FILE_WHICH('../src/', filetest) && print,resu2a
% Keyword RESU2A not allowed in call to: PRINT
% Execution halted at: $MAIN$