]> gerrit.simantics Code Review - simantics/platform.git/blob - bundles/org.simantics.basicexpression/src/org/simantics/basicexpression/Expressions.java
Fixed all line endings of the repository
[simantics/platform.git] / bundles / org.simantics.basicexpression / src / org / simantics / basicexpression / Expressions.java
1 /*******************************************************************************
2  * Copyright (c) 2007, 2010 Association for Decentralized Information Management
3  * in Industry THTH ry.
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
8  *
9  * Contributors:
10  *     VTT Technical Research Centre of Finland - initial API and implementation
11  *******************************************************************************/
12 package org.simantics.basicexpression;
13
14 import java.io.PushbackReader;
15 import java.io.StringReader;
16
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
22 public class Expressions {
23
24         private static final boolean DEBUG = false;
25         
26     public static void evaluate(String expression, DepthFirstAdapter evaluator) {
27         
28         try
29         {
30             // Create a Parser instance.
31             Parser p =
32                 new Parser(
33                         new Lexer(
34                                 new PushbackReader(new StringReader(expression))));
35
36             // Parse the input.
37             Start tree = p.parse();
38             
39             if(DEBUG)
40                 tree.apply(new PrettyPrintExpressionVisitor());
41             
42 //            System.out.println("tree=" + tree.getClass().getName());
43             
44             // Apply the translation.
45             tree.apply(evaluator);
46
47         }
48         catch(Exception e)
49         {
50                 e.printStackTrace();
51                 evaluator.except(e);
52         }        
53         
54     }
55
56 }