Javacode production.

Power Java
Parsing With JavaCC
by Steve Kapp
Listing 4. Javacode production.


01    JAVACODE void skip_to_matching_brace() {
02        Token tok;
03        int nesting = 1;
04        while (true) {
05            tok = getToken(1);
06            if (tok.kind == LBRACE) nesting++;
07            if (tok.kind == RBRACE) {
08                nesting-;
09                if (nesting == 0) break;
10            }
11            tok = getNextToken();
12        }
13    }
14    void matchBraces() : { } {
15        "{" skip_to_matching_brace()
16    }

About the Author

Steve Kapp is a client partner at EMRT in Rochester, NY. Steve can be contacted at [email protected].