/** * Create a new abstract syntax tree (AST). * * @param arr * @param head * the header expression of the function. If the ast represents a function like * <code>f[x,y], Sin[x],...</code>, the <code>head</code> will be an instance of type ISymbol. * @return */ public static IASTAppendable ast(final IExpr[] arr, final IExpr head) { return new AST(head, arr); }
private int compareToAST(final AST ast) { // compare the headers of the 2 expressions: int cp = head().compareTo(ast.head()); if (cp != 0) { return cp; } final int commonArgSize = (size() > ast.size()) ? ast.size() : size(); for (int i = 1; i < commonArgSize; i++) { cp = get(i).compareTo(ast.get(i)); if (cp != 0) { return cp; } } return size() - ast.size(); }
/** * Create a new abstract syntax tree (AST). * * @param head * the header expression of the function. If the ast represents a function like * <code>f[x,y], Sin[x],...</code>, the <code>head</code> will be an instance of type ISymbol. * */ public final static IASTAppendable ast(final IExpr head) { return AST.newInstance(head); }
/** * * @param intialCapacity * the initial capacity (i.e. number of arguments without the header element) of the list. * @param head * @return */ public static AST newInstance(final int intialCapacity, final IExpr head) { AST ast = new AST(intialCapacity + 1, false); ast.append(head); return ast; }
public int isVector() { if (isEvalFlagOn(IAST.IS_VECTOR)) { return size() - 1; } if (head().equals(F.List)) { final int dim = size() - 1; if (dim > 0) { if (get(1).isList()) { return -1; } for (int i = 2; i < size(); i++) { if (get(i).isList()) { // row is a list return -1; } } } addEvalFlags(IAST.IS_VECTOR); return dim; } return -1; }
token = tokenizer.nextToken(); if (token.equals("[")) { argList = newInstance(null); argList.setHeader(StringX.valueOf(arg)); parseList(tokenizer, argList); list.add(argList); } else { list.add(StringX.valueOf(arg)); continue; token = tokenizer.nextToken(); if (token.equals("[")) { argList = newInstance(null); argList.setHeader(StringX.valueOf(arg)); parseList(tokenizer, argList); list.add(argList); } else { list.add(StringX.valueOf(arg)); continue;
/** * Constructs a list with header <i>symbol</i> and the arguments containing * the given DoubleImpl matrix values as <i>List</i> rows * * @see Num */ public static AST newInstance(final ISymbol symbol, final double[][] matrix) { // AST ast; // if (Config.SERVER_MODE) { // ast = FACTORY.object(); // } else { // ast = new AST(5, false); // } AST ast = new AST(5, false); ast.add(symbol); AST row; for (int i = 1; i <= matrix.length; i++) { row = newInstance(F.List, matrix[i - 1]); ast.add(i, row); } return ast; }
/** * simple parser to simplify unit tests. The parser assumes that the String * contains no syntax errors. * * Example "List[x,List[y]]" */ public static AST parse(final String inputString) { final StringTokenizer tokenizer = new StringTokenizer(inputString, "[],", true); final AST list = newInstance(null); String token = tokenizer.nextToken(); list.setHeader(StringX.valueOf(token)); token = tokenizer.nextToken(); if (token.equals("[")) { parseList(tokenizer, list); return list; } // syntax fError occured return null; }
public IExpr getAt(final int index) { return get(index); }
/** * simple parser to simplify unit tests. The parser assumes that the String contains no syntax errors. * * Example "List[x,List[y]]" * * @param inputString * @return */ public static IAST parse(final String inputString) { final StringTokenizer tokenizer = new StringTokenizer(inputString, "[],", true); String token = tokenizer.nextToken(); final IASTAppendable list = newInstance(StringX.valueOf(token)); token = tokenizer.nextToken(); if ("[".equals(token)) { parseList(tokenizer, list); return list; } // syntax fError occured return null; }
public IAST copyHead() { return newInstance(get(0)); }
/** * Constructs a list with header <i>symbol</i> and the arguments containing the given DoubleImpl matrix values as * <i>List</i> rows * * @param symbol * @param matrix * @return * @see Num */ public static AST newInstance(final ISymbol symbol, final double[][] matrix) { IExpr[] eArr = new IExpr[matrix.length + 1]; eArr[0] = symbol; for (int i = 1; i <= matrix.length; i++) { eArr[i] = newInstance(F.List, matrix[i - 1]); } return new AST(eArr); }
public static AST newInstance(final ISymbol symbol, final int[] arr) { // AST ast; // if (Config.SERVER_MODE) { // ast = FACTORY.object(); // } else { // ast = new AST(5, false); // } AST ast = new AST(5, false); ast.add(symbol); for (int i = 1; i <= arr.length; i++) { ast.add(i, IntegerSym.valueOf(arr[i - 1])); } return ast; }
/** * {@inheritDoc} */ public boolean addAll(List<? extends IExpr> ast, int startPosition, int endPosition) { if (ast.size() > 0 && startPosition < endPosition) { ensureCapacity(size() + (endPosition - startPosition)); for (int i = startPosition; i < endPosition; i++) { add(ast.get(i)); } return true; } return false; }