Experience with JavaCC parser for Language API plug-in?

I'm looking to make a plugin for a language which already has a JavaCC
grammar defined. I wonder if anyone has gotten a JavaCC grammar to work
as the lexer and parser for a Language plug-in. I'm not familiar with
parser generation or much of this stuff so I don't know how I would even
integrate them so I hope someone has some experience and can help me.

Thanks

6 comments
Comment actions Permalink

Keith Lea wrote:

I'm looking to make a plugin for a language which already has a JavaCC
grammar defined. I wonder if anyone has gotten a JavaCC grammar to work
as the lexer and parser for a Language plug-in. I'm not familiar with
parser generation or much of this stuff so I don't know how I would even
integrate them so I hope someone has some experience and can help me.


This is probably not very helpful, but I found ANTLR much easier to
understand than JavaCC. It requires a runtime library though (not sure
if JavaCC does).

Ciao,
Gordon

--
Gordon Tyler (Software Developer)
Quest Software <http://www.quest.com/>
260 King Street East, Toronto, Ontario M5A 4L5, Canada
Voice: (416) 933-5046 | Fax: (416) 933-5001

0
Comment actions Permalink

Jython uses JavaCC for its parsing. I'd like to use the same parser.

Gordon Tyler wrote:

Keith Lea wrote:

>> I'm looking to make a plugin for a language which already has a JavaCC
>> grammar defined. I wonder if anyone has gotten a JavaCC grammar to
>> work as the lexer and parser for a Language plug-in. I'm not familiar
>> with parser generation or much of this stuff so I don't know how I
>> would even integrate them so I hope someone has some experience and
>> can help me.


This is probably not very helpful, but I found ANTLR much easier to
understand than JavaCC. It requires a runtime library though (not sure
if JavaCC does).

Ciao,
Gordon


0
Comment actions Permalink

Any luck with JavaCC and IDEA?

I, too, work on a project with an existing JavaCC grammar and would like to work on it from within IDEA. More importantly, I'd like IDEA to know to generate the Java class sources from the JavaCC input files so that I need not go outside of IDEA for an extra build step.

0
Comment actions Permalink

B. K. Oxley (binkley) wrote:

Any luck with JavaCC and IDEA?

I, too, work on a project with an existing JavaCC grammar and would like to
work on it from within IDEA. More importantly, I'd like IDEA to know to
generate the Java class sources from the JavaCC input files so that I need
not go outside of IDEA for an extra build step.


Maxim Shafirov said that existing parsers like JavaCC do not build an AST if
errors are present in the file, which is incompatible with IDEA's
parse-as-you-type system.

However, I think your best bet for running javacc as part of your build step is
to use Ant, and to make an Ant target which runs before or after you compile.

0
Comment actions Permalink

have you been able to integrate ANTLR into a language plugin?

0
Comment actions Permalink

Hello Bryan,

have you been able to integrate ANTLR into a language plugin?


In general it is not recommended to use ANTLR for language plugins because
most ANTLR grammars don't handle error recovery well (if you have an error
in the middle of the file, the rest of the file could not be parsed at all).
This is more or less OK for tools like compilers, but not OK for IDEs where
the normal state of code is syntactically invalid (in the middle of typing).

Of course you can probably build a grammar to handle this, but in our experience
it's simpler to write a recursive-descent parser by hand. It's tedious, but
it's not hard, and implementing error recovery is very simple.

--
Dmitry Jemerov
Development Lead
JetBrains, Inc.
http://www.jetbrains.com/
"Develop with Pleasure!"


0

Please sign in to leave a comment.