本文介绍了为什么将令牌分配给通道时出现错误?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的 .g4 文件中有以下代码.

I have the following code in my .g4 file.

@lexer::members{
public static final int WHITESPACE = 1;
public static final int COMMENTS = 2;
}


WS :  (' '|'\t'|'\f')+ -> channel(WHITESPACE)
   ;

COMMENT
    :   '//' ~('\n'|'\r')* -> channel(COMMENTS)
    ;

LINE_COMMENT
    :   '/*' .*? '*/' NEWLINE? -> channel(WHITESPACE)
    ;

我收到以下错误:

warning(155): Shiro.g4:239:34: 规则 'WS' 包含一个具有无法识别的常量值的词法分析器命令;词法分析器解释器可能会产生不正确的输出

warning(155): Shiro.g4:243:38: 规则COMMENT"包含一个词法分析器命令,该命令具有无法识别的常量值;词法分析器解释器可能会产生不正确的输出

warning(155): Shiro.g4:243:38: rule 'COMMENT' contains a lexer command with an unrecognized constant value; lexer interpreters may produce incorrect output

warning(155): Shiro.g4:247:42: rule 'LINE_COMMENT' 包含一个无法识别的常量值的词法分析器命令;词法分析器解释器可能会产生不正确的输出

warning(155): Shiro.g4:247:42: rule 'LINE_COMMENT' contains a lexer command with an unrecognized constant value; lexer interpreters may produce incorrect output

这是 Terrence 在 ANTLR4 书中描述的将令牌放在不同通道上的技术.为什么我会收到这些警告?我应该担心吗?

This is the technique described by Terrence in the ANTLR4 book to put tokens on separate channels. Why am I getting these warnings? Should I be concerned?

推荐答案

您没有收到错误;这是一个警告.特别是,它是 UNKNOWN_LEXER_CONSTANT 警告,这是 ANTLR 4.2 的新功能.

You are not receiving an error; it is a warning. In particular, it is the UNKNOWN_LEXER_CONSTANT warning, which is new to ANTLR 4.2.

编译器警告 155.

rule 'rule' 包含一个带有无法识别的常量值的词法分析器命令;词法分析器解释器可能会产生不正确的输出

rule 'rule' contains a lexer command with an unrecognized constant value; lexer interpreters may produce incorrect output

词法分析器规则包含标准词法分析器命令,但该命令的常量值参数是无法识别的字符串.因此,词法分析器命令将被转换为自定义词法分析器操作,从而阻止该命令在某些解释模式下执行.词法分析器的输出可能与生成的词法分析器的输出不匹配.

A lexer rule contains a standard lexer command, but the constant value argument for the command is an unrecognized string. As a result, the lexer command will be translated as a custom lexer action, preventing the command from executing in some interpreted modes. The output of the lexer interpreter may not match the output of the generated lexer.

以下规则产生此警告.

@members {
public static final int CUSTOM = HIDDEN + 1;
}

X : 'foo' -> channel(HIDDEN);           // ok
Y : 'bar' -> channel(CUSTOM);           // warning 155

这篇关于为什么将令牌分配给通道时出现错误?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-24 10:37