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.
Notation | Meaning |
[ pattern ] | optional |
{ pattern } | repetition |
( pattern ) | grouping |
pattern1 | pattern2 | choice |
pattern1 | difference; elements of pattern1 except those of pattern2 |
hello | terminal syntax in typewriter font |
The following abbreviations will be used to describe the lexical structure of Keli.
Abbreviation | Meaning |
id | identifier |
op | operator |
alnum | alphanumeric |
Term | Definition |
program | { lexeme | whitespace } |
lexeme | id | literal | reservedOp |
id | alnumId | symbolicId |
alnumId | ( # | ? | _ | alphabet ) { alphabet | digit |# | ? | - | _ } |
operator | ( ~ | ! | @ | $ | % | ^ | & | * | - | = | + | / | < | > | : | \ ) |
alphabet | a | ... |z | A | ... | Z |
digit | 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 |
literal | integer | float | string |
integer | decimal |
float | decimal . decimal |
decimal | digit { digit } |
string | " { space | escape | gap } " |
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 | / / { / } |
Comments are actually whitespaces. Comments starts with 2 slahses and extends until before the following newline. For example:
// this is a comment
A constant identifier is any sequences of characters that satisfy the following grammar:
(
$
| _
| alphabet ) { alphabet | digit | -
| _
}For example:
Term | Validity |
hello | Valid |
_ | Valid |
true | Valid |
snake_case | Valid |
aVariable | Valid |
x123 | Valid |
crazy_stuff_lol | Valid |
Content-Type | Valid |
12x | Invalid |
Constant identifiers are used for identifying:
- 1.Function parameter
- 2.Type
- 3.Object property
- 4.Type variable
Function identifiers are used for identifying functions, they can be any sequences of characters that satisfy the following grammar:
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 |
plus | Valid |
toString | Valid |
+ | Valid |
-> | Valid |
== | Valid |
= | Invalid, reserved operator |