Compilation phase error messages

Top  Previous  Next

During the compilation phase GAMS carefully checks the input file for consistency with GAMS syntax and semantics.  In turn, GAMS provides feedback and suggestions about how to correct errors or avoid ambiguities as discussed in the Compiler Errors chapter.

Several hundred different types of errors can be detected during compilation.  Most of the errors will be caused by simple mistakes: forgetting to declare an identifier, putting indices in the wrong order, leaving out a necessary semicolon, or misspelling a label.  For errors that are not caused by mistakes, the explanatory error message text will help you diagnose the problem and correct it as shown in the Compiler Errors chapter.

When a compilation error is discovered  a line is inserted in the echo print marked with four asterisks '****'.  Also in that line a $-symbol is inserted followed by a number which cross references to a list of error conditions followed by a brief explanation of the nature of the error.  This $ is inserted immediately below the place in the line where the error arose (usually to the right).  If more than one error is encountered on a line the $-signs may be suppressed and error numbers squeezed together.  GAMS will not list more than 10 errors on any one line.  The IDE also provides help in locating errors as discussed in the GAMS Usage chapter.

When errors are present, the LST file contains a list of all the different types of errors encountered by error number just after the end of the echo print listing.  That list which includes a description of the probable cause of each error.  The error messages are generally self-explanatory and will not be listed here.  However, I do provide a list of the most common ones and their cause in the Compiler Errors chapter.  These messages can be repositioned as discussed below.

Example:

The example shorterr.gms illustrates the general reporting format for compiler errors.  The part of shorterr.LST relevant to errors is:

 

   6  SET PROCESS   PRODUCTION PROCESSES /makechair,maketable,makelamp/

   7      RESOURCE  TYPES OF RESOURCES   /plantcap,salecontrct/;

   8  PARAMETER PRICE(PROCESS)      PRODUCT PRICES BY PROCESS

   9                /makechair 6.5 ,maketable 3, makelamp 0.5/

  10            Yield(process)  yields per unit of the process

  11                /Makechair 2   ,maketable 6 ,makelamp 3/

  12          PRODCOST(PROCESS)     COST BY PROCESS

  13                /Makechair 10  ,Maketable 6, Makelamp 1/

  14          RESORAVAIL(RESOURCE)  RESOURCE AVAILABLITY

  15               /plantcap 10 ,salecontrct 3/;

  16  TABLE RESOURUSE(RESOURCE,PROCESS) RESOURCE USAGE

  17                     Makechair   Maketable  Makelamp

  18       plantcap         3          2          1.1

  19       salecontrct      1         -1;

  20  POSITIVE VARIABLES PRODUCTION(PROCESS) ITEMS PRODUCED BY PROCESS;

  21  VARIABLES          PROFIT              TOTALPROFIT;

  22  EQUATIONS          OBJT OBJECTIVE FUNCTION ( PROFIT )

  23                     AVAILABLE(RESOURCE) RESOURCES AVAILABLE

  24  OBJT.. PROFIT=E=   SUM(PROCESS,(PRICE(PROCESS)*yield(process)

****      $96                        $2   $195      $96

  25                         -PRODCOST(PROCESS))*PRODUCTION(PROCESS)) ;

****                         $409

  26  AVAILABLE(RESOURCE).. SUM(PROCESS,RESOURUSE(RESOURCE,PROCESS)

  27                   *PRODUCTION(PROCESS))  =L= RESORAVAIL(RESOURCE);

  28  MODEL RESALLOC /ALL/;

  29  SOLVE RESALLOC USING LP MAXIMIZING PROFIT;

****                                          $257

  32  solprod(PROCESS)= PRODUCTION.l(PROCESS);

****                               $141

  34  display solprod;

 

Error Messages

  2  Identifier expected

 96  Blank needed between identifier and text

       (-or- illegal character in identifier)

       (-or- check for missing ';' on previous line)

141  Symbol neither initialized nor assigned

        A wild shot: You may have spurious commas in the explanatory

        text of a declaration. Check symbol reference list.

195  Symbol redefined with a different type

257  Solve statement not checked because of previous errors

409  Unrecognizable item - skip to find a new statement

       looking for a ';' or a key word to get started again

 

**** 7 ERROR(S)   0 WARNING(S)

Notes:

The lines containing the **** mark the errors encountered and also contain numbered error message references.
The $ insertions cross reference the error messages to the listing of descriptions of the conditions at the end of the echo print while also indicating the placement of the error in the input file.  In particular the lines

  23                     AVAILABLE(RESOURCE) RESOURCES AVAILABLE

  24  OBJT.. PROFIT=E=   SUM(PROCESS,(PRICE(PROCESS)*yield(process)

****      $96                        $2   $195      $96

 

 show that error 96 has occurred in line 24

Blank needed between identifier and text

(-or- illegal character in identifier)

 (-or- check for missing ';' on previous line)

 

 at the position of the $ markers.  The first error $96 occurs at the position of the .. in the line above and the associated message shows GAMS is expecting something different.  In this case the problem arises because of the line before as the third line of the error message suggests.  Namely the line before was not ended with a semicolon.

The example shows one of the common findings when dealing with compilation errors.  Namely one error typically proliferates throughout the code causing may other errors.  In this case the only error in the code is the omission of a semicolon (;) at the end of line  23.

 23 AVAILABLE(RESOURCE) RESOURCES;

 

 Typically many more compilation errors are marked than truly exist and can often be traced back to just one specific omission or error in the GAMS input.

The almost certain proliferation of errors caused by early errors in the GAMS program means it is always advisable to check carefully from the top of the echo print finding and repairing the cause of the first few errors in the code if one can figure them out then rerunning.
The example also shows an error may not be detected until the statement following its occurrence, where it may produce a number of error conditions with baffling explanations.
One very common error is the omission of a semi colon.
One can insert their own error messages using $abort or $error.  The **** marker can be changed using $Stars.