@Override protected ParseToken inverseOperation(ParseToken node) { return new ParseToken(TokenType.Power, node, new ParseTokenNumber(Complex.MINUS_ONE)); }
@Override protected ParseToken inverseOperation(ParseToken node) { ParseToken[] content; if (node.tokenType == TokenType.Product) { content = new ParseToken[1 + node.content.length]; content[0] = new ParseTokenNumber(Complex.MINUS_ONE); System.arraycopy(node.content, 0, content, 1, node.content.length); } else content = new ParseToken[]{ new ParseTokenNumber(Complex.MINUS_ONE), node }; return new ParseToken(TokenType.Product, content); }
@Override public ParseToken parseToken(String expression, cc.redberry.core.parser.Parser parser) { Complex value; try { value = NumberParser.COMPLEX_PARSER.parse(expression); } catch (NumberFormatException e) { return null; } return new ParseTokenNumber(value); }
&& arguments.size() == 1 && arguments.get(0).getIndices().getFree().size() == 0) return new ParseToken(TokenType.Power, new ParseToken[]{arguments.get(0), new ParseTokenNumber(Complex.ONE_HALF)});
public static ParseToken tensor2AST(Tensor tensor) { if (tensor instanceof TensorField) { TensorField tf = (TensorField) tensor; ParseToken[] content = new ParseToken[tf.size()]; int i = 0; for (Tensor t : tf) content[i++] = tensor2AST(t); return new ParseTokenTensorField(tf.getIndices(), tf.getStringName(), content, tf.getArgIndices()); } if (tensor instanceof SimpleTensor) { SimpleTensor st = (SimpleTensor) tensor; return new ParseTokenSimpleTensor(st.getIndices(), st.getStringName()); } if (tensor instanceof Complex) return new ParseTokenNumber((Complex) tensor); if (tensor instanceof Expression) return new ParseTokenExpression(false, tensor2AST(tensor.get(0)), tensor2AST(tensor.get(1))); ParseToken[] content = new ParseToken[tensor.size()]; int i = 0; for (Tensor t : tensor) content[i++] = tensor2AST(t); if (tensor instanceof ScalarFunction) return new ParseTokenScalarFunction(tensor.getClass().getSimpleName(), content); return new ParseToken(TokenType.valueOf(tensor.getClass().getSimpleName()), content); }