TL/1 language specification

Introduction

TL/1 is a pascal like one pass compiler for 8bit cpu, which is implented by Hiroshi Ohnishi in 1980. It has very fast compilation speed, but only supports 8bit variable and array. 16bit addressed memory can be accessed by MEM variable.

example TL/1 source

t1.tl1
% TEST PROGRAM **
PROC WAIT,TIME
%--- MAIN ---
VAR I
BEGIN
  WRITE(1:"Do ")
  FOR I:=1 TO 10 DO [
    WRITE(1:I,CRLF)
    TIME
    ]
  WAIT
END
%-- PROCEDURE WAIT --
WAIT
VAR I,J,K
BEGIN
  FOR I:=0 TO 1 DO [
    FOR J:=0 TO 255 DO [
      FOR K:=0 TO 255 DO []]]
END
%-- PROCEDURE TIME --
TIME
VAR I,J
BEGIN
  FOR I:=0 TO 10 DO [
    FOR J:=0 TO 150 DO []]
END
t2.tl1 t3.tl1

This document is a summary of the language specification of the programming language TL/1. Based on the explanation in magazines and the web etc., it is what I reorganized into the format of the specification with the addition of my interpretation and the indication of ambiguous parts.

We may use terms that are not in the original document for the purpose of explanation.

The places in this text that are referred to as "undefined" are explicit indications that the original source material can not be judged.

Although syntax diagrams are prepared, it is better to read the sentences first and then refer to the syntax diagrams because there is a unique part in the interpretation of identifiers.

Token

Comment

The percent sign (%) to the next newline is ignored, and it is treated as whitespace. Use it to describe the program description etc.

Identifier

It consists of zero or more alphanumeric characters, beginning with an alphabetic character. The word continues up to just before a character (space or symbol) that does not form an identifier. Uppercase and lowercase letters are not distinguished.   There is no upper limit on the identifier length.

Reserved words, procedure names, function names, global single variable names, global array names, small area single variables, and small area array names may have the same spelling. It is not checked at the time of declaration if it is identical to the existing name. Except where in the declaration, the implementation tries the name search in the following order and interprets it as the identifier of the first attribute found.

  1. Local array name
  2. Local single variable name
  3. Global array name
  4. Global single variable name
  5. function name
  6. Procedure name
  7. reserved words

Number

There are 4 types of expressions.

The numbers that can be handled directly with TL/1 are byte sizes, so the numeric representations that appear in a program are always in the range of 0-255.

In places where a boolean value is required in the syntax, 255 is interpreted as true, and other values are interpreted as false. A function that returns a boolean value returns 255 as true and 0 as false.

decimal constant

One or more of the characters 0-9 can be numbers in the range 0-255.

Behavior is not defined if you add an extra 0 at the beginning (such as 02).

Hexadecimal constant

Symbols beginning '$' which follows 0 to 9 or a to f represent 0 to 255 in hexadecimal notation. The letters a to f have the same meaning even if they use uppercase letters (A to F).

Do not put a space character after the symbol $.

It is permissible to add an extra 0 (for example $0A) to make two digits in hexadecimal, but if you add more 0 (for example $002) The behavior of) is undefined.

Character literal constant

Expressed by a single character between quotes. It is considered that the same numerical value as the one-letter ASCII code is written.

 'A' has the same meaning as 65.

Logical constant

represented by TRUE or FALSE . TRUE is equivalent to $FF and FALSE is equal to 0.

symbol

Others, symbols are used for operators and syntax, but they will be covered in the syntax description below.

Space character

It can be inserted between words. One word is sufficient for word separation, but the meaning does not change even if it continues several times. Please use it to adjust the appearance. The following characters are interpreted as whitespace characters.

There are also habitual meanings to how to use, which will be described later.

Program configuration

Programs are organized in the following order.

      
  1. Procedure name declaration
  2.   
  3. Function name declaration
  4.   
  5. Global single variable name declaration
  6.   
  7. Global array name / array size declaration
  8.   
  9. Main program definition
  10.   
  11. Procedure or function definition group

The contents of each are as follows.

Procedure Name Declaration

Comma separated list of the procedure names to be used in the program following the reserved word PROC .

 PROC   procedure 1 ,  procedure 2 ,  Procedure 3  ...

The declaration can be ommited if there are zero procedures.

Function name declaration

Comma separated list of the function name to be used in the program following the reserved word FUNC .

 FUNC   function 1 ,  function 2 ,  Function 3  ...

If the number of functions is zero, the declaration is omitted.

Global scalar variable name declaration

Comma separated list of scalar variable names used throughout the program following the reserved word VAR .

 VAR   single variable 1 ,  single variable 2 ,  single variable 3  ...

The declaration can be ommited if there are zero global scalar variables.

The variables must be within 256 bytes in total with the global array described below. Furthermore, if you call subprogram , you need room for 2 bytes (the sum of global single variable and global array needs to be less than 254 bytes) .

Global array name / array size declaration

Camma separated list of an array name and its size to be used throughout the program following the reserved word ARRAY . The size of the array is indicated by the numerical value enclosed by square brackets after the array name.


ARRAY array1 [ size of array1 ] ,
      array2 [ size of array2 ] ,
      array3 [ size of array3 ] ...

The size of the array is the maximum value of array subscripts. For example, for arrays declared as A[10], it means that they can be safely referenced with an index of 0-10. It is not the number of elements of the array such as C.

Main program definition

0 or more statements between BEGIN and END .

Subprogram definitions

A subprogram is a procedure or a function. It is organized in the following order:

  1. Sub-program name
  2. formal argument list
  3. Sub-area single variable name declaration
  4. Small-area array name / array size declaration
  5. Reserved words BEGIN
  6. 0 or more statements
  7. Reserved words END

This is repeated by the number of subprograms.

The definition of a subprogram does not have to match the order of declaration.

Sub program name

The name must be delcared in the procedure or the function name declaration part of the program.

Formal argument list

Multiple identifiers enclosed in parentheses. Separate multiple identifiers with commas.

( argument 1 ,  argument 2 ,  argument 3  .. .)

Arguments are passed by values. These are local sacalar variables which are initialized with the actual argument at the time of invocation. (Implicit local scalar variable declaration)

If there are no arguments, you can omit the parentheses.

Local scalar variable name declaration

Declare single variables that can be referenced only in the relevant subprogram. The format is the same as a global single variable.

Omit the declaration if there are zero subregion single variables.

Similar to global single variables and global arrays, the combined size of the subregion single variables and the subregion array must be 256 bytes or less.

Local array name declaration

Declare an array that can be referenced only in the subprogram. The format is the same as for a global array.

statements

compound statements

You can combine 0 or more statements with one or more statements into one statement.

  BEGIN   statement list   END  
 { statement list } 
 [ statement list ] 
 ( statement list ) 

Compound sentences behave as if they were one statement, so they can appear anywhere the statement can appear in the following explanation. A compound statement with 0 enclosed execution statements is called a blank statement.

Any parenthesis means the same thing, but it must be closed with the corresponding closing parenthesis. For example, it is not possible to start with "{" and close it with "]".

It is customary to write a semicolon (;) which is ignored as a space character to separate each statement in a compound statement.

The main program and sub program text is also a kind of compound sentence, but as shown above, there must be in BEGIN and END . You can not use other parentheses.

STOP

Stop the execution and jump to the monitor.

It is inserted automatically at the end of the main program, so it does not have to be written, but it can be written anywhere in the main program / subprogram.

RETURN

Returns from a procedure or function.

RETURN
RETURN expression

When returning from a procedure, write in a format without an expression, and when returning from a function, write in a format followed by one expression.

It is inserted automatically at the end of the procedure, so it does not have to be written, but it can be used anywhere in the procedure. (Do not use it in FOR loop in some implementations).

At least one must be used in the function definition. (Note that it is not checked at compile time. Also, should not be used in a FOR loop)

The behavior when hit is undefined when it reached to the end ( END , which represents the end of the function definition) without passing RETURN statement in a function

FOR

Repeats statements while changing the value of a single variable.

 FOR   variable : =  expression   TO   expression   DO   statements 
 FOR   variable : =  expression 1   DOWNTO   expression 2   DO   statements  
> Assign the value of the expression to the scalar variable for

counting, and increment or decrease scalar variable by 1 at a time, repeat executing the statements.

The increment of

variable is +1 when TO is used, DOWNTO When using it is -1. ( DOWNTO can not use DOWNTO on some implementations.)

REPEAT

  REPEAT   statement list   UNTIL   expression  
statement list is repeated until the value of

expression becomes true. statement list is a sequence of zero or more execution statements.

WHILE

  WHILE   expression   DO   statement  
If the value of

expression is false, it will move to the next processing without executing statement .

If the value of the expression is true, execute execution statement to return to the evaluation of expression again.

IF

  IF   expression   THEN   statement 1  
  IF   expression   THEN   statement 1   ELSE   statement 2  
If the value of

expression is true, execute statement 1 is executed.

if the value of the expression is false and the ELSE clause is not omitted statement 2 .

If the value of the

expression is false and the ELSE clause is omitted, the process proceeds to the next process without doing anything. (In some implementations, ELSE clause Can not be used. )

CASE


 CASE   expression 0   OF 
      expression 1   statement 1 
     ...
      expression k-1   statement k-1 
      ELSE   statement k 
If the value of

expression 0 is compared with the value of expression 1 and it matches Execution statement 1 . After that, it moves on to the next processing of statement k .

If it does not match, it compares with the expression one after another until it matches in the same way, and executes the execution statement corresponding to the matched expression.

If there is a reserved word ELSE in the

part of the expression, it is regarded as unconditional and statement k

The ELSE clause in the

CASE statement is the end of the CASE statement There is also a marker indicating that it is a condition, so it can not be omitted. If there is no statement to be executed in the ELSE clause, write a blank statement.

WRITE

 WRITE  ( expression :  output list )
Outputs the contents of the output list to the output device represented by the value of

expression. Although the correspondence between numbers and output devices is undefined, it is generally assumed that 0 is the console screen.

The output list consists of the following output elements, separated by commas if more than one.

expression

Write an expression. Output with decimal number left justified.

right justified

# ( expression 1 ,  expression 2 )
Outputs the value of

expression 2 with the number of digits of expression 1 with decimal right justification.

string

"  string  "

Output a string enclosed in double quotes.

ASCII code

 ASCII  ( expression )

Outputs the character equivalent to the ASCII code given by the expression .

blank

 SPACE  ( expression )

Outputs the number of blanks given by the expression . If the value of expression is 0, nothing is output.

Line feed

 CRLF  ( expression )
 CRLF 

Outputs the number of line breaks given by the expression . If the value of expression is 0, nothing is output.

expression is omitted form 1 newline output.

Hex

 HEX  ( expression )

output the value given by the expression in 2 hexadecimal digits.

Not available on some implementations.

Assignment

  variable : =  expression  
  variable 1 ,  variable 2 , ...,  Variable k : =  expression  
Assign the value of

expression to variable .

If the variable is a comma separated list, assign the value of expression to all variables on the left side.

Because the assignment symbol consists of two words, colon and equal, even if there is a space character between colon and equal, it is recognized as an assignment symbol, but in general it writes without a space.

Procedure call

Call a procedure.

 procedure name  ( expression ,  expression , ...  expression )
 procedure name 

A procedure with arguments is called with an actual argument. When calling a procedure that does not have an argument, you can call it with parentheses omitted, but it is an error if you write a procedure without an argument without omitting the parentheses.

FOO ()% such a call is an error

Since the method of passing actual arguments is limited to so-called value passing, even if the actual argument is a variable, the value does not change when returning from the procedure.

CALL

Call a machine language subroutine.

 CALL  ( AH ,  AL ,  A ,  H ,  L )
 CALL  ( AH ,  AL ,  A ,  H )
 CALL  ( AH ,  AL ,  A )
 CALL  ( AH ,  AL )

Each parameter has the following meaning.

The value given to the H register in the 80th series CPU and the value given to the X register in the 6502 series CPU / tr> Value given to L register in 80 series CPUs, Value given to Y register in 6502 series CPUs
AH upper 8 bits of address
AL lower 8 bits of address
A value given to accumulator
H
L

A , H , L may be abbreviated However, if omitted, each value will be undefined.

This procedure can not be used on some implementations.

SENSE

The PC detects whether the STOP key has been pressed, and APPLE has detected whether the cont-C has been pressed. If the key has been pressed, it returns to the monitor mode.

Variables

Variables are all 1 byte long. There are 4 types below.

Single variable

VAR An alphanumeric string that begins with a declared letter.

There is a distinction between global and small areas.

Array variable

  array variable name  [ expression ] 

ARRAY The expression 's element of a declared array.

There is a distinction between global and small areas.

MEM variable

  MEM  ( formula 1 ,  formula 2 ) 

1 byte in memory with the value of expression 2 as the lower address.

PORT

  PORT  ( expression ) 

PC version only.

Corresponds to INP and OUT of N-BASIC. If it is on the left side of the assignment statement, it acts the same as OUT. If it is on the right side, it acts the same as INP.

expression

Constant

Represents a constant in one of the four formats shown in

Numbers .

Function call

  function name  ( formula 1 ,  formula 2 , ...,  expression k ) 
  function name  

Calls a function declared by a declaration or a system function (described later) provided by the processing system. When calling a function without arguments only the function name You can call It is an error if you try to call a function without arguments in parenthesized form.

FOO: = BAR ()% Such a call is an error

MHIGH

The result of multiplication by 1 byte can be 2 bytes, but only the lower 1 byte is represented in the expression. The upper one byte is stored in a dedicated location, and can be fetched with the MHIGH function.

MOD

The division returns the quotient, but at the same time the remainder is calculated and stored in a dedicated location, and can be retrieved using the MOD function.

RND

 RND  ( expression )

1 or more expression Returns a uniform random number below.

GET

 GET  ( expression )

Enters one character from the input device represented by the expression and returns the value of its ASCII code.

The correspondence between numbers and input devices is undefined, but in general 0 seems to be a keyboard.

READ

 READ  ( expression )

Enter a decimal number from the input device that corresponds to the value of the expression and return that value. The RUBOUT code is considered as a delimiter.

NOT

 NOT  ( expression )

Returns 1's complement. Same as COM below.

NEG

 NEG  ( expression )

Returns 2's complement.

COM

 COM  ( expression )

Returns 1's complement.

LSR

 LSR  ( expression )

Shift right by 1 bit. The most significant bit contains 0 and the least significant bit enters the carry.

ASR

 ASR  ( expression )

Shift right by 1 bit. The most significant bit does not change and the least significant bit goes into carry.

ASL

 ASL  ( expression )

Shift left by 1 bit. The least significant bit contains 0 and the most significant bit enters the carry.

ROR

 ROR  ( expression )

Shift right by 1 bit. The carry is in the most significant bit and the least significant bit is in the carry.

ROL

 ROL  ( expression )

Shift left by 1 bit. The carry is in the least significant bit and the most significant bit is in the carry.

USR

  USR  ( AH ,  AL ,  A ,  AH ,  L ) 
  USR  ( AH ,  AL ,  A ,  AH ) 
  USR  ( AH ,  AL ,  A ) 
  USR  ( AH ,  AL ) 

The function is the same as the CALL statement, but the value of the accumulator after the execution of the machine language subroutine is returned as the return value.

It can not be used depending on the processing system.

RDHEX

  RDHEX  ( expression ) 

Enter one hexadecimal digit from the input device.

It can not be used depending on the processing system.

RRC

  RRC  ( expression ) 

Shifts the value of the expression one bit to the right without going through carry. The least significant bit is the most significant.

It can not be used depending on the processing system.

RLC

  RLC  ( expression ) 

Shifts the value of the expression one bit to the left without going through carry. The most significant bit is in the least significant bit.

It can not be used depending on the processing system.

Binary operator

This is an operator that calculates two terms on the left and right.

  term 1   operator   term 2  
The precedence of

operators is as shown in the table. Operators with the same precedence are left coupled.

1 multiplication and division operator
2 addition-subtraction operator
3 relational operators
4 logical operators
5 carry with addition / subtraction operator

Use expression brackets if you want to change the priority. The following three types of parentheses can be used as expression brackets, but in the standard case we will use parentheses.

 { expression } 
 [ expression ] 
 ( expression ) 
It is customary to put periods on both sides that are interpreted as whitespace for the operator of the identifier rather than the

symbol. In my opinion, it is thought to be a device that makes it easier to distinguish from function calls.

.  AND . 

Multiplication division operator

* multiplication
/ quotient of division

Addition-subtraction operator

+ addition
- subtraction

Relational operator

Compares two values ​​and returns a boolean value. GT and LT compare and compare left and right numbers as signed binary numbers in 2's complement representation. Other operators interpret numbers as unsigned binary.

> large
< small
# not equal
= equal
GT large
LT large

Logical operator

AND logical product
OR disjunction
EOR exclusive OR

Carry with addition and subtraction operator

An operator that adds two terms and adds the carry value, or subtracts two terms and subtracts the carry value.

ADC Add with Carry
SBC subtraction with borrow

While it is specified that part of the system function changes the flag, it is undefined which process changes the flag. In general, addition and subtraction seem to change the flag, but depending on the processing system, it may be changed when accessing an array element. It is considered safe to use carry addition / subtraction only immediately after addition / subtraction.