Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

No Format
e   :   e '^' e // right associative
    |   e '*' e
    |   '++' e
    |   '-' e
    |   e ('+'|'-') e
    |   suffix
    |   e '.++'
ID     |   e '[(' e '])'
    |   INT
  e '(' e (',' e)* ')'  |   ID
    ;

suffix
    |:   e '++.' ID
    |   e '([' e ')]'
    |   INTe '(' e (','  |e)* ')'
  ID     ;

The beauty of this is that it would automatically know how to build ASTs (or with a little bit of help from you for the complicated ones like method calls and array indexing). Further, the precedence specified as usual by the order of the alternatives. Anything that starts and stops with e is considered a binary (or possibly trinary) operator. Any other alternative that starts with e is a suffix operation. Any other alternative that ends with e is a unitary operation. Alts that are simply rule references identify groups of operations at the same level such as the suffix rule. Anything else is part of the primary rule.

...

No Format
e   :   e '^' e // right associative
    |   e '*' e
    |   unary
    |   e ('+'|'-') e
    |   e '.' IDsuffix_
    |   suffix
    |   primary
    ;

unary_
    :  '++' e
    |   '-' e
    ;

suffix_
    :   e '.' ID
    ;

suffix
    :   e '[' e ']'
    |   e '(' e (',' e)* ')'
    |   e '++'
    ;

primary_
    :   '(' e ')'
    |   INT
    |   ID
    ;

once Once I had identified these elements, I could generate something like the following:

...