2016-08-18 83 views
0

我已經創建了xtext語法並且有警告(見下文)我知道XText生成了ambigious ANTLR語法,但不明白爲什麼。 那麼,我的語法有什麼問題?XText生成unambigious語法

問候, 弗拉基米爾

grammar com.idc.net.Validator with org.eclipse.xtext.common.Terminals 

generate validator "http://www.idc.com/net/Validator" 

Model: 
    netDescriptions+=NetDescription+; 

NetDescription: 
    descriptionPairs+=DescriptionPair+; 

DescriptionPair: 
    IPADDR | NETMASK | SPEED | MTU | TSO | GATEWAY | VLAN | ROUTER | SUBNET | NO_VLANS | VLAN; 
//List of numbers with 3 digit 
VLAN: 
    'VLAN_' name=ID '=' 
    value=IntList; 

IntList: 
    valueList+=INT+ | '"' valueList+=INT+ '"'; 

IPAddrList: 
    ipNum1=INT '.' ipNum2=INT '.' ipNum3=INT '.' ipNum4=INT; 

//List of numbers with 3 digit 
NO_VLANS: 
    'NO_VLANS_' name=ID '=' list+=IntList; 

SUBNET: 
    'SUBNET_' name=ID '=' list+=IPWithQuotes; 

ROUTER: 
    'ROUTER_' name=ID '=' list+=IPWithQuotes; 

GATEWAY: 
    'GATEWAY_' name=ID '=' list+=IPWithQuotes; 

MTU: 
    'MTU_' name=ID '=' val=IntWithQuotes; 

TSO: 
    'TSO_' name=ID '=' '"' value=ON_OFF '"'; 

ON_OFF: 
    'on' | 'off'; 

NETMASK: 
    'NETMASK_' name=ID '=' list+=IPWithQuotes; 

SPEED: 
    'SPEED_' name=ID '=' value=IntWithQuotes; 

IPADDR: 
    'IPADDR_' name=ID '=' list+=IPWithQuotes; 

IPWithQuotes: 
    IPAddrList | '"' IPAddrList '"'; 

IntWithQuotes: 
    value=INT | '"' value=INT ' 

「「。

warning(200): ../com.idc.net.validator/src-gen/com/idc/net/parser/antlr/internal/InternalValidator.g:132:2: Decision can match input such as "'SPEED_'" using multiple alternatives: 1, 2 
As a result, alternative(s) 2 were disabled for that input 
warning(200): ../com.idc.net.validator/src-gen/com/idc/net/parser/antlr/internal/InternalValidator.g:132:2: Decision can match input such as "'GATEWAY_'" using multiple alternatives: 1, 2 
As a result, alternative(s) 2 were disabled for that input 
warning(200): ../com.idc.net.validator/src-gen/com/idc/net/parser/antlr/internal/InternalValidator.g:132:2: Decision can match input such as "'VLAN_'" using multiple alternatives: 1, 2 
As a result, alternative(s) 2 were disabled for that input 
warning(200): ../com.idc.net.validator/src-gen/com/idc/net/parser/antlr/internal/InternalValidator.g:132:2: Decision can match input such as "'IPADDR_'" using multiple alternatives: 1, 2 
As a result, alternative(s) 2 were disabled for that input 
warning(200): ../com.idc.net.validator/src-gen/com/idc/net/parser/antlr/internal/InternalValidator.g:132:2: Decision can match input such as "'MTU_'" using multiple alternatives: 1, 2 
As a result, alternative(s) 2 were disabled for that input 
warning(200): ../com.idc.net.validator/src-gen/com/idc/net/parser/antlr/internal/InternalValidator.g:132:2: Decision can match input such as "'TSO_'" using multiple alternatives: 1, 2 
As a result, alternative(s) 2 were disabled for that input 
warning(200): ../com.idc.net.validator/src-gen/com/idc/net/parser/antlr/internal/InternalValidator.g:132:2: Decision can match input such as "'NO_VLANS_'" using multiple alternatives: 1, 2 
As a result, alternative(s) 2 were disabled for that input 
warning(200): ../com.idc.net.validator/src-gen/com/idc/net/parser/antlr/internal/InternalValidator.g:132:2: Decision can match input such as "'NETMASK_'" using multiple alternatives: 1, 2 
As a result, alternative(s) 2 were disabled for that input 
warning(200): ../com.idc.net.validator/src-gen/com/idc/net/parser/antlr/internal/InternalValidator.g:132:2: Decision can match input such as "'ROUTER_'" using multiple alternatives: 1, 2 
As a result, alternative(s) 2 were disabled for that input 
warning(200): ../com.idc.net.validator/src-gen/com/idc/net/parser/antlr/internal/InternalValidator.g:132:2: Decision can match input such as "'SUBNET_'" using multiple alternatives: 1, 2 
As a result, alternative(s) 2 were disabled for that input 
warning(200): ../com.idc.net.validator/src-gen/com/idc/net/parser/antlr/internal/InternalValidator.g:150:2: Decision can match input such as "'VLAN_' RULE_ID '=' RULE_INT" using multiple alternatives: 7, 11 
As a result, alternative(s) 11 were disabled for that input 
warning(200): ../com.idc.net.validator/src-gen/com/idc/net/parser/antlr/internal/InternalValidator.g:150:2: Decision can match input such as "'VLAN_' RULE_ID '=' '"' RULE_INT '"'" using multiple alternatives: 7, 11 
As a result, alternative(s) 11 were disabled for that input 
error(201): ../com.idc.net.validator/src-gen/com/idc/net/parser/antlr/internal/InternalValidator.g:150:2: The following alternatives can never be matched: 11 

回答

0

有兩個問題

第一VLAN是兩次在列表中,它應該是

DescriptionPair: 
    IPADDR | NETMASK | SPEED | MTU | TSO | GATEWAY | VLAN | ROUTER | SUBNET | NO_VLANS; 

那麼你在這裏

Model: 
    netDescriptions+=NetDescription+; 

NetDescription: 
    descriptionPairs+=DescriptionPair+; 

列出問題清單,應該是要麼

Model: 
    netDescriptions=NetDescription; 

NetDescription: 
    descriptionPairs+=DescriptionPair+; 

Model: 
    netDescriptions+=NetDescription+; 

NetDescription: 
    descriptionPairs=DescriptionPair;