1

我目前正在研究一种Xtext语法,并遇到了左递归图的一些问题。我已经在我的语法中消除了所有直接左递归,但现在我有一些间接左递归,它们在 IDE 中显示为消息This rule call is part of a left recursive call graph.

这是我的问题的一个例子:

grammar com.stackoverflow.Example with org.eclipse.xtext.common.Terminals

generate example "http://stackoverflow.com/Example"

Type:
    var157=ValueType | var158=ReferenceType;

ValueType:
    var160=StructType | var161=EnumType;

StructType:
    var162=TypeName | var163=SimpleType | var164=NullableType;

TypeName:
    var165=ID;

SimpleType:
    var166=NumericType | "bool";

NumericType:
    "decimal";

NullableType:
    var169=NonNullableValueType "?";

NonNullableValueType:
    var170=Type;

EnumType:
    var171=TypeName;

ReferenceType:
    var172=ClassType | var173=InterfaceType | var174=ArrayType;

ClassType:
    var176=TypeName | "object" | "dynamic" | "string";

InterfaceType:
    var177=TypeName;

ArrayType:
    var178=NonArrayType "[]";

NonArrayType:
    var180=Type;

我怎样才能解决这样的左递归?

4

1 回答 1

1

这个语法并不是真正的左因素。它是高度模棱两可的。在这里运行是一个起点(忽略歧义并遗漏一些东西)

Type:
    ReferenceType;

TypeName returns Type:
    var165=ID;

ReferenceType returns Type:
     ClassType (({NullableType.type=current} "?") | ({ArrayType.componentType=current} "[]"))*;

ClassType returns Type:
    TypeName | ({ClassType} type=("object" | "dynamic" | "string"));
于 2016-01-13T20:02:15.623 回答