Skip to main content

Notice: this Wiki will be going read only early in 2024 and edits will no longer be possible. Please see: https://gitlab.eclipse.org/eclipsefdn/helpdesk/-/wikis/Wiki-shutdown-plan for the plan.

Jump to: navigation, search

Difference between revisions of "EDT:Language Overview04"

(EGL Syntax)
Line 1: Line 1:
 
= EGL Syntax  =
 
= EGL Syntax  =
  
The smallest units of meaning in the EGL source code are the '''tokens''', which can categorized as keywords, identifiers, operators, literals, and special characters.  At a more composite level, the language includes type definitions, expressions, and statements.   
+
The smallest units of meaning in the EGL source code are the '''tokens'''.  As in other languages, they can be categorized as keywords, identifiers, operators, literals, and special characters.  At a more composite level, EGL includes type definitions, expressions, and statements.   
  
A set-values block is a code area that sets annotations and field values and is delimited by curly brackets ({}), as shown in the following declaration:  
+
One often-used construct is the '''set-values block''', which is a code area that sets annotations and field values and is delimited by curly brackets ({}).  Consider the following declaration:  
 
<pre>myCarCount NumberOfCars { InputRequired = yes };
 
<pre>myCarCount NumberOfCars { InputRequired = yes };
 
</pre>
 
</pre>
The example set-values block declares an '''InputRequired''' annotation for the <code>myCarCount</code> variable.<br>
+
The example set-values block declares an '''InputRequired''' annotation for the <code>myCarCount</code> variable.<br><br>Set-values blocks are used in various ways in type definitions, statements, expressions, and other set-values blocks.
 
+
'''Keywords''', which are the the EGL reserved words; for example, '''While'''.&nbsp;
+
 
+
*'''Identifiers'''.&nbsp;which are the&nbsp;names of types, functions, variables, and constants. An example is <code>myCarCount</code>, which is a variable name.
+
*'''Literals''', which are fixed&nbsp;values of a given type. Examples are the integer 5, the string “yes!”, and the Boolean value TRUE.
+
*'''Operators''', which are symbols that affect a value.&nbsp;The value, or operand,&nbsp;is on the left or right of an operator. For example, the &lt; operator is part of a condition that tests whether the operand on the left has a lesser value than the operand on the right.
+
*'''Special characters''',&nbsp;which are punctuation marks that divide tokens, as necessary for the parsing done by the EGL compiler. For example, parentheses (( )) might surround a condition such as <code>myVariable &lt; yourVariable</code>.&nbsp;
+
 
+
At a more composite level, the language includes the following constructs:
+
 
+
*'''Type definitions''', which are sequences of tokens that define a type.
+
*'''Expressions''', which are&nbsp;sequences of tokens that express unnamed instances. For example, 4 + 5 might be assigned to a variable, but is itself a value of type INT.
+
*'''Statements''', which is an&nbsp;instruction that causes work to occur at run time or that organizes code at development and transformation time:
+
**The runtime work might be variable declaration, data manipulation, logic invocation, output to&nbsp;a user interface or persistent data storage, and so forth.
+
**The organization work might include assigning types to packages, importing types from other packages, and enabling a shortcut for referencing identifiers that are in libraries.<br>
+
 
+
:Most statements begin with an EGL keyword. For example, the following statement writes “yes!” to the standard output:&nbsp; <code>SysLib.writeStdOut("yes!");</code>
+
 
+
*'''Set-values blocks''', which are code areas that set annotations and field values and are delimited by curly brackets ({}), as shown in the following declaration:
+
 
+
:<pre>myCarCount NumberOfCars { InputRequired = yes };</pre>
+
 
+
:The example set-values block declares&nbsp;an '''InputRequired''' annotation for the <code>myCarCount</code> variable.<br><br>Set-values blocks are used in various ways in type definitions, statements, expressions, and other set-values blocks.
+
  
 
= <br>Scope  =
 
= <br>Scope  =

Revision as of 17:13, 2 December 2011

EGL Syntax

The smallest units of meaning in the EGL source code are the tokens.  As in other languages, they can be categorized as keywords, identifiers, operators, literals, and special characters.  At a more composite level, EGL includes type definitions, expressions, and statements. 

One often-used construct is the set-values block, which is a code area that sets annotations and field values and is delimited by curly brackets ({}).  Consider the following declaration:

myCarCount NumberOfCars { InputRequired = yes };

The example set-values block declares an InputRequired annotation for the myCarCount variable.

Set-values blocks are used in various ways in type definitions, statements, expressions, and other set-values blocks.


Scope

The scoping rules tell whether a given variable, constant, parameter, or function is visible to an expression.  

The order of priority for resolving a reference is as follows:

  1. First in precedence are declarations that are local to the function where the expression resides. This category includes variable, constant, and function-parameter declarations.
  2. Second in precedence are declarations that are outside of a function but are inside the type where the expression resides. Each field is program global, which means that it is accessible to all members in the type. This category includes variable, constant, program-parameter, and function declarations.
  3. Third are declarations that are outside a function but are inside a library that is accessible to the expression. Each public field is run-unit global, which means that it is accessible to all functions that run as a unit such that an unhandled exception terminates the unit. This category includes the variable, constant, and function declarations in the library. Those declarations are program global to other functions in the same library.

A reference in an expression can include a series of identifiers, with a period (.) separating one from the next. Here is an expression in which each operand is fully qualified:

autoPkg.AutoLibrary.numberInFleet –
autoPkg.CarLibrary.DebtRecord.carLimit 

As appropriate, the identifiers can include a package name, the name of a container type, the name of a contained type, and a field name. A contained type can itself be a container type, to any level of depth.

The package and type names are especially useful for accessing values and functions in a library, as suggested in the example. However, for library access you can code a use statement, which offers the convenience of referring more directly to the declarations inside the library.

If a local declaration has the same name as the program-global declaration, only the local declaration is visible to the expression; but you can override that rule by using the this keyword.

Back to the top