302
社区成员
发帖
与我相关
我的任务
分享类图

├── Factor (接口,用于解析后建立AST)
│ ├── DeriveFactor
│ ├── ExpFactor
│ ├── FuncFactor
│ ├── NumFactor
│ ├── RecFuncFactor
│ ├── SelFactor
│ ├── Expr
│ ├── Term
│ └── VarFactor
以上均是各类因子的实现类,其中funcfactor特殊,对于自定义函数和递推函数,处理的方法在functionexpander工具类中
├── Mono
├── Poly
建立AST后,对每个因子都要转为poly类型,用于后续的计算,mono则是poly的基本组成单位,三次作业之后mono的标准格式为:num*x^index1*y^index2*exp(expr)
├── FunctionExpander
用于展开自定义函数和递推函数,将递推函数转换为普通函数
├── Lexer
├── Parser
├── MainClass
| Class | OCavg | OCMax(类的最大响应集) | WMC(类的加权方法数) |
|---|---|---|---|
| DeriveFacto | 1.00 | 1 | 2 |
| ExpFactor | 1.50 | 3 | 6 |
| Expr | 1.25 | 3 | 10 |
| FuncFactor | 1.00 | 1 | 3 |
| FunctionExp | 3.25 | 13 | 52 |
| Lexer | 1.75 | 3 | 7 |
| MainClass | 4.00 | 4 | 4 |
| Mono | 2.41 | 12 | 41 |
| NumFactor | 1.00 | 1 | 3 |
| Parser | 4.27 | 12 | 47 |
| Poly | 4.83 | 14 | 58 |
| RecFuncFac | 1.00 | 1 | 4 |
| SelFactor | 1.00 | 1 | 5 |
| Term | 1.33 | 3 | 8 |
| VarFactor | 1.50 | 3 | 6 |
| Total | 256 | ||
| Average | 2.56 | 5.00 | 17.07 |
| Method | CogC(认知复杂度) | ev(G)(本质复杂度) | iv(G)(设计复杂度) | v(G)(圈复杂度) |
|---|---|---|---|---|
| DeriveFactor.DeriveFactor(Expr, char) | 0 | 1 | 1 | 1 |
| DeriveFactor.toPoly() | 0 | 1 | 1 | 1 |
| ExpFactor.ExpFactor(Factor, BigInteger) | 0 | 1 | 1 | 1 |
| ExpFactor.getExp() | 0 | 1 | 1 | 1 |
| ExpFactor.getIndex() | 0 | 1 | 1 | 1 |
| ExpFactor.toPoly() | 3 | 2 | 4 | 4 |
| Expr.Expr() | 0 | 1 | 1 | 1 |
| Expr.SetIndex(BigInteger) | 0 | 1 | 1 | 1 |
| Expr.addSign(String) | 0 | 1 | 1 | 1 |
| Expr.addTerm(Term) | 0 | 1 | 1 | 1 |
| Expr.getIndex() | 0 | 1 | 1 | 1 |
| Expr.getSigns() | 0 | 1 | 1 | 1 |
| Expr.getTerms() | 0 | 1 | 1 | 1 |
| Expr.toPoly() | 4 | 1 | 3 | 3 |
| FuncFactor.FuncFactor(Factor) | 0 | 1 | 1 | 1 |
| FuncFactor.getPara() | 0 | 1 | 1 | 1 |
| FuncFactor.toPoly() | 0 | 1 | 1 | 1 |
| FunctionExpander.copyPoly(Poly) | 0 | 1 | 1 | 1 |
| FunctionExpander.ensureRecursiveReady() | 2 | 2 | 1 | 4 |
| FunctionExpander.evalExprWithArg(Expr, Poly, Integer, Map<String, Poly>) | 4 | 1 | 3 | 3 |
| FunctionExpander.evalFactorWithArg(Factor, Poly, Integer, Map<String, Poly>) | 24 | 11 | 13 | 14 |
| FunctionExpander.evalTermWithArg(Term, Poly, Integer, Map<String, Poly>) | 2 | 1 | 3 | 3 |
| FunctionExpander.expandRecursiveByOrder(int, Poly, Map<String, Poly>) | 5 | 3 | 4 | 5 |
| FunctionExpander.expandRecursiveWithArgument(String, Factor) | 0 | 1 | 1 | 1 |
| FunctionExpander.expandWithArgPoly(Poly) | 0 | 1 | 1 | 1 |
| FunctionExpander.expandWithArgument(Factor) | 1 | 2 | 1 | 2 |
| FunctionExpander.extractFunctionBody(String) | 1 | 2 | 1 | 2 |
| FunctionExpander.initFunction(String) | 1 | 2 | 1 | 2 |
| FunctionExpander.initRecursiveFunction(String[]) | 12 | 8 | 4 | 11 |
| FunctionExpander.normalizeExpression(String) | 0 | 1 | 1 | 1 |
| FunctionExpander.parseExprFromString(String) | 0 | 1 | 1 | 1 |
| FunctionExpander.reset() | 0 | 1 | 1 | 1 |
| FunctionExpander.resolveOrder(String, Integer) | 7 | 5 | 4 | 7 |
| Lexer.Lexer(String) | 0 | 1 | 1 | 1 |
| Lexer.getNumber() | 2 | 1 | 3 | 3 |
| Lexer.next() | 3 | 2 | 2 | 3 |
| Lexer.peek() | 0 | 1 | 1 | 1 |
| MainClass.main(String[]) | 4 | 1 | 4 | 4 |
| Mono.Mono(BigInteger, BigInteger, BigInteger, Poly) | 0 | 1 | 1 | 1 |
| Mono.add(Mono) | 0 | 1 | 1 | 1 |
| Mono.copyPoly(Poly) | 0 | 1 | 1 | 1 |
| Mono.derivative(char) | 10 | 2 | 5 | 8 |
| Mono.derive(char) | 1 | 2 | 2 | 2 |
| Mono.etoString() | 5 | 3 | 3 | 3 |
| Mono.getCoefficient() | 0 | 1 | 1 | 1 |
| Mono.getStr() | 0 | 1 | 1 | 1 |
| Mono.getXIndex() | 0 | 1 | 1 | 1 |
| Mono.getYIndex() | 0 | 1 | 1 | 1 |
| Mono.isSimilar(Mono) | 1 | 1 | 3 | 3 |
| Mono.mul(Mono) | 0 | 1 | 1 | 1 |
| Mono.setNegative() | 0 | 1 | 1 | 1 |
| Mono.sub(Mono) | 0 | 1 | 1 | 1 |
| Mono.toString() | 21 | 4 | 16 | 18 |
| Mono.xtoString() | 3 | 3 | 2 | 3 |
| Mono.ytoString() | 3 | 3 | 2 | 3 |
| NumFactor.NumFactor(BigInteger) | 0 | 1 | 1 | 1 |
| NumFactor.getNum() | 0 | 1 | 1 | 1 |
| NumFactor.toPoly() | 0 | 1 | 1 | 1 |
| Parser.Parser(Lexer) | 0 | 1 | 1 | 1 |
| Parser.expectToken(String) | 1 | 2 | 2 | 2 |
| Parser.parseDeriveFactor() | 4 | 3 | 3 | 4 |
| Parser.parseExponent(Lexer) | 3 | 1 | 3 | 3 |
| Parser.parseExpr() | 18 | 1 | 12 | 13 |
| Parser.parseFactor() | 23 | 9 | 14 | 15 |
| Parser.parseRecFuncFactor() | 1 | 1 | 2 | 2 |
| Parser.parseSelFactor() | 2 | 1 | 2 | 2 |
| Parser.parseTerm() | 1 | 1 | 2 | 2 |
| Parser.skipToTopLevelColon() | 8 | 5 | 4 | 6 |
| Parser.skipToTopLevelRightBracket() | 5 | 1 | 4 | 5 |
| Poly.Poly() | 0 | 1 | 1 | 1 |
| Poly.add(Poly) | 1 | 1 | 2 | 2 |
| Poly.addFreshMono(Mono) | 0 | 1 | 1 | 1 |
| Poly.addMono(Mono, Boolean) | 13 | 4 | 7 | 7 |
| Poly.derive(char) | 4 | 2 | 3 | 3 |
| Poly.isEqual(Poly) | 20 | 8 | 10 | 15 |
| Poly.isExpr() | 12 | 6 | 11 | 17 |
| Poly.isZero() | 4 | 4 | 2 | 4 |
| Poly.mul(Poly) | 3 | 1 | 3 | 3 |
| Poly.pow(BigInteger) | 4 | 1 | 3 | 3 |
| Poly.sub(Poly) | 1 | 1 | 2 | 2 |
| Poly.toString() | 22 | 6 | 12 | 16 |
| RecFuncFactor.RecFuncFactor(String, Factor) | 0 | 1 | 1 | 1 |
| RecFuncFactor.getOrderExpr() | 0 | 1 | 1 | 1 |
| RecFuncFactor.getPara() | 0 | 1 | 1 | 1 |
| RecFuncFactor.toPoly() | 0 | 1 | 1 | 1 |
| SelFactor.SelFactor(Factor, Factor, Factor) | 0 | 1 | 1 | 1 |
| SelFactor.getFactor1() | 0 | 1 | 1 | 1 |
| SelFactor.getFactor2() | 0 | 1 | 1 | 1 |
| SelFactor.getResultFactor() | 0 | 1 | 1 | 1 |
| SelFactor.toPoly() | 0 | 1 | 1 | 1 |
| Term.Term() | 0 | 1 | 1 | 1 |
| Term.addFactor(Factor) | 0 | 1 | 1 | 1 |
| Term.changeIsPositive() | 0 | 1 | 1 | 1 |
| Term.getFactors() | 0 | 1 | 1 | 1 |
| Term.isPositive() | 0 | 1 | 1 | 1 |
| Term.toPoly() | 2 | 1 | 3 | 3 |
| VarFactor.VarFactor(BigInteger, char) | 0 | 1 | 1 | 1 |
| VarFactor.getIndex() | 0 | 1 | 1 | 1 |
| VarFactor.getValue() | 0 | 1 | 1 | 1 |
| VarFactor.toPoly() | 2 | 1 | 1 | 3 |
num*x^indexnum*x^index^exp(expr)如果增添多个函数:由于函数因子中预留下函数名,并在函数处理工具类有函数名与函数体的键值对容器,这样只需要添加一个根据函数名获取函数体的方法即可得到单个函数的函数体,从而复用已有的处理路径
关于性能分的优化:
Unit1的作业让我更加熟悉了递归下降的方法,如何将一个复杂的、嵌套的语法分解为各个部分,大大简化了解析。然后是统一成poly进行计算的方式也很巧妙,我一开始设计架构时在如何计算化简考虑了很久,参考了公众号才采用了这种统一计算的方式。
我认为未来可以加上一些对于性能优化的提示,然后对于博客需要的度量值也可以提供一下可采用的工具