summary refs log tree commit diff
diff options
context:
space:
mode:
authorQuentin Carbonneaux <quentin.carbonneaux@yale.edu>2015-10-12 12:50:58 -0400
committerQuentin Carbonneaux <quentin.carbonneaux@yale.edu>2015-10-12 12:50:58 -0400
commitf4dc0f98a5fc6b6c78400798d545b4f119bef665 (patch)
tree5b9f7de747572f65f2a3d7edb61439699c03a0e5
parentd1b2cf2d49cad7978b7c6307a2c17cc3d34aa42c (diff)
downloadroux-f4dc0f98a5fc6b6c78400798d545b4f119bef665.tar.gz
add a cheap implementation of sizeof
-rw-r--r--minic/minic.y14
1 files changed, 8 insertions, 6 deletions
diff --git a/minic/minic.y b/minic/minic.y
index 79fb5f2..2acd5a2 100644
--- 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;