Anlr SQL parser code

Source: Internet
Author: User
Tags lexer sql using
In the blog, I wrote an article about the SQL parser-OQL implemented by anlr, which roughly describes a simple SQL parser implemented by anlr.
Many people are interested in anlr and want to provide the source code of this project as a reference. The reasons are as follows:

1. anlr version problems.
The anlr version used during development is updated shortly later. It is not compatible with earlier versions (including those used in projects) and the syntax files in the project cannot be used in the current anlr version.
The uploaded project contains the currently used anlr runtime dll file (which should be 3.0.1), and the Code contains the generated lexer and parser cs files. However, if you want to regenerate lexer and parser from the. g syntax file, you have to use the corresponding anlr java package. I have no more options. You can check whether the anlr website provides download.

2. Implementation is messy.

This was written in the past few years for project development. The development of this item is not within the Project Plan. Therefore, it takes only a week to get out of anlr and the code, later, it was just a little bit of bug change, and there was no structural adjustment, so it really had no reference effect.
The main idea is very simple. You can generate AST using anlr and traverse AST to generate SQL using the visitor mode. The visitor interface is designed to facilitate ORM ing. However, due to the rush of time, you have no in-depth understanding of anlr, and the code implementation and syntax files can only be described in one word: Chaos. I was planning to study anlr and sort out the project, but I was always lazy.
Looking at HQL parsing of nhib.pdf in the first two weeks, his structure is much better. We suggest you really want to know how to use anlr as an SQL parser. Please refer to nhib.pdf or hibernate.

Because some people often send messages and want to learn, please download the anlr SQL parser code here.
1. Set the output type to the windows application form, which contains a form to test the parsing effect.
2. Only standard select query statements are supported.

Related Article

E-Commerce Solutions

Leverage the same tools powering the Alibaba Ecosystem

Learn more >

Apsara Conference 2019

The Rise of Data Intelligence, September 25th - 27th, Hangzhou, China

Learn more >

Alibaba Cloud Free Trial

Learn and experience the power of Alibaba Cloud with a free trial worth $300-1200 USD

Learn more >

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: and provide relevant evidence. A staff member will contact you within 5 working days.