📄 simplestructurecheckexpr.java
字号:
/* * Copyright (C) 2003-2008 Wang Pengcheng <wpc0000@gmail.com> * Permission is granted to copy, distribute and/or modify this * document under the terms of the GNU Free Documentation License, * Version 2.0 or any later version published by the Free Software Foundation; * with no Invariant Sections. * You may obtain a copy of the License at * http://www.gnu.org/licenses/lgpl.txt *///1 Mar 2008package cn.edu.whu.iss.algorithm.unit10.expression.structure;import static cn.edu.whu.iss.algorithm.unit10.expression.structure.AbstractErrorInforInExpr.*;public class SimpleStructureCheckExpr extends AbstractStructureCheckExpr { @Override protected boolean isExpressionStructureRight() { //TODO finish boolean f = true; if(expression==null||expression.length()<=0){ f = false; }else{ int i=0; char c = expression.charAt(i); if(isCharOperator(c)){ if(!isNegativeSign(c)||!isLeftBracket(c)){ f = false; errorSet.add( new SimpleErrorInforInExpr(i,OPERATOR_USE_ERROR)); } } while(i<expression.length()-1){ i++; c = expression.charAt(i); char cl = expression.charAt(i-1); if(isCharOperator(cl)){ if(isCharOperator(c)&&!isLeftBracket(c)){ if(!isLeftBracket(cl)){ f=false; errorSet.add( new SimpleErrorInforInExpr(i,OPERATOR_USE_ERROR)); }else if(!isNegativeSign(c)){ f=false; errorSet.add( new SimpleErrorInforInExpr(i,OPERATOR_USE_ERROR)); } } } } }// for(int i=0;i<expression.length();i++){// char c = expression.charAt(i);// char cl=OPERATOR_ADD;// if(i>0){// cl = expression.charAt(i-1);// }// if(isCharOperator(c)){// if(isCharOperatorWithoutBracket(c)){// if(isCharOperatorWithoutBracket(cl)){// errorSet.add(new SimpleErrorInforInExpr(i,OPERATOR_USE_ERROR));// f=false;// }else if(isLeftBracket(cl)&&!isNegativeSign(c)){// errorSet.add(new SimpleErrorInforInExpr(i-1,LEFT_BRACKET_ERROR));// f=false;// }// }else if(isRightBracket(c)){// if(isCharOperator(c)){// errorSet.add(new SimpleErrorInforInExpr(i,RIGHT_BRACKET_ERROR));// f=false;// }// }// }// if(i==expression.length()-1&&!isRightBracket(c)&&isCharOperator(c)){// f=false;// errorSet.add(new SimpleErrorInforInExpr(i,OPERATOR_USE_ERROR));// }// } return checkBracketMatch()&&f; } public SimpleStructureCheckExpr() { super(); } public SimpleStructureCheckExpr(String expression) { super(expression); }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -