Skip to content

Latest commit

 

History

History
 
 

java

Folders and files

NameName
Last commit message
Last commit date

parent directory

..
 
 
 
 
 
 
 
 
 
 
 
 

Java Antlr Grammar

Based on the previous optimized Java7 grammar by Terence Parr and Sam Harwell with the same BSD license. This grammar does not exactly corresponds to the formal Java specification unlike usual Java8 grammar, but passes tests such as AllInOne7.Java and AllInOne8.java. Performance, practical usage and clarity in priority.

This grammar parses the file ManyStringsConcat.java much more faster than original grammar without left recursion expressions.

Supported Java versions

  • Java 7
  • Java 8

Main contributors

Tests

The grammar contains AllInOne7.java and AllInOne8.java files that almost fully covered Java syntax.

Benchmarks

Grammar performance has been tested on the following projects:

  • jdk8
  • Spring Framework
  • Elasticsearch
  • RxJava
  • JUnit4
  • Guava
  • Log4j

See Benchmarks page for details.

Grammar style

Parse rules

parserRule
    : token1 (token2* OPERATOR token3?)
    ;

Tokens

INT:                'int';
INTERFACE:          'interface';

Fragments

fragment
HexDigit
    : [0-9a-fA-F]
    ;

Tokens using

Please use token names instead of literal names if possible and justified. It's more convenient during parse tree bypass.

modifier
    : classOrInterfaceModifier
    | NATIVE
    | SYNCHRONIZED
    | TRANSIENT
    | VOLATILE
    ;

instead of

modifier
    : classOrInterfaceModifier
    | 'native'
    | 'synchronized'
    | 'transient'
    | 'volatile'
    ;