Top Down or Bottom Up for Expression Evaluation ?

Law And Order Criminal Intent Antithesis Recap

Legit Paper Writing Services

Dissertation Read Online I will not release today the port because actually I had not time to make sure it is bugfree and I’ve only a working version for Mac, but I plan to release it shortly if you will ever need it for your own tasks. My goal for today was to compare the speed of the parser I wrote with an automatically generated bottom up parser, to see which is the faster approach.

Homework Help Global Warming

http://corporate-coach.com/literary-essay-help/ Literary Essay Help

http://asbsteel.com/?research-paper-for-me Research Paper For Me The parser grammar is really simple and really readable:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
%{
%}
%token NUMBER SYMBOL
%left '+' '-'
%left '*' '/'
%left NEG
%%
program
: expr                { Vars.result = $1; }
;
expr
: expr '+' expr       { $$ = $1 + $3; }
| expr '-' expr       { $$ = $1 - $3; }
| expr '*' expr       { $$ = $1 * $3; }
| expr '/' expr       { $$ = $1 / $3; }
| '-' expr %prec NEG  { $$ = -$2; }
| '(' expr ')'        { $$ = $2; }
| SYMBOL '(' expr ')' {
if( Vars.SYMBOL_TABLE[ $1 ] )
{
$$ = Vars.SYMBOL_TABLE[ $1 ]( $3 );
} else
{
trace( "can't find function" );
}
}
| SYMBOL              {
if( Vars.SYMBOL_TABLE[ $1 ] )
{
$$ = Vars.SYMBOL_TABLE[ $1 ];
} else
{
trace( "can't find symbol" );
}
}
| NUMBER              { $$ = yyval; }
;
%%

Cultural Competence And Dissertation

http://www.codica-cables.fr/how-to-write-a-high-school-application-essay-junior/ How To Write A High School Application Essay Junior

As you might have noted there is a really big difference about how the expression will be evaluated here and how do I evaluate it in my original expression parser: the expression is executed as soon as a rule is matched, and it is not compiled into an intermediate abstract syntax tree.
Usually those kind of tools are used in conjunction with a lexer generator (Flex is a good example of lexer generator – don’t confuse it with Adobe Flex!! :D), that is able to automatically generate the code for a scanner based in a set of rules usually defined by regular expressions. I didn’t ported this kind of tool because I was already having a working scanner for my needs that is a porting of the scanner used in the expression evaluator library:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
package it.sephiroth.expr2
{
   public class Lexer
   {
      private var _pos: int;
      private var _pool: Array;
      private var _source: String;
      public function Lexer( source: String )
      {
         _pos = 0;
         _source = source;
         _pool = new Array();
      }
      public function scan(): Object
      {
         if( _pool.length > 0 )
         {
            return _pool.shift();
         }
         skipWhites();
         if( isEOF() )
         {
            return null;
         }
         var c: String = _source.charAt( _pos++ );
         switch( c )
         {
            case '+':
            case '-':
            case '*':
            case '/':
            case '(':
            case ')':
            case ',':  return  { type: c.charCodeAt( 0 ), val: c };
            default:
               var buf: String = "";
               var code: int = c.charCodeAt( 0 );
               if( isNumber( code ) )
               {
                  var num: Number;
                  while( isNumber( code ) )
                  {
                     buf += c;
                     if( isEOF() )
                     {
                        ++_pos;
                        break;
                     }
                     c  = _source.charAt( _pos++ );
                     code = c.charCodeAt( 0 );
                  }
                  if( c == '.' )
                  {
                     buf += c;
                     c  = _source.charAt( _pos++ );
                     code = c.charCodeAt( 0 );
                     while( isNumber( code ) )
                     {
                        buf += c;
                        if( isEOF() )
                        {
                           ++_pos;
                           break;
                        }
                        c  = _source.charAt( _pos++ );
                        code = c.charCodeAt( 0 );
                     }
                     num = parseFloat( buf );
                  }else
                  {
                     num = parseInt( buf );
                  }
                  ->pos;
                  return  { type: Token.NUMBER, val: num };
               }
               if( isAlpha( code ) || ( c == '_' ) )
               {
                  while( isAlpha( code ) || ( c == '_' ) || isNumber( code ) )
                  {
                     buf += c;
                     if( isEOF() )
                     {
                        ++_pos;
                        break;
                     }
                     c  = _source.charAt( _pos++ );
                     code = c.charCodeAt( 0 );
                  }
                  ->pos;
                  return  { type: Token.SYMBOL, val: buf };
               }
               break;
         }
         return null;
      }
      public function pushBack( token: Token ): void
      {
         _pool.push( token );
      }
      protected function isNumber( c: int ): Boolean
      {
         return ( c >= 48 ) && ( c < = 57 );
      }
      protected function isAlpha( c: int ): Boolean
      {
         return ( ( c >= 97 ) && ( c < = 122 ) ) || ( ( c >= 65 ) && ( c < = 90 ) );
      }
      protected function isEOF(): Boolean
      {
         return ( _pos >= _source.length );
      }
      protected function skipWhites(): void
      {
         while( !isEOF() )
         {
            var c: String = _source.charAt( _pos++ );
            if( ( c != " " ) && ( c != "\t" ) )
            {
               ->pos;
               break;
            }
         }
      }
   }
}

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
package {
   import flash.display.Sprite;
   import flash.utils.getTimer;
   import it.sephiroth.expr.CompiledExpression;
   import it.sephiroth.expr.Parser;
   import it.sephiroth.expr.Scanner;
   import it.sephiroth.expr2.Vars;
   public class TestExprEval extends Sprite
   {
      public static const ITERATIONS: int = 10000;
      public static const EXPRESSION: String = "sin( x / ( 4 / 2.0 * 2 + (- 2.12345 + 2.12345) * x / x ) ) * 100 - ( sin( x / ( 4 / 2.0 * 2 + (- 2.12345 + 2.12345) * x / x ) ) * 100 )";
      public function TestExprEval()
      {
         runTests();
      }
      private function runTests(): void
      {
         trace( "Running tests (this may take a while)" );
         runTopDown();
         runBottomUp();
      }
      private function runTopDown(): void
      {
         var sum: Number = 0;
         for( var i: int = 0; i < ITERATIONS; ++i )
         {
            var t: Number = getTimer();
            var scanner: Scanner = new Scanner( EXPRESSION );
            var parser: Parser = new Parser( scanner );
            var compiled: CompiledExpression = parser.parse();
            compiled.execute( {
               'x'    : Math.random(),
               'sin'  : Math.sin,
               'cos'  : Math.cos
            } );
            sum += ( getTimer() - t );
         }
         trace( "Top Down parser:", sum / ITERATIONS );
      }
      private function runBottomUp(): void
      {
         var sum: Number = 0;
         Vars.symbolTable.sin = Math.sin;
         for( var i: int = 0; i < ITERATIONS; ++i )
         {
            Vars.symbolTable.x = Math.random();
            var t: Number = getTimer();
            var myparser: TestBottomUpParser = new TestBottomUpParser();
            myparser.yyparse()
            sum += ( getTimer() - t );
         }
         trace( "Bottom Up parser:", sum / ITERATIONS );
      }
   }
}
import it.sephiroth.expr2.BottomUpParser;
import it.sephiroth.expr2.Lexer;
class TestBottomUpParser extends BottomUpParser
{
   private var _lexer: Lexer;
   public function TestBottomUpParser()
   {
      super();
      _lexer = new Lexer( TestExprEval.EXPRESSION );
   }
   override public function yylex(): int
   {
      var value: Object = _lexer.scan();
      if( value == null )
      {
         return 0;
      }
      set_yylval( value.val );
      return value.type;
   }
}

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
$ mxmlc -debug=true TestExprEval.as
Loading configuration file /Applications/Adobe Flex Builder 3 Plug-in/sdks/3.0.0/frameworks/flex-config.xml
/Users/gabriele/Desktop/TestExprParsers/src/TestExprEval.swf (11647 bytes)
$ fdb TestExprEval.swf
Adobe fdb (Flash Player Debugger) [build 3.0.0.477]
Copyright (c) 2004-2007 Adobe, Inc. All rights reserved.
Attempting to launch and connect to Player using URL
TestExprEval.swf
Player connected; session starting.
Set breakpoints and then type 'continue' to resume the session.
[SWF] Users:gabriele:Desktop:TestExprParsers:src:TestExprEval.swf - 25.942 bytes after decompression
(fdb) continue
[trace] Running tests (this may take a while)
[trace] Top Down parser: 0.6979
[trace] Bottom Up parser: 0.9063
(fdb) quit

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
private function runTopDownCompiled(): void
{
   var sum: Number = 0;
   var scanner: Scanner = new Scanner( EXPRESSION );
   var parser: Parser = new Parser( scanner );
   var compiled: CompiledExpression = parser.parse();
   for( var i: int = 0; i < ITERATIONS; ++i )
   {
      var t: Number = getTimer();
      compiled.execute( {
         'x':     Math.random(),
         'sin'  : Math.sin,
         'cos'  : Math.cos
      } );
      sum += ( getTimer() - t );
   }
   trace( "Top Down parser (precompiled):", sum / ITERATIONS );
}

http://talkingtech.net/cv-writing-services-usa/ Cv Writing Services Usa

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
$ mxmlc -debug=true TestExprEval.as
Loading configuration file /Applications/Adobe Flex Builder 3 Plug-in/sdks/3.0.0/frameworks/flex-config.xml
/Users/gabriele/Desktop/TestExprParsers/src/TestExprEval.swf (11794 bytes)
$ fdb TestExprEval.swf
Adobe fdb (Flash Player Debugger) [build 3.0.0.477]
Copyright (c) 2004-2007 Adobe, Inc. All rights reserved.
Attempting to launch and connect to Player using URL
TestExprEval.swf
Player connected; session starting.
Set breakpoints and then type 'continue' to resume the session.
[SWF] Users:gabriele:Desktop:TestExprParsers:src:TestExprEval.swf - 26.272 bytes after decompression
(fdb) continue
[trace] Running tests (this may take a while)
[trace] Top Down parser: 0.698
[trace] Bottom Up parser: 0.9001
[trace] Top Down parser (precompiled): 0.0315

http://sacredsourcework.com/?buy-essay-not-plagiarized Buy Essay Not Plagiarized