规则未得到承认

时间:2014-08-06 20:27:23

标签: eclipse xtext ambiguous-grammar

我写了一个语法,应该允许我定义变量和数组。一切正常,直到我将变量分成局部变量和全局变量。现在我的解析器不再识别数组(它说它将是一个变量,并为此提供语法错误)。

我的语法:

grammar sqf.Sqf with org.eclipse.xtext.common.Terminals

generate sqf "http://www.Sqf.sqf" 

Model:
    elements += Element*
;

    Element:
        Declaration ";" | Command ";"
    ;

        Declaration:
            Array | Variable
        ;

            Variable:
                LocalVariable | GlobalVariable
            ;

            LocalVariable:
                name=LOCALVARNAME "=" content=VARCONTENT (("+"|"-"|"*"|"/") content2+=VARCONTENT)*
            ;

            GlobalVariable:
                name=GLOBALVARNAME "=" content=VARCONTENT (("+"|"-"|"*"|"/") content2+=VARCONTENT)*
            ;


            Array:
                name=ID "=" content=ArrayLiteral | name=ID "=" "+" content2=[Array]
            ;

                ArrayLiteral:
                    "[" (content += ArrayContent)* "]" (("+"|"-")content1+=Extension)*
                ;

                    ArrayContent:
                        content01=Acontent ("," content02+=Acontent)*
                    ;

                        Acontent:
                            STRING | DOUBLE | ArrayLiteral
                        ;

                    Extension:
                        STRING | DOUBLE
                    ;




    Command:
        Interaction
    ;

        Interaction:
            hint
        ;

            hint:
                Normal | Format | Special
            ;

                Normal:
                    name=("hint" | "hintC" | "hintCadet" | "hintSilent") content=STRING
                ;

                Format:
                    name=("hint" | "hintC" | "hintCadet" | "hintSilent") "format" "[" content=STRING "," variable=DECREF "]"
                ;

                Special:
                    hintCArray
                ;

                    hintCArray:
                        title=STRING "hintC" (content1=ArrayLiteral | content=STRING)
                    ;


VARCONTENT:
    STRING | DOUBLE | DECREF | "true" | "false" | "nil"
;

DOUBLE:
    INT ("."INT)?
;

DECREF:
    ref1=[Array|ID] | ref2=[LocalVariable|LOCALVARNAME] | ref3=[GlobalVariable|GLOBALVARNAME]
;

terminal LOCALVARNAME:
    "_" ('a'..'z'|'A'..'Z') ('a'..'z'|'A'..'Z'|'_'|'0'..'9')*
;

terminal GLOBALVARNAME:
    '^'?('a'..'z'|'A'..'Z') ('a'..'z'|'A'..'Z'|'_'|'0'..'9')*
;

你们有谁知道问题是什么? (也欢迎任何其他代码改进)
迎接Krzmbrzl

1 个答案:

答案 0 :(得分:0)

您的规则GLOBALVARNAME完全隐藏规则ID。您只需使用ID而不是GLOBALVARNAME。