Building a Translator with a Listener
Imagine your boss assigns you to build a tool that generates a Java interface file from the methods in a Java class definition. Panic ensues if youâre a junior programmer. As an experienced Java developer, you might suggest using the Java reflection API or the javap tool to extract method signatures. If your Java tool building kung fu is very strong, you might even try using a bytecode library such as ASM.[19] Then your boss says, âOh, yeah. Preserve whitespace and comments within the bounds of the method signature.â Thereâs no way around it now. We have to parse Java source code. For example, weâd like to read in Java code like this:
â | âimportâ java.util.List; |
â | âimport ... |
Get The Definitive ANTLR 4 Reference, 2nd Edition now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.