private Term parseTerm(Lexer lexer, boolean first) throws UcumException { Term res = new Term(); if (first && lexer.getType() == TokenType.NONE) { res.setComp(new Factor(1)); } else if (lexer.getType() == TokenType.SOLIDUS) { res.setOp(Operator.DIVISION); lexer.consume(); res.setTerm(parseTerm(lexer, false)); } else { if (lexer.getType() == TokenType.ANNOTATION) { res.setComp(new Factor(1)); // still lose the annotation lexer.consume(); } else res.setComp(parseComp(lexer)); if (lexer.getType() != TokenType.NONE && lexer.getType() != TokenType.CLOSE) { if (lexer.getType() == TokenType.SOLIDUS) { res.setOp(Operator.DIVISION); lexer.consume(); } else if (lexer.getType() == TokenType.PERIOD) { res.setOp(Operator.MULTIPLICATION); lexer.consume(); } else if (lexer.getType() == TokenType.ANNOTATION) res.setOp(Operator.MULTIPLICATION); // implicit else lexer.error("Expected '/' or '.'"); res.setTerm(parseTerm(lexer, false)); } } return res; }
private Term parseTerm(Lexer lexer, boolean first) throws UcumException { Term res = new Term(); if (first && lexer.getType() == TokenType.NONE) { res.setComp(new Factor(1)); } else if (lexer.getType() == TokenType.SOLIDUS) { res.setOp(Operator.DIVISION); lexer.consume(); res.setTerm(parseTerm(lexer, false)); } else { if (lexer.getType() == TokenType.ANNOTATION) { res.setComp(new Factor(1)); // still lose the annotation lexer.consume(); } else res.setComp(parseComp(lexer)); if (lexer.getType() != TokenType.NONE && lexer.getType() != TokenType.CLOSE) { if (lexer.getType() == TokenType.SOLIDUS) { res.setOp(Operator.DIVISION); lexer.consume(); } else if (lexer.getType() == TokenType.PERIOD) { res.setOp(Operator.MULTIPLICATION); lexer.consume(); } else if (lexer.getType() == TokenType.ANNOTATION) res.setOp(Operator.MULTIPLICATION); // implicit else lexer.error("Expected '/' or '.'"); res.setTerm(parseTerm(lexer, false)); } } return res; }
Term t = term; while (t != null) { if (t.getComp() instanceof Term) { Canonical temp = normalise(indent+" ", (Term) t.getComp()); if (div) { result.divideValue(temp.getValue()); } else if (t.getComp() instanceof Factor) { if (div) result.divideValue(((Factor) t.getComp()).getValue()); else result.multiplyValue(((Factor) t.getComp()).getValue()); } else if (t.getComp() instanceof Symbol) { Symbol o = (Symbol) t.getComp(); Canonical temp = normalise(indent, o); if (div) { div = t.getOp() == Operator.DIVISION; t = t.getTerm();
Term t = term; while (t != null) { if (t.getComp() instanceof Term) { Canonical temp = normalise(indent+" ", (Term) t.getComp()); if (div) { result.divideValue(temp.getValue()); } else if (t.getComp() instanceof Factor) { if (div) result.divideValue(((Factor) t.getComp()).getValue()); else result.multiplyValue(((Factor) t.getComp()).getValue()); } else if (t.getComp() instanceof Symbol) { Symbol o = (Symbol) t.getComp(); Canonical temp = normalise(indent, o); if (div) { div = t.getOp() == Operator.DIVISION; t = t.getTerm();