実験の目的
タイニー設定言語字句解析(スキャナ)、サードパーティ製のツールlexの設定を使用する必要があります。結果:構成されたスキャナは、サンプルコードでは、出力トークンに分け与えられた小さな言語の教科書の例、に読み込むことができます。
ソースファイルアドレス
デザイン入力
{ Sample program
in TINY language -
computes factorial
}
read x; { input an integer }
if 0 < x then { don't compute if x <= 0 }
fact := 1;
repeat
fact := fact * x;
x := x - 1
until x = 0;
write fact { output factorial of x }
end
出力デザイン
reserved word:read
ID,name= x
;
reserved word:if
NUM,val= 0
<
ID,name= x
reserved word:then
ID,name= fact
:=
NUM,val= 1
;
reserved word:repeat
ID,name= fact
:=
ID,name= fact
*
ID,name= x
;
ID,name= x
:=
ID,name= x
-
NUM,val= 1
reserved word:until
ID,name= x
=
NUM,val= 0
;
reserved word:write
ID,name= fact
reserved word:end
完全な結果