问题描述:

This is my grammar. I simply want to make a C like language. Problem occurs when I add the BoolAssignment and IntAssignment statements. I get the following error error(211): ../org.xtext.cbb/src-gen/org/xtext/parser/antlr/internal/InternalCbb.g:114:2: [fatal] rule ruleStatement has non-LL(*) decision due to recursive rule invocations reachable from alts 3,4. Resolve by left-factoring or using syntactic predicates or using backtrack=true option.

  1. I have tried setting the backtrack=true and the error persists
  2. I know Antlr shouldn't be used for such things

    • What is the correct way to have both the Declaration and Assignments both to work?
    • Are there any improvements in the grammar that I can make?
    • Are there any tools out there that do a similar job to Xtext and have the UI capabilities found in Xtext that would be easier to develop such language?

Thanks

Module:

(statements+=Statement)*;

Statement:

Boolean |

Integer |

BoolAssignment |

IntAssignment;

//BOOLEANS

Boolean:

('bool' name=ID ('=' expr=BoolExpression)? ';') |

('const' 'bool' name=ID '=' expr=BoolExpression ';');

BoolAssignment:

assignee=[Boolean] '=' expr=BoolExpression';';

BoolExpression:

Logical;

Logical returns BoolExpression:

Comparison (({Not.left=current} '!' | {And.left=current} '&&'| {Or.left=current} '||') right=Comparison)*;

Comparison returns BoolExpression:

PrimaryBoolExpression (({Equal.left=current} '==' | {NotEqual.left=current} '!=' | {LessThan.left=current} '<' | {LessThanEqual.left=current} '<=' | {GreaterThan.left=current} '>' | {GreaterThanEqual.left=current} '>=') right=PrimaryBoolExpression)*;

PrimaryBoolExpression returns BoolExpression:

'(' BoolExpression ')' |

{BooleanLiteral} value=boolean_value |

{BooleanReference} ref=[Boolean];

boolean_value:

'true' | 'false';

// INTEGERS

Integer:

'const' 'int' name=ID '=' expr=IntExpression ';' |

'int' name=ID (assignment_operator expr=IntExpression)? ';';

IntAssignment:

assignee=[Integer] assignment_operator expr=IntExpression';';

IntExpression:

Addition;

Addition returns IntExpression:

Multiplication (({Plus.left=current} '+' | {Minus.left=current} '-') right=Multiplication)*;

Multiplication returns IntExpression:

Bitwise (({Multi.left=current} '*' | {Div.left=current} '/') right=Bitwise)*;

Bitwise returns IntExpression:

PrimaryIntExpression (({Not.left=current} '~' | {And.left=current} '&' | {Or.left=current} '|' | {Xor.left=current} '^' | {RightShift.left=current} '>>' | {LeftShift.left=current} '<<') right=PrimaryIntExpression)*;

PrimaryIntExpression returns IntExpression:

'(' IntExpression ')' |

{IntegerLiteral} value=integer_value |

{IntegerIncrementDecrement} (increment_decrement_operator ref=[Integer]|ref=[Integer] increment_decrement_operator) |

{IntegerReference} ref=[Integer];

assignment_operator:

'=' | '+=' | '-=' | '*=' | '/=' | '%=' | '&=' | '|=' | '^=' | '<<=' | '>>=';

increment_decrement_operator:

'++' | '--';

integer_value:

'-'?INT+;

相关阅读:
Top