-
Notifications
You must be signed in to change notification settings - Fork 8
Expand file tree
/
Copy pathparser.ym
More file actions
42 lines (28 loc) · 710 Bytes
/
parser.ym
File metadata and controls
42 lines (28 loc) · 710 Bytes
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
%{
#import "MessageBlocks.h"
int yylex(void);
void yyerror(char *s);
%}
%union {
float value;
NSString *identifier;
}
%token <value> INTEGER
%token <value> FLOAT
%token <identifier> IDENTIFIER
%type <value> expr
%type <value> number
%destructor { [$$ release]; } IDENTIFIER
%left '+' '-'
%left '*' '/'
%%
calc : expr { if (ParseTestSuccessBlock) ParseTestSuccessBlock($1); }
expr : number { $$ = $1; }
| expr '*' expr { $$ = $1 * $3; }
| expr '/' expr { $$ = $1 / $3; }
| expr '+' expr { $$ = $1 + $3; }
| expr '-' expr { $$ = $1 - $3; }
number : INTEGER { $$ = $1; }
| FLOAT { $$ = $1; }
| IDENTIFIER { if ([$1 isEqualToString:@"pi"]) $$ = M_PI; else $$ = 0.0; [$1 release]; }
%%