Home | pfodApps/pfodDevices | WebStringTemplates | Java/J2EE | Unix | Torches | Superannuation | | About Us

Forward Logo (image)      

Android Programming

Antlr For Android (download Eclipse Android Antlr 4.2.2 Lexer library project)

Antlr is a powerful parser generator for reading, processing, executing, or translating structured text or binary files.

Unfortunately for Android programmers it uses as number of Java libraries that are not available on Android systems. (When you go to package the app, proguard complains about missing swing classes and others)

This web page contains a partial port of Antlr 4.2.2 release of ANTLR to Android. Only the Lexer part of the Antlr release has been ported. That was all I needed to write my parser for pfodApp. In pfodApp the lexer parses all the text formatting codes and call support methods to build up a SpannableStringBuilder with the specified formatting applied.

The ported Eclipse Android Antlr 4.2.2 Lexer library project is available here as a zip file.

What was changed for Antlr 4.2.2 Lexer library for Android.

This is what was done to port the Lexer portion of Antlr V4.2.2 to an Android library.

  1. generated lexer java file from grammar and check that is was correct using standard runtime library

  2. removed runtime library from project

  3. added java files from antlr4 runtime source directory one at a time to resolve compile errors

    1. removed all @NonNull and @Nullable references

    2. commented out code that references javax etc mainly toString() and tree display methods

    3. added implementations of Arrays.copyOf and binarySearch that Android does not provide to misc.Utils and fixed all references in files used.

    4. Removed all references to System.out and System.err (TODO add in Android Log calls as needed)

    5. removed unsupported @SuppressWarnings

    6. removed unused imports

The entire atn and dfa runtime packages have been ported to Android API 7 (Android V2.1+)

In misc package, GraphicsSupport.java, JFileChooserConfirmOverwrite.java, LogManager.java and TestRig.java have been omitted.

In Utils, waitForClose and addWindowListener methods have been removed and copyOf and binarySearch methods added.

In tree package, packages gui, pattern and xpath and other classes not need for compile have been removed, as this is a lexer only project. This is were more work is needed for a 'complete' port.

In runtime package, ConsoleErrorListener.java was removed (TODO replace with Android Log error listener), String.isEmpty() was replaced with (String.length() == 0), in DiagnosticErrorListener.java, compileParseTreePattern methods where removed from Parser as not needed the pfodApp Lexer (TODO fix this), ParserInterpreter was removed needs ArrayDeque and Deque implementations (TODO fix this), in Recognizer, ConsoleErrorListener.INSTANCE was removed, in RuleContext, save() and inspect() and toStringTree() methods where removed and toString() was replaced with empty string return.

Result is the port to Android that is about 80% complete.

If you do any further porting please feed that back here so we can provide a more complete port.


Forward home page link (image)

Contact Forward Computing and Control by
©Copyright 1996-2017 Forward Computing and Control Pty. Ltd. ACN 003 669 994