0

I wanted to create a simple compiler using ANTLR 3.5 and java 1.6 + I added jar files but I am getting this error and "Reason could not create a grammar" but I don't understand why any help? It is not the whole code but I tried to the code by bits and it is still not compiling

grammar LittleNic;
@members {
    public ErrorReporter err;
    public void displayRecognitionError(String[] tokenNames,
                                        RecognitionException e) {
      String msg = getErrorMessage(e, tokenNames);
      err.reportSyntaxError(e.line, e.charPositionInLine, msg);
    }
}

@lexer::members {
    public ErrorReporter err;
    public void displayRecognitionError(String[] tokenNames,
                                        RecognitionException e) {
        String msg = getErrorMessage(e, tokenNames);
    err.reportSyntaxError(e.line, e.charPositionInLine, msg);
    }
}

options {
  language = Java;
}

program: 'PROGRAM' IDEN ';' (dec (';' dec)*)? body ';' ;
dec:' ';
body: 'BEGIN' statementlist 'END';
statementlist:' ';



fragment FIRSTS: 'a'..'z'|'A'..'Z';
IDEN: (FIRSTS(FIRSTS|'0'..'9'|'_')*);
4

1 回答 1

1

从改变

grammar LittleNic;
@members {
    public ErrorReporter err;
    public void displayRecognitionError(String[] tokenNames,
                                        RecognitionException e) {
      String msg = getErrorMessage(e, tokenNames);
      err.reportSyntaxError(e.line, e.charPositionInLine, msg);
    }
}

@lexer::members {
    public ErrorReporter err;
    public void displayRecognitionError(String[] tokenNames,
                                        RecognitionException e) {
        String msg = getErrorMessage(e, tokenNames);
    err.reportSyntaxError(e.line, e.charPositionInLine, msg);
    }
}

options {
  language = Java;
}

grammar LittleNic;

options {
  language = Java;
}

@members {
    public ErrorReporter err;
    public void displayRecognitionError(String[] tokenNames,
                                        RecognitionException e) {
      String msg = getErrorMessage(e, tokenNames);
      err.reportSyntaxError(e.line, e.charPositionInLine, msg);
    }
}

@lexer::members {
    public ErrorReporter err;
    public void displayRecognitionError(String[] tokenNames,
                                        RecognitionException e) {
        String msg = getErrorMessage(e, tokenNames);
    err.reportSyntaxError(e.line, e.charPositionInLine, msg);
    }
}

然后再试一次。option应该放在最上面。

于 2013-06-03T06:46:45.017 回答