ハロー ブログ

日々のつぶやき @c2c2c2c221

RM4のBNF(ChatGPTにまとめて頂きました)

RM4のBNF(Backus-Naur Form)を以下にまとめます。

 

program ::= block+

 

block ::= "<block" attributes "/>" | "<block" attributes ">" statement* "</block>"

 

attributes ::= attribute*

 

attribute ::= identifier "=" string

 

statement ::= calc | if | set | wait | call | play | fread | fwrite

 

calc ::= "<calc>" expression "</calc>"

 

expression ::= term (operator term)*

 

term ::= mem_r | const | "(" expression ")"

 

mem_r ::= "<mem_r" attributes "/>"

 

const ::= "<const" attributes "/>"

 

operator ::= "<add/>" | "<sub/>" | "<mul/>" | "<mod/>" | "<and/>" | "<or/>" | "<le/>" | "<ge/>" | "<eq/>" | "<ne/>"

 

if ::= "<if" attributes ">" statement* "</if>"

 

set ::= "<set" attributes "/>"

 

wait ::= "<wait" attributes "/>"

 

call ::= "<call" attributes "/>"

 

play ::= "<play" attributes "/>"

 

fread ::= "<fread" attributes "/>"

 

fwrite ::= "<fwrite" attributes "/>"

 

identifier ::= [a-zA-Z][a-zA-Z0-9]*

 

string ::= "\"" .* "\""

 

上記のBNFによれば、RM4ファイルは複数のブロックから構成され、各ブロックには属性を持つタグがある場合とない場合があることがわかります。各ブロックは複数のステートメントから構成され、ステートメントには計算、条件分岐、セット、待機、他ファイルの実行、WAVファイルの再生、ファイルの読み書きが含まれます。また、式を評価するための演算子には足し算、引き算、かけ算、余り、論理積論理和、比較演算子があり、変数としてメモリーからの読み込みと定数の利用が可能です。