Section 2: Lexical Structure
This chapter will describe the lexical structure of Keli. Most of the information on this page can be ignored during the first reading of this report.
2.1 Notational Conventions
The following notations are used to described the grammar of Keli (for more info, lookup EBNF):
Notation | Meaning |
[ pattern ] | optional |
{ pattern } | repetition |
( pattern ) | grouping |
pattern1 | pattern2 | choice |
pattern1 | difference; elements of pattern1 except those of pattern2 |
| terminal syntax in typewriter font |
2.2 Abbreviations
The following abbreviations will be used to describe the lexical structure of Keli.
Abbreviation | Meaning |
id | identifier |
op | operator |
alnum | alphanumeric |
2.3 Lexical Program Structure
Term | Definition |
program | { lexeme | whitespace } |
lexeme | id | literal | reservedOp |
id | alnumId | symbolicId |
alnumId | ( |
operator | ( |
alphabet |
|
digit |
|
literal | integer | float | string |
integer | decimal |
float | decimal |
decimal | digit { digit } |
string |
|
reservedOp |
|
whitespace | whitestuff { whitestuff } |
whitestuff | whitechar | comment |
whitechar | newline | vertab | space | tab | unicodeWhitespace |
newline | return linefeed | return | linefeed | formfeed |
return | a carriage return |
linefeed | a line feed |
vertab | a vertical tab |
formfeed | a form feed |
space | a space |
tab | horizontal tab |
unicodeWhitespace | any Unicode character defined as whitespace |
comment | slashes [ nonnewline { nonnewline }] newline |
slashes |
|
2.4 Comments
Comments are actually whitespaces. Comments starts with 2 slahses and extends until before the following newline. For example:
2.5 Constant Identifiers
A constant identifier is any sequences of characters that satisfy the following grammar:
( $
| _
| alphabet ) { alphabet | digit | -
| _
}
For example:
Term | Validity |
| Valid |
| Valid |
| Valid |
| Valid |
| Valid |
| Valid |
| Valid |
| Valid |
| Invalid |
Constant identifiers are used for identifying:
Function parameter
Type
Object property
Type variable
2.6 Function identifiers
Function identifiers are used for identifying functions, they can be any sequences of characters that satisfy the following grammar:
constId | ({operator }) <reservedOp>
In layman term, a function identifier can be a constant identifiers OR a sequences of symbols that are not reserved operator.
Examples of function identifiers:
Term | Validity |
| Valid |
| Valid |
| Valid |
| Valid |
| Valid |
| Invalid, reserved operator |
Last updated