Parsing Java code with Java

前端 未结 5 1236
予麋鹿
予麋鹿 2021-01-29 11:32

Is it possible to parse some Java code with a regex?

So let\'s say I want a list of the int variables from this:



        
5条回答
  •  悲&欢浪女
    2021-01-29 11:52

    I would recommend you look into parser generators, eg. JavaCC. JavaCC lets you describe the grammar in an BNF-like style and creates Java classes according to it. There are also already grammars available for JavaCC to parse Java code, I think even as an example or tutorial that comes with JavaCC.

提交回复
热议问题