commit f4dc0f98a5fc6b6c78400798d545b4f119bef665
parent d1b2cf2d49cad7978b7c6307a2c17cc3d34aa42c
Author: Quentin Carbonneaux <quentin.carbonneaux@yale.edu>
Date: Mon, 12 Oct 2015 12:50:58 -0400
add a cheap implementation of sizeof
Diffstat:
1 file changed, 8 insertions(+), 6 deletions(-)
diff --git a/minic/minic.y b/minic/minic.y
@@ -501,7 +501,7 @@ mkstmt(int t, void *p1, void *p2, void *p3)
%token <n> NUM
%token <n> STR
%token <n> IDENT
-%token PP MM LE GE
+%token PP MM LE GE SIZEOF
%token TINT TLNG
%token IF ELSE WHILE
@@ -592,11 +592,12 @@ pref: post
post: NUM
| STR
| IDENT
- | '(' expr ')' { $$ = $2; }
- | IDENT '(' arg0 ')' { $$ = mknode('C', $1, $3); }
- | post '[' expr ']' { $$ = mkidx($1, $3); }
- | post PP { $$ = mknode('P', $1, 0); }
- | post MM { $$ = mknode('M', $1, 0); }
+ | SIZEOF '(' type ')' { $$ = mknode('N', 0, 0); $$->u.n = SIZE($3); }
+ | '(' expr ')' { $$ = $2; }
+ | IDENT '(' arg0 ')' { $$ = mknode('C', $1, $3); }
+ | post '[' expr ']' { $$ = mkidx($1, $3); }
+ | post PP { $$ = mknode('P', $1, 0); }
+ | post MM { $$ = mknode('M', $1, 0); }
;
arg0: arg1
@@ -620,6 +621,7 @@ yylex()
{ "if", IF },
{ "else", ELSE },
{ "while", WHILE },
+ { "sizeof", SIZEOF },
{ 0, 0 }
};
int i, c, c1, n;