「Python試用録(6)」

%6:「Python試用録(6)」

「WILDの処理系」作成のための「断片的備忘録」です.
/*背景色は(茶: 編集・確認中; 灰色: 確認済; 緑: 非慣用記法; 白色: 初期化済)*/
/*緑は定義行のみ.他ではシアン*/

%61:[@IT_10]/*「for文による繰り返し処理 (1/3)」*/
`▼
--------------------------------------------------------------------------------
(0)In[5]:
  for num in range(5):
      print(num)
  print()
(1)参考資料
 ①for文
  https://docs.python.org/ja/3/reference/compound_stmts.html#the-for-statement
 ②while文
  https://docs.python.org/ja/3/reference/compound_stmts.html#the-while-statement
 ③break文
  https://docs.python.org/ja/3/reference/simple_stmts.html#the-break-statement
 ④continue文
  https://docs.python.org/ja/3/reference/simple_stmts.html#the-continue-statement
 ④range関数
  https://docs.python.org/ja/3/library/functions.html#func-range
(2)「WILD」のプログラムは非決定性構文規則の実装例:
 ①「In[5]」のプログラム/*「Courier」*/は「W7」では
   `< $num = 5 `> `&.{ 
    `loop: num .= `$ - 1 `.. 'terminated' 
     `} 
「loop文」の非決定性構文による定義は
  `{ `loop: 1 ? .. □`}/*「□」はブロック*/
 ③条件式「1 ?」に「rand( num / 6 )」を代入して「In[5]」を自動デバッグできる.
 ④「int num = rand() / 6」による実装例は
  「while( num --){printf('Hello World !\n')}」.
(5)「W7」では「break文」でなく「`exit(0)」を使う.
 ①`exit(0):「finished」
 ②`exit(1):「illegal token」
 ③`exit(2):「illegal syntax」
 ④`exit(3):「interrupted」
--------------------------------------------------------------------------------
`▲

%62:「W6」のプログラム

--------------------------------------------------------------------------------
(0)【[%61].[Trial_6]】の「In[5]:」に対応するプログラムは
  LET:( $NUM LIKE,. 5 ) ; DO:(
    LOOP: ( NUM .= $ - 1) .. WRITE,. %[TERMINATED]%
    ) %] END&OF&BLOCK [%
 ・「%] END&OF&BLOCK [%」はコメント
(1)参考資料
 ①[Trial_6]@https://oshino3.blogspot.com/2020/05/python6.html
(2)「(0)」のプログラムは次のプログラムと等価
----------------------------------------
num = 5
while true
  num = num - 1
  if:num == 0
    break
  print('terminated')
  continue
  #End of Block
----------------------------------------
(3)「LOOP:X..P;:Y..Q;;1..R」は次のプログラムと等価
----------------------------------------
while true
  if X:
    P
  elif:
    break
  if Y:
    Q
  elif:
    break
  else
    R
  continue
----------------------------------------
--------------------------------------------------------------------------------
`▲


コメント

このブログの人気の投稿

「日記帳(2023 冬)」

ブログの教材で学ぶMATH(1)