view src/sdl/expr.y @ 28:2efb971df515

bringing in SDL package
author Robert McIntyre <rlm@mit.edu>
date Sun, 04 Mar 2012 21:06:50 -0600
parents f9f4f1b99eed
children
line wrap: on
line source
1 %{
2 namespace std {
3 #include <stdio.h>
4 #include <memory.h>
5 #include <stdlib.h>
6 #include <string.h>
7 }
9 using namespace std;
11 #include "System.h"
12 #include "elf.h"
13 #include "exprNode.h"
15 extern int yyerror(char *);
16 extern int yylex();
17 extern char *yytext;
20 //#define YYERROR_VERBOSE 1
21 //#define YYDEBUG 1
23 Node *result = NULL;
24 %}
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 %%
32 final: expression { result = $1; }
33 ;
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 ;
49 number:
50 TOKEN_NUMBER { $$ = exprNodeNumber(); }
51 ;
53 ident:
54 TOKEN_IDENTIFIER {$$ = exprNodeIdentifier(); }
55 ;
57 %%
59 int yyerror(char *s)
60 {
61 return 0;
62 }
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