EGL language overview

To review the core aspects of the EGL language, see the sections in this topic. For information about day-to-day development, see the links at the end of this topic.

Data types

EGL data types include primitive types, such as strings, numbers of various kinds, and Boolean types. EGL also includes data parts, which are customizable data types. IBM® Rational® EGL Community Edition includes these data parts:
  • A DataItem part is a primitive type that you can name and customize for a specific use. For example, in a car-insurance application, a DataItem part named NumberOfCars identifies a type (an integer) that can be basis of one or more variables.
    DataItem NumberOfCars INT {} end
    Your logic can include variables based on that DataItem part. Here is an example:
    carCount NumberOfCars;

    The variable carsInPolicy refers to the number of cars in an insurance policy. You can use the name of a DataItem part to focus on a business issue.

  • A Record part is a collection of fields:
    Record CarPolicy type BasicRecord {}
       policyID STRING; 
       carCount NumberOfCars;
       driverCount NumberofDrivers
    end
    This code is a variable, or record, declaration with data assignments:
    myCarPolicy CarPolicy;
    myCarPolicy.policyID = "ABC123";
    myCarPolicy.carCount = 2;

    Much of your work with EGL might involve primitive types, DataItem parts, and Record parts.

  • A Dictionary is a predefined, system data part that is much like a primitive type. You can declare a variable that is based on the Dictionary part and then add or remove data whose identifiers, or keys, are known at run time only.
  • A DataTable is a predefined, system data part that is similar to a dictionary but takes fixed-length data, has any number of columns, and has special support for validation.

For further details about data parts in EGL, see “User-defined data parts” and “System data parts."

Logic and prototype parts

You define logic parts to process data or to access code that processes data.

Some logic parts can have a set of functions that include local variables and constants. Such parts also can have a set of variables and constants that are program global: available to every function in the part.

Rational EGL Community Edition includes these logic parts:
  • A library can contain functions, variables, and constants that can be accessed from other EGL code that runs on the same platform. You can use libraries to reuse local code.

    When you define a part that uses the code in a library, you can specify a use statement in that part. The use statement identifies the library to the part so that you can avoid repeating the library name when you reference the functions, variables, and constants in the library. For details, see “use.”

  • A service is similar to a library but can accessed from other code, potentially from anywhere in the world.
  • A handler is code that defines a series of complex interactions with the user. The handler that is available in the product is the Rich UI handler, which guides the behavior of Rich UI applications.
Another set of logic parts is sometimes called prototype parts, which include the details needed to access a particular kind of logic but do not include that logic. In EGL, you can use the following prototype parts:
  • Interface parts, which identify operations in a service
  • External types, which provide access to non-EGL code from within your code
  • Delegate parts, which provide an advanced capability like that of function pointers in other languages

Each of these parts is similar to a data part and is intended to be the basis of a variable.

For further details about prototype parts, see “Logic parts.”

Generatable parts

The workbench uses generatable parts to start a generation process. For example, the workbench might start generation with a Service part and then continue with non-generatable parts, such as the DataItems and Record parts that are used by the Service part.

The generatable parts are Handler, Service, and DataTable. Library is also treated as a generatable part, but is generated only when the Service or Rich UI handler is generated.

The following rules apply to generatable parts:
  • A source file can contain zero or one generatable part.
  • A generatable part must have the same name as the source file, without the .egl extension of the source file. The part name and file name must have the same case: myService is different from MYSERVICE.
  • Any number of non-generatable parts can be included in the same source file as a generatable part.

    Keep collections of Record parts and DataItems in files that do not have a generatable part. This practice gives you more modular code and is especially useful over time, for easier maintenance.

Set-value blocks

An important part of EGL syntax is the set-value block, which is the area between curly brackets in a part definition or variable declaration. In a part definition, you use set-value blocks to assign property values for use during EGL build or generation. In a variable definition, you use set-value blocks to assign runtime values.

This code is an assignment of runtime values in a set-value block:
myCarPolicy CarPolicy
   {
      policyID = "ABC123", 
      carCount = 2
   };  

For further details about set-value blocks, see "Set-value blocks."

Variables and constants

A constant names an unchangeable data area. A variable names a changeable data area. You can declare a set of constants or a set of variables by specifying a comma-separated series of identifiers:
   const MYCONSTANT01, MYCONSTANT02 INT = 5;
   myVariable01, myVariable02 INT;
You can use two kinds of variables:
  • Value variables name data areas that contain a value of direct interest to your application. For example, an INT variable is a value variable and names a data area that holds an integer value.
  • Reference variables name data areas that contain memory addresses and that refer to values of direct interest to your application. One example is a variable based on the primitive type ANY. You can use that data type for advanced purposes.

    In general, the use of reference variables gives you flexibility; however, when you copy data to or from a reference variable, you need to know the processing implications.

    The new operator allocates, or reserves, a data area at run time and places the address of that area into a variable. The operator is most often used with reference variables, as in the following example:
    myFlexibleVariable Any = new Any;

For further details about variables, see “Declaring variables and constants.”

Arrays

Most of your work with arrays is likely to involve a dynamic array, which is an array whose number of elements is changeable at run time. You make a size change by invoking an array-specific function, such as removeElement, insertElement, or appendElement.

EGL also supports array literals:
   myINTArray     INT[] = [1,2,3];
   my2Dimension   INT[][] = [[1,2],[3,4]];
   mySTRINGArray  STRING[] = ["bye", "ciao"];
   myBooleanArray BOOLEAN[] = [ (myPay < 10000), (yourPay > 50000) ];   

For further details about arrays, see “Arrays.”

Expressions and operators

An expression is a sequence of operands such as constants, variables, literals, and function invocations; operators, such as + and -; and special characters such as parentheses. At run time, each expression resolves to a value of a specific type.

For further details, see “Expressions and operators.”

EGL statements

Your can use EGL statements to complete tasks in a function. For details, see “EGL statements.”

System libraries

In addition to developing libraries that include variables, constants, and functions, you can access the EGL system libraries. For details, see “EGL system libraries and variables."


Feedback