Syntax diagrams

<< Click to Display Table of Contents >>

Navigation:  Gekko User Manual > Syntax basics >

Syntax diagrams

Previous pageReturn to chapter overviewNext page

Gekko 3.0 has a more strict syntax than Gekko 2.x and earlier. The following diagrams illustrate some of the fundamental building blocks of the syntax of 3.0. So whenever Gekko refuses one of your expressions, and the syntax error does not make sense, you may consult the following diagrams and perhaps understand the issue by means of these. The blue boxes below provide examples.

 

One of the most fundamental building blocks of Gekko is the name.

 

clip0012

 

Here, alphanum means alphanumerical characters: letters, digits, and underscore, whereas expr is any legal Gekko expression (for instance a mathematical expression). Gekko will evaluate whatever is inside the {}-curlies, and will expect the inside to be a string or a list of strings. Note that alphanum excludes %, #, !, : and other symbols.

 

To make it possible to write for instance x{%i} shorter as x%i, a "complicated name" (cname) is introduced:

 

clip0002

In many cases, such a cname can be used instead of a normal name. Note that the name part of the cname may contain {}-curlies, not just alphanumeric characters. The cname is mostly used to avoid typing too many {}-curlies, cf. the examples in the blue box. In Gekko program files, procedures and functions, it is recommended to use name instead of cname, for readability and maintainability. That is, it is recommended to use x{%s}y rather than x%s|y.

 

A variable name is a precise reference to an object residing in a particular Gekko databank. It may include prefix symbols % or # (for scalars or collections), or frequency ! (for timeseries). The upper part of the diagram illustrates timeseries, which have no prefix symbols and may include frequency. The lower part of the diagram illustrates scalars and collections, starting with a type symbol.

 

clip0003

Note that if you want to compose a scalar or collection name using a cname, you must use parentheses. For instance, %(a%b) designates a scalar name, where the name itself (excluding the %) is a%b. But in general it is much clearer to use the equivalent name version %a{%b} instead of the cname version %(a%b). Note that %a%b is not legal syntax, since it would be too confusing.

 

A varname can reside in any databank (or MAP), and a bankvarname is hence designated as follows:

 

clip0004

 

So either there is no bankname, else a colon (:) is used, or @ can be used to imply the reference databank (@x should be read as short-hand for ref:x).

 

Indexing can be done with either []-brackets, or with a dot (.). You can use .. to designate a sequence inside the []-brackets.

 

clip0005

The dot (.) is used in three ways. The expression #m.x picks out the series x from the map #m (alternatively, #m[x] or #m['x'] does the same thing). The expression x.f(a) is equivalent to f(x, a), because Gekko implements UFCS. Finally, an expression like x.1 is equivalent to x[-1], that is, a one period lag.

 

The function syntax is completely standard:

 

clip0006

 

Lists are defined in the following way (this is a strict list definintion using soft parentheses; note that a naked list definition without parentheses is possible, too):

 

clip0007

 

 

 

Maps are defined in the following way:

 

clip0008

 

 

Matrices are defined in the following way:

 

clip0009

 

A logical statement:

 

clip0010

 

 

The keyword in checks if the first expr is a member of the second expr.

 

Dollar-conditionals:

 

clip0011

 

Note that parentheses are always used, and membership uses the in keyword. A GAMS expression like x(i) $ i0(i) is thus translated into x[#i] $ (#i in #i0). Using x[#i] $ #i0[#i] or x[#i] $ (#i0[#i]) will not work. See the "Details" section of this page for an explanation.