How do I tokenize input using Java's Scanner class and regular expressions?

前端 未结 4 1570
北海茫月
北海茫月 2021-01-01 03:46

Just for my own purposes, I\'m trying to build a tokenizer in Java where I can define a regular grammar and have it tokenize input based on that. The StringTokenizer class i

4条回答
  •  轻奢々
    轻奢々 (楼主)
    2021-01-01 04:15

    Most of the answers here are already excellent but I would be remiss if I didn't point out ANTLR. I've created entire compilers around this excellent tool. Version 3 has some amazing features and I'd recommend it for any project that required you to parse input based on a well defined grammar.

提交回复
热议问题