1 /*******************************************************************************
2 * Copyright (c) 2007, 2010 Association for Decentralized Information Management
4 * All rights reserved. This program and the accompanying materials
5 * are made available under the terms of the Eclipse Public License v1.0
6 * which accompanies this distribution, and is available at
7 * http://www.eclipse.org/legal/epl-v10.html
10 * VTT Technical Research Centre of Finland - initial API and implementation
11 *******************************************************************************/
12 package org.simantics.basicexpression;
14 import java.io.PushbackReader;
15 import java.io.StringReader;
17 import org.simantics.basicexpression.analysis.DepthFirstAdapter;
18 import org.simantics.basicexpression.lexer.Lexer;
19 import org.simantics.basicexpression.node.Start;
20 import org.simantics.basicexpression.parser.Parser;
21 import org.slf4j.Logger;
22 import org.slf4j.LoggerFactory;
24 public class Expressions {
26 private static final Logger LOGGER = LoggerFactory.getLogger(Expressions.class);
28 private static final boolean DEBUG = false;
30 public static void evaluate(String expression, DepthFirstAdapter evaluator) {
34 // Create a Parser instance.
38 new PushbackReader(new StringReader(expression))));
41 Start tree = p.parse();
44 tree.apply(new PrettyPrintExpressionVisitor());
46 // System.out.println("tree=" + tree.getClass().getName());
48 // Apply the translation.
49 tree.apply(evaluator);
54 if (LOGGER.isDebugEnabled())
55 LOGGER.debug("Failed to evaluate expression {}", expression, e);