-
Notifications
You must be signed in to change notification settings - Fork 4
Syntax
The language's syntax is summarized below. The following considerations were made: Fixed type elements are be literals, parenthesis group elements, alternative elements are separated by a vertical bar (or pipe), optional elements are wrapped by square brackets, elements that occur zero or more times are wrapped by ⟨ and ⟩. Some elements in the syntax may be elements of the language described if represented in fixed type (e.g., parenthesis).
file | ⟨ declaration ⟩ |
---|---|
declaration | variable; | function |
variable | [ qualifier ] type identifier [ = expression ] |
function | [ qualifier ] ( type | procedure ) identifier( [ variables ] ) [ = literal ] [ body ] |
variables | variable ⟨ , variable ⟩ |
type | integer | real | string | [ type ] |
body | block |
block | { ⟨ declaration ⟩ ⟨ instruction ⟩ } |
statement | expression; | expression! | expression!! |
next | stop | return | |
conditional-statement | iteration-statement | block | |
conditional-statement | if ( expression ) statement ⟨ elsif ( expression ) statement ⟩ [ else statement ] |
iteration-statement | while ( expression ) statement |
sweep( + | - ) ( lvalue : expression : expression [: expression] ) statement | |
expressions | expression ⟨ , expression ⟩ |
Some definitions have been left out of the syntax: data types, identifier (see identifiers), literal (see literals), expressions (see expressions).
Left-values are memory positions that can be modified (except when not allowed by certain data types). An expression's elements that can be used as left-values can be found and individually identified in the expressions' semantics.
The main file is the file containing the main function.
A variable declaration always indicates a data type and an identifier.
Examples:
- Integer:
int i
- Real:
real r
- String:
string s
- Pointer to integer:
[int] p1
(equivalent toint *
in C) - Pointer to real:
[real] p2
(equivalent todouble *
in C) - Pointer to string:
[string] p3
(equivalent tochar **
in C) - Pointer to pointer to int:
[[int]] p4
(equivalent to toint **
in C)
By default, symbols are private within a module and can't be imported by modules.
The public
marker allows an identifier to be declared as public, making it accessible to other modules.
The use
marker (optional for functions) allows the declaration of entities defined in other modules. Entities can't be initialized in an imported declaration.
Examples:
- Variable declaration private to a module:
real pi = 22.0/7
/* Proof that 22/7 exceeds π */ - Public variable declaration:
public real pi = 22/7.0
- Using an external definition:
use real pi
When it exists, it consists of an expression followed by the sign =
("equals"): integer, real, pointer. Real entities can be initialized by integer expressions (implicit conversion). An initialization expression should be a literal if the variable is global.
Strings are (possibly) initialized as a non-null list of values without separators.
Examples:
- Integer (literal):
int i = 3
- Integer (expression):
int i = j + 1
- Real (literal):
real r = 3.2
- Real (expression):
real r = i - 2.5 + f(3)
- String (literal):
string s = "hello"
- String (literals):
string s = "hello" "mum"
- Pointer (literal):
[[[real]]] q = null
- Pointer (expression):
[int] p = q + 1