Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How sharding-jdbc learns antlr4

2025-04-07 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >

Share

Shulou(Shulou.com)06/02 Report--

This article introduces sharding-jdbc how to learn antlr4, the content is very detailed, interested friends can refer to, hope to be helpful to you.

First of all, read the official website of ANTLR4 (ANother Tool for Language Recognition). ANTLR4 is a powerful parser generation tool that can be used to read, process, execute and translate structured text or binary files, such as mysql, which can be viewed in https://github.com/antlr/grammars-v4.

ANTLR4 Segmentation Analyzer and Syntax Analyzer

The lexical analyzer parses the input data into words (Token)

The grammar parser parses words into abstract grammar trees (AST)

Environment building

# OS X$ cd / usr/local/lib$ sudo curl-O https://www.antlr.org/download/antlr-4.7.2-complete.jar# Editing ~ / .bash_profile file adds the environment variable $vim ~ / .bash_profileexport 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. TestRigned $source ~ / .bash_profile# tests whether antlr is configured successfully $antlr4 $

ANTLR development process

1) define .g4 syntax file

2) use ANTLR 4 to generate target programming language code for lexical analyzer (Lexer) and parser (Parser), supported programming languages: Java, JavaScript, Python, C and C++, etc.

3) traversing AST (Abstract Syntax Tree Abstract Syntax Tree), ANTLR 4 supports two modes: visitor mode (Visitor) and listener mode (Listener)

The idea plug-in installs antlr, and uses the plug-in to parse the g4 file of msql in ss, as shown in the figure:

Maven plug-in

Create a new directory antlr4 under the project src/main path

Then, the new package path is src/main/antlr4/imports/mysql and the .g4 file is stored.

Edit the pom.xml file and add a plug-in:

Org.antlr antlr4-maven-plugin 4.3 antlr src/main/antlr4/imports/mysql/ false false antlr4

# compile mvn clean compile-DskipTests

The plug-in generates the corresponding code in the target/generated-sources/antlr4 directory for the .g4 file under src/main/antlr4

About sharding-jdbc how to learn antlr4 to share here, I hope the above content can be of some help to you, can learn more knowledge. If you think the article is good, you can share it for more people to see.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Internet Technology

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report