-
Notifications
You must be signed in to change notification settings - Fork 1
Modifications on language spec
This is mostly to resolve inconsistencies in the specification document itself.
- Redefine operator precedences
Operator precedence as defined in the grammar does not make sense. The precedence will be redefined such that it is consistent with what everyone knows and is comfortable with (example:
+before<).
-
notaccepts boolean
The grammar only mentions the
notlogical operator before an IntegerLiteral. We will allow it to be used with boolean expressions as well.
- Equality check is by reference
For arrays and records, assignment is defined by reference. The same is not mentioned for equality comparison, so it is assumed. It remains by value for primitive types.
- Array length either has
[]with an expression inside or no[].
The spec requires that an array's length be specified when declaring an array, but not necessarily when declaring a routing parameter. The grammar is inconsistent on whether that should be like
routine main (param: array [] integer)orroutine main (param: array integer), so we assumed the latter.
- Array length property name is
length
The spec defines that arrays have a property (accessible with dot-notation) that holds an integer value with the number of elements in the array, but leaves the name undefined. We chose the property name "
length".
- Can alias a type for use in params only
The only type with some ambiguity is the array, since it can be specified without a size only in certain contexts (routine parameters). We allow the same syntax to be used in type aliasing, but that alias would only be allowed in the same context that the type is allowed in. Example:
type Graph is array array integer;
routine dijkstra (graph: Graph) is
// ...
end
- Parameter declaration type is parsed as Type, not Identifier
The grammar defines that
ParameterDeclaration ::= Identifier ':' Identifier. This prohibits us from writing something likeroutine dijkstra (graph: array array integer), or even simply using any primitive type without aliasing it. We decided to change it such that it becomesParameterDeclaration ::= Identifier ':' Type
- Add RoutineCall as Primary
According to the given grammar, a routine call cannot be part of an expression. This means they cannot be even used in simple assignment or basically anything other than for a side effect (no return value used). We modified this so that a
RoutineCallcan be considered aPrimary, thus allowing its use inExpressions