Question about ANTLR and recursions [message #555844] |
Sun, 29 August 2010 13:55 |
Michael Frey 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 |
Henrik Lindberg 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
|
|
|
|
Powered by
FUDForum. Page generated in 0.02899 seconds