PHPで字句解析 + 構文木生成ツールを作る その2

俺俺BNF構文木生成までやっとたどり着いた。
予定ではこのBNFを元に文法を定義できるようにするつもり。

俺俺BNF

// コメント
// よくある感じの定義
newline := "\r\n" | "\n" | "\r\r"

blank := " " | "\v" | "\t"

space := ( blank | newline )+

@leaf
identifier := [a-zA-Z_] [a-zA-Z0-9_]* 

上のBNFを元に生成した構文木

bnf {
   define {
      identifier('newline')
      exp {
         atom {
            double_quote_string('\\r\\n')
         }
         or_operator('|')
         atom {
            double_quote_string('\\n')
         }
         or_operator('|')
         atom {
            double_quote_string('\\r\\r')
         }
      }
   }
   define {
      identifier('blank')
      exp {
         atom {
            double_quote_string(' ')
         }
         or_operator('|')
         atom {
            double_quote_string('\\v')
         }
         or_operator('|')
         atom {
            double_quote_string('\\t')
         }
      }
   }
   define {
      identifier('space')
      exp {
         atom {
            exp {
               atom {
                  identifier('blank')
               }
               or_operator('|')
               atom {
                  identifier('newline')
               }
            }
            repetition_operator('+')
         }
      }
   }
   define {
      decorator {
         identifier('leaf')
      }
      identifier('identifier')
      exp {
         atom {
            char_class {
               char_class_exp {
                  char('a')
                  char('z')
               }
               char_class_exp {
                  char('A')
                  char('Z')
               }
               char_class_exp {
                  char('_')
               }
            }
         }
         atom {
            char_class {
               char_class_exp {
                  char('a')
                  char('z')
               }
               char_class_exp {
                  char('A')
                  char('Z')
               }
               char_class_exp {
                  char('0')
                  char('9')
               }
               char_class_exp {
                  char('_')
               }
            }
            repetition_operator('*')
         }
      }
   }
}