t3x.org / t3x / t3x-manual / 51.html
 
T3X - A Minimum Procedural Language
Version 8.1.5, Online Edition
Copyright(C) 1996-2004
Nils M Holm
 
Previous:
5. Formal Definitions
TOC | Index | Back Next:
5.2 Formal Syntax

5.1 Syntax Description Language

Basically, the syntax of the T3X language is described in a BNF-style form similar to the one accepted by the YACC parser generator. A more detailed description follows.

The T3X grammar is described as a set of rules of the following format:

Name:   Pattern1
        | Pattern2
        | ...
        | PatternN
        ;

It reads 'Name may also be written as Pattern1 OR Pattern2 OR ... OR PatternN'. Each pattern may consist of names of rules or terminal symbols. Each terminal symbol is enclosed in apostrophes, like '=', 'CONST', or '0x'. An apostrophy may be included in a terminal (symbol) by doubling it. Consequently, a terminal represented by an apostrophy is written ''''.

A terminal symbol is a symbol which represents itself. For example, 'CLASS' represents the literal string CLASS. Non-terminal symbols represent rules.

An example: The rule

BinaryDigit: '0' | '1' ;

is read 'A BinaryDigit may be represented by either the string '0' or the string '1'. A (recursive) rule to define arbitrary-length binary numbers based upon BinaryDigit would look like this:

BinaryNumber:
        BinaryDigit
        | BinaryDigit BinaryNumber
        ;

In this case, a BinaryNumber would be either a single BinaryDigit or a BinaryDigit followed by another BinaryNumber (and therefore more BinaryDigits).

The hash symbol (#) is used to indicate that no white space is allowed between the elements of a pattern. While the above rule would match

1 0 1 1 0 1 0 1

a rule containing the concatenation symbol (#) would match

10110101

Such a rule would be written this way:

BinaryNumber:
        BinaryDigit
        | BinaryDigit # BinaryNumber
        ;

A special rule named <character>, which is not defined inside of the formal grammer, is used to refer to an arbitrary character contained in the character set of the implementation environment.

Previous:
5. Formal Definitions
TOC | Index | Back Next:
5.2 Formal Syntax