2013-04-27 43 views
0

我想創建一個簡單的編譯器,使用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

變化從

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應放在頂部。