Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Newer
Older
100644 65 lines (49 sloc) 1.847 kb
05eedb5 @itod initial add
authored
1 // Copyright 2010 Todd Ditchendorf
2 //
3 // Licensed under the Apache License, Version 2.0 (the "License");
4 // you may not use this file except in compliance with the License.
5 // You may obtain a copy of the License at
6 //
7 // http://www.apache.org/licenses/LICENSE-2.0
8 //
9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS IS" BASIS,
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 // See the License for the specific language governing permissions and
13 // limitations under the License.
14
15 #import "TDArithmeticAssembler.h"
16 #import <ParseKit/ParseKit.h>
17
18 @implementation TDArithmeticAssembler
19
253c2e0 @itod merging changes from google code
authored
20 - (void)parser:(PKParser *)p didMatchPlus:(PKAssembly *)a {
05eedb5 @itod initial add
authored
21 PKToken *tok2 = [a pop];
22 PKToken *tok1 = [a pop];
23 [a push:[NSNumber numberWithDouble:tok1.floatValue + tok2.floatValue]];
24 }
25
26
253c2e0 @itod merging changes from google code
authored
27 - (void)parser:(PKParser *)p didMatchMinus:(PKAssembly *)a {
05eedb5 @itod initial add
authored
28 PKToken *tok2 = [a pop];
29 PKToken *tok1 = [a pop];
30 [a push:[NSNumber numberWithDouble:tok1.floatValue - tok2.floatValue]];
31 }
32
33
253c2e0 @itod merging changes from google code
authored
34 - (void)parser:(PKParser *)p didMatchTimes:(PKAssembly *)a {
05eedb5 @itod initial add
authored
35 PKToken *tok2 = [a pop];
36 PKToken *tok1 = [a pop];
37 [a push:[NSNumber numberWithDouble:tok1.floatValue * tok2.floatValue]];
38 }
39
40
253c2e0 @itod merging changes from google code
authored
41 - (void)parser:(PKParser *)p didMatchDivide:(PKAssembly *)a {
05eedb5 @itod initial add
authored
42 PKToken *tok2 = [a pop];
43 PKToken *tok1 = [a pop];
44 [a push:[NSNumber numberWithDouble:tok1.floatValue / tok2.floatValue]];
45 }
46
47
253c2e0 @itod merging changes from google code
authored
48 - (void)parser:(PKParser *)p didMatchExp:(PKAssembly *)a {
05eedb5 @itod initial add
authored
49 PKToken *tok2 = [a pop];
50 PKToken *tok1 = [a pop];
51
eb778c5 @itod merging changes from Google Code SVN repo
authored
52 double n1 = tok1.floatValue;
53 double n2 = tok2.floatValue;
05eedb5 @itod initial add
authored
54
eb778c5 @itod merging changes from Google Code SVN repo
authored
55 double res = n1;
05eedb5 @itod initial add
authored
56 NSUInteger i = 1;
57 for ( ; i < n2; i++) {
58 res *= n1;
59 }
60
61 [a push:[NSNumber numberWithDouble:res]];
62 }
63
64 @end
Something went wrong with that request. Please try again.