/* File: IDLParser.java * Copyright (C) 2002-2003 The University of Iowa * Created by: Jeremy Faden * Jessica Swanner * Edward E. West * * This file is part of the das2 library. * * das2 is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ package org.das2.util; import java.util.StringTokenizer; import java.util.Vector; import java.util.logging.Logger; /** * This was created originally to evaluate expressions found in das2server dsdf files that would * describe column locations, which would be expressions like "10^(findgen(3)/3.3)" * @author jbf */ public class IDLParser { public static final int EXPR=1; public static final int EXPR_LIST=2; public static final int FACTOR=3; public static final int TERM=4; public static final int NUMBER=5; public static final int NOPARSER=6; /** Creates a new instance of idlParser */ public IDLParser() { } public String[] IDLTokenizer(String s) { String delimiters=" \t[,]()^*/+-"; StringTokenizer st = new StringTokenizer(s, delimiters, true); int countTokens=st.countTokens(); String[] tokens=new String[countTokens]; for (int i=0; i 0) { String[] temp = new String[tokens.length-nullcount]; int tIndex = 0; for (int i = 0; i < tokens.length; i++) { if (tokens[i] == null) continue; temp[tIndex] = tokens[i]; tIndex++; } tokens = temp; } return tokens; } public double parseIDLScalar(String s) { String[] tokens= IDLTokenizer(s); IDLValue expr= parseIDLArrayTokens(tokens,EXPR); if (expr == null) return Double.NaN; else return expr.toScalar(); } public double[] parseIDLArray(String s) { String[] tokens= IDLTokenizer(s); IDLValue expr= parseIDLArrayTokens(tokens,EXPR); if (expr == null) return null; else return expr.toArray(); } private IDLValue parseIDLExprList(String[] tokens) { int ileft= 0; int nleft= 0; int iright=0; int itok; Vector exprs= new Vector(); ileft=1; for (itok=1; itok