Git Product home page Git Product logo

wkantlr's Introduction

the code is derived from ANTLR4 and Mustache

installation

  1. Install Java (version 1.7 or higher)
  2. Download antlr-4.10.1-complete.jar (or whatever version) from https://www.antlr.org/download.html.Save to your directory for 3rd party Java libraries, say C:/Javalib
  3. Add antlr-4.10.1-complete.jar to CLASSPATH
  4. Create short convenient commands for the ANTLR Tool

Copy _dep/antlr4.bat and _dep/grun.bat to a folder, such as C:/Javalib, then add the path C:/Javalib to PATH

  1. Testing the installation

    java org.antlr.v4.Tool java -jar C:/Javalib/antlr-4.10.1-complete.jar

usage

In a temporary directory, put the following grammar inside file 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

Then run ANTLR the tool on it:

cd Test/Hello
antlr4 Hello.g4
javac Hello*.java

Now test it:

$ grun Hello r -tree
(Now enter something like the string below)
hello parrt
(now,do:)
^Z
(The output:)
(r hello parrt)
(That ^D means EOF on unix; it's ^Z in Windows.) The -tree option prints the parse tree in LISP notation.
It's nicer to look at parse trees visually.
$ grun Hello r -gui
hello parrt
^Z

tips

  • some useful arguments
antlr /*-visitor -Dlanguage=Cpp */ *.g4 
antlr {{the fliename}} {{the grammar name}} -gui
  • There is an antlr plugin on vscode, which is easier to use.
  • But sometimes an error will occur when using the VS terminal to enter commands directly. At this time, you can directly open cmd and try

Test

Window,Vs2022

wkantlr's People

Watchers

hegaoxiang avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.