Many amenities can be mapped as areas.
[potlatch2.git] / it / sephiroth / expr / CompiledExpression.as
1 package it.sephiroth.expr
2 {
3         import flash.utils.ByteArray;
4         
5         import it.sephiroth.expr.ast.IExpression;
6         
7         public class CompiledExpression
8         {
9                 private var _expression: IExpression;
10                 private var _symbols: SymbolTable;
11                 
12                 public function CompiledExpression( expression: IExpression, symbols: SymbolTable )
13                 {
14                         _expression = expression;
15                         _symbols = symbols;
16                 }
17                 
18                 public function execute( context: Object ): Number
19                 {
20                         for( var key: String in context )
21                         {
22                                 var ident: Ident = _symbols.find( key );
23                                 if( ident )
24                                 {
25                                         ident.value = context[ key ];
26                                 }
27                         }
28                         
29                         return _expression.evaluate();
30                 }
31                 
32                 public function toString(): String
33                 {
34                         return _expression.toString();
35                 }
36                 
37                 public function compile(): ByteArray
38                 {
39                         var compiler: SWFCompiler = new SWFCompiler( _expression, _symbols );
40                         
41                         return compiler.compile();
42                 }
43
44         }
45 }