Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » TMF (Xtext) » Question about ANTLR and recursions
Question about ANTLR and recursions [message #555844] Sun, 29 August 2010 13:55 Go to next message
Michael Frey is currently offline Michael FreyFriend
Messages: 48
Registered: August 2010
Member
Hi,

I'm not sure but my ANTLR issue might be an recursion issue. So far, I've specified a language which consists upon variables, statements, functions, loops and conditions. While a block in my language could contain a variable, statement, loop or condition I've specified a block expression:

BlockExpression:
  Variable | Statement | Loop | ConditionalExpression;


The conditional expression itself is:

ConditionalExpression:
  IfElseCondition | SwitchCaseCondition;
	
IfElseCondition:
  'if' '(' condition=Or ')' '{' 
    ifAction+=BlockExpression		
  '}' 'else' '{'
    elseAction+=BlockExpression
  '}';

SwitchCaseCondition:
  'switch' '(' condition=Or ')' '{' 
    case+=(CaseStatement)* 'default' ':' default=Or
  '}';

CaseStatement:
  'case' condition=Or ':' action=Or;


and I assume that the following part is the problem

...
  ifAction+=BlockExpression		
...
  elseAction+=BlockExpression


And that's the error I get while I generate the artifacts

warning(205): ../de.example.flow.ui/src-gen/de/hs_rm/cs/vs/dsm/ui/contentassist/antlr/internal/InternalFlow.g:1:8: ANTLR could not analyze this decision in rule Tokens; often this is because of recursive rule references visible from the left edge of alternatives.  ANTLR will re-analyze the decision with a fixed lookahead of k=1.  Consider using "options {k=1;}" for that decision and possibly adding a syntactic predicate.
warning(209): ../de.example.flow.ui/src-gen/de/hs_rm/cs/vs/dsm/ui/contentassist/antlr/internal/InternalFlow.g:10186:1: Multiple token rules can match input such as "'^'": RULE_ID, RULE_ANY_OTHER
As a result, tokens(s) RULE_ANY_OTHER were disabled for that input
warning(209): ../de.example.flow.ui/src-gen/de/hs_rm/cs/vs/dsm/ui/contentassist/antlr/internal/InternalFlow.g:10186:1: Multiple token rules can match input such as "'b'": T51, RULE_ID, RULE_ANY_OTHER
As a result, tokens(s) RULE_ID,RULE_ANY_OTHER were disabled for that input
...


Probably that's a total no go in xtext? Somebody has an idea for a workaround? Thanks in advance!

Regards,
Michael
Re: Question about ANTLR and recursions [message #555857 is a reply to message #555844] Sun, 29 August 2010 17:07 Go to previous messageGo to next message
Henrik Lindberg is currently offline Henrik LindbergFriend
Messages: 2509
Registered: July 2009
Senior Member
You have to show the entire grammar as the part we are seeing does not
tell enough about what is going on.

Besides other issues, your BlockExpression is non repeating - you
probably want:
ifAction+=BlockExpression*

or
ifAction = BlockExpression

and make BlockExpression repeating
BlockExpression: expressions += (Variable | Statement | Loop |
ConditionalExpression)*;

Implementing an expression based language is a bit tricky - take a look
at the arithmetic example, and xbase. You can also look at the eclipse
b3 project which has a rich grammar.

Regards
- henrik

On 8/29/10 3:55 PM, Michael Frey wrote:
> Hi,
>
> I'm not sure but my ANTLR issue might be an recursion issue. So far,
> I've specified a language which consists upon variables, statements,
> functions, loops and conditions. While a block in my language could
> contain a variable, statement, loop or condition I've specified a block
> expression:
>
>
> BlockExpression:
> Variable | Statement | Loop | ConditionalExpression;
>
>
> The conditional expression itself is:
>
>
> ConditionalExpression:
> IfElseCondition | SwitchCaseCondition;
>
> IfElseCondition:
> 'if' '(' condition=Or ')' '{' ifAction+=BlockExpression
> '}' 'else' '{'
> elseAction+=BlockExpression
> '}';
>
> SwitchCaseCondition:
> 'switch' '(' condition=Or ')' '{' case+=(CaseStatement)* 'default' ':'
> default=Or
> '}';
>
> CaseStatement:
> 'case' condition=Or ':' action=Or;
>
>
> and I assume that the following part is the problem
>
>
> ...
> ifAction+=BlockExpression
> ...
> elseAction+=BlockExpression
>
>
> And that's the error I get while I generate the artifacts
>
>
> warning(205):
> ../de.example.flow.ui/src-gen/de/hs_rm/cs/vs/dsm/ui/contenta ssist/antlr/internal/InternalFlow.g:1:8:
> ANTLR could not analyze this decision in rule Tokens; often this is
> because of recursive rule references visible from the left edge of
> alternatives. ANTLR will re-analyze the decision with a fixed lookahead
> of k=1. Consider using "options {k=1;}" for that decision and possibly
> adding a syntactic predicate.
> warning(209):
> ../de.example.flow.ui/src-gen/de/hs_rm/cs/vs/dsm/ui/contenta ssist/antlr/internal/InternalFlow.g:10186:1:
> Multiple token rules can match input such as "'^'": RULE_ID, RULE_ANY_OTHER
> As a result, tokens(s) RULE_ANY_OTHER were disabled for that input
> warning(209):
> ../de.example.flow.ui/src-gen/de/hs_rm/cs/vs/dsm/ui/contenta ssist/antlr/internal/InternalFlow.g:10186:1:
> Multiple token rules can match input such as "'b'": T51, RULE_ID,
> RULE_ANY_OTHER
> As a result, tokens(s) RULE_ID,RULE_ANY_OTHER were disabled for that input
> ...
>
>
> Probably that's a total no go in xtext? Somebody has an idea for a
> workaround? Thanks in advance!
>
> Regards,
> Michael
Re: Question about ANTLR and recursions [message #555953 is a reply to message #555857] Mon, 30 August 2010 11:26 Go to previous message
Michael Frey is currently offline Michael FreyFriend
Messages: 48
Registered: August 2010
Member
Hi,

Quote:

You have to show the entire grammar as the part we are seeing does not tell enough about what is going on.



I will keep that in mind while I'm posting to the TMF forum. The multiplicty '*' seemed to fix my antlr issue.

Thanks!
Best regards,
Michael
Previous Topic:Improving xtext building
Next Topic:[XTEXT] Cannot create instance of abstract class
Goto Forum:
  


Current Time: Tue Sep 24 09:12:21 GMT 2024

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

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

Back to the top