【发布时间】:2015-03-29 12:47:52
【问题描述】:
我的语法中有一个循环,它会产生以下错误消息
Error: Line 395, Column 1: Left recursion detected:
"PostfixExpression... --> FunctionCall... --> FunctionCallOrMethod... --> FunctionCallGeneric... --> FunctionCallHeaderWithParameters... --> FunctionCallHeader... --> FunctionIdentifier... --> PostfixExpression..."
Detected 1 errors and 1 warnings.
来自以下语法
void PostfixExpression() : {}
{
/* recursive version:
PrimaryExpression()
| PostfixExpression() <LEFT_BRACKET> IntegerExpression() <RIGHT_BRACKET>
| FunctionCall()
| PostfixExpression() <DOT> FieldSelection()
| PostfixExpression() <INC_OP>
| PostfixExpression() <DEC_OP>
*/
PrimaryExpression() [PostfixExpressionPrime()]
| FunctionCall() [PostfixExpressionPrime()]
}
void PostfixExpressionPrime() : {}
{
<LEFT_BRACKET> IntegerExpression() <RIGHT_BRACKET> [PostfixExpressionPrime()]
| <DOT> FieldSelection() [PostfixExpressionPrime()]
| <INC_OP> [PostfixExpressionPrime()]
| <DEC_OP> [PostfixExpressionPrime()]
}
void FunctionCall() : {}
{
FunctionCallOrMethod()
}
void FunctionCallOrMethod() : {}
{
FunctionCallGeneric()
}
void FunctionCallGeneric() : {}
{
FunctionCallHeaderWithParameters() <RIGHT_PAREN>
| FunctionCallHeaderNoParameters() <RIGHT_PAREN>
}
void FunctionCallHeaderWithParameters() : {}
{
/* recursive version:
FunctionCallHeader() AssignmentExpression()
| FunctionCallHeaderWithParameters() <COMMA> AssignmentExpression()
*/
FunctionCallHeader() AssignmentExpression() [FunctionCallHeaderWithParametersPrime()]
}
void FunctionCallHeaderWithParametersPrime() : {}
{
<COMMA> AssignmentExpression() [FunctionCallHeaderWithParametersPrime()]
}
void FunctionCallHeader() : {}
{
FunctionIdentifier() <LEFT_PAREN>
}
void FunctionIdentifier() : {}
{
TypeSpecifier()
| PostfixExpression()
}
我可以应用某种算法来消除这个问题吗?如果没有,在这种情况下我该怎么做?
【问题讨论】:
标签: javacc