Skip to content

Instantly share code, notes, and snippets.

@loradd
Last active July 2, 2019 12:08
Show Gist options
  • Select an option

  • Save loradd/f9c71ff5ed7064539a096dbc13cb8e20 to your computer and use it in GitHub Desktop.

Select an option

Save loradd/f9c71ff5ed7064539a096dbc13cb8e20 to your computer and use it in GitHub Desktop.
Xtext - Operator Precedence and Associativity

Precedence

  Expression returns Expression: Multiplication;
  Multiplication returns Expression: Addition => ({Multiplication.left = current} '*' right = Addition)*;
  Addition returns Expression: Primary => ({Addition.left = current} '+' right = Primary)*;
  Primary returns Expression: Integer | '(' Expression ')';
  Integer returns Integer: value = INT;

Associativity

Left

  Expression returns Expression: Addition;
  Addition returns Expression: Integer => ({Addition.left = current) '+' right = Integer)*;
  Integer returns Integer: value = INT;

Right

  Expression returns Expression: Addition;
  Addition returns Expression: Integer => ({Addition.left = current} '+' right = Addition)?;
  Integer returns Integer: value = INT;

None

  Expression returns Expression: Addition;
  Addition returns Expression: Integer => ({Addition.left = current} '+' right = Integer)?;
  Integer returns Integer: value = INT;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment