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