user4588727
user4588727

Reputation:

Wrote a grammar and created everything using ANTLR, trying to figure out how to link this to a Java program

So I have a grammar that I created and compiled and everything for Java in ANTLR. The parser does work correctly and can verify that statements written in the grammar are correct. Now I am trying to link the parser to Java so that it can carry out the functions.

For example, CREATE TABLE animals (name VARCHAR(20), kind VARCHAR(8), years INTEGER) wants to create a file named animals.db, which each animal has a name, kind, and age. I am confused on how to link Java methods to things like 'CREATE TABLE' in a method called create, which takes in the parameters for the table (name and attributes).

Upvotes: 0

Views: 67

Answers (1)

Suresh Matyal
Suresh Matyal

Reputation: 21

Already @sepp2k mentioned, you can achieve that things using Listeners or Visitors for reference you can go through very helpful links provided below--

  1. How to work with Java using ANTLR --> https://theendian.com/blog/antlr-4-lexer-parser-and-listener-with-example-grammar/

  2. About/diff between Listeners & Visitors --> http://jakubdziworski.github.io/java/2016/04/01/antlr_visitor_vs_listener.html

Upvotes: 2

Related Questions