当我在 ANTLRWorks 3.4 中调试语法时,它给了我以下错误,
javax.swing.text.BadLocationException: Position not represented by view
下面列出了给出上述错误的语法。
grammar CMinusMinus;
program : (vardeclaration | fundeclaration)* EOF ;
vardeclaration : INT ID (OPENSQ NUM CLOSESQ)? SEMICOL ;
fundeclaration : typespecifier ID OPENP params CLOSEP compoundstmt ;
typespecifier : INT | VOID ;
params : VOID | paramlist ;
paramlist : param (COMMA param)* ;
param : INT ID (OPENSQ CLOSESQ)? ;
compoundstmt : OPENCUR vardeclaration* statement* CLOSECUR ;
statementlist : statement* ;
statement : expressionstmt | compoundstmt | selectionstmt
| iterationstmt | returnstmt ;
expressionstmt : (expression)? SEMICOL ;
selectionstmt : IF OPENP expression CLOSEP statement
( (ELSE)=> ELSE statement
| ( )
)
;
iterationstmt : WHILE OPENP expression CLOSEP statement ;
returnstmt : RETURN (expression)? SEMICOL ;
expression : (var ASSIGN) => var ASSIGN expression
| simpleexpression ;
var : ID ( OPENSQ expression CLOSESQ )? ;
simpleexpression: addexpr ( ( LOREQ | LESS | GRTR | GOREQ | EQUAL | NTEQL) addexpr)? ;
addexpr : mulexpr ( ( PLUS | MINUS ) mulexpr)* ;
mulexpr : factor ( ( MULTI | DIV ) factor )* ;
factor : ( OPENP expression CLOSEP ) | var | call | NUM ;
call : ID OPENP arglist? CLOSEP ;
arglist : expression ( COMMA expression)* ;
ELSE : 'else' ;
IF : 'if' ;
INT : 'int' ;
RETURN : 'return' ;
VOID : 'void' ;
WHILE : 'while' ;
PLUS : '+' ;
MINUS : '-' ;
MULTI : '*' ;
DIV : '/' ;
LESS : '<' ;
LOREQ : '<=' ;
GRTR : '>' ;
GOREQ : '>=' ;
EQUAL : '==' ;
NTEQL : '!=' ;
ASSIGN : '=' ;
SEMICOL : ';' ;
COMMA : ',' ;
OPENP : '(' ;
CLOSEP : ')' ;
OPENSQ : '[' ;
CLOSESQ : ']' ;
OPENCUR : '{' ;
CLOSECUR: '}' ;
SCOMMENT: '/*' ;
ECOMMENT: '*/' ;
ID : ('a'..'z' | 'A'..'Z')+/*(' ')*/ ;
NUM : ('0'..'9')+ ;
WS : (' ' | '\t' | '\n' | '\r'/* | '\f'*/)+ {$channel = HIDDEN;};
COMMENT: '/*' .* '*/' {$channel = HIDDEN;};
测试文件是,
/* A program to perform selection sort on a 10
element array. */
int x[10];
int miniloc ( int a[], int low, int high )
{ int i, int x, int k;
if (a<b)
if (b<c)
b=0;
else
c=0;
else
a=0;
k= low;
x = a[low];
i = low + 1;
while ( i < high)
{ if (a[i] < x)
{ x= a[i];
k= i;}
i = i+1;
}
return k;
}
void sort( int a[], int low, int high)
{ int i, int k;
i = low;
while (i < high - 1)
{ int t;
k = minloc(a,i,high);
t = a[k];
a[k] = a[i];
a[i] = t;
i = i+1;
}
}
void main(void)
{
int i;
i = 0;
while (i < 10)
{ x[i] = input();
i = i+1;}
sort(x, 0, 10);
i=0;
while(i<10)
{ output(x[i]);
i = i + 1;}
}
有没有办法解决这个错误。这通常是如何发生的
谢谢你。