目录

環境設定

  1. 下載 Jar 檔,設定環境。
    $ cd /usr/local/lib
    $ curl -O http://www.antlr.org/download/antlr-4.7-complete.jar
    $ export CLASSPATH=".:/usr/local/lib/antlr-4.7-complete.jar:$CLASSPATH"
    $ alias antlr4='java -jar /usr/local/lib/antlr-4.7-complete.jar'
    $ alias grun='java org.antlr.v4.gui.TestRig'
  2. 下載範例。
    # cd; mkdir antlr; cd antlr
    # curl -O http://media.pragprog.com/titles/tpantlr2/code/tpantlr2-code.tgz
    # tar xvf tpantlr2-code.tgz
    # cd code/install
    $ git clone https://github.com/azru0512/antlr.git
    $ cd install
    $ antlr4 Hello.g4
    $ javac *.java
    # grun grammer_name start_rule
    $ grun Hello r -tokens
    $ grun Hello r -gui

Part I

Part II

Part III