Reputation:
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
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--
How to work with Java using ANTLR --> https://theendian.com/blog/antlr-4-lexer-parser-and-listener-with-example-grammar/
About/diff between Listeners & Visitors --> http://jakubdziworski.github.io/java/2016/04/01/antlr_visitor_vs_listener.html
Upvotes: 2