One True Implementation Language Syntax Reference
As this language is still being designed this document will contain a number of vagaries.
Please also read the general and datatypes pages.
General Notes
- OTIL is case-insensitive.
- Source code is (currently) restricted to standard ASCII characters.
- Before compilation the file is pre-processed by Mac.
Deliminators
The following characters are used to separate symbols and operators from each other. These characters cannot be used in symbols (or operators for that matter):
- space
- newline
- tab
- (
- )
- :
- ;
- [
- ]
If this may seem a brutish approach to language design, you are correct.
Source file type
Like Pascal and unlike C, OTIL requires that a source file explicitly states its purpose. There are three types of file:
The Program file type
This provides the starting point of a program along with the name of compiled executable. Note that the name of the executable is not added to the program's namespace. That is to say that it can be re-used as the name of a module, variable, function, etc.
PROGRAM name; USES library-1("version"); USES module-1; Declarations BEGIN Statements END
The Library file type
Allows programs to share common code by compiling them as dynamically linked libraries. Note that the name of the library will be added to the namespace of any programs that link against the library. Also note that libraries require a revision number or similar given as a string.
LIBRARY name VERSION "version-string"; USES library-1 ("version"); USES module-1; Interface declarations IMPLEMENTATION Implementation Declarations END
The Module file type
This is similar to a library but meant to only be used within the context of a single program or as implementation details to a library and thus does not support versioning. All other rules of the library file-type apply.
MODULE name; USES library-1("version"); USES module-2; Interface Declarations IMPLEMENTATION Implementation declarations END
Sub-routines
Like Pascal OTIL separates sub-routines into functions and procedures. Functions have return values but no side-effects while procedures have side-effects but no return values. This is an entirely artificial distinction meant to encourage good software architecture.
Functions
FUNCTION name(parameter-1, parameter-2, etcetera) : return-type; Variable and constant declarations BEGIN Statements END
Return values
Functions must be exited from by returning a value to its caller.
RETURN expression;
This can happen anywhere in the function's body but must include the function's final line. It is highly recommend however that all return statements are equally nested.
Procedure syntax
PROCEDURE name(parameter-1, parameter-2, etcetera); Variable and constant declarations BEGIN Statements END
Procedures will silently be exited from upon reaching the last line but may also exited from early using an explicit exit statement. This though is discouraged.
Forward declarations
Functions and procedures can be declared to exist ahead of their use and implementation.
FUNCTION name(parameter-1, parameter-2, etcetera) : type;
or
PROCEDURE name(parameter-2, parameter-2, etcetera);
Data Declarations
Unlike modern C OTIL syntax designates specific locations in source code for declaring constants and variables. These are:
- The header section of a program source file
- The header section of a library or module source file (for public access)
- The implementation section of a library or module source file (for private access)
- The header section of a function or procedure
When a constant is declared outside of a sub-routine's local scope the expression assigned to it is computed by the compiler. This means that it may note invoke any functions.
Constants
CONST name: type <- value;
Variables
VAR name: type <- expression;
or
VAR name: type;
See also: Record declaration.
Expressions, Comparitors and Arithmetic Operators
Expressions in OTIL are restricted to:
- Value assignment
- Sub-routine arguments
- Tests in conditionals and loops
- Indices of lists, bit-strings and slices
Order of operations
OTIL disregards mathematical conventions and uses a simple right-to-left order of evaluations. This is a very deliberate feature to save Ryan from having to remember how proper equations work.
NOTE: The original plan was left-to-right but as it turns out right-to-left is easier to implement.
Comparitors
- = Gives true if left expression is equal to right expression, else false
- <> Gives true if left expression is not equal to the tight expression, else false
- < Gives true if left expression is lesser than right expression, else false
- > Gives true if left expression is greater than right expression, else false
Arithmetic Operators
- + Adds two expressions
- - Subtracts the right expression from the left expression
- * Multiplies two expressions
- / Divides the left expression by the right expression
- ^ Raises the left expression by the power of the right expression
Conditionals
If
IF expression THEN Statements END
Else
IF expression THEN Statements ELSE Other statements END
Else If
IF expression THEN Statements ELSE IF expression THEN Other statements ELSE Yet more statements END
Unless
Single line statements can be made conditional by appending an unless clause to them.
Statement UNLESS expression;
Loops
While
WHILE expression DO Statements END
For
FOR assignment statement TO final value DONE Statements END
Break
Exits from a loop. Discouraged.
Skip
Bypasses the rest of the loops body. Discouraged.
Casting values
Sooner or later values have to be translated between data-types.
name-1 <- (type) name-2;