Mismatched parentheses - error H

Top  Previous  Next

Parentheses must match up in expressions.  An excess number of open "(" parentheses are marked with $8 while excess closed ")" parentheses are marked with $408 [i.e., cases like SUM (I,X(I); or SUM (I,X(I))); generate errors] and but other errors can enter.  The example shorterr10.gms illustrates such errors under the use of the errmsg=1 option which repositions the error message explanatory text.

 

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

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

****                                                                      $8

****   8  ')' expected

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

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

****                                            $37,408$409

****  37  '=l=' or '=e=' or '=g=' operator expected

**** 408  Too many ),] or }

**** 409  Unrecognizable item - skip to find a new statement

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

  28  scalar x;

  29  x=sum((resource,process),RESOURUSE(RESOURCE,PROCESS)));

****                                                       $408

**** 408  Too many ),] or }

  30  x=sum((resource,process),(RESOURUSE(RESOURCE,PROCESS));

****                                                        $8

****   8  ')' expected

 

Two error prevention strategies are possible when dealing with parentheses.

Many editors, including the one in the IDE, contain a feature that allows one to ask the program to identify the matching parentheses with respect to the parenthesis that is sitting underneath the cursor.  It is highly recommended that GAMS users employ this feature during model coding to make sure that parentheses are properly located for the end of sums, if statements, loops etc.
Alternative characters can be used in place of parentheses.  In particular, the symbols { } or [ ] can be used instead of the conventional ( ). GAMS is programmed to differentially recognize these symbols and generate compile errors if they do not match up.  Thus a statement such as

 

         x = sum( j, ABS ( TTS (j) ) );

 

can be restated as

 

         x = sum[ j, ABS { TTS(j) } ];

 

Such a restatement would provide a visual basis for examining whether the parentheses were properly matched.  It would also generate errors if one did not use the alternative parenthesis forms in the proper sequence.  For example, the following statement would stimulate compiler errors:

 

         x = sum[ j, ABS { TTS(j} ] );.