|
This chapter describes the lexical elements of the language. Lexical elements are identifiers, literals, and delimiters. They are the basic elements used to build language constructs such as expressions, definitions, and so on. Lexical elements are composed of characters of a basic character set. All characters used in a program must be part of the basic character set. The characters of the basic character set are subdivided in five categories:
Layout characters are used to control the layout of a program and may be used to separate adjacent lexical elements (see Section 1.6). Identifiers are used as names to identify definitions, parameters, variables, and other program entities. An identifier consists of a sequence of letters, digits, and the underscore (_) character. The first character of an identifier may not be a digit. Examples of valid identifiers are:
Uppercase and lowercase letters are distinct, so Count and count are different identifiers. As a convention, all identifiers which have a predefined meaning in the language, such as keywords, basic type names and built-in definitions, are in lowercase. That means that you can define uppercase versions for other purposes. For example, If is different from if. However, in most situations it is unwise to choose identifiers that differ only slightly from each other. Identifiers starting with underscore are reserved for special facilities related to the implementation and the run-time environment, so it is not recommended to use such identifiers for other purposes. Keywords Keywords are identifiers with a special meaning. In Elisa there are two categories of keywords: reserved keywords, and context dependent keywords. Reserved keywords are reserved identifiers with a predefined and fixed meaning in the language. They may not be used for other purposes. Examples of reserved keywords are:
Context dependent keywords are identifiers which have a specific meaning within a given context. They may also be used for different purposes within other contexts where the meaning can be established unambiguously. However, it is often unwise to choose identifiers with the same name but with different meanings. The following identifiers are examples of context dependent keywords:
A literal represents a constant value. The form of the literal determines the value and its type. There are four types of literals: integer-literals, real-literals, character-literals and text-literals. The types integer, real, character and text are predefined in the language and are discussed later on. An integer literal consists of one or more digits, representing an unsigned integer number. Examples are: 0, 21, 3456, 32767. A real literal represents an unsigned real number and consists of an integer portion, a decimal point followed by a fractional portion, and an optional exponent. At least one digit should be specified before the decimal point (the integer portion). You may omit the digits after the decimal point (the fractional portion). The optional exponent specifies the power of ten by which the preceding number is to be multiplied to obtain the value. Examples of real literals are: 0.0, 123., 123.45, 3.142, 3142.0E-3. A character literal represents one character and is formed by enclosing a single character from the basic character set within single quotation marks. The following examples illustrate some character-literals:
To represent non-displayable characters, quotation marks and layout characters, an escape sequence must be used. An escape sequence consists of a backslash(\) followed by a letter or an integer constant. An escape sequence is regarded as a single character and should represent a valid character value. A text literal represents a string of characters and is of the predefined type text. It consists of a string of characters from the basic character set enclosed in double quotation marks. All characters, except the first and last quotation marks, are part of the text. An empty text-literal is represented by two adjacent double quotation marks(""). To represent non-displayable characters, quotation marks and layout characters, an escape sequence may be used in the same way as has been described for character literals. The following examples illustrate some text-literals:
Escape Sequences Escape sequences are described in the following table.
Table of Escape Sequences The following examples illustrate some character-literals with escape characters:
If a backslash precedes a character that does not appear in the table, the backslash is ignored. The sequence \ddd allows you to specify any character in the basic character set as a three-digit integer character code. For example, you can give the backspace character as \008. The numeric value of the character code may not exceed 255. A delimiter consists of one or two special characters from the basic character set. Delimiters are used as separators and operators. Separators are to used for separation and grouping of language elements. Examples are ( ) , [ ] { } ;. Examples of operator symbols are <, <=, >, >=, +, -, *, /, **. The operator symbols and their names are listed in the following table.
Comments are used for documentation purposes; they do not affect the meaning of a program. Comments may be inserted between any two adjacent lexical elements. Comment are distinguished from the rest of the program by being enclosed in special brackets << and >>, as in:
Comments may be nested by using balanced << >> pairs, as in:
In a comment, the characters can include any combination of characters from the basic character set, including layout characters, but excluding the end-comment symbols. Layout characters like blanks, tabs, carriage returns, line feeds may be used for the physical layout of a program. Adjacent lexical elements may be separated by layout characters or comments. A name or a literal must be separated in this way from an adjacent name or literal. Layout characters can not occur within names or literals, excepting text-literals. Because line separations also act as separators, lexical elements such as names, integer-literals, real-literals, character-literals and double character delimiters may not be written on two successive lines but must always be kept on one line. Text-literals and comments may extend over more than one line.
|
<!-- Start of StatCounter Code for Default Guide --> <script type="text/javascript"> var sc_project=11338540; var sc_invisible=0; var sc_security="f2d7a14f"; var sc_https=1; var scJsHost = (("https:" == document.location.protocol) ? "https://secure." : "http://www."); document.write("<sc"+"ript type='text/javascript' src='" + scJsHost+ "statcounter.com/counter/counter.js'></"+"script>"); </script> <noscript><div class="statcounter"><a title="Web Analytics Made Easy - StatCounter" href="http://statcounter.com/" target="_blank"><img class="statcounter" src="//c.statcounter.com/11338540/0/f2d7a14f/0/" alt="Web Analytics Made Easy - StatCounter"></a></div></noscript> <!-- End of StatCounter Code for Default Guide --> |