RESOL (REtro Statement Oriented Language) is a programming language inspired by fixed-format FORTRAN. It does not do anything backwards.
A comment line has C in the first column. For all other lines, columns 1-5 are used for labels, column 6 is used for indicating a continuation line, and columns 7-72 are used for the statement.
A continuation line has at least six columns, and a non-space character in the 6th column. It is illegal for the first line to be a continuation line, and it is illegal for a continuation line to directly follow a comment line. A continuation line continues both the label and statement of the preceding line.
Statements have an optional label. Labels consist of a list of 1 or more digits (0-9). It is illegal for more than one statement to have the same label. Leading zeros are significant.
Each labeled statement has its own call stack. This permits convoluted code where the returns are not in the reverse order of the calls.
Each labeled DATA statement has a queue stack, where the top of the stack is the statement's queue. The queue is a queue of digits (0-9). The first argument of the DATA statement defines the size of the queue item in number of digits. The second argument, if present, defines the initial contents of the queue, which would otherwise initially be empty.
There are 5 statements: DATA, CALL, CONTINUE, IF, and STOP.
- DATA: If its first argument does not match a the label of a DATA statement, it's a no-op. If it has a single argument, it removes the top item from the queue of the matching DATA statement. Otherwise, it adds the value of the second argument, as defined later, to the queue of the matching DATA statement.
- CALL: Its first argument must match a label. The statement following the CALL is pushed onto the matching statement's call stack, and execution continues with the matching statement. If the matching statement is a DATA statement, then a new queue is pushed onto its queue stack. If the CALL statement has a second argument, the new queue contains the value of the second argument, as defined later, otherwise the new queue is empty.
- CONTINUE: Its first argument must match a label. Its second argument, if present, must match a label. If the matching statement is not a DATA statement or if the matching DATA statement's queue is empty, execution continues with the statement popped from the matching statement's call stack. The top of the queue stack is also popped if relevant. Otherwise, if there is a second argument, execution continues with the statement matching the second argument. Otherwise, execution continues with the statement matching the first argument. As a special case, if the matching statement is the first statement and a DATA statement, if the matching statement's (input) queue is empty, execution continues with the statement following the CONTINUE statement, otherwise execution continues with the statement matching the second argument, if present, otherwise execution continues with the first statement.
- IF: If the value of the first argument, as defined later, is not equal to the value of the second argument, as defined later, the next statement is skipped.
- STOP: Stops the program. Execution continuing beyond the last statement results in a run-time error.
The value of an argument (the 2nd argument of a DATA or CALL statment, both arguments of an IF statement) is the top item of the queue of the DATA statement whose label matches the argument. If there is no matching DATA statement, then the value of the argument is the literal value of the argument.
Input and output
In order to do input or output, the first statement must be a labeled DATA statement. The size of its queue item determines how the values enqueued and dequeued are translated to and from the output and input bits. Each queue item represents the largest number of bits that it can. For example, if the queue item size is 1, then it represents 3 bits, and the value of the output bits is the value of the queue item modulo 8. If the queue item size is 2, then it represents 6 bits, and the value of the output bits is the value of the queue item modulo 64. If the queue item size is 3, then it represents 9 bits. If the queue item size is 4, then it represents 13 bits. Larger sizes are analogous.
Reading the first statement with IF, CALL, or the second argument of DATA reads the input. Dequeueing from the first statement with a single argument DATA statement allows reading subsequent input. Enqueueing to the first statement with a two argument DATA statement writes to the output.
HELLO WORLD (ASCII):
07734 DATA 4 000001 DATA 07734,23125425157546133742526705450266 000002 STOP 000003
0 DATA 1 000001 1 CONTINUE 0,2 000002 STOP 000003 2 DATA 0,0 000004 DATA 0 000005 CONTINUE 0,2 000006 STOP 000007