Mercurial > vba-linux
comparison src/sdl/expr.y @ 1:f9f4f1b99eed
importing src directory
author | Robert McIntyre <rlm@mit.edu> |
---|---|
date | Sat, 03 Mar 2012 10:31:27 -0600 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
0:8ced16adf2e1 | 1:f9f4f1b99eed |
---|---|
1 %{ | |
2 namespace std { | |
3 #include <stdio.h> | |
4 #include <memory.h> | |
5 #include <stdlib.h> | |
6 #include <string.h> | |
7 } | |
8 | |
9 using namespace std; | |
10 | |
11 #include "System.h" | |
12 #include "elf.h" | |
13 #include "exprNode.h" | |
14 | |
15 extern int yyerror(char *); | |
16 extern int yylex(); | |
17 extern char *yytext; | |
18 | |
19 | |
20 //#define YYERROR_VERBOSE 1 | |
21 //#define YYDEBUG 1 | |
22 | |
23 Node *result = NULL; | |
24 %} | |
25 | |
26 %token TOKEN_IDENTIFIER TOKEN_DOT TOKEN_STAR TOKEN_ARROW TOKEN_ADDR | |
27 %token TOKEN_SIZEOF TOKEN_NUMBER | |
28 %left TOKEN_DOT TOKEN_ARROW '[' | |
29 %expect 6 | |
30 %% | |
31 | |
32 final: expression { result = $1; } | |
33 ; | |
34 | |
35 expression: | |
36 simple_expression { $$ = $1; } | | |
37 '(' expression ')' { $$ = $2; } | | |
38 expression TOKEN_DOT ident { $$ = exprNodeDot($1, $3); } | | |
39 expression TOKEN_ARROW ident { $$ = exprNodeArrow($1, $3); } | | |
40 expression '[' number ']' { $$ = exprNodeArray($1, $3); } | |
41 ; | |
42 simple_expression: | |
43 ident { $$ = $1; } | | |
44 TOKEN_STAR expression { $$ = exprNodeStar($2); } | | |
45 TOKEN_ADDR expression { $$ = exprNodeAddr($2); } | | |
46 TOKEN_SIZEOF '(' expression ')' { $$ = exprNodeSizeof($3); } | |
47 ; | |
48 | |
49 number: | |
50 TOKEN_NUMBER { $$ = exprNodeNumber(); } | |
51 ; | |
52 | |
53 ident: | |
54 TOKEN_IDENTIFIER {$$ = exprNodeIdentifier(); } | |
55 ; | |
56 | |
57 %% | |
58 | |
59 int yyerror(char *s) | |
60 { | |
61 return 0; | |
62 } | |
63 | |
64 #ifndef SDL | |
65 extern FILE *yyin; | |
66 int main(int argc, char **argv) | |
67 { | |
68 // yydebug = 1; | |
69 ++argv, --argc; | |
70 if(argc > 0) | |
71 yyin = fopen(argv[0], "r"); | |
72 else | |
73 yyin = stdin; | |
74 if(!yyparse()) | |
75 result->print(); | |
76 } | |
77 #endif |