TL/1 language specification

Introduction

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 executable statements
  7. Reserved words END
  8. 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 executable statements with one or more executable statements into one executable statement.

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

    Compound sentences behave as if they were one executable statement, so they can appear anywhere the executable 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 executable 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

    単変数の値を変化させながら繰返しする処理を表します。

    FOR 単変数 :=  TO  DO 実行文
    
    FOR 単変数 := 式1 DOWNTO 式2 DO 実行文

    カウント用の 単変数 に式の値を代入し、 単変数 を 1 ずつ増加または減少させながら実行文を繰返します。

    単変数 の増分は、 TO を用いたとき +1 、 DOWNTO を用いたときは -1 です。 (一部の処理系では DOWNTO を使えません。)

    REPEAT

    REPEAT 文リスト UNTIL 

    の値が真値になるまで 文リスト を繰返し実行します。 文リスト は 0 個以上の実行文を並べたものです。

    WHILE

    WHILE  DO 実行文

    の値が偽ならば 実行文 を実行せずに次の処理へ移ります。

    式の値が真の場合は 実行文 を実行して再び の評価に戻ります。

    IF

    IF  THEN 実行文1
    IF  THEN 実行文1 ELSE 実行文2

    の値が真なら 実行文1を実行します。

    の値が偽であり ELSE 節が省略されていないならば 実行文2 を実行します。

    式の値が偽であり ELSE 節が省略されているならば何もせずに次の処理へ移ります。 (一部の処理系では ELSE 節は使えません。)

    CASE

    
    CASE 式0 OF
         式1 実行文1
         ...
         式k-1 実行文k-1
         ELSE 実行文k
    

    式0 の値を 式1 の値と比較して合致すれば 実行文1 を実行します。 その後は 実行文k の次の処理に移ります。

    合致しなければ、同様にして合致するまで次々と式と比較し、合致した式に対応した実行文を実行します。

    式の箇所に予約語 ELSE が有った場合は無条件に合致したものとみなして 実行文k を実行します。

    CASE 文における ELSE 節は CASE 文の最後の条件であることを示すマーカーでもあるので省略することは出来ません。 ELSE 節に実行すべき実行文がない場合は空文を書いてください。

    WRITE

    WRITE (  : 出力リスト )
    

    式の値が表す出力装置に対して出力リストの内容を出力します。 数値と出力装置との対応付けについては未定義ですが、一般的に 0 はコンソール画面であるとされています。

    出力リストは以下の出力要素からなり、ひとつ以上の場合はカンマで区切ります。

    式を記述します。 十進数左詰めで出力します。

    右詰め

    # ( 式1 , 式2 )
    

    式2 の値を 式1 の桁数で十進右詰めで出力します。

    文字列

    " 文字列 "
    

    ダブルクォーテーションで囲まれた文字列を出力します。

    アスキーコード

    ASCII (  )
    

    で与えられたアスキーコードに相当する文字を出力します。

    空白

    SPACE (  )
    

    で与えられた個数分の空白を出力します。 の値が 0 の場合は何も出力しません。

    改行

    CRLF (  )
    
    CRLF
    

    で与えられた個数分の改行を出力します。 の値が 0 の場合は何も出力しません。

    を省略した形式の場合は 1 個の改行を出力します。

    十六進数

    HEX (  )
    

    で与えられた値を十六進数 2 桁で出力します。

    一部の処理系では使えません。

    代入

    変数 := 
    変数1 , 変数2 , ... , 変数k := 

    の値を 変数 に代入します。

    変数がカンマで区切られたリストの場合は の値を左辺全ての変数に代入します。

    代入記号はコロンとイコールの 2 語から成っているのでコロンとイコールの間に空白文字が有っても代入記号として認識されますが、一般的には間を空けずに書きます。

    手続き呼出し

    手続きを呼出します。

    手続き名 (  ,   , ...   )
    
    手続き名
    

    引数をもつ手続きでは実引数を与えて呼出します。 引数を持たない手続きを呼出す場合には丸括弧ごと省略した記法で呼出せますが、引数を持たない手続きを丸括弧を省略せずに記述した場合はエラーです。

    FOO() % このような呼び方はエラー
    

    実引数の渡し方はいわゆる値渡しに限定されているので、実引数が変数であっても手続きから戻ったときに値は変化しません。

    CALL

    機械語サブルーチンを呼出します。

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

    各パラメータは以下の意味を持ちます。

    AHアドレスの上位 8 ビット
    ALアドレスの下位 8 ビット
    Aアキュムレータに与える値
    H80 系 CPU では H レジスタに与える値、 6502 系 CPU では X レジスタに与える値
    L80 系 CPU では L レジスタに与える値、 6502 系 CPU では Y レジスタに与える値

    A, H, L は省略した形式がありますが、省略した場合はそれぞれの値は不定となります。

    この手続きは一部の処理系では利用できません。

    SENSE

    PC では STOP キー、 APPLE では cont-C が押されているか否かを検出し、押されていればモニタモードに戻ります。

    変数

    変数はすべて 1 バイト長です。 以下の 4 種類があります。

    単変数

    VAR 宣言された英字で始まる英数字の列です。

    大域、小域の区別があります。

    配列変数

    配列変数名 [  ]

    ARRAY 宣言された配列の 番目の要素です。

    大域、小域の区別があります。

    MEM変数

    MEM ( 式1 , 式2 )

    式1 の値を上位、 式2 の値を下位のアドレスとするメモリ内の 1 バイト。

    PORT

    PORT  ( )

    PC 版専用です。

    N-BASIC の INP, OUT に相当します。 代入文の左辺にあれば OUT 、 右辺にあれば INP と同等の作用をします。

    定数

    数値の項で示した 4 種類のいずれかの形式で定数を表します。

    関数呼出し

    関数名 ( 式1 , 式2 , ... , 式k )
    関数名

    FUNC 宣言によって宣言された関数、または処理系が用意しているシステム関数 (後述) を呼出します。 引数のない関数を呼出す場合は関数名のみで呼出せます。 引数がない関数を括弧付きの書式で呼出そうとした場合はエラーです。

    FOO := BAR() % このような呼び方はエラー
    

    MHIGH

    1 バイト同士の掛け算の結果は 2 バイトになり得ますが、式の中では下位 1 バイトしか表現されません。 上位 1 バイトは専用の場所に格納されており、 MHIGH 関数で取出すことが出来ます。

    MOD

    割り算すると商が返りますが、同時に余が計算されて専用の場所に格納されており、 MOD 関数で取出すことが出来ます。

    RND

    RND (  )
    

    1 以上 以下の一様乱数を返します。

    GET

    GET (  )
    

    が表す入力装置から 1 文字を入力し、そのアスキーコードの値を返します。

    数値と入力装置の対応付けは未定義ですが、一般に 0 はキーボードであるようです。

    READ

    READ (  )
    

    の値に対応する入力装置から十進数を 1 つ入力し、その値を返します。 RUBOUT コードは区切り記号とみなされます。

    NOT

    NOT (  )
    

    1 の補数を返します。 後述の COM と同じです。

    NEG

    NEG (  )
    

    2 の補数を返します。

    COM

    COM (  )
    

    1 の補数を返します。

    LSR

    LSR (  )
    

    1 ビット右シフトします。 最上位ビットには 0 が入り、最下位ビットはキャリーに入ります。

    ASR

    ASR (  )
    

    1 ビット右シフトします。 最上位ビットは変化せず、最下位ビットはキャリーに入ります。

    ASL

    ASL (  )
    

    1 ビット左シフトします。 最下位ビットには 0 が入り、最上位ビットはキャリーに入ります。

    ROR

    ROR (  )
    

    1 ビット右シフトします。 キャリーは最上位ビットに入り、最下位ビットはキャリーに入ります。

    ROL

    ROL (  )
    

    1 ビット左シフトします。 キャリーは最下位ビットに入り、最上位ビットはキャリーに入ります。

    USR

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

    CALL 文と機能は同じですが、機械語サブルーチン実行後のアキュムレータの値を返却値として返します。

    処理系によっては使えません。

    RDHEX

    RDHEX ()

    入力装置から十六進数1桁を入力します。

    処理系によっては使えません。

    RRC

    RRC ()

    キャリーを経由せずに式の値を右に 1 ビットシフトします。 最下位ビットは最上位に入ります。

    処理系によっては使えません。

    RLC

    RLC ()

    キャリーを経由せずに式の値を左に 1 ビットシフトします。 最上位ビットは最下位ビットに入ります。

    処理系によっては使えません。

    二項演算子

    左右に 2 個の項をとって計算する演算子です。

    項1 演算子 項2

    演算子の優先順位は表の通りです。 優先順位の同じ演算子は左結合します。

    乗除算演算子
    加減算演算子
    関係演算子
    論理演算子
    キャリー付き加減算演算子

    優先順位を変更したい場合は式括弧を使用します。 以下 3 種類の括弧が式括弧として使えますが標準的には丸括弧を用いることとします。

    {  }
    [  ]
    (  )

    記号ではなく識別子の演算子については空白文字と解釈されるピリオドを両側に置く習慣があります。 私見ですが、関数呼出しとの区別をしやすくする工夫だと考えられます。

    .AND.

    乗除算演算子

    *乗算
    /除算の商

    加減算演算子

    +加算
    -減算

    関係演算子

    2 つの値を比較して真偽値を返します。 GTLT は左右の数値を 2 の補数表現の符号付き二進数とみなして比較します。 その他の演算子は数を符号なし二進数と解釈します。

    >大きい
    <小さい
    #等しくない
    =等しい
    GT大きい
    LT大きい

    論理演算子

    AND論理積
    OR論理和
    EOR排他的論理和

    キャリー付き加減算演算子

    二項を足した上でキャリーの値を足す、または二項を減算した上でキャリーの値を引く演算子です。

    ADCキャリー付き加算
    SBCボロー付き減算

    システム関数の一部がフラグを変化させることが明記されている他はどの処理がフラグを変化させるかは未定義です。 一般に加減算はフラグを変化させるようですが、処理系によっては配列要素へアクセスしたときに変化させてしまう場合もあるようです。 キャリー付き加減算は加減算の直後に限って使うのが安全であると考えられます。