antlr / antlr4

ANTLR (ANother Tool for Language Recognition) is a powerful parser generator for reading, processing, executing, or translating structured text or binary files.
http://antlr.org
BSD 3-Clause "New" or "Revised" License
17.01k stars 3.26k forks source link

Antlr 3.4 error compiling to Java target #65

Closed rajah9 closed 12 years ago

rajah9 commented 12 years ago

I am getting a Java compile error on a grammar.

I'm using Eclipse Indigo SR2 and these plugins:

I am having Eclipse place the generated Java code in a package antlr-generated. The build path for antlr-generated includes antlr-3.4-complete.jar.

Here is my grammar:

/* Entry point */
 8: swiftMessage: block4 ;

10: block4: STARTBLOCK '4:' tag_value_pair+ ENDMESSAGEBLOCK ;

12: tag_value_pair :   NEWLINE tag value ;

16: tag :  COLON '1'..'9' '0'..'9' ('A'..'Z')?  ;

18: value :   COLON ('a'..'z' | 'A'..'Z' | '0'..'9' | ' ' | ',' | '.' )* ;

20: STARTBLOCK : '{' ;

22: ENDMESSAGEBLOCK : '-}' ;

24: NEWLINE : '\n' ;

26: COLON: ':' ; 

Here is the generated SwiftBugParser code (portions of comments ommitted):

    // $ANTLR start "tag"
    // \\SwiftBug.g:16:1: tag : COLON '1' .. '9' '0' .. '9' ( 'A' .. 'Z' )? ;
    public final void tag() throws RecognitionException {
        try {
            // \\SwiftBug.g:16:5: ( COLON '1' .. '9' '0' .. '9' ( 'A' .. 'Z' )? )
            // \\SwiftBug.g:16:8: COLON '1' .. '9' '0' .. '9' ( 'A' .. 'Z' )?
            {
            match(input,COLON,FOLLOW_COLON_in_tag68); 

            matchRange('1','9');  // FIRST ERROR, LINE 193

            matchRange('0','9');  // SECOND ERROR, LINE 195

            // \\SwiftBug.g:16:32: ( 'A' .. 'Z' )?
            int alt2=2;
            int LA2_0 = input.LA(1);

            if ( () ) {           // THIRD ERROR, LINE 201
                alt2=1;
            }
            switch (alt2) {
                case 1 :
                    // \\SwiftBug.g:
                    {
                    if (  ) {     // FOURTH ERROR, LINE 208
                        input.consume();
                        state.errorRecovery=false;
                    }
                    else {
                        MismatchedSetException mse = new MismatchedSetException(null,input);
                        throw mse;
                    }

                    }
                    break;

            }

            }

        }
        catch (RecognitionException re) {
            reportError(re);
            recover(input,re);
        }

        finally {
            // do for sure before leaving
        }
        return ;
    }
    // $ANTLR end "tag"

I am getting these four Java compilation errors:

Description Resource    Path    Location    Type
The method matchRange(char, char) is undefined for the type SwiftBugParser  SwiftBugParser.java /SwiftMessage/antlr-generated   line 193    Java Problem
The method matchRange(char, char) is undefined for the type SwiftBugParser  SwiftBugParser.java /SwiftMessage/antlr-generated   line 195    Java Problem
Syntax error on token "(", Expression expected after this token SwiftBugParser.java /SwiftMessage/antlr-generated   line 201    Java Problem
Syntax error on token "(", Expression expected after this token SwiftBugParser.java /SwiftMessage/antlr-generated   line 208    Java Problem
sharwell commented 12 years ago

This repository is for ANTLR v4. I believe you are looking for antlr/antlr3.