Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8759087
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T14:42:48+00:00 2026-06-13T14:42:48+00:00

I have ANTLR parser and tree grammar that is working fine. I want user

  • 0

I have ANTLR parser and tree grammar that is working fine. I want user to input the grammar in the JTextarea(I am using java swing for gui development). Once, the grammar is in the JTextarea, the user shall press a button (run) and the result of the grammar (the actions) shall be shown in another text area.

For the sake of simplicity, the simplest HelloWorld ANTLR grammar(parser and tree grammar) can be used to demonstrate how can we run ANTLR grammar from Java Swing gui’s JTextarea.

I haven’t found anything that relates ANTLR with JavaSwing GUI or anything that says how to run ANTLR Grammar from Java Swing GUI’s JTextArea.

Any thoughts/suggestions/simple example/demonstration?
EDIT-Solution
Below is a portion of code from my GUI class that deals with the simulate button. User inputs ANTLR grammar in a JTextarea.

private void addReRunButtonListener() {
        btnReRun.addActionListener(new ActionListener() {

            @Override
            public void actionPerformed(ActionEvent e) {

                 try {
                     //for Random Simulation
                     if(rdbtnRandomWithSeed.isSelected())
                     {
                      String line = "";
                      String nl ;

                      Process p = Runtime.getRuntime().exec("java org.antlr.Tool protocol.g protocolWalker.g");
                      p.waitFor();
                      p = Runtime.getRuntime().exec("javac protocolLexer.java protocolParser.java protocolWalker.java SimulatorRandom.java");
                      p.waitFor();
                      p = Runtime.getRuntime().exec("java RandomSimulator");

                      OutputStreamWriter stdin = new OutputStreamWriter(p.getOutputStream ());

                      stdin.write(simAlgoEdit.getText()+"\n");

                              stdin.close();

                      BufferedReader bri = new BufferedReader
                        (new InputStreamReader(p.getInputStream()));
                      nl = bri.readLine();
                      while (nl != null) {
                          line = line + nl + "\n";
                          nl = bri.readLine();

                      }
                      bri.close();

                      System.out.println("Done.");
                      simGraphicsArea.setText(line);
                      graphicsArea.setText(line);

                     }

The above code also grabs the output and inserts it in another JTextarea in my GUI.
@trashgod: Thank you very much for your help.

Thank you

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-13T14:42:49+00:00Added an answer on June 13, 2026 at 2:42 pm

    You can evoke ANTLR using ProcessBuilder just as you would from the command line. There’s a related example here. You can use the append() method of JTextArea to display the result from stdout.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am creating a parser using ANTLR 3.x that targets java. I have written
I have an antlr generated Java parser that uses the C target and it
I currently have a working, simple language implemented in Java using ANTLR. What I
I have a script language based on Antlr: A parser and a tree grammar
Hi I have a small problem in my ANTLR tree grammar. I am using
I generated a Lua Parser using the Lua.g grammar with antlr in java. My
By default, a parser generated using ANTLR-3 extends from org.antlr.runtime.Parser. How do I have
I am using ANTLR 3 , I have a question is that How can
I have a tree parser that's doing semantic analysis on the AST generated by
I am using ANTLR to create an and/or parser+evaluator. Expressions will have the format

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.