文法定義ファイルのコンパイル

 文法定義ファイルを準備したらsableccコマンドを使ってJava Sourceを生成します。

 このコマンドにより文法ファイルのあるパスにソースファイルが生成されます。ソースを生成するパスを変更したい場合は -d オプションでパスを指定する事が出来ます。

 Javaのコンパイルは通常通り行っていただければ良いのですが、{package folder}/parser/parser.dat及び{package folder}/lexer/lexer.datを.classと同じフォルダに配置する必要があります。build時にファイルをコピーするようにしてください。

 Androidのプロジェクト内で使いたい場合、以下の図の様に、プロジェクトフォルダにparserというフォルダを作ってbuild.xmlを文法定義ファイルと一緒におき、カスタムビルドの設定をして使うと便利かと思います。

 build.xmlの内容は以下の通りです。最初の二行の太字の場所を実際の設定にあわせて書き換える必要があります。

 カスタムビルダの設定を行います。

  1. ProjectのPropertiesを開きます。Buildersを選択
<div id="attachment_650" style="width: 310px" class="wp-caption alignnone">
  <a href="/post/2012/01/project-properties-builders.png"><img src="/post/2012/01/project-properties-builders-300x198.png" alt="Project Properties - Builders" title="Project Properties - Builders" width="300" height="198" class="size-medium wp-image-650" srcset="/post/2012/01/project-properties-builders-300x198.png 300w, /post/2012/01/project-properties-builders.png 793w" sizes="(max-width: 300px) 100vw, 300px" /></a>
  
  <p class="wp-caption-text">
    プロジェクトのプロパティのBuilders
  </p>
</div>
  1. Buildersを選択してNewからParserを追加
<div id="attachment_651" style="width: 310px" class="wp-caption alignnone">
  <a href="/post/2012/01/choose_config_antbuilder.png"><img src="/post/2012/01/choose_config_antbuilder-300x296.png" alt="Choose Config - Ant Builder" title="Choose Config - Ant Builder" width="300" height="296" class="size-medium wp-image-651" srcset="/post/2012/01/choose_config_antbuilder-300x296.png 300w, /post/2012/01/choose_config_antbuilder.png 382w" sizes="(max-width: 300px) 100vw, 300px" /></a>
  
  <p class="wp-caption-text">
    Ant Builderを選択します。
  </p>
</div>
  1. Mainの設定-名前を設定した後にBuildfileとBase Directoryを設定します(Base Directoryは設定しなくてもいけるはずですが、一応)
<div id="attachment_652" style="width: 310px" class="wp-caption alignnone">
  <a href="/post/2012/01/parser-builder-main.png"><img src="/post/2012/01/parser-builder-main-300x232.png" alt="Parser Builder - Main" title="Parser Builder - Main" width="300" height="232" class="size-medium wp-image-652" srcset="/post/2012/01/parser-builder-main-300x232.png 300w, /post/2012/01/parser-builder-main.png 792w" sizes="(max-width: 300px) 100vw, 300px" /></a>
  
  <p class="wp-caption-text">
    ParserのBuilder設定 Main
  </p>
</div>
  1. Refreshの設定-こちらの画面の様に設定してください。
<div id="attachment_653" style="width: 310px" class="wp-caption alignnone">
  <a href="/post/2012/01/parser-builder-refresh.png"><img src="/post/2012/01/parser-builder-refresh-300x232.png" alt="Parser Builder - Refresh" title="Parser Builder - Refresh" width="300" height="232" class="size-medium wp-image-653" srcset="/post/2012/01/parser-builder-refresh-300x232.png 300w, /post/2012/01/parser-builder-refresh.png 792w" sizes="(max-width: 300px) 100vw, 300px" /></a>
  
  <p class="wp-caption-text">
    ParserのBuilder設定 Refresh
  </p>
</div>
  1. Targetsの設定-こちらの画面の様に設定してください。この設定だとAuto Build時の設定が入っていませんので、Grammarを変更したりClean後はManual Buildが必要です。
<div id="attachment_656" style="width: 310px" class="wp-caption alignnone">
  <a href="/post/2012/01/parser-builder-targets.png"><img src="/post/2012/01/parser-builder-targets-300x232.png" alt="Parser Builder - Targets" title="Parser Builder - Targets" width="300" height="232" class="size-medium wp-image-656" srcset="/post/2012/01/parser-builder-targets-300x232.png 300w, /post/2012/01/parser-builder-targets.png 792w" sizes="(max-width: 300px) 100vw, 300px" /></a>
  
  <p class="wp-caption-text">
    パーサのBuilder設定 Targets
  </p>
</div>
  1. OKを押して設定画面を閉じます。