• mac antrl4环境安装&第一个程序


    $ cd /usr/local/lib
    $ sudo curl -O https://www.antlr.org/download/antlr-4.7.2-complete.jar
     
    // 设置环境变量
    $ vim .bash_profile  
    $ export CLASSPATH=".:/usr/local/lib/antlr-4.7.2-complete.jar:$CLASSPATH"
    $ alias antlr4='java -jar /usr/local/lib/antlr-4.7.2-complete.jar'
    $ alias grun='java org.antlr.v4.gui.TestRig'
    $ wq!  // 保存
    $ source .bash_profile  
     
    // 测试,以下则成功:
    $ antlr4
    ANTLR Parser Generator  Version 4.7.2
     -o ___              specify output directory where all output is generated
     -lib ___            specify location of grammars, tokens files
     -atn                generate rule augmented transition network diagrams
     -encoding ___       specify grammar file encoding; e.g., euc-jp
     -message-format ___ specify output style for messages in antlr, gnu, vs2005
     -long-messages      show exception details when available for errors and warnings
     -listener           generate parse tree listener (default)
     -no-listener        don't generate parse tree listener
     -visitor            generate parse tree visitor
     -no-visitor         don't generate parse tree visitor (default)
     -package ___        specify a package/namespace for the generated code
     -depend             generate file dependencies
     -D<option>=value    set/override a grammar-level option
     -Werror             treat warnings as errors
     -XdbgST             launch StringTemplate visualizer on generated code
     -XdbgSTWait         wait for STViz to close before continuing
     -Xforce-atn         use the ATN simulator for all predictions
     -Xlog               dump lots of logging info to antlr-timestamp.log
     -Xexact-output-dir  all output goes into -o dir regardless of paths/package
    

      第一个测试程序:

    $ mkdir test
    $ cd test/
    $ vim Hello.g4
     
    输入:
    // Define a grammar called Hello
    grammar Hello;
    r  : 'hello' ID ;         // match keyword hello followed by an identifier
    ID : [a-z]+ ;             // match lower-case identifiers
    WS : [ \t\r\n]+ -> skip ; // skip spaces, tabs, newlines
     
    $ wq! // 保存
    $ antlr4 Hello.g4
    $ ls
    Hello.g4		HelloBaseListener.java	HelloLexer.tokens
    Hello.interp		HelloLexer.interp	HelloListener.java
    Hello.tokens		HelloLexer.java		HelloParser.java
     
    $ javac Hello*.java
    $ ls
    Hello.g4			HelloLexer.java
    Hello.interp			HelloLexer.tokens
    Hello.tokens			HelloListener.class
    HelloBaseListener.class		HelloListener.java
    HelloBaseListener.java		HelloParser$RContext.class
    HelloLexer.class		HelloParser.class
    HelloLexer.interp		HelloParser.java
     
    $ grun Hello r -gui  // 按回车
    hello test  // 输入这个,再按回车
    ^D // 按ctrl+D 就出现gui图形界面了
     
     
     
    

      

    本文来自博客园,作者:ReluStarry,转载请注明原文链接:https://www.cnblogs.com/relustarry/p/15609158.html

  • 相关阅读:
    使用RestTemplate上传文件到远程接口
    设计模式(五)之适配器模式
    设计模式(四)之装饰者模式
    设计模式(三)之模板方法模式
    设计模式(二)之责任链模式
    BUG-jQuery提交表单submit方法-TypeError: e[h] is not a function
    数据类型--集合 set
    数据类型--字典 dic
    字符 str 串需要记住的语法
    数据类型--列表 list
  • 原文地址:https://www.cnblogs.com/relustarry/p/15609158.html
Copyright © 2020-2023  润新知