SSブログ

ABNFのパーサー [RFC]

RFCの仕様の中で、各種の定義を表記する際にABNFと言う記法が利用されている時があるんですが、このABNFのCのパーサーを出力するソフトってないのかな?と思って探してみたらありました。有名なのかどうかは知りませんが、「APG」と言うのを見つけたので利用してみます。

ソースを展開してビルドをした所、エラーが出ました。

-----
$ ./configure
$ make
...
gcc -DHAVE_CONFIG_H -I. -I../..    -g -O2 -D_APG_CFG_DEBUG -I../../ApgLib -I../../ApgUtilities  -MT apg-CommandLine.o -MD -MP -MF .deps/apg-CommandLine.Tpo -c -o apg-CommandLine.o `test -f '../../Generator/CommandLine.c' || echo './'`../../Generator/CommandLine.c
../../Generator/CommandLine.c:31:20: error: malloc.h: No such file or directory
make[4]: *** [apg-CommandLine.o] Error 1
make[3]: *** [all-recursive] Error 1
make[2]: *** [all-recursive] Error 1
make[1]: *** [all-recursive] Error 1
make: *** [all] Error 2
-----


「malloc.h」が無いとか。いろいろ情報を検索してみた所、いろんな意見がある様なのですが、「/usr/include/malloc/malloc.h」にファイルがあるとの事なので、シンボリックリンクを張ってみました。

-----
$ cd /usr/include
$ sudo ln -s malloc/malloc.h malloc.h
-----


これで、再度ビルドします。

-----
$ ./configure
$ make
$ sudo make install
-----


で、なんか成功したのか失敗したのかよくわからない出力が出ていましたが、「/usr/loca/bin/apg」と言う実行ファイルが出来上がってました。「apg」の実行でこんな感じ。

-----
$ apg

*** input file name is required

COMMAND LINE OPTIONS FOUND
apg 

APG(version 6.3)
Usage: apg options
options: one or more of the following:

help options
?                 - print this help screen
help              - print this help screen
/?                - print this help screen
/help             - print this help screen
-help             - print this help screen
--help            - print this help screen

version options
--version         - print version
-v                - print version
/v                - print version

name options
/in:pathname      - pathname of input SABNF grammar (required)
/out:path         - path for generated parser, including trailing delimiter (default = ./ or current working directory)
/log:pathname     - log output to pathname (default is console)
/C:name           - C-language parser project name (outputs files name.h & name.c)
/C++:name         - C++ language parser project name (outputs files name.h & name.cpp)

true/false options, all defaults are false
/dv               - verbose, implies all display options except /dopcodes & /dast
/dconfig          - display all of the configuration parameters
/dgrammar         - display input grammar file with one-based line numbers
/dwarnings        - display grammar syntax warnings
/dgrammar-metrics - display grammar metrics
/dattributes      - display attributes
/drules           - display rules and udts
/dast             - display AST records (caution: may generate many records)
/dtypes           - display the integer type sizes
/dopcodes         - display grammar opcodes in human-readable format (caution: may generate many opcodes)

options are case sensitive and must appear exactly as indicated above
paths, pathnames and names must be < 128 in length
default values of all true/false options are false
-----


RFCから抜き出したABNFの定義を処理させてみましたが、どうも下記の様な感じですぐには処理できませんでした。

  1. 定義が完全でないと失敗する
  2. 改行コードはCRLFでないといけない
  3. 定義の行頭に空白があると失敗する


2, 3はRFCから抜き出したものを編集する事で対処可能ですが、1がちょっと厄介ですね。RFCの定義は一つの仕様内で閉じていない事が多そうな感じですからねぇ・・・。その辺、ちょっとアバウトに扱って、とりあえずできる限り出力してくれるとうれしいんですが・・。どうしましょうかね・・。


【参考】
APG - coasttocoastResearchinc
parse2
VineGen
Augmented BNF for Syntax Specifications: ABNF
Comparison of parser generators - WIKIPEDIA

malloc.h on OS X - /var/log/blog.log
MacOSXでmallocを使う - 便利なスクリプト
Tips for Allocating Memory - Mac Developer Library



   

nice!(0)  コメント(0)  トラックバック(0) 
共通テーマ:パソコン・インターネット

nice! 0

コメント 0

コメントを書く

お名前:
URL:
コメント:
画像認証:
下の画像に表示されている文字を入力してください。

トラックバック 0

ブログを作る(無料) powered by SSブログ

この広告は前回の更新から一定期間経過したブログに表示されています。更新すると自動で解除されます。