Incidence of compilation errors

Top  Previous  Next

GAMS requires strict adherence to language syntax.  It is very rare for even experienced users to get their syntax exactly right the first time.  GAMS marks places where syntax does not correspond exactly as compilation errors in the echo print listing.  For example I present the echo print from a syntactically incorrect variant of the economic equilibrium problem.  In that example (econequilerr.gms) I have introduced errors in the form of a different spelling of the variable named Qd between line's 1, 3, 5 and 6 spelling it as Qd in line 1 and Qdemand in the other three lines.  I also omit a required ; in line 4.

 

  1  POSITIVE VARIABLES  P, Qd , Qs;

  2  EQUATIONS     PDemand,PSupply, Equilibrium;

  3  Pdemand..     P            =g= 6 - 0.3*Qdemand;

****                                               $140

  4  Psupply..    ( 1 + 0.2*Qs) =g= P

  5  Equilibrium.. Qs           =g=  Qdemand;

****           $409

  6  MODEL PROBLEM /Pdemand.Qdemand, Psupply.Qs,Equilibrium.P/;

****                               $322

  7  SOLVE PROBLEM USING MCP;

****                       $257

 

Error Messages

140  Unknown symbol

257  Solve statement not checked because of previous errors

322  Wrong complementarity pair. Has to be equ.var.

409  Unrecognizable item - skip to find a new statement

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

 

The above echo print contains the markings relative to the compiler errors.  A compiler error message consists of three important elements.  First a marker **** appears in line just beneath the line where an error occurred.  Second a $ is placed in the LST file just underneath the position in the above line where the error occurred.  Third a numerical code is entered just after the $ which cross-references to a list appearing later in the LST file of the heirs encountered and a brief explanation of their cause sometimes containing a hint on how to repair the error.

Notes:

The above messages and markings show GAMS provides help in locating errors and givies clues as to what's wrong.  Above there are error markings in every position where Qdemand appears indicating that GAMS does not recognize the item mainly because it does not match with anything within the variable or other declarations above.  It also marks the 409 error in the Equilibrium equation just after the missing ; and prints a message that indicates that  a ; may be the problem.
The **** marks all error messages whether they be compilation or execution errors.  Thus, one can always search in the LST file for the **** marking to find errors.
It is recommended that users do not use lines with **** character strings in the middle of their code (say in a comment as can be entered by placing an * in column 1—see the Including Comments chapter) but rather employ some other symbol.
The example illustrates error proliferation.  In particular the markings for the errors 140, 322 and 409 identify the places mistakes were made but the error to 257 does not mark a mistake.  Also while the 140 and 322 mark mistakes, the real mistake may be that in line 1 where Qd should have been spelled as Qdemand.  It is frequent in GAMS that a declaration error causes a lot of subsequent errors.
In this case only two corrections need to be made to repair the file.  One should spell Qd in line 1 as Qdemand or conversely change all the later references to Qd. One also needs to add a semi colon to the end of line 4.
The IDE contains a powerful navigation aid which helps users directly jump from error messages into the place in the GMS code where the error message occurs as discussed in the Running Jobs with GAMS and the GAMS IDE chapter.
When multiple errors occur in a single position, GAMS cannot always locate the $ just in the right spot as that spot may be occupied.
New users may find it desirable to reposition the error message locations so the messages appear just below the error markings as discussed in the Fixing Compilation Errors chapter.
Here I have only presented a brief introduction to compilation error discovery.  The chapter on Fixing Compilation Errors goes substantially further and covers through example a number of common error messages received and their causes.