view TL1/test/t4.tl1 @ 178:4d83154d2a78

add - {} some builtin in TL/1
author Shinji KONO <kono@ie.u-ryukyu.ac.jp>
date Mon, 15 Apr 2019 09:43:28 +0900
parents 3770e86114aa
children c3145f913f3d
line wrap: on
line source

% ** TEST PROGRAM **
FUNC SEARCH
%--- MAIN ---
VAR DICT,BUF
ARRAY TEND[2]
BEGIN
  POSITION(DICT,TEND)
  DICT := OPENM($2,0)
  WRITE(DICT:ASCII(0))
  WRITE(DICT:ASCII(30),ASCII(-'P'),"ROC")
  WRITE(DICT:ASCII(31),ASCII(-'F'),"UNC")
  WRITE(DICT:ASCII(33),ASCII(-'V'),"AR",CRLF)
  POSITION(DICT,TEND)
  BUF := OPENM($2,0)
  WRITE(BUF:"FUNC",ASCII(0))
  WRITE(0:SEARCH(BUF),CRLF)
  SEEK(BUF,0)
  WRITE(BUF:"NONAME",ASCII(0))
  WRITE(0:SEARCH(BUF),CRLF)
END

SEARCH(BUF)
VAR VAL,K,C
ARRAY BEND
BEGIN
  VAL := SEEK(DICT,TEND)
  POSITION(BUF,BEND)
  WHILE VAL#0 DO [
     C:=SEEKR(BUF,-1)
     K:=SEEKR(DICT,-1)
     IF K.LT.0 THEN [
       IF C=-K THEN
          RETURN VAL    % FOUND
       VAL := SEEKR(DICT,-1)
     ] ELSE IF C#K THEN [
       SEEK(BUF,BEND)
       REPEAT
          K:=SEEKR(DICT,-1)
       UNTIL K.LT.0
       VAL := SEEKR(DICT,-1)
     ]
  ]
  RETURN VAL % NOT FOUND
END