📄 check.java~356~
字号:
}
state = 0;
tknln = 0;
return tkn;
}
}
else
if(oneortwo==2){//If there is two operators,output '<=','>=','=='or'!='
oneortwo=0;
if(chr[forward-2]=='<'){
token tkn=new token("<=","Operator",line+1,position-1);//Output '<='
for(int count=tknln-1;count>=0;count--){
stringbuffer.deleteCharAt(count);
}
state = 0;
tknln = 0;
return tkn;
}
else
if(chr[forward-2]=='>'){
token tkn=new token(">=","Operator",line+1,position-1);//Output '>='
for(int count=tknln-1;count>=0;count--){
stringbuffer.deleteCharAt(count);
}
state = 0;
tknln = 0;
return tkn;
}
else
if(chr[forward-2]=='='){
token tkn=new token("==","Operator",line+1,position-1);//Output '=='
for(int count=tknln-1;count>=0;count--){
stringbuffer.deleteCharAt(count);
}
state = 0;
tknln = 0;
return tkn;
}
else
if(chr[forward-2]=='!'){
token tkn=new token("!=","Operator",line+1,position-1);//Output '!='
for(int count=tknln-1;count>=0;count--){
stringbuffer.deleteCharAt(count);
}
state = 0;
tknln = 0;
return tkn;
}
}
else
if(oneortwo>=3){//If there is three operators in sequence,output "Other"
oneortwo=0;
token tkn=new token(stringbuffer.toString(),"Other"+"\t",line+1,position-tknln+1);
for(int count=tknln-1;count>=0;count--){
stringbuffer.deleteCharAt(count);
}
state = 0;
tknln=0;
return tkn;
}
}
break;
case 8:
c=chr[forward];
++forward;
position++;
if(c=='<'){//Go to case 7 to check if it is '<='
state=7;
oneortwo++;
}
else{
state=9;
forward--;
position--;
}
break;
case 9:
c=chr[forward];
++forward;
position++;
if(c=='>'){//If it is '>' ,go to case 7
state=7;
oneortwo++;
}
else{
state=10;
forward--;
position--;
}
break;
case 10:
c=chr[forward];
++forward;
position++;
if(c=='!'){//If it is '!' ,go to case 10
state=7;
oneortwo++;
}
else{
state=11;
forward--;
position--;
}
break;
case 11: //delimiters ( { } ( ) ; )
c=chr[forward];
++forward;
position++;
if(c=='{'){
token tkn=new token("{","Delimiter",line+1,position);
state = 0;
return tkn;
}
else {
forward--;
position--;
state=12;
}
break;
case 12:
c=chr[forward];
++forward;
position++;
if(c=='}'){
token tkn=new token("}","Delimiter",line+1,position);
state = 0;
return tkn;
}
else {
forward--;
position--;
state=13;
}
break;
case 13:
c=chr[forward];
++forward;
position++;
if(c=='('){
token tkn=new token("(","Delimiter",line+1,position);
state = 0;
return tkn;
}
else {
forward--;
position--;
state=14;
}
break;
case 14:
c=chr[forward];
++forward;
position++;
if(c==')'){
token tkn=new token(")","Delimiter",line+1,position);
state = 0;
return tkn;
}
else {
forward--;
position--;
state=15;
}
break;
case 15:
c=chr[forward];
++forward;
position++;
if(c==';'){
token tkn=new token(";","Delimiter",line+1,position);
state = 0;
return tkn;
}
else {
forward--;
position--;
state=16;
}
break;
case 16:
c=chr[forward];
forward++;
position++;
if((Character.isDigit(c)||c=='.'||c=='E')&&oneortwo<=1){
if(c=='.'){
oneortwo++;
is_float=true;
is_exponent=false;
is_int=false;
}
else if(c=='E'){
is_exponent=true;
is_float=false;
is_int=false;
oneortwo++;
}
stringbuffer.append(c);
tknln++;
state=16;
}
else{
if ( (oneortwo >= 2) || chr[forward - 1] == '.' ||
chr[forward - 1] == 'E') {
token tkn = new token(stringbuffer.toString(), "Error", line + 1,
position - tknln );
for(int count=tknln-1;count>=0;count--){
stringbuffer.deleteCharAt(count);
}
forward--;
state=0;
tknln=0;
return tkn;
}
else {
if (is_float) {
token tkn = new token(stringbuffer.toString(), "FloatNumber",line + 1, position - tknln );
for(int count=tknln-1;count>=0;count--){
stringbuffer.deleteCharAt(count);
}
forward--;
is_float=false;
state=0;
tknln=0;
return tkn;
}
else
if (is_exponent) {
token tkn = new token(stringbuffer.toString(), "ExpNumber",
line + 1, position - tknln );
for(int count=tknln-1;count>=0;count--){
stringbuffer.deleteCharAt(count);
}
forward--;
is_exponent=false;
state=0;
tknln=0;
return tkn;
}
else
if(is_int==true)
{
token tkn = new token(stringbuffer.toString(), "IntNumber",
line + 1, position - tknln );
for(int count=tknln-1;count>=0;count--){
stringbuffer.deleteCharAt(count);
}
forward--;
state=0;
tknln=0;
return tkn;
}
else break;
}
}
break;
}
}
}
public int getforward(){
return forward;
}
public int getchrnum(){
return chrnum;
}
public void charforward(){ //for the time that the stringbuffer used
tknln++;
++forward;
position++;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -