--- /dev/null
+/*******************************************************************************\r
+ * Copyright (c) 2007, 2010 Association for Decentralized Information Management\r
+ * in Industry THTH ry.\r
+ * All rights reserved. This program and the accompanying materials\r
+ * are made available under the terms of the Eclipse Public License v1.0\r
+ * which accompanies this distribution, and is available at\r
+ * http://www.eclipse.org/legal/epl-v10.html\r
+ *\r
+ * Contributors:\r
+ * VTT Technical Research Centre of Finland - initial API and implementation\r
+ *******************************************************************************/\r
+package org.simantics.basicexpression;\r
+\r
+import java.io.PushbackReader;\r
+import java.io.StringReader;\r
+\r
+import org.simantics.basicexpression.analysis.DepthFirstAdapter;\r
+import org.simantics.basicexpression.lexer.Lexer;\r
+import org.simantics.basicexpression.node.Start;\r
+import org.simantics.basicexpression.parser.Parser;\r
+\r
+public class Expressions {\r
+\r
+ private static final boolean DEBUG = false;\r
+ \r
+ public static void evaluate(String expression, DepthFirstAdapter evaluator) {\r
+ \r
+ try\r
+ {\r
+ // Create a Parser instance.\r
+ Parser p =\r
+ new Parser(\r
+ new Lexer(\r
+ new PushbackReader(new StringReader(expression))));\r
+\r
+ // Parse the input.\r
+ Start tree = p.parse();\r
+ \r
+ if(DEBUG)\r
+ tree.apply(new PrettyPrintExpressionVisitor());\r
+ \r
+// System.out.println("tree=" + tree.getClass().getName());\r
+ \r
+ // Apply the translation.\r
+ tree.apply(evaluator);\r
+\r
+ }\r
+ catch(Exception e)\r
+ {\r
+ e.printStackTrace();\r
+ evaluator.except(e);\r
+ } \r
+ \r
+ }\r
+\r
+}\r