Keli Language
  • Motivation
  • Showcase
  • Design goals
  • Features
  • Specification
    • Section 1: Introduction
    • Section 2: Lexical Structure
    • Section 3: Basic Expressions
    • Section 4: Magic Expressions
    • Section 5: Declarations
    • Section 6: Modules
    • Section 7: Type annotations
    • Section 8: Packages
  • Style guide
    • Naming conventions
  • Techniques
    • Singleton
    • Default values for functions
  • Installation
    • How to install Keli?
  • Tutorial
    • Creating a new package
  • CONTRIBUTE
    • Github source
  • Blog
    • Interval comparison operator for free!
Powered by GitBook
On this page
  • 2.1 Notational Conventions
  • 2.2 Abbreviations
  • 2.3 Lexical Program Structure
  • 2.4 Comments
  • 2.5 Constant Identifiers
  • 2.6 Function identifiers

Was this helpful?

  1. Specification

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.

PreviousSection 1: IntroductionNextSection 3: Basic Expressions

Last updated 6 years ago

Was this helpful?

2.1 Notational Conventions

The following notations are used to described the grammar of Keli (for more info, lookup ):

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

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

( # | ? | _ | 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

/ / { / }

2.4 Comments

Comments are actually whitespaces. Comments starts with 2 slahses and extends until before the following newline. For example:

// this is a comment

2.5 Constant Identifiers

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

2.6 Function identifiers

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

| ({operator }) <reservedOp>

EBNF
constId