Getting started with ANTLR and avoiding common mistakes

微笑、不失礼 提交于 2019-12-03 06:41:38

I agree - ANTLR is not for the faint of heart. It does expect a high entry level, because grammars and parsers are not trivial.

With that said, here are a few suggestions:

  1. Forget about v2. Version 3 is the standard; don't even waste time considering the earlier version or its documentation.
  2. OutOfMemoryError is telling you that there's something circular in the grammar you've defined.
  3. IntelliJ has a wonderful IDE for working with ANTLR v3. It'll give you a graphical representation of your grammar, step-through debugging, etc. If you're going to be doing a lot of work with ANTLR it'd be worth a few dollars to buy a license.

ANTLR won't be easy to master. The book is good, but dense. The error messages are cryptic, as you've noted. I'd be surprised if anyone here could make it easy.

Sorry but my experience of ANTLR (indeed javacc, bison or any full function parser) is that most of your learning will be by fixing your own mistakes!

Getting good examples of other peoples code will cut this down somewhat, the best examples look really simple -- but you are missing all the sweat and hair pulling it took to get them looking that easy.

Even if you prefer command line, it is worth using AntlrWorks when you have problems. The diagramatic representation can make it easier to see what i sgoing wrong.

A picture is worth a thousand error messages.

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!