Why such warnings occur [message #848516] |
Wed, 18 April 2012 09:53 |
Jingang Zhou Messages: 57 Registered: December 2010 |
Member |
|
|
H, all
When I compile the grammar below:
Model:
cons += LogicExpr+
;
LogicExpr:
left=Expr (op=LogicOp right=LogicExpr)? ;
enum LogicOp: AND='&&'|OR='||'|AND='and'|OR='or'|XOR='xor';
Expr: ID | ('(' logic=LogicExpr ')') | ('!' logic=LogicExpr);
The following warnings occur:
warning(200): ../org.xtext.example.test/src-gen/org/xtext/example/parser/antlr/internal/InternalTest.g:204:2: Decision can match input such as "'or'" using multiple alternatives: 1, 2
As a result, alternative(s) 2 were disabled for that input
warning(200): ../org.xtext.example.test/src-gen/org/xtext/example/parser/antlr/internal/InternalTest.g:204:2: Decision can match input such as "'&&'" using multiple alternatives: 1, 2
As a result, alternative(s) 2 were disabled for that input
warning(200): ../org.xtext.example.test/src-gen/org/xtext/example/parser/antlr/internal/InternalTest.g:204:2: Decision can match input such as "'xor'" using multiple alternatives: 1, 2
As a result, alternative(s) 2 were disabled for that input
warning(200): ../org.xtext.example.test/src-gen/org/xtext/example/parser/antlr/internal/InternalTest.g:204:2: Decision can match input such as "'and'" using multiple alternatives: 1, 2
As a result, alternative(s) 2 were disabled for that input
warning(200): ../org.xtext.example.test/src-gen/org/xtext/example/parser/antlr/internal/InternalTest.g:204:2: Decision can match input such as "'||'" using multiple alternatives: 1, 2
As a result, alternative(s) 2 were disabled for that input
What's the problem?
Thans.
Robin
|
|
|
Re: Why such warnings occur [message #848669 is a reply to message #848516] |
Wed, 18 April 2012 13:15 |
|
Hi Robin,
the problem is that in your grammar the tree of can grow on both side in
a not deterministic way for the same input. The following Grammar should
explain what I ment and by the way does the same as yours. ;-) Have a
look at the documentation concerning left recursion and assignedactions.
Model:
cons += Expr+
;
Expr returns Expr:
ParenthesizedExpr | NotExpr | LogicExpr
;
ParenthesizedExpr :
'(' value=Expr ')'
;
NotExpr:
'!' value=Expr
;
LogicExpr :
OrExpr;
OrExpr:
XOrExpr (=> OrOp {OrOperation.left=current} right=Expr)?
;
XOrExpr:
AndExpr (=> XOrOp {XOrOperation.left=current} right=Expr)?
;
AndExpr:
Literal (=> AndOp {AndOperation.left=current} right=Expr)?
;
AndOp:
'&&' | 'and'
;
OrOp:
'||' | 'or'
;
XOrOp:
'xor'
;
Literal: value=ID ;
--
Need professional support for Eclipse Modeling?
Go visit: http://xtext.itemis.com
--
Need professional support for Eclipse Modeling?
Go visit: http://xtext.itemis.com
|
|
|
|
Powered by
FUDForum. Page generated in 0.03120 seconds