解释器已禁用

时间:2013-04-27 10:05:02

标签: antlr antlr3

我想用ANTLR 3.5和java 1.6 +创建一个简单的编译器我添加了jar文件但我收到此错误并且“理由无法创建语法”但我不明白为什么有任何帮助?这不是整个代码,但我尝试按位编码,但仍然没有编译

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

1 个答案:

答案 0 :(得分: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应该放在首位。