1

我有一个单独的词法分析器和解析器语法(源自示例 ModeTagsLexer/ModeTagsParser)并在 AntlrWorks 2 中收到我不理解的警告:

警告(125):解析器中标记 OPEN 的隐式定义

如果我用警告替换OPEN规则'<'就会消失。OPEN我想知道和CLOSEist which get's no warning 有什么区别。

我正在使用 antlr-4.1-complete.jar 和 2013-01-22-antlrworks-2.0。

词法分析器 STLexer.g4:

lexer grammar STLexer;

// Default mode rules (the SEA)
OPEN  : '<'     -> pushMode(ISLAND) ;       // switch to ISLAND mode
TEXT  : ~'<'+ ;                         // clump all text together

mode ISLAND;
CLOSE : '>'     -> popMode ; // back to SEA mode
SLASH : '/' ;
ID    : [a-zA-Z0-9"=]+ ;                     // match/send ID in tag to parser
WS    : [ \t]+ -> channel(HIDDEN);

解析器 STParser.g4:

parser grammar STParser;

options { tokenVocab=STLexer; } // use tokens from STLexer.g4



unit: (tag | TEXT)* ;

tag : OPEN ID+ CLOSE
    | OPEN SLASH ID+ CLOSE
    ;

如果我稍微重命名规则并删除附加模式,它甚至会持续存在:

lexer grammar STLexer;

词法分析器(修改):

// Default mode rules (the SEA)
OPPEN  : '<'    ;// -> pushMode(ISLAND) ;       // switch to ISLAND mode
TEXT  : ~'<'+ ;                         // clump all text together

//mode ISLAND;
CLOSE : '>'  ; //   -> popMode ; // back to SEA mode
SLASH : '/' ;
ID    : [a-zA-Z0-9"=]+ ;                     // match/send ID in tag to parser
WS    : [ \t]+ -> channel(HIDDEN);

解析器(修改):

parser grammar STParser;

options { tokenVocab=STLexer; } // use tokens from STLexer.g4



unit: (tag | TEXT)* ;

tag : ID OPPEN ID+ CLOSE
    | ID OPPEN SLASH ID+ CLOSE
    ;
4

0 回答 0