# Description of the alg_parse(stg) SETL procedure

This is a simple stacking parse. The symbols allowed are single alphabetics, parens, *+-/¥.

If a left paren is encountered, examine the type of the preceding symbol. If this is a numeric or a letter, generate a null operator instead and handle it as a normal operator. Otherwise stack this.

If an op is encountered, examine the preceding symbol. Diagnose an error if it is an operator or paren and this cannot be monadic; but if this can be monadic, introduce a null op. If the preceding symbol is not an operator, examine the symbol before it. If that has lower precedence, stack this. If it has equal or greater precedence, generate it if it has greater precedence, otherwise stack this.

If a numeric is encountered, examine the preceding symbol. Diagnose an error unless it is an operator. Otherwise stack the numeric.

If a letter is encountered, examine the type of the preceding symbol. If this is a numeric or a letter, generate a null operator instead and handle it as a normal operator. Otherwise stack this.

If space is encountered, bypass it.

If a bad character is encountered, diagnose it and end the parse.

If a right paren is encountered, insist that a numeric, letter, or right paren precede. If this is so, unstack the prior operators in precedence groups, and insist that the left parenthesis eventually found matches this.

The parse is readily adaptable to a larger set of operators, including comparison, Boolean, and conditional operators, also set membership. The following conventions are proposed. We allow the operators

    =,~=,<,>,<=,>=; &,|,~,^,- (which is the same as <=),

when the Boolean values are taken to be 0 (false) and 1 (true); << (min) and >> (max); a:b:c:d:e (necessarily in sequences of an odd number of components, meaning a:b:(c:d:e), where the middle is evaluated first and must be Boolean, and then the left (if true) or the right (if false); and x@s (for x in s). Functions and set operators can also be handled:

## Possible diagnostics

- -- ^**** ERROR: Empty parentheses are not allowed.
- -- ^**** ERROR: Closing parenthesis cannot follow right after an operator sign.
- -- ^**** ERROR: Mismatched right-opening parenthesis.
- -- ^**** ERROR: Mismatched left-opening parenthesis.
- -- ^**** ERROR: Illegal character.
- -- ^**** ERROR: Multiple decimal points in number symbol.
- -- ^**** ERROR: Monadic use of this operator is not allowed.
- -- ^**** ERROR: Unmatched right-opening parenthesis.
- -- ^**** ERROR: Number symbol can only follow open parenthesis or operator.
- -- ^**** ERROR: Left parentheses are not allowed at end of formula.
- -- ^**** ERROR: Formula cannot end with an operator sign.
- -- ^**** ERROR: Unmatched left parenthesis.
- -- ^**** ERROR: Illegal operator sign
- -- ^**** ERROR: Impossibly long run of operator signs.
- -- ^**** ERROR: Logical negation operator cannot be binary.