Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » TMF (Xtext) » Why such warnings occur
Why such warnings occur [message #848516] Wed, 18 April 2012 09:53 Go to next message
Jingang Zhou is currently offline Jingang ZhouFriend
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 Go to previous messageGo to next message
Holger Schill is currently offline Holger SchillFriend
Messages: 75
Registered: July 2009
Member
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
Re: Why such warnings occur [message #851705 is a reply to message #848669] Sat, 21 April 2012 07:52 Go to previous message
Jingang Zhou is currently offline Jingang ZhouFriend
Messages: 57
Registered: December 2010
Member
Holger Schill wrote on Wed, 18 April 2012 09: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. Wink 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 ;
--


Thanks a lot.
Previous Topic:Another Content Assist doubt
Next Topic:cross referencing resource contents of another language
Goto Forum:
  


Current Time: Fri Apr 19 23:29:10 GMT 2024

Powered by FUDForum. Page generated in 0.03120 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top