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