{ v0g A Java 17 grammar written in IXML.

Copyright (c) 2026 Fredrik Öhrström libxmq (spdx: MIT)

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.

The grammar parses Java 17 source files, which are UTF-8. The tree has the
contents of the code: names, literals, operators, comments and the structure.
Whitespace and punctuation are dropped.

The grammar is written for the LL(*) parser generator (xmqj generate-parser)
as well as the ixml engine, in the style of library/lang/c.ixml:

  - Whitespace and comments (ws) are placed at the end of each token, except
    in the first rule, which accepts leading white space. No rule may start
    with ws, otherwise whitespace can be split ambiguously. A comment on the
    line of the token is a comment, a comment on the following lines is a
    leading_comment, which java.xslq moves to the declaration or statement
    that follows it.
  - Tokens use the not operator ! to implement maximal munch, e.g. an
    IDENTIFIER cannot be followed by another identifier character (!idchar) and
    the token + cannot be followed by + or =. Keywords cannot be identifiers
    (!keyword). The contextual keywords (var, yield, record, sealed, permits)
    are identifiers, matched as keywords only where the syntax needs them.
  - > is always a single token, so that List<List<String>> closes two type
    argument lists. The shift operators >> and >>> are > tokens without
    whitespace between them. The assignments >>= and >>>= are tokens.
  - Unicode escapes (A) are only recognized inside char, string and
    text block literals.
  - Literals keep their source text without the quotes, escapes are not
    translated, e.g. "a\n" is STRING_LITERAL = a\n

The tree, eg for public static <T> List<T>[] f(final int x) throws E { ... }

  method(name = f) {
      modifier = public
      modifier = static
      type_parameters { type_parameter(name = T) }
      type { name = List  type_arguments { type { name = T } }  dim }
      parameter(name = x) { modifier = final  type { primitive = int } }
      throws { type { name = E } }
      block
  }

  - Declared names are attributes: class(name = A), variable(name = x), ...
  - A type has a primitive (int) or a dotted name (java.util.List), then its
    type_arguments, and a dim for every []. A name is split only where type
    arguments or annotations come between its parts:
    Outer<String>.Inner is type { name = Outer  type_arguments {...}  name = Inner }
  - wildcard { extends {...} } or wildcard { super {...} } for ? extends T.
  - Annotations and modifiers are kept in source order.
  - void, varargs, static (of an initializer) and dim are empty elements.
  - A comment keeps its text without // or /* */, eg comment = ' the x'. After
    java.xslq the comments on their own lines before a declaration or
    statement are its first children, eg the javadoc of a method, the
    comments before a closing brace are the last children of the block, and
    a comment on the line of a token is after the element of the token.

The grammar accepts more than Java in a few places: an expression statement
can be any primary (a; is accepted, Java requires a call, x++ or an
assignment) and the left side of an assignment can be any primary (1 = x;).

Not supported: annotation type declarations (@interface), annotations on
types (eg List<@NonNull String>, annotations before a type are modifiers),
method references on a generic type (List<String>::size),
module-info.java and the Java 21 features (record patterns, patterns in switch). }

compilation_unit = lws, package?, import_declaration*, type_declaration*.

package = -PACKAGE, -name, -SEMI.

-import_declaration = import | static_import.
import = -IMPORT, -name, on_demand?, -SEMI.
static_import = -IMPORT, -STATIC, -name, on_demand?, -SEMI.
-on_demand = dot, '*', ws.

{ A dotted name, eg java.util.List, is a single name. No rule continues a name
  with a dot and an identifier, so a.b.c is never split. }
name = -IDENTIFIER, (dot, -IDENTIFIER)*.
-dot = '.', !['0'-'9'; '.'], ws.

{ Modifiers and annotations, in any order. sealed and non-sealed are
  contextual keywords. }
-modifiers = (modifier | annotation)*.
modifier = ('public' | 'protected' | 'private' | 'abstract' | 'static' | 'final'
           | 'transient' | 'volatile' | 'synchronized' | 'native' | 'strictfp'
           | 'default' | 'sealed' | 'non-sealed'), !idchar, ws.
{ A local variable, parameter, catch parameter, resource or pattern can only be
  final and have annotations. }
-variable_modifiers = (variable_modifier>modifier | annotation)*.
variable_modifier = 'final', !idchar, ws.
annotation = -AT, name, (-LPAREN, (pair++-COMMA | element_value)?, -RPAREN)?.
pair = @ident>name, ws, -assign, element_value.
-element_value = conditional_expression | annotation | ^element_values>array_initializer.
-element_values = -LBRACE, (element_value++-COMMA)?, -COMMA?, -RBRACE.

{ Types. var, yield, record, sealed and permits cannot be the name of a type.
  An annotation before the type of a field, method, parameter or record
  component is a modifier. Elsewhere a type can start with annotations, eg
  List<@NonNull String>, implements @A I, throws @A E. }
type = (primitive | class_type), dim*.
annotated_type = annotation+, (primitive | class_type), dim*.
-any_type = type | annotated_type>type.
primitive = ('boolean' | 'byte' | 'short' | 'char' | 'int' | 'long' | 'float' | 'double'),
            !idchar, ws.
{ After its name a class type continues only with type arguments or
  annotations, eg Outer<String>.Inner or Outer.@A Inner, otherwise the name
  has all the dotted parts. }
-class_type = !restricted, name, class_type_rest?.
-class_type_rest = type_arguments, (-DOT, annotation*, name, class_type_rest?)?
                 | -DOT, annotation+, name, class_type_rest?.
-restricted = 'var', notid | 'yield', notid | 'record', notid | 'sealed', notid
            | 'permits', notid.
dim = annotation*, -LBRACKET, -RBRACKET.
type_arguments = -lt, (type_argument++-COMMA)?, -gt.
-type_argument = any_type | wildcard.
wildcard = -'?', ws, (extends | super)?.
super = -SUPER, any_type.

type_parameters = -lt, type_parameter++-COMMA, -gt.
type_parameter = annotation*, @ident>name, ws, extends?.
extends = -EXTENDS, any_type, (-amp, any_type)*.

-lt = -'<', !['<='], ws.
-gt = -'>', !gt_follow, ws.
-amp = -'&', !['&='], ws.
-assign = -'=', !'=', ws.

{ Type declarations }

-type_declaration = class | interface | enum | record | -SEMI.

class = modifiers, -CLASS, @ident>name, ws, type_parameters?, extends?, implements?,
        permits?, body.
interface = modifiers, -INTERFACE, @ident>name, ws, type_parameters?,
            ^interface_extends>extends?, permits?, body.
enum = modifiers, -ENUM, @ident>name, ws, implements?, ^enum_body>body.
record = modifiers, -'record', !idchar, ws, @ident>name, ws, type_parameters?,
         -LPAREN, components?, -RPAREN, implements?, body.

-interface_extends = -EXTENDS, any_type++-COMMA.
implements = -IMPLEMENTS, any_type++-COMMA.
permits = -'permits', !idchar, ws, any_type++-COMMA.

body = -LBRACE, member*, -RBRACE.
-enum_body = -LBRACE, (constant++-COMMA)?, -COMMA?, (-SEMI, member*)?, -RBRACE.
constant = annotation*, @ident>name, ws, arguments?, body?.
-components = (component, -COMMA)*, (component | ^variable_arity_component>component).
component = annotation*, type, @ident>name, ws.
-variable_arity_component = annotation*, type, varargs, @ident>name, ws.

{ Members }

-member = field | method | constructor | compact_constructor | initializer
        | class | interface | enum | record | -SEMI.

field = modifiers, type, variable++-COMMA, -SEMI.
variable = @ident>name, ws, dim*, (-assign, variable_initializer)?.

method = modifiers, type_parameters?, (type | void), @ident>name, ws,
         -LPAREN, parameters?, -RPAREN, dim*, throws?, (block | -SEMI).
void = -VOID.
constructor = modifiers, type_parameters?, @ident>name, ws,
              -LPAREN, parameters?, -RPAREN, throws?, block.
compact_constructor = modifiers, @ident>name, ws, block.
initializer = static?, block.
static = -STATIC.

{ The first parameter can be the receiver, eg void m(@A Foo this) or, in the
  constructor of an inner class, Inner(Outer Outer.this).
  Only the last parameter can have varargs (...). }
-parameters = receiver, (-COMMA, parameter_list)? | parameter_list.
-parameter_list = (parameter, -COMMA)*, (parameter | ^variable_arity>parameter).
receiver = variable_modifiers, type, (@ident>outer, ws, -DOT)?, -THIS.
parameter = variable_modifiers, type, @ident>name, ws, dim*.
-variable_arity = variable_modifiers, type, varargs, @ident>name, ws.
varargs = annotation*, -ELLIPSIS.
throws = -THROWS, any_type++-COMMA.

{ Statements }

block = -LBRACE, block_statement*, -RBRACE.
-block_statement = local_variable | class | interface | enum | record | statement.

{ A local variable declaration wins over an expression statement, eg
  List<String> x = y; is a declaration (the expression statement has a cost). }
local_variable = variable_modifiers, (type | var), variable++-COMMA, -SEMI.
var = -'var', !idchar, ws.

-statement = block | empty | label | expression_statement | if | assert | switch
           | while | do | for | foreach | break | continue | return | throw
           | synchronized | try | yield | constructor_call.

empty = -SEMI.
label = @ident>name, ws, -colon, statement.

{ Only the expressions that Java allows as statements, see statement_expression.
  So a local variable declaration and an expression statement never both fit. }
expression_statement = statement_expression, -SEMI.

{ The dangling else binds to the closest if, using !kw_else. }
if = -IF, -LPAREN, expression, -RPAREN, statement, (else | !kw_else).
else = -ELSE, statement.
-kw_else = 'else', notid.

assert = -ASSERT, expression, (-colon, expression)?, -SEMI.

while = -WHILE, -LPAREN, expression, -RPAREN, statement.
do = -DO, statement, -WHILE, -LPAREN, expression, -RPAREN, -SEMI.

{ for (init; condition; update) and for (T x : xs). The init is a local
  variable declaration or statement expressions, eg for (i = 0, j = 1; ...). }
for = -FOR, -LPAREN, for_init?, -SEMI, expression?, -SEMI, for_update?, -RPAREN, statement.
for_init = variable_modifiers, (type | var), variable++-COMMA | statement_expression++-COMMA.
for_update = statement_expression++-COMMA.
foreach = -FOR, -LPAREN, variable_modifiers, (type | var), @ident>name, ws, -colon, expression,
          -RPAREN, statement.

break = -BREAK, (@ident>label, ws)?, -SEMI.
continue = -CONTINUE, (@ident>label, ws)?, -SEMI.
return = -RETURN, expression?, -SEMI.
throw = -THROW, expression, -SEMI.
yield = -'yield', !idchar, ws, expression, -SEMI.
synchronized = -SYNCHRONIZED, -LPAREN, expression, -RPAREN, block.

{ try, try-with-resources, catch with alternatives (A | B e) and finally. A
  resource is a declaration or an existing variable. }
try = -TRY, (resources, block, catch*, finally? | block, (catch+, finally? | finally)).
resources = -LPAREN, resource++-SEMI, -SEMI?, -RPAREN.
resource = variable_modifiers, (type | var), @ident>name, ws, -assign, expression
         | primary.
catch = -CATCH, -LPAREN, variable_modifiers, type, (-bar, type)*, @ident>name, ws, -RPAREN, block.
finally = -FINALLY, block.

{ switch with rules (case A, B -> ...) or groups of statements (case A: case B: ...).
  The labels of a group are followed by statements, except in the last group,
  so that case 1: case 2: x(); is a single group. }
switch = -SWITCH, -LPAREN, expression, -RPAREN,
         -LBRACE, (switch_rule+ | switch_group*, ^last_switch_group>switch_group?), -RBRACE.
switch_rule = (case | default), -arrow, (expression, -SEMI | block | throw).
switch_group = ((case | default), -colon)+, block_statement+.
-last_switch_group = ((case | default), -colon)+.
{ A case label is not a lambda, case A -> x(); }
case = -CASE, conditional_expression++-COMMA.
default = -DEFAULT.

-colon = -':', !':', ws.
-arrow = -'->', ws.
-bar = -'|', !['|='], ws.

{ Expressions (step 5).

  The grammar is written for the generated LL(*) parser, which handles direct
  left recursion (x = -y | x, op, y), as in library/lang/c.ixml. In the raw
  tree an operand has the element of its level and the operator with its
  operands is in the element of the level above, eg a + b is
  conditional_expression { additive { a } PLUS multiplicative { b } }, and the
  method calls, field and array accesses are a chain of selectors on a primary,
  eg a.b.c(x) is primary { primary { primary { name = a } field_select(name = b) }
  call(name = c) { arguments } }. The cleanup library/lang/java.xslq (used
  automatically with ixml:lang/java) removes the levels without an operator,
  makes method_call, field_access and array_access of the selectors and folds a
  chain of names into a dotted name: a.b.c(x) is method_call(name = a.b.c). }

{ An assignment is left factored: a conditional expression with an optional
  assignment operator, the cleanup removes an assignment without an operator.
  Java requires a variable on the left, the grammar accepts any conditional
  expression there, except in an expression statement, see statement_expression. }
-expression = lambda | assignment.
assignment = conditional_expression, (assignment_operator, expression)?.
-assignment_operator = ASSIGN | PLUS_ASSIGN | MINUS_ASSIGN | STAR_ASSIGN | SLASH_ASSIGN
                     | MOD_ASSIGN | AND_ASSIGN | OR_ASSIGN | XOR_ASSIGN | SHL_ASSIGN
                     | SHR_ASSIGN | USHR_ASSIGN.

{ The true branch comes first, then the false branch. The condition is an
  element, so that the operands of its operator are not mixed with the branches. }
conditional_expression = logical_or, (-question, expression, -colon, (conditional_expression | lambda))?.
-question = -'?', ws.

logical_or = -logical_and | logical_or, OR, logical_and.
logical_and = -bitwise_or | logical_and, AND, bitwise_or.
bitwise_or = -bitwise_xor | bitwise_or, BITOR, bitwise_xor.
bitwise_xor = -bitwise_and | bitwise_xor, CARET, bitwise_and.
bitwise_and = -equality | bitwise_and, BITAND, equality.
equality = -relational | equality, (EQ | NE), relational.
relational = -shift | relational, (LT | GT | LE | GE), shift
           | relational, ^INSTANCEOF>instanceof, (type | pattern).
pattern = variable_modifiers, type, @ident>name, ws.
shift = -additive | shift, (SHL | SHR | USHR), additive.
additive = -multiplicative | additive, (PLUS | MINUS), multiplicative.
multiplicative = -unary_level | multiplicative, (STAR | SLASH | PERCENT), unary_level.

{ >> and >>> are > tokens in types, so that List<List<String>> works, but in
  an expression they are shift operators. }
SHR = '>>', !['>='], ws.
USHR = '>>>', !'=', ws.

-unary_level = unary | prefix | unary_not_plus_minus.
unary = (PLUS | MINUS), unary_level.
prefix = (INC | DEC), unary_level.
-unary_not_plus_minus = postfix | not_unary>unary | cast | switch.
not_unary = (TILDE | NOT), unary_level.

{ A cast to a primitive type is followed by any unary expression, (int) -x,
  a cast to a reference type only by one that does not start with + or -, so
  (a) - b is a subtraction. A reference type can have additional bounds,
  (Runnable & Serializable) () -> {}. }
cast = -LPAREN, ^primitive_cast_type>type, -RPAREN, unary_level
     | -LPAREN, ^reference_type>type, (-amp, any_type)*, -RPAREN, (unary_not_plus_minus | lambda).
-primitive_cast_type = primitive.
-reference_type = class_type, dim* | primitive, dim+.

postfix = -primary | new_array | postfix, (INC | DEC).

{ A primary and its selectors: .f(x) call, .f field_select, [i] index, ::f reference,
  .new Inner() outer_new, .this outer_this, .super outer_super, [].class
  class_selector. }
{ An array creation is not indexed directly, new int[1][2] is a two
  dimensional array, but it can have the other selectors, new int[1].length. }
primary = -primary_start | new_array, (call | field_select | reference) | primary, selector.
-selector = call | field_select | index | reference | outer_new | outer_this | outer_super
          | class_selector.
call = -DOT, type_arguments?, @ident>name, ws, arguments.
field_select = -DOT, @ident>name, ws.
index = -LBRACKET, expression, -RBRACKET.
reference = dim*, -COLONCOLON, type_arguments?, (@ident>name, ws | @new_kw>name, ws).
outer_new = -DOT, new.
outer_this = -DOT, -THIS.
outer_super = -DOT, -SUPER.
class_selector = dim*, -DOT, -CLASS.
-new_kw = 'new', !idchar.

{ An unqualified method cannot be called yield, yield (x); is a yield statement. }
-primary_start = IDENTIFIER>name | !yield_word, ^unqualified_call>call | literal
               | ^THIS>this | ^SUPER>super | -LPAREN, expression, -RPAREN
               | new | class_literal | primitive_reference>method_reference.
-unqualified_call = @ident>name, ws, arguments.
-yield_word = 'yield', notid.
arguments = -LPAREN, (expression++-COMMA)?, -RPAREN.

-literal = INTEGER_LITERAL | FLOATING_POINT_LITERAL | CHARACTER_LITERAL | STRING_LITERAL
         | TEXT_BLOCK | BOOLEAN_LITERAL | NULL_LITERAL.
BOOLEAN_LITERAL = ('true' | 'false'), !idchar, ws.
NULL_LITERAL = 'null', !idchar, ws.

{ int.class, int[].class, void.class and int[]::new. A class literal of a
  class, String.class, is a class_selector on a name. }
class_literal = (^primitive_with_dims>type | ^VOID>void), -DOT, -CLASS.
-primitive_with_dims = primitive, dim*.
primitive_reference = ^primitive_with_dims>type, -COLONCOLON, @new_kw>name, ws.

{ new Foo<>(x) { body }, new int[n][], new int[] { 1, 2 } }
new = -NEW, type_arguments?, ^new_type>type, arguments, body?.
-new_type = annotation*, class_type.
new_array = -NEW, ^array_element_type>type, dim_expression>dim+, dim*
          | -NEW, type, array_initializer.
-array_element_type = primitive | class_type.
dim_expression = annotation*, -LBRACKET, expression, -RBRACKET.
array_initializer = -LBRACE, (variable_initializer++-COMMA)?, -COMMA?, -RBRACE.
-variable_initializer = expression | array_initializer.

{ x -> x + 1, (a, b) -> {...}, (int a, String... b) -> ..., (var a) -> ... }
lambda = lambda_parameters, -arrow, (expression | block).
-lambda_parameters = ^inferred_parameter>parameter
                   | -LPAREN, (^inferred_parameter>parameter++-COMMA | lambda_parameter++-COMMA)?, -RPAREN.
-inferred_parameter = @ident>name, ws.
-lambda_parameter = parameter | ^variable_arity>parameter | ^var_parameter>parameter.
-var_parameter = variable_modifiers, var, @ident>name, ws.

{ The expressions that can be statements: an assignment to a postfix, or a
  postfix (a primary, eg a method call, or x++), or ++x. So a local variable
  declaration, eg List<String> x = y; is never also an expression statement. }
-statement_expression = prefix | ^statement_assignment>assignment.
-statement_assignment = postfix, (assignment_operator, expression)?.

{ this(x); super(x); outer.super(x); in a constructor. }
constructor_call = (type_arguments?, (^THIS>this | ^SUPER>super)
                    | primary, -DOT, type_arguments?, ^SUPER>super),
                   arguments, -SEMI.


{ Whitespace and comments. The byte order mark is whitespace too.

  The ws after a token is split at the end of its line. A comment on the same
  line as the token is a comment, eg int x; // the x, it stays where the token
  is. The comments on the following lines, up to the next token, are each a
  leading_comment. java.xslq moves a leading comment to the declaration or
  statement that follows it, eg the javadoc of a method is in the method. }

-ws = (-hspace | comment)*, (-eol, lws | !wsstart).
-lws = (-[' '; #9; #a; #c; #d; #feff] | leading_comment)*, !wsstart.
-hspace = -[' '; #9; #c; #feff].
-eol = -#a | -#d, -#a | -#d, !#a.
-wsstart = [' '; #9; #a; #c; #d; #feff] | '//' | '/*'.
comment = -'//', ~[#a; #d]*, !~[#a; #d]
        | -'/*', comment_char*, -'*/'.
leading_comment = -'//', ~[#a; #d]*, !~[#a; #d]
                | -'/*', comment_char*, -'*/'.
-comment_char = ~['*'] | '*', !'/'.

{ Literals }

INTEGER_LITERAL = (-hex_numeral | -binary_numeral | -digits), ['lL']?, !numchar, ws.
-numchar = [L; Nd; '_'; '.'].
-digits = ['0'-'9'], (['0'-'9'; '_']*, ['0'-'9'])?.
-hex_digits = hex_digit, ([Nd; 'a'-'f'; 'A'-'F'; '_']*, hex_digit)?.
-hex_digit = ['0'-'9'; 'a'-'f'; 'A'-'F'].
-hex_numeral = '0', ['xX'], hex_digits.
-binary_numeral = '0', ['bB'], ['01'], (['01_']*, ['01'])?.

FLOATING_POINT_LITERAL = (-decimal_float | -hex_float), !numchar, ws.
-decimal_float = digits, '.', digits?, exponent?, float_suffix?
               | '.', digits, exponent?, float_suffix?
               | digits, exponent, float_suffix?
               | digits, float_suffix.
-exponent = ['eE'], ['+-']?, digits.
-float_suffix = ['fFdD'].
-hex_float = '0', ['xX'], (hex_digits, '.'? | hex_digits?, '.', hex_digits),
             ['pP'], ['+-']?, digits, float_suffix?.

CHARACTER_LITERAL = -"'", (~["'\"; #a; #d] | -escape), -"'", ws.
STRING_LITERAL = !'"""', -'"', (~['"\'; #a; #d] | -escape)*, -'"', ws.
-escape = '\', ( ['btnfrs"\'; "'"]
               | octal_escape
               | 'u'+, hex_digit, hex_digit, hex_digit, hex_digit).
-octal_escape = ['0'-'3'], ['0'-'7'], ['0'-'7']
              | ['0'-'3'], ['0'-'7'], !['0'-'7']
              | ['4'-'7'], ['0'-'7']
              | ['0'-'7'], !['0'-'7'].

{ A text block starts with """ and the rest of the line, the contents start on
  the next line and end with """. A " or "" in the contents is not the end. }
TEXT_BLOCK = -'"""', -[' '; #9; #c]*, -#d?, -#a, (-text_block_char)*, -'"""', ws.
-text_block_char = ~['"\']
                 | '"', !'""'
                 | escape
                 | '\', #d?, #a.

{ Separators, they are not part of the tree. }

-LPAREN = -'(', ws.
-RPAREN = -')', ws.
-LBRACE = -'{', ws.
{ The closing brace is an empty element in the raw tree, so that java.xslq can
  tell a comment before the brace from one after it. java.xslq removes it. }
-RBRACE = rbrace, ws.
rbrace = -'}'.
-LBRACKET = -'[', ws.
-RBRACKET = -']', ws.
-SEMI = -';', ws.
-COMMA = -',', ws.
-DOT = -'.', !['0'-'9'; '.'], ws.
-ELLIPSIS = -'...', ws.
-AT = -'@', ws.
-COLONCOLON = -'::', ws.


{ Operators }

ASSIGN = '=', !'=', ws.
GT = '>', !gt_follow, ws.
-gt_follow = '=' | '>=' | '>>='.
LT = '<', !['<='], ws.
NOT = '!', !'=', ws.
TILDE = '~', ws.
QUESTION = '?', ws.
COLON = ':', !':', ws.
ARROW = '->', ws.
EQ = '==', ws.
GE = '>=', ws.
LE = '<=', ws.
NE = '!=', ws.
AND = '&&', ws.
OR = '||', ws.
INC = '++', ws.
DEC = '--', ws.
PLUS = '+', !['+='], ws.
MINUS = '-', !['-=>'], ws.
STAR = '*', !'=', ws.
SLASH = '/', !['/*='], ws.
BITAND = '&', !['&='], ws.
BITOR = '|', !['|='], ws.
CARET = '^', !'=', ws.
PERCENT = '%', !'=', ws.
SHL = '<<', !'=', ws.
PLUS_ASSIGN = '+=', ws.
MINUS_ASSIGN = '-=', ws.
STAR_ASSIGN = '*=', ws.
SLASH_ASSIGN = '/=', ws.
AND_ASSIGN = '&=', ws.
OR_ASSIGN = '|=', ws.
XOR_ASSIGN = '^=', ws.
MOD_ASSIGN = '%=', ws.
SHL_ASSIGN = '<<=', ws.
SHR_ASSIGN = '>>=', ws.
USHR_ASSIGN = '>>>=', ws.


{ Identifiers and keywords. An identifier is not a keyword, eg classes, done
  and if_x are identifiers. true, false, null and _ are reserved as well. }

IDENTIFIER = ident, ws.
-ident = !keyword, idstart, idchar*, !idchar.
-idstart = [L; Nl; Sc; Pc].
-idchar = [L; Nl; Sc; Pc; Nd; Mn; Mc].

-keyword = 'abstract', notid
         | 'assert', notid
         | 'boolean', notid
         | 'break', notid
         | 'byte', notid
         | 'case', notid
         | 'catch', notid
         | 'char', notid
         | 'class', notid
         | 'const', notid
         | 'continue', notid
         | 'default', notid
         | 'do', notid
         | 'double', notid
         | 'else', notid
         | 'enum', notid
         | 'extends', notid
         | 'final', notid
         | 'finally', notid
         | 'float', notid
         | 'for', notid
         | 'goto', notid
         | 'if', notid
         | 'implements', notid
         | 'import', notid
         | 'instanceof', notid
         | 'int', notid
         | 'interface', notid
         | 'long', notid
         | 'native', notid
         | 'new', notid
         | 'package', notid
         | 'private', notid
         | 'protected', notid
         | 'public', notid
         | 'return', notid
         | 'short', notid
         | 'static', notid
         | 'strictfp', notid
         | 'super', notid
         | 'switch', notid
         | 'synchronized', notid
         | 'this', notid
         | 'throw', notid
         | 'throws', notid
         | 'transient', notid
         | 'try', notid
         | 'void', notid
         | 'volatile', notid
         | 'while', notid
         | 'true', notid
         | 'false', notid
         | 'null', notid
         | '_', notid.
-notid = ~[L; Nl; Sc; Pc; Nd; Mn; Mc].

-ABSTRACT = -'abstract', !idchar, ws.
-ASSERT = -'assert', !idchar, ws.
-BOOLEAN = -'boolean', !idchar, ws.
-BREAK = -'break', !idchar, ws.
-BYTE = -'byte', !idchar, ws.
-CASE = -'case', !idchar, ws.
-CATCH = -'catch', !idchar, ws.
-CHAR = -'char', !idchar, ws.
-CLASS = -'class', !idchar, ws.
-CONST = -'const', !idchar, ws.
-CONTINUE = -'continue', !idchar, ws.
-DEFAULT = -'default', !idchar, ws.
-DO = -'do', !idchar, ws.
-DOUBLE = -'double', !idchar, ws.
-ELSE = -'else', !idchar, ws.
-ENUM = -'enum', !idchar, ws.
-EXTENDS = -'extends', !idchar, ws.
-FINAL = -'final', !idchar, ws.
-FINALLY = -'finally', !idchar, ws.
-FLOAT = -'float', !idchar, ws.
-FOR = -'for', !idchar, ws.
-GOTO = -'goto', !idchar, ws.
-IF = -'if', !idchar, ws.
-IMPLEMENTS = -'implements', !idchar, ws.
-IMPORT = -'import', !idchar, ws.
-INSTANCEOF = -'instanceof', !idchar, ws.
-INT = -'int', !idchar, ws.
-INTERFACE = -'interface', !idchar, ws.
-LONG = -'long', !idchar, ws.
-NATIVE = -'native', !idchar, ws.
-NEW = -'new', !idchar, ws.
-PACKAGE = -'package', !idchar, ws.
-PRIVATE = -'private', !idchar, ws.
-PROTECTED = -'protected', !idchar, ws.
-PUBLIC = -'public', !idchar, ws.
-RETURN = -'return', !idchar, ws.
-SHORT = -'short', !idchar, ws.
-STATIC = -'static', !idchar, ws.
-STRICTFP = -'strictfp', !idchar, ws.
-SUPER = -'super', !idchar, ws.
-SWITCH = -'switch', !idchar, ws.
-SYNCHRONIZED = -'synchronized', !idchar, ws.
-THIS = -'this', !idchar, ws.
-THROW = -'throw', !idchar, ws.
-THROWS = -'throws', !idchar, ws.
-TRANSIENT = -'transient', !idchar, ws.
-TRY = -'try', !idchar, ws.
-VOID = -'void', !idchar, ws.
-VOLATILE = -'volatile', !idchar, ws.
-WHILE = -'while', !idchar, ws.
-TRUE = -'true', !idchar, ws.
-FALSE = -'false', !idchar, ws.
-NULL = -'null', !idchar, ws.
-UNDERSCORE = -'_', !idchar, ws.