Language Reference/Lexical Elements

The Visual Prolog Compiler is applied to a source file. This source file may include other source files, which are (conceptually) inserted into the original source file to constitute one compilation unit. The compilation of a compilation unit is done in two conceptual steps:
 * first the input is transformed into a sequence of tokens;
 * and then these tokens are syntactically analyzed and transformed into executable code.

The lexical analysis of the program will break the compilation unit  into a list of input elements 

: -list

:   

Only tokens are significant to the subsequent syntax analysis.

Comments
A Visual Prolog comment is written in one of the following ways:
 * The /* (slash, asterisk) characters, followed by any sequence of characters (including new lines), terminated by the */ (asterisk, slash) characters. These comments can be multi-lined. They can also be nested.
 * The % (percent sign) character, followed by any sequence of characters. Comments that begin with character % (percent sign) continue until the end of the line. Therefore, they are commonly called single-line comments.

Notice the following comment example:

/* Begin of Comment1 % Nested Comment2 */ Comment 1 is not terminated (single-line comment) This is the real termination of Comment1 */

Whitespace
:   

Here  is a space character,  is a tabulation character and  is a new line character.

Tokens
<Token>: <Identifier> <Keyword> <Punctuator> <Operator> <Literal>

Identifiers
<Identifier>: <LowercaseIdentifier> <UppercaseIdentifier> <AnonymousIdentifier> <Ellipsis>

A <LowercaseIdentifier> is a sequence of letters, digits, and underscores that starts with a small letter. An <UppercaseIdentifier> is a sequence of letters, digits, and underscores that starts either with a capital letter or with an underscore.

<AnonymousIdentifier> :   _

<Ellipsis> : ...

Keywords
Keywords are divided into major and minor keywords, this division is only cosmetic however, there is no formal difference between major and minor keywords. In the sequel we will however use different coloring for them.

<Keyword> : <MajorKeyword> <MinorKeyword>

<MajorKeyword> : one of  class clauses constants constructors delegate domains end facts goal implement inherits interface monitor namespace open predicates properties resolve supports where

<MinorKeyword> : one of  align and anyflow as    bitsize catch determ digits div do  else elseif  erroneous externally failure finally foreach from guard if in   language mod multi nondeterm otherwise or orelse procedure quot rem single then to try

All keywords except <vp>as</vp> and <vp>language</vp> are reserved words.

<vp>end</vp> is always combined with another key word:

end class end implement end interface end if end foreach end try

Punctuation Marks
Punctuation marks in Visual Prolog have syntactic and semantic meaning to the compiler, but do not specify by themselves an operation that yields a value. Some punctuation marks, either alone or in combinations, can also be Visual Prolog operators.

Punctuation marks are:

<PunctuationMarks>: one of  ;    ! ,   .    #    [    ]    |        {    }    :-    :    ::

Operators
specify an evaluation to be performed on involved operands. <Operators>: one of  ^ /   *  div mod quot rem +   -   =    <    >    <>    ><    <=    >=    :=    ==      ++    **    ^^    >>    <<


 * <vp></vp> is a  operator.
 * <vp>-</vp> and <vp>+</vp> are both and  operators.
 * all other operators are.

<vp>div</vp>, <vp>mod</vp>, <vp>quot</vp> and <vp>rem</vp> are reserved words.

Literals
Literals fall into following categories: integer, character, floating-point, string, binary and list.

<Literal>: <IntegerLiteral> <RealLiteral> <CharacterLiteral> <StringLiteral> <BinaryLiteral>

Integral Literals
<IntegerLiteral>: <UnaryPlus>-opt   <DecimalDigit>-list <UnaryMinus>-opt  <DecimalDigit>-list <UnaryPlus>-opt   <OctalPrefix> <OctalDigit>-list <UnaryMinus>-opt  <OctalPrefix> <OctalDigit>-list <UnaryPlus>-opt   <HexadecimalPrefix> <HexadecimalDigit>-list <UnaryMinus>-opt  <HexadecimalPrefix> <HexadecimalDigit>-list

<UnaryPlus>: +

<UnaryMinus>: -

<OctalPrefix>: 0o

<OctalDigit>: one of  0 1 2 3 4 5 6 7

<DecimalDigit>: one of  0 1 2 3 4 5 6 7 8 9

<HexadecimalPrefix>: 0x

<HexadecimalDigit>: one of  0 1 2 3 4 5 6 7 8 9 A a B b C c D d E e F f

An integral literal can belong to or  domains and it should not exceed maximum and minimum  or  values.

Real Literal
<RealLiteral>: <UnaryMinus>-opt <DecimalDigit>-list <FractionOfFloat>-opt <Exponent>-opt

<FractionOfFloat>: . <DecimalDigit>-list

<Exponent>: <ExponentSymbol> <ExponentSign>-opt <DecimalDigit>-list

<ExponentSymbol>: one of  e E

<ExponentSign>: one of  - +

A real literal should not exceed maximum and minimum real values. Notice that any integral literal can also be used as a real value.

Character Literals
<CharacterLiteral>: ' <CharacterValue> '

<CharacterValue> can be any printable character or an escape sequence:


 * \\ representing <vp>\</vp>
 * <vp>\t</vp> representing Tab character
 * <vp>\n</vp> representing New Line character
 * <vp>\r</vp> representing carriage return
 * <vp>\'</vp> representing single quote
 * <vp>\"</vp> representing double quote
 * <vp>\u</vp> <XXXX>, here <XXXX> should be exactly four <HexadecimalDigit> 's representing the Unicode character corresponding to the digits.

String Literals
<StringLiteral>: <StringLiteralPart>-list

<StringLiteralPart>: ' <CharacterValue>-list-opt ' " <CharacterValue>-list-opt " @<AtOpenChar> <AnyCharacter>-list-opt <AtCloseChar>

A string literal consists of one or more <StringLiteralPart> 's, which are concatenated.

The first two forms (the ' and " forms) uses escape sequences to express certain characters


 * <vp>\\</vp> representing <vp>\</vp>
 * <vp>\t</vp> representing Tab character
 * <vp>\n</vp> representing New Line character
 * <vp>\r</vp> representing carriage return
 * <vp>\</vp><vp>"</vp> representing double quote
 * <vp>\</vp><vp>'</vp> representing single quote
 * <vp>\u</vp> <XXXX>, here <XXXX> should be exactly four <HexadecimalDigit> 's representing the Unicode character corresponding to the digits.

In single quoted strings it is optional to escape double quotes, and likewise it is optional to escape single quotes in double quoted strings.

Single quoted strings must contain at least two characters otherwise they will be assumed to be a character literal.

The @-literals can be used to avoid obscuring the string literals with escape characters. The literals starts with @ followed by some non-letter character <AtOpenChar>. And it terminates when the close character <AtCloseChar> is met. For most characters the close character is the same as the opening character, but for diverse paranthesis charactes the close character is the corresponding opposite paranthesis.

For all non-paranthesis opening character the close character is the same as the open character, for example @" is closed by ".

For all @-strings it is the case the twice the closing character does not close the string, but means one occurence of the closing character in the string.

Binary Literals
<BinaryLiteral>: $[ <ElementValue>-comma-sep-list-opt ] <ElementValue>: <IntegerLiteral>

<ElementValue> should be any integral arithmetic expression (for example, constant), which should be calculated while compilation-time and be in the range from <vp>0</vp> till <vp>255.</vp>