Jump to content

Annotated King Reference Manual/Lexical Elements

From Wikibooks, open books for an open world

Lexical Elements

[edit | edit source]

Items

[edit | edit source]

Each lexical element is formed from a sequence of characters, and is either a delimiter, an identifier, a reserved word, a numeric_literal, a character_literal, a string_literal, or a comment.

The text of a compilation is divided into lines.

Separators code points are: 16#20# (SPACE, except within a comment, a string_literal, or a character_literal), 16#0A# (LINE FEED), 16#0D# (CARRIAGE RETURN).

Rationale

[edit | edit source]

A compilation is a sequence of lines, conceptually terminated by a line terminator. King does not specify what character(s), if any, make up a line terminator in a compilation text. Common text file formats on the kinds of systems that King is intended to be used on use one or two characters (CR, LF) as line terminators, so this is probably correct in practice (if King is ever implemented).

Discussion

[edit | edit source]

-

Delimiters

[edit | edit source]

Single

[edit | edit source]
&    '    (    )    *    +    ,    -    .    /    :    ;    <    =    >    @    [    ]    |    {    }    ^    \

Compound

[edit | edit source]

=>    ..    <-    /=    >=    <=     <>

Rationale

[edit | edit source]

-

Discussion

[edit | edit source]

-

Identifiers

[edit | edit source]

Examples

[edit | edit source]
Invalid

V_String

Is_Empty

Latin_1_String

Syntax

[edit | edit source]
identifier ::= identifier_start {underline identifier_extend}

identifier_start ::= letter_uppercase {letter_uppercase | number_decimal}
                     {letter_lowercase | number_decimal}

identifier_extend ::= identifier_start | number_decimal {letter_uppercase | number_decimal}
                      {letter_lowercase | number_decimal}

Once built as above, specifics rules (see TBD) are enforced to define a valid identifier.

Rationale

[edit | edit source]

An identifier is made up of words separated by underlines. There is an initial word and zero or more subsequent words. The initial word must begin with a capital letter. Subsequent words can begin with a capital letter or a digit.

Discussion

[edit | edit source]

-

Reserved Words

[edit | edit source]

all and

begin body

case constant

declare delta digits

else else_if end exit

for function

hidden

if in is

loop

macro map module

new not null

of or others out

procedure

range record renames return reverse

select separate sequence set some subtype

task then type

use

wait when with

xor

Rationale

[edit | edit source]

-

Discussion

[edit | edit source]

-

Numeric Literals

[edit | edit source]

Examples

[edit | edit source]

universal_integer

[edit | edit source]
99

478E70

16#CAFE#

universal_real

[edit | edit source]
3.14

0.0

0.25

16#F.FF#E+2

36#THE_QUICK_BROWN_FOX_JUMPS.OVER_THE_LAZY_DOG#

Syntax

[edit | edit source]
numeric_literal ::= decimal_literal | based_literal

decimal_literal ::= numeral [.numeral] [exponent]

numeral ::= digit {[underline] digit}

exponent ::= E [+] numeral | E - numeral

digit ::= number_decimal

based_literal ::= base # based_numeral [.based_numeral] # [exponent]

base ::= numeral

based_numeral ::= extended_digit {[underline] extended_digit}

extended_digit ::= digit | letter_uppercase

Rationale

[edit | edit source]

-

Discussion

[edit | edit source]

-

Character Literals

[edit | edit source]

Examples

[edit | edit source]
'@'

'Δ'

' '

'''

Syntax

[edit | edit source]
character_literal ::= 'graphic_character'

Rationale

[edit | edit source]

-

Discussion

[edit | edit source]

-

String Literals

[edit | edit source]

Examples

[edit | edit source]
"une soirée passée à étudier les mathématiques ℕ⊂𝕂..." -- Unicode characters

" " -- Space character

"" -- Null string

(See expressions for examples of building strings with quotation mark)

Syntax

[edit | edit source]
string_literal ::= "{string_element}"

string_element ::= non_quotation_mark_graphic_character

Rationale

[edit | edit source]

-

Discussion

[edit | edit source]

-

Comments

[edit | edit source]

Examples

[edit | edit source]
-- Returns the number of Elements in List

Syntax

[edit | edit source]
comment ::= --{non_end_of_line_graphic_character}

Rationale

[edit | edit source]

-

Discussion

[edit | edit source]

-