LogoThe Eiffel Compiler / Interpreter (tecomp)


Lexical Conventions, Constants

An Eiffel program or library is stored in one or more Eiffel class files. The source code for the Eiffel class CLASS_NAME has to be stored in the file "class_name.e".

Tokens, Comments, Identifiers and Keywords


Tokens are identifiers, keywords, constants, operators and other separators. Blanks, horizontal and vertical tabs, newlines, formfeeds and comments (in other words "white space") are ignored except as they separate tokens. Some white space is required to separate otherwise adjacent identifiers, keywords and constants.


The characters -- start a comment. A comment ends at the end of the line. Multiline comments are not possible. Each comment line must start with --.


An identifier is a sequence of letters, digits and underscores. The first character must be a letter. Eiffel is not case sensitive, i.e. A_NAME, a_name and a_Name are identical identifiers.


The following identifiers are reserved for use as keywords, and may not be used otherwise:

  agent       alias      all          and          as           assign
  attached    attribute  check        class        convert      create
  debug       deferred   detachable   do           else         elseif
  end         ensure     expanded     export       external     feature
  from        frozen     if 	      implies      inherit      inspect
  invariant   like       local 	      loop 	   not 	        note           
  obsolete    old	 once 	      or	   redefine     rename
  require     rescue     retry        select       separate     then
  undefine    until      variant      when 	   xor
  Current     Result     Void         True         False        TUPLE          


Eiffel defines standard operators and free operators. A standard operator is one of

     //             -- integer division
     \\             -- remainder
     and then
     or else

A free operator is any nonempty sequence of the operator symbols

  : \ ? = ~ / ! # $ % & * + - / < > @ ^ ` |

which does not create any ambiguity with other constructs (comments, etc). Precise rules: TDB.

The table below lists the precedence level and associativity of the operators.

  precedence  associativity    operators
  10                           old not + - (unary) all free unary operators
   9                           all free binary operators
   8          right to left    ^
   7          left to right    * / // \\
   6          left to right    + - (binary)
   5                           ..
   4                           = /= ~ /~ < > <= >=
   3          left to right    and  and then
   2          left to right    or  xor  or else
   1          left to right    implies

Note: "implies", "and then" and "or else" are the semistrict boolean operators.

Note: There are symbolic operators like "+", "-", "/", ... and keyword operators like "and", "not", "or", .... The keyword operators "and then" and "or else" are one token. Only blanks are allowed to separate the keywords in "and then" and "or else", no other whitespace characters.


There are

Boolean constants

There are the two boolean constants


representing the two possible truth values. According to the usual Eiffel style, constants begin with an uppercase letter and the rest in lowercase. But this is just a style guideline, since Eiffel is not case sensitive (True and tRUe represent the same value).

Integer constants

Integer constants can be given in decimal, hexadecimal, octal and binary form.


             0     -- decimal integer 
   0x0fab_0c45     -- hexadecimal integer 
   0b1101_0011     -- binary integer
        0c7710     -- octal integer

An integer constant is an optional prefix followed by a sequence of digits and underscores which must begin with a digit. Hexadecimal constants are prefixed with 0x, binary constants with 0b and octal constants with 0c. Only decimal constants can have an optional sign.

Integer constants are case insensitive like identifiers.

Between the sign and the decimal digit sequence no blank is allowed.

Integer constants can be in the range of the type INTEGER. The type INTEGER is either a synonym for INTEGER_32 or INTEGER_64. This can be selected by a compiler switch. The default is INTEGER_32. I.e. the range of an integer constant is one of

Out of range constants must be prefixed by a conversion specifier. In order to represent the constant 2147483648 (in case INTEGER_32 is selected) one has to write one of the following

    {NATURAL}    2_147_483_648 
    {INTEGER_64} 2_147_483_648

because 2147483648 is not a valid INTEGER_32.

Character constants

A character constant is a sequence of one or more characters enclosed in single quotes as in 'x'. The sequence of characters is one of

Value must represent a valid character code depending on the default setting of the compiler. CHARACTER is either a synonym for CHARACTER_8 or CHARACTER_32. In the first case value has to be in the range 0..255. In the second case in the range 0..4294967295.

Special character can be represented by the escape sequences

    '%A'   -- At-sign         @
    '%B'   -- Backspace       BS   *
    '%C'   -- Circumflex      ^
    '%D'   -- Dollar          $
    '%F'   -- Formfeed        FF   *
    '%H'   -- BackslasH       BS
    '%L'   -- TiLde           ~
    '%N'   -- Newline         NL   *
    '%Q'   -- BackQuote       `
    '%R'   -- CarriageReturn  CR   *
    '%S'   -- Sharp           #
    '%T'   -- HorizontalTab   HT   *
    '%U'   -- NUll            NUL  *
    '%V'   -- Vertical bar    |
    '%%'   -- Percent         %    *
    '%''   -- Single quote    '    *
    '%"'   -- Double quote    "
    '%('   -- Opening bracket [
    '%)'   -- Closing bracket ]
    '%<'   -- Opening brace   {
    '%>'   -- Closing brace   }

Only the special characters marked with * are essential, the others can in most environments represented directly (like '@', '~', '$', '#', ...) and don't need escape sequences.


   'a'           -- character a
   '%T'          -- special character TAB
   '%/32/'       -- character 32, i.e. blank in decimal,
   '%/0x20/'     -- in hexadecimal,
   '%/0c40/'     -- in octal,
   '%/0b1_0000/' -- and in binary notation

Real constants

A real constant consist of an integer part, a decimal point, a fraction part, an e or E and an optionally signed integer exponent.

The integer and fraction parts both consist of sequences of decimal digits.

Either the integer part or the fraction part (not both) can be missing; either the decimal point or the e and the exponent (not both) may be missing.



String constants

There are 3 forms of string constants (also called manifest strings or string literals).


   "This is a simple string with an embedded %N newline character"
   "This is a line wrapped string%
   % with embedeed escape sequences like e.g. %
   % newline %N and TAB %T"
       This is a sequence of lines which are taken verbatim.
       The indentation at the left side and the newlines are kept.
       I.e. this string constant has 3 embedded newline characters.
       This is a sequence of lines which are taken verbatim.
       The indentation at the left side is removed but the newlines are kept.
       I.e. this string constant has 3 embedded newline characters.
 Local Variables: 
 mode: outline
 coding: iso-latin-1
 outline-regexp: "=\\(=\\)*"
Table of contents

- Tokens, Comments, Identifiers and Keywords

- Tokens

- Comments

- Identifiers

- Keywords

- Operators

- Constants

- Boolean constants

- Integer constants

- Character constants

- Real constants

- String constants