【问题标题】:left recursion with xtext使用 xtext 进行左递归
【发布时间】:2018-07-12 00:24:40
【问题描述】:

我在使用 xtext 时遇到了一个大问题,我真的不知道如何解决它,所以我正在使用一小部分语法:

typename:
    IDENTIFIER=IDENTIFIER | qualified_ident=qualified_ident
;

qualified_ident:
    packagename "." IDENTIFIER
;

packagename:
    IDENTIFIER
;

terminal IDENTIFIER: 
    LETTER (LETTER | DECIMAL_DIGIT)*
;

terminal LETTER:
    'a' .. 'z' | 'A' .. 'Z' | "_"
;

terminal DECIMAL_DIGIT:
    '0' .. '9'
;

还有我在 Eclipse 上遇到的错误:

error(211): ../org.xtext.example.mydsl/src- 
gen/org/xtext/example/mydsl/parser/antlr/internal/InternalMyDsl.g:7253:2: 
[fatal] rule ruletypename has non-LL(*) decision due to recursive rule 
invocations reachable from alts 1,2.  Resolve by left-factoring or using 
syntactic predicates or using backtrack=true option.

它说语法已经离开递归,但我看不到它,我不知道如何解决这个问题。我在整个语法上都遇到了这样的问题,但我相信如果有人向我解释如何解决这个问题,我可以解决剩下的问题。

更新:你可以看到整个语法here

【问题讨论】:

标签: grammar xtext left-recursion


【解决方案1】:

您可以按如下方式更改工作流程

    language = StandardLanguage {
        name = "org.xtext.example.mydsl2.MyDsl"
        ...

        parserGenerator = {
            debugGrammar = true
        }
    }

然后使用ANTLRworks 3x版找出左递归在哪里

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2013-08-03
    • 1970-01-01
    • 2011-06-04
    • 2018-11-02
    • 2015-02-02
    • 2012-07-08
    • 1970-01-01
    相关资源
    最近更新 更多