diff 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 diff
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/src/sdl/expr.y	Sun Mar 04 21:06:50 2012 -0600
     1.3 @@ -0,0 +1,77 @@
     1.4 +%{
     1.5 +namespace std {  
     1.6 +#include <stdio.h>
     1.7 +#include <memory.h>
     1.8 +#include <stdlib.h>
     1.9 +#include <string.h>
    1.10 +}
    1.11 +
    1.12 +using namespace std;
    1.13 + 
    1.14 +#include "System.h"
    1.15 +#include "elf.h"
    1.16 +#include "exprNode.h" 
    1.17 +
    1.18 +extern int yyerror(char *);
    1.19 +extern int yylex(); 
    1.20 +extern char *yytext;
    1.21 +
    1.22 +  
    1.23 +//#define YYERROR_VERBOSE 1
    1.24 +//#define YYDEBUG 1
    1.25 +
    1.26 + Node *result = NULL;
    1.27 +%}
    1.28 +
    1.29 +%token TOKEN_IDENTIFIER TOKEN_DOT TOKEN_STAR TOKEN_ARROW TOKEN_ADDR
    1.30 +%token TOKEN_SIZEOF TOKEN_NUMBER
    1.31 +%left TOKEN_DOT TOKEN_ARROW '['
    1.32 +%expect 6
    1.33 +%%
    1.34 +
    1.35 +final: expression { result = $1; }
    1.36 +;
    1.37 +
    1.38 +expression:
    1.39 +  simple_expression { $$ = $1; } |
    1.40 +  '(' expression ')' { $$ = $2; } |
    1.41 +  expression TOKEN_DOT ident { $$ = exprNodeDot($1, $3); } |
    1.42 +  expression TOKEN_ARROW ident { $$ = exprNodeArrow($1, $3); } |
    1.43 +  expression '[' number ']' { $$ = exprNodeArray($1, $3); }
    1.44 +;
    1.45 +simple_expression:
    1.46 +  ident  { $$ = $1; } |
    1.47 +  TOKEN_STAR expression { $$ = exprNodeStar($2); } |
    1.48 +  TOKEN_ADDR expression { $$ = exprNodeAddr($2); } |
    1.49 +  TOKEN_SIZEOF '(' expression ')' { $$ = exprNodeSizeof($3); }
    1.50 +;
    1.51 +
    1.52 +number:
    1.53 +  TOKEN_NUMBER { $$ = exprNodeNumber(); }
    1.54 +;
    1.55 +
    1.56 +ident:
    1.57 +  TOKEN_IDENTIFIER {$$ = exprNodeIdentifier(); }
    1.58 +;
    1.59 +
    1.60 +%%
    1.61 +
    1.62 +int yyerror(char *s)
    1.63 +{
    1.64 +  return 0;
    1.65 +}
    1.66 +
    1.67 +#ifndef SDL
    1.68 +extern FILE *yyin;
    1.69 +int main(int argc, char **argv)
    1.70 +{
    1.71 +  //  yydebug = 1;
    1.72 +  ++argv, --argc;
    1.73 +  if(argc > 0)
    1.74 +    yyin = fopen(argv[0], "r");
    1.75 +  else
    1.76 +    yyin = stdin;
    1.77 +  if(!yyparse())
    1.78 +    result->print();
    1.79 +}
    1.80 +#endif