From f4dc0f98a5fc6b6c78400798d545b4f119bef665 Mon Sep 17 00:00:00 2001 From: Quentin Carbonneaux Date: Mon, 12 Oct 2015 12:50:58 -0400 Subject: add a cheap implementation of sizeof --- minic/minic.y | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) (limited to 'minic/minic.y') 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 NUM %token STR %token 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; -- cgit 1.4.1