user2326533
user2326533

Reputation: 1

The interpreter is disabled

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'|'_')*);

Upvotes: 0

Views: 102

Answers (1)

Lex Li
Lex Li

Reputation: 63203

Change from

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;
}

to

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);
    }
}

and try again. option should be put at top.

Upvotes: 1

Related Questions