为具有一个字符的标识符定义antlr规则 [英] Defining antlr rule for identifiers with one character
问题描述
ID:('a'..'z'|'A'..'Z')+ ;
这有什么问题?
谢谢!
您是完全正确的,规则本身很好,但是我发现ANTLR中的很多内容都取决于规则的顺序.我之前有另一个规则,该规则已经与ID规则匹配.最终这是有道理的,因为Lexer无法决定采用哪个规则.
谢谢!
i like to define a very simple rule, which should represent identifiers. This works quite well for identifiers which are longer than one characters, but for identifiers with exactly one character I get a MismatchedTokenException(64!=45). This is the rule:
ID : ('a'..'z' | 'A'..'Z')+ ;
What is wrong with that?
Thanks!
You're absolutely right, the rule on its own is fine, but I figured out that a lot in ANTLR depends on the order of rules. I had another rule before, which did already match the ID rule. Finally it makes sense, because the Lexer cannot decide which rule to take.
Thanks!
这篇关于为具有一个字符的标识符定义antlr规则的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!