Saturday, August 29, 2015

Super Simple Syntax

Super Simple Syntax

Wombat likes to take minimalism to extremes. The only built in types are procedure types and tuples (Which includes Unit, the 0-tuple). There is no builtin syntax. All syntax is defined with the syntax creation scheme called Super Simple Syntax (SSS) which is available to library writers and even end-users. If the programmer doesn’t like the syntax she can make big or small changes, without affecting interoperability with other modules.
Some programming languages have user defined operators with just one precedence number that is the same on both sides. This means that you also have to specify left or right associativity. In Wombat the left and right can have different precedence. The operator associates to the left if the right precedence is higher.
Wombat allows operators with no left operand, or no right operand, or both. Indeed an identifier is just an operator, with no left or right, from a syntactic viewpoint. Operators can have following sub-operators, such as then and else for the if operator. Sub-operators can repeat or be optional, and can have a nested structure. There can be repeating groups, such as elif-then pairs in an if operator.
Operators can have a left parameter in which case they have a left priority. They can have a right parameter in which case they have a right priority. Technically the right priority belongs to trailing sub-operators such as else, but this is commonly the operator itself when it doesn’t have other sub-operators. (The operator counts as a sub-operator of itself.)
An operator can have a sub-operator (not itself) which is also in use as an operator. It only takes its sub-operator meaning where it is expected.
Priorities form a partial order. If priorities are not comparable then they can’t do battle for an expression between them. This stops different libraries from getting in each other’s way. The partial order includes as a subset the positive decimal numbers with a finite number of digits (Dewey decimal style), which the ordinary programmer might prefer to use. Additional priorities are defined by names together with enough comparisons between each other and (if desired) the numerical priorities. The partial order is the resulting transitive closure.
Most operators just map to a procedure. The parameters are combined into a tuple in the same order that they occur. Repeated parameters map to an n-tuple where n is the number of repeats. Optional parameters map to a 0-tuple or a 1-tuple. The procedure has to be appropriately polymorphic.
Every (sub)expression starts with an operator with no left and ends with an operator with no right. Every operator with no left is the start of one or more expressions, and every operator with no right is the end of one or more expressions. Every operator with no left will be preceded by a suboperator with a right which will swallow one of the expressions it starts. Every operator with no right is followed by an operator with a left to swallow one of the expressions it ends.
When an expression is required after a (sub)operator, and the following operator has no left, then the 0-tuple (unit:Unit) is inserted automatically. This means that unit can be written (), but also that it can be omitted almost anywhere that it might appear. [Note that '(' is an operator in Wombat, with ')' as a suboperator.]
When an operator with no right (such as an identifier or a parenthesized expression) is followed by an operator with no left, then a space-break token is inserted. In standard Wombat this is left associative procedure call. Actually if there is no actual white space (the break is created by the lexical analysis) then it is a different operator: tight-break. This also maps to procedure call. Tight-break is always an operator: it can't be used as a suboperator. Space-break can be used as a suboperator, and is so used in the list constructor operator (e.g. [12 34 56]).

Some initial code for SSS has been released. See the preceding post and

No comments:

Post a Comment