« Return to Thread: Antlr v3 and Netbeans Lexer Integration

Re: Antlr v3 and Netbeans Lexer Integration

by Jeff Johnston-3 :: Rate this Message:

Reply to Author | View in Thread

>>1. I don't totally understand why you have have these methods empty:

I was just trying to adapt the JavaCC tutorial. They left it off and it seems to work fine without it.

http://wiki.netbeans.org/New_Language_Support_Tutorial_Antlr

>>2. There's another way of doing error handling of syntax errors in ANTLR...

My reasoning for not doing the @rulecatch way was I thought that ANTLR would report multiple errors for the same part of the syntax. The reason I thought this is further up the calling chain is this comment and early exit from the reportError() method. I didn't test out this assumption though, and if that is not the case then I like the clarity of the @rulecatch. Plus thinking about it, to really get good error messages for specific parts of the grammer I will probably have to use the @rulecatch on specific grammer methods. Thanks!

public void reportError(RecognitionException e) {
        // if we've already reported an error and have not matched a token
        // yet successfully, don't report any errors.
        if ( state.errorRecovery ) {
            //System.err.print("[SPURIOUS] ");
            return;
        }
       ...
}

I am not on the ANTLR mailing list but I probably should just to engage in the discussions.

This whole learning and integration of Netbeans and ANTLR has been a lot of fun as it is all very new to me! To figure this out I have my ANTLR book, 2 Netbeans books, as well as all the source code checked out for both projects. So then I just keep reading and digging and somehow manage to keep moving forward :). I woud probably feel reluctant to even post what I have done so far but ANTLR for Netbeans doesn't seem to be documented anywhere else so I figure this would at least push someone else in the right direction. As I get better at both and my editor gets better I will keep updating the wiki!

-Jeff Johnston


On Sun, Jul 5, 2009 at 6:11 PM, Andreas Stefik <stefika@...> wrote:
This looks great Jeff!

 I'll definitely be using some of the wiki info in my project.  Here's a couple thoughts:

1. I don't totally understand why you have have these methods empty:

public void addChangeListener(ChangeListener changeListener) {}
public void removeChangeListener(ChangeListener changeListener) {}

Does this have to do with ANTLR not being an incremental parser generator, or is this totally unrelated? All the documentation for the API says about these methods (posted here):

http://bits.netbeans.org/dev/javadoc/org-netbeans-modules-parsing-api/org/netbeans/modules/parsing/spi/Parser.html

for this method is "Registers new listener," which doesn't help very much. If you know something more it might be good to post info about it.

2. There's another way of doing error handling of syntax errors in ANTLR. The way Terrence Par talks about it in his book is to define an @rule catch block, which looks like this:

@rulecatch {
    catch(RecognitionException re) {
    }
}

What I usually do for projects like this (for good or ill), is to 1) create some general abstractions (e.g., compiler error manager classes), 2) catch all of the errors ANTLR outputs and send them to the abstractions. This usually makes it a bit easier to manage the errors, especially if you are implementing further stages in a compiler/virtual machine architecture. Anyway, that's all probably too much for your tutorial, but I thought I'd mention @rulecatch as an alternative error handling mechanism in case you'd never heard of it.

Great tutorial and thanks for posting it! If you aren't on the ANTLR mailing list, I can cross post it there. I image there's some folks there that would be interested in this as well.

Andreas

 « Return to Thread: Antlr v3 and Netbeans Lexer Integration