I'm trying to make AST of Swift sources in Java. I also use Windows
What I did:
antlr-4.7.1-complete.jar
grun.bat
and antlr4.bat
, added them to PATH antlr4 -Dlanguage=Java Swift3.g4
antlr4-runtime-4.7.2-SNAPSHOT.jar
using those instructions https://github.com/antlr/antlr4/blob/master/doc/building-antlr.md But now I don't understand what should I do with https://github.com/antlr/grammars-v4/blob/master/swift3/src/main/java/SwiftSupport.java which is also a part of Swift grammar. What should I do with generated files? Simply add them to my sources, define package
and job is done? I also see that ANTLR generates only tokens, will I have to build AST by myself? Thanks!
Looks like I did everything good, now I can parse Swift files with code
Swift3Lexer swiftLexer = new Swift3Lexer(CharStreams.fromFileName(file.getAbsolutePath()));
CommonTokenStream commonTokenStream = new CommonTokenStream(swiftLexer);
Swift3Parser swiftParser = new Swift3Parser(commonTokenStream);
Top_levelContext topLevel = swiftParser.top_level(); // it works
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.