问题:无法正确打印Unicode字符。
这是我的语法:
options { k=1; filter=true;
// Allow any char but \uFFFF (16 bit -1)
charVocabulary='\u0000'..'\uFFFE';
}
ANYCHAR :'$'
| '_' { System.out.println("Found underscore: "+getText()); }
| 'a'..'z' { System.out.println("Found alpha: "+getText()); }
| '\u0080'..'\ufffe' { System.out.println("Found unicode: "+getText()); }
;
调用lexer的主方法的代码段:
public static void main(String[] args) {
SimpleLexer simpleLexer = new SimpleLexer(System.in);
while(true) {
try {
Token t = simpleLexer.nextToken();
System.out.println("Token : "+t);
} catch(Exception e) {}
}
}
用于输入
“γ”
,我得到以下输出:
Found unicode:
Token : ["Ã ",<5>,line=1,col=7]
Found unicode:
Token : ["¤",<5>,line=1,col=8]
Found unicode:
Token : [" ",<5>,line=1,col=9]
似乎lexer将unicode字符“_”视为三个单独的字符。我的目标是扫描并打印“_”。