• The syntax of C in Backus-Naur Form というサイトがある

    • K&R 第2版からの引用っぽい?
  • ::= って書くのはダルいから = と書くことにする

    • イコール単体が出てくるときは '=' と表す
  • Backus-Naur Form (BNF) Definition - Intel を適宜参照

    • このCのBNFは ’{’ ではなくて { と表しているらしい
      • 前後に空白があったら '{' という意味らしい
    • グループ化の () を波括弧で代用している?
      • 上のIntelの定義だと、[] は optional、 {} は0回以上の繰り返し、 () はグループ
        • このBNFでは {}* と書いているらしい と思ったら {}? も出てきた
      • 空白なしの ( あるいは ) は使われていない(文字としての括弧としてのみ登場)
        • IntelによるBNFの定義とは異なり、{} をグループとして扱っているらしい
  • <translation-unit> = {<external-decoration>}*

    • 翻訳単位ってやつですね
  • <external-declaration> = <function-definition> | <declaration>

  • <function-definition> = {<declaration-specifier>}* <declarator> {<declaration>}* <compound-statement>

    • <declaration-specifier> はexternとかstaticとか、voidとかintとか、constとかvolatileとか
      • ’、’ 区切りで前から順に<storage-class-specifier>, <type-specifier>, <type-qualifier>
    • <declarator> は関数名?
    • {<declaration>}* は変数宣言、たぶんC89における関数の引数を宣言するやつかな
  • <compound-statement> = { {<declaration>}* {<statement>}* }

    • つまりブロックだよね
    • <declaration><statement> の後に置くことができないのが見て取れる
  • <statement> には色々な種類がある(<compound-statement> も含まれている)

    • <expression-statement> = {<expression>}? ;
      • 式の文というなんだか奇妙なidenfier(妥当ではあるが)
    • <labeled-statement> はgotoで飛ぶためのラベルとかswitch内部とか
      bnf
  <identifier> : <statement>
| case <constant-expression> : <statement>
| default : <statement>
- `<selection-statement>`
    - switch直後は `<compound-statement>` じゃなくていいんですか?
        - 良いらしい(`switch (hoge) default: printf("hello");` とかでもコンパイルが通って実行ができる)

bnf

  if ( <expression> ) <statement>
| if ( <expression> ) <statement> else <statement>
| switch ( <expression> ) <statement>