" FOLLOW_set_in_" ...在生成的解析器未定义 [英] "FOLLOW_set_in_"... is undefined in generated parser

查看:229
本文介绍了" FOLLOW_set_in_" ...在生成的解析器未定义的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经写了隐约类似Java的DSL语法。虽然还存在一些问题,它(它不承认所有的投入,因为我希望它),什么最关心我的是生成的C code不是编译。

I have written a grammar for vaguely Java-like DSL. While there are still some issues with it (it doesn't recognize all the inputs as I would want it to), what concerns me most is that the generated C code is not compilable.

我用AntlrWorks 1.5 ANTLR的3.5(4 ANTLR的显然不支持C的目标)。

I use AntlrWorks 1.5 with Antlr 3.5 (Antlr 4 apparently does not support C target).

问题是,与前pression规则。我有规则prio14Ex pression到prio0Ex pression其处理运营商precedence。以问题为优先级2,其计算preFIX和后缀运算符:

The problem is with expression rules. I have rules prio14Expression to prio0Expression which handle operator precedence. To problem is at priority 2, which evaluates prefix and postfix operators:

...
prio3Expression: prio2Expression (('*' | '/' | '%') prio2Expression)*;

prio2Expression: ('++' | '--' | '!' | '+' | '-')* prio1Expression ('++' | '--')*;  

prio1Expression:
    prio0Expression (
        ('.' prio0Expression) |
        ('(' (expression (',' expression)*)? ')') |
        ('[' expression (',' expression)* ']')
    )*;

prio0Expression: 
    /*('(') => */('(' expression ')') |
    IDENTIFIER |
    //collectionLiteral |
    coordinateLiteral |
    'true' |
    'false' |
    NUMBER |
    STRING 
    ;
...

防爆pression是prio14Ex pression的标签。你可以看到完整的语法<一个href=\"https://$c$c.google.com/p/geogen/source/browse/branches/ggs/src/GeoGen/Grammar/GeoGenScript.g?spec=svn1209&r=1209\">here.

在code一代本身是成功的(没有任何错误或严重警告)。它产生以下code:

The code generation itself is successful (without any errors or serious warnings). It generates following code:

CONSTRUCTEX();
EXCEPTION->type         = ANTLR3_MISMATCHED_SET_EXCEPTION;
EXCEPTION->name         = (void *)ANTLR3_MISMATCHED_SET_NAME;
EXCEPTION->expectingSet = &FOLLOW_set_in_prio2Expression962;

RECOVERFROMMISMATCHEDSET(&FOLLOW_set_in_prio2Expression962);
goto ruleprio2ExpressionEx;

不与错误打造错误5错误C2065:FOLLOW_set_in_prio2Ex pression962':未声明的标识符

难道我做错事的语法?没有其他规则会导致这个错误,如果我有点改写有关规则,生成code是有效的(但随后的语法并不做什么,我希望它)。我能做些什么来解决这个问题?

Did I do something wrong in the grammar? No other rules cause this error and if I somewhat reformulate the rule concerned, the generated code is valid (but then the grammar doesn't do what I want it to). What can I do to fix this issue?

感谢您的帮助。

推荐答案

我遇到过同样的问题。

我觉得它发生,如果解析器规则有简单的OR-ED令牌这样的一部分:

I think it happens if parser rule has a part of simple OR-ed token like this:

problem_case: problematic_rule;
problematic_rule: 'A' | 'B' ;

如果是词法规则这不会发生。

This doesn't happen if it is lexer rule.

workaround1: As_lexer_rule;
As_lexer_rule: 'A' | 'B' ;

或者,如果它是复杂的规则(不是简单的OR-ED令牌)。

Or, if it is complicated rule (not simple OR-ed token).

workaround2: make_it_complicated_needlessly;
make_it_complicated_needlessly: 'A' | 'B' | {false}? NeverUsedRule;
NeverUsedRule: /* don't care*/ ;

(我用语义predicate{}假的?对于这个修改。
我相信,它不会改变目标语言的语法。)

( I used semantic predicate "{false}?" for this modification. I believe it doesn't change the grammar of target language.)

这篇关于&QUOT; FOLLOW_set_in_&QUOT; ...在生成的解析器未定义的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆