/** * Evaluate a function at a specific point for one single variable. Evaluation is done between * xmin and xmax. It is assumed that there are no any other variable involved * * @param indvars Define independent variable, like 'x' Only one variable is allowed * @param xmin xmin value for independent varible * @param xmax xmax value for independent varible * @return true if no errors */ public boolean eval(String indvars, double xmin, double xmax) { boolean suc = true; String name = proxy.getName(); int points = proxy.getPoints(); double min = xmin; double max = xmax; x = new double[points]; y = new double[points]; for (int i = 0; i < points; i++) { x[i] = min + i * (max - min) / (points - 1); jep.addVariable(indvars.trim(), x[i]); try { Object result = jep.evaluate(node); if (result instanceof Double) { y[i] = ((Double) jep.evaluate(node)).doubleValue(); } } catch (ParseException e) { jhplot.utils.Util.ErrorMessage( "Failed to parse function " + name + " Error:" + e.toString()); suc = false; } } if (suc) isEvaluated = true; return suc; } // end 1-D evaluation
/** Invoked by the HTTPClient. */ public int requestHandler(Request req, Response[] resp) throws ModuleException { // parse Accept-Encoding header int idx; NVPair[] hdrs = req.getHeaders(); for (idx = 0; idx < hdrs.length; idx++) if (hdrs[idx].getName().equalsIgnoreCase("Accept-Encoding")) break; Vector pae; if (idx == hdrs.length) { hdrs = Util.resizeArray(hdrs, idx + 1); req.setHeaders(hdrs); pae = new Vector(); } else { try { pae = Util.parseHeader(hdrs[idx].getValue()); } catch (ParseException pe) { throw new ModuleException(pe.toString()); } } // done if "*;q=1.0" present HttpHeaderElement all = Util.getElement(pae, "*"); if (all != null) { NVPair[] params = all.getParams(); for (idx = 0; idx < params.length; idx++) if (params[idx].getName().equalsIgnoreCase("q")) break; if (idx == params.length) // no qvalue, i.e. q=1.0 return REQ_CONTINUE; if (params[idx].getValue() == null || params[idx].getValue().length() == 0) throw new ModuleException("Invalid q value for \"*\" in " + "Accept-Encoding header: "); try { if (Float.valueOf(params[idx].getValue()).floatValue() > 0.) return REQ_CONTINUE; } catch (NumberFormatException nfe) { throw new ModuleException( "Invalid q value for \"*\" in " + "Accept-Encoding header: " + nfe.getMessage()); } } // Add gzip, deflate and compress tokens to the Accept-Encoding header if (!pae.contains(new HttpHeaderElement("deflate"))) pae.addElement(new HttpHeaderElement("deflate")); if (!pae.contains(new HttpHeaderElement("gzip"))) pae.addElement(new HttpHeaderElement("gzip")); if (!pae.contains(new HttpHeaderElement("x-gzip"))) pae.addElement(new HttpHeaderElement("x-gzip")); if (!pae.contains(new HttpHeaderElement("compress"))) pae.addElement(new HttpHeaderElement("compress")); if (!pae.contains(new HttpHeaderElement("x-compress"))) pae.addElement(new HttpHeaderElement("x-compress")); hdrs[idx] = new NVPair("Accept-Encoding", Util.assembleHeader(pae)); return REQ_CONTINUE; }
public static void main(String[] args) { try { Node root = new MiniRAParser(System.in).Goal(); // System.out.println("Program parsed successfully"); Object a = root.accept(new GJDepthFirst(), null); // root.accept(new GJNoArgu(a)); } catch (ParseException e) { System.out.println(e.toString()); } }
public static void main(String[] args) { try { Node root = new MiniJavaParser(System.in).Goal(); HashMap<String, String> s = (HashMap<String, String>) root.accept(new GJNoArguDepthFirst()); // Your assignment part is invoked here. root.accept(new GJDepthFirst<Object, Object>(), s); System.out.println("Program type checked successfully"); } catch (ParseException e) { System.out.println(e.toString()); } }
/** * Construct a connection to the specified url. A cache of * HTTPConnections is used to maximize the reuse of these across * multiple HttpURLConnections. * * <BR>The default method is "GET". * * @param url the url of the request * @exception ProtocolNotSuppException if the protocol is not supported */ public HttpURLConnection(URL url) throws ProtocolNotSuppException, IOException { super(url); // first read proxy properties and set try { String hosts = System.getProperty("http.nonProxyHosts", ""); if (!hosts.equalsIgnoreCase(non_proxy_hosts)) { connections.clear(); non_proxy_hosts = hosts; String[] list = Util.splitProperty(hosts); for (int idx=0; idx<list.length; idx++) HTTPConnection.dontProxyFor(list[idx]); } } catch (ParseException pe) { throw new IOException(pe.toString()); } catch (SecurityException se) { } try { String host = System.getProperty("http.proxyHost", ""); int port = Integer.getInteger("http.proxyPort", -1).intValue(); if (!host.equalsIgnoreCase(proxy_host) || port != proxy_port) { connections.clear(); proxy_host = host; proxy_port = port; HTTPConnection.setProxyServer(host, port); } } catch (SecurityException se) { } // now setup stuff con = getConnection(url); method = "GET"; method_set = false; resource = url.getFile(); headers = default_headers; do_redir = getFollowRedirects(); output_stream = null; urlString = url.toString(); }
/** * Evaluate a function at a specific point for one single variable. Evaluation is done between * xmin and xmax * * @param indvars Define independent variable, like 'x' Only one variable is allowed * @param xmin xmin value for independent varible * @param xmax xmax value for independent varible * @param vars define values for other variables, like 'y=1,z=3' * @return true if no errors */ public boolean eval(String indvars, double xmin, double xmax, String vars) { String name = proxy.getName(); int points = proxy.getPoints(); boolean suc = true; String[] tmp = vars.split(","); // double[] vd = new double[tmp.length]; fixedVars = vars; for (int i = 0; i < tmp.length; i++) { String[] vv = tmp[i].split("="); if (vv.length != 2) { ErrorMessage("Error in parsing list of input variablse. Did you use val=number? "); } try { double d = Double.valueOf(vv[1].trim()).doubleValue(); jep.addVariable(vv[0].trim(), d); } catch (NumberFormatException nfe) { System.out.println("NumberFormatException: " + nfe.getMessage()); suc = false; } } double min = xmin; double max = xmax; x = new double[points]; y = new double[points]; for (int i = 0; i < points; i++) { x[i] = min + i * (max - min) / (points - 1); jep.addVariable(indvars.trim(), x[i]); try { Object result = jep.evaluate(node); if (result instanceof Double) { y[i] = ((Double) jep.evaluate(node)).doubleValue(); } } catch (ParseException e) { jhplot.utils.Util.ErrorMessage( "Failed to parse function " + name + " Error:" + e.toString()); suc = false; } } if (suc) isEvaluated = true; return suc; } // end 1-D evaluation
public static void main(String[] args) { try { // File file = new File("C:\\tiger2\\testcases\\BinarySearch.java"); // File file = new File("C:\\tiger2\\testcases\\BinaryTree.java"); // File file = new File("C:\\tiger2\\testcases\\BubbleSort.java"); File file = new File("C:\\tiger2\\testcases\\Factorial.java"); // File file = new File("C:\\tiger2\\testcases\\LinearSearch.java"); // File file = new File("C:\\tiger2\\testcases\\LinkedList.java"); // File file = new File("C:\\tiger2\\testcases\\QuickSort.java"); // File file = new File("C:\\tiger2\\testcases\\Test1.java"); // File file = new File("C:\\tiger2\\testcases\\TreeVisitor.java"); FileInputStream stream = new FileInputStream(file); Program root = new MiniJavaParser(stream).Goal(); // Print the original source code from the abstract syntax tree: root.accept(new PrettyPrintVisitor()); // root.accept(new ASTPrintVisitor()); // Print the abstract syntax tree: // root.accept(new ASTPrintVisitor()); // Should this have been called "UglyPrintVisitor"? :) } catch (ParseException e) { System.out.println(e.toString()); } catch (FileNotFoundException fnfe) { System.out.println("File not found!"); } /*try { //File file = new File("C:\\tiger2\\testcases\\Factorial.java"); File file = new File("C:\\tiger2\\testcases\\BubbleSort.java"); //File file = new File("C:\\tiger2\\testcases\\Test1.java"); FileInputStream stream = new FileInputStream(file); MiniJavaParser parser = new MiniJavaParser(stream); parser.Goal(); System.out.println("Parse succeeded."); } catch (FileNotFoundException fnfe) { System.out.println("File not found!"); } catch (ParseException e) { System.out.println("Parser Error : \n"+ e.toString()); }*/ }
/** Invoked by the HTTPClient. */ public void responsePhase3Handler(Response resp, RoRequest req) throws IOException, ModuleException { String ce = resp.getHeader("Content-Encoding"); if (ce == null || req.getMethod().equals("HEAD") || resp.getStatusCode() == 206) return; Vector pce; try { pce = Util.parseHeader(ce); } catch (ParseException pe) { throw new ModuleException(pe.toString()); } if (pce.size() == 0) return; String encoding = ((HttpHeaderElement) pce.firstElement()).getName(); if (encoding.equalsIgnoreCase("gzip") || encoding.equalsIgnoreCase("x-gzip")) { Log.write(Log.MODS, "CEM: pushing gzip-input-stream"); resp.inp_stream = new GZIPInputStream(resp.inp_stream); pce.removeElementAt(pce.size() - 1); resp.deleteHeader("Content-length"); } else if (encoding.equalsIgnoreCase("deflate")) { Log.write(Log.MODS, "CEM: pushing inflater-input-stream"); resp.inp_stream = new InflaterInputStream(resp.inp_stream); pce.removeElementAt(pce.size() - 1); resp.deleteHeader("Content-length"); } else if (encoding.equalsIgnoreCase("compress") || encoding.equalsIgnoreCase("x-compress")) { Log.write(Log.MODS, "CEM: pushing uncompress-input-stream"); resp.inp_stream = new UncompressInputStream(resp.inp_stream); pce.removeElementAt(pce.size() - 1); resp.deleteHeader("Content-length"); } else if (encoding.equalsIgnoreCase("identity")) { Log.write(Log.MODS, "CEM: ignoring 'identity' token"); pce.removeElementAt(pce.size() - 1); } else { Log.write(Log.MODS, "CEM: Unknown content encoding '" + encoding + "'"); } if (pce.size() > 0) resp.setHeader("Content-Encoding", Util.assembleHeader(pce)); else resp.deleteHeader("Content-Encoding"); }
public static void main(String args[]) { String language = "java"; ArrayList recFiles = new ArrayList(); JFile curFile = null; for (int i = 0; i < args.length; i++) { if ("-l".equalsIgnoreCase(args[i]) || "--language".equalsIgnoreCase(args[i])) { language = args[i + 1].toLowerCase(); i++; } else { recFiles.add(args[i]); } } if (!"c++".equals(language) && !"java".equals(language) && !"c".equals(language)) { System.out.println("Cannot recognize language:" + language); System.exit(1); } if (recFiles.size() == 0) { System.out.println("No record files specified. Exiting."); System.exit(1); } for (int i = 0; i < recFiles.size(); i++) { curFileName = (String) recFiles.get(i); File file = new File(curFileName); try { curFile = parseFile(file); } catch (FileNotFoundException e) { System.out.println("File " + (String) recFiles.get(i) + " Not found."); System.exit(1); } catch (ParseException e) { System.out.println(e.toString()); System.exit(1); } System.out.println((String) recFiles.get(i) + " Parsed Successfully"); try { curFile.genCode(language, new File(".")); } catch (IOException e) { System.out.println(e.toString()); System.exit(1); } } }
public final JFile Include() throws ParseException { String fname; Token t; jj_consume_token(INCLUDE_TKN); t = jj_consume_token(CSTRING_TKN); JFile ret = null; fname = t.image.replaceAll("^\"", "").replaceAll("\"$", ""); File file = new File(curDir, fname); String tmpDir = curDir; String tmpFile = curFileName; curDir = file.getParent(); curFileName = file.getName(); try { FileReader reader = new FileReader(file); Rcc parser = new Rcc(reader); try { ret = parser.Input(); System.out.println(fname + " Parsed Successfully"); } catch (ParseException e) { System.out.println(e.toString()); System.exit(1); } try { reader.close(); } catch (IOException e) { } } catch (FileNotFoundException e) { System.out.println("File " + fname + " Not found."); System.exit(1); } curDir = tmpDir; curFileName = tmpFile; { if (true) return ret; } throw new Error("Missing return statement in function"); }
public static void main(String... args) { try { CommandLineParser parser = new DefaultParser(); CommandLine cmd = parser.parse(createOptions(), args); if (cmd.hasOption("h")) { printHelp(); } else { GeneratorParameter parameter = extractParameter(cmd); if (parameter.hasSufficientData()) { TestHelper testHelper = new TestHelper(); testHelper.generateTestHelper(parameter); } else { log.error( "Parameters are not sufficient, exiting. " + "WMPRT folder, output folder and namespace must be set."); } } } catch (ParseException e) { log.error(e.toString()); } }