2016-01-13 111 views
0

我目前正在研究Xtext語法,並用左遞歸圖得到了一些問題。我已經消除了所有直接左遞歸在我的語法,但現在我有一些間接的左遞歸,這是在與消息This rule call is part of a left recursive call graph.刪除左遞歸調用圖

這裏的IDE顯示的是我的問題的一個例子:

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; 

我該如何解決這樣的左遞歸?

回答

0

這個語法不是真的被考慮在內。它非常模糊。 在這裏得到這個運行是一個起點(忽略含糊不清和一些東西)

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"));