我想用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'|'_')*);
答案 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
应该放在首位。