] >
An L756 program is a sequence of (possibly labeled) statements. Normally, statements are executed in their order of appearance in the sequence unless a transfer of control is specified by a GOTO statement, an IF statement, or a FOR statement.
Any number of blanks can appear between adjacent tokens, and no blank may separate adjacent characters of a token. Line break characters are treated as space characters.
The following are the features of L756.
A variable is denoted by a string of letters and digits whose first character is a letter. Strings which agree on their first seven characters are assumed to denote the same variable. Labels are similarly defined but they must be followed by ”:”.
Each variable must be defined at the start of the program using a DCL instruction of the form ‘DCL <id>’.
Arithmetic expressions are formulas for computing a value. They are made up using ṉumbers, variables, the four arithmetic operators +, -, *, /, and the left and right parentheses.
The order in which operations are performed is normally from left to right except that
The general form of an Assignment statement is
The value of the arithmetic expression is computed and assigned to the variable.
The general form of a GOTO statement is ‘GOTO <id>’. Control is transferred to the statement with the specified label.
The general form of a Conditional Statement is:
where the relational operators are =, <>, <, <=, >, and >=.
If the relation holds between the values of the two arithmetic expressions then the control is transferred to the specified label. Otherwise, control passes to the code that appear after the instruction.
FOR statements are used to set up program loops. There are two general forms of FOR Statements:
The second form is interpreted in the same way as the first except that all the step size (arithmetic expression 3) is assumed equal to 1. The FOR statement forms the entrance of a program loop that continues through any number of subsequent statements until a NEXT to close the loop is reached.
Informally, the statements in the loop between the FOR and the NEXT are executed over and over again a number of times as specified by the FOR statement. Each time around the loop the value of the variable is incremented by the step and compared with the final value to determine whether to enter the loop again or to terminate the FOR statement.
Specifically, the execution of the FOR Statement is as follows:
It is allowable to have loops within loops, but they must be properly nested.
Every program must have a single END statement – the last (highest-numbered) statement in the program.
Comments can be added to a program using the REM statement, the general form of which is
The compiler ignores the input stream between (and including) the REM and its first following semicolon.
| 1. | <program> | <dcl> <body> END | |
| 2. | <dcl> | DCL <id> <dcl> | |
| 3. | |||
| 4. | <body> | <stat> <body> | |
| 5. | |||
| 6. | <stat> | <stat> | |
| 7. | <label> <stat> | ||
| 8. | <label> | <id> : | |
| 9. | <stat> | LET <id> = <expr> | |
| 10. | GOTO <id> | ||
| 11. | IF <expr> <relop> <expr> THEN GOTO <id> | ||
| 12. | <for> <body> NEXT | ||
| 13. | READ <id> | ||
| 14. | WRITE <expr> | ||
| 15. | <for> | FOR <id> = <expr> <step> TO <expr> DO | |
| 16. | <step> | STEP <expr> | |
| 17. | |||
| 18. | <relop> | <relop> | |
| 19. | = | ||
| 20. | <expr> | <expr> | |
| 21. | <expr> | <expr> <+-> <term> | |
| 22. | <term> | ||
| 23. | <term> | <term> <*/> <oprnd> | |
| 24. | <oprnd> | ||
| 25. | <oprnd> | <number> | |
| 26. | <id> | ||
| 27. | ( <expr> ) |
Note: relop stands for the class of relation operations: