Changing Main

11 views
Skip to first unread message

Bill Dickenson

unread,
Apr 2, 2020, 8:05:51 PM4/2/20
to antlr-discussion
I need to get some additional output from Antlr4. I found a response that seems very close to what I want, and a code snippet that should work. But it doesnt.

import org.antlr.runtime.*;
import org.antlr.runtime.tree.*;
import org.antlr.stringtemplate.*;

public class Main {
  public static void main(String[] args) throws Exception {
    String src = "true && (false || true && (true || false))";
    ASTDemoLexer lexer = new ASTDemoLexer(new ANTLRStringStream(src));
    ASTDemoParser parser = new ASTDemoParser(new CommonTokenStream(lexer));
    CommonTree tree = (CommonTree)parser.parse().getTree();
    DOTTreeGenerator gen = new DOTTreeGenerator();
    StringTemplate st = gen.toDOT(tree);
    System.out.println(st);
  }
}

but when I compile, I get these errors




The first challenge is stringtemplate which I thought was part of ANTLR4
I am hoping the rest are derivatives of that. I dont want to install stringtemplate twice.

Thoughts ?
Reply all
Reply to author
Forward
0 new messages