diff options
author | Quentin Carbonneaux <quentin.carbonneaux@yale.edu> | 2015-10-04 21:08:57 -0400 |
---|---|---|
committer | Quentin Carbonneaux <quentin.carbonneaux@yale.edu> | 2015-10-04 21:08:57 -0400 |
commit | 4eb54dc750a3269e737910ffda9b7f385cb41223 (patch) | |
tree | 116ed588454b99a149c7bd542b41ca1c083a58bd /minic | |
parent | ae38614f9447fabc679c964bd1d4e97d1d9f13ae (diff) | |
download | roux-4eb54dc750a3269e737910ffda9b7f385cb41223.tar.gz |
support unary minus
Diffstat (limited to 'minic')
-rw-r--r-- | minic/minic.y | 15 |
1 files changed, 14 insertions, 1 deletions
diff --git a/minic/minic.y b/minic/minic.y index 66d576d..3465ca5 100644 --- a/minic/minic.y +++ b/minic/minic.y @@ -446,6 +446,18 @@ mkidx(Node *a, Node *i) return n; } +Node * +mkneg(Node *n) +{ + static Node *z; + + if (!z) { + z = mknode('N', 0, 0); + z->u.n = 0; + } + return mknode('-', z, n); +} + Stmt * mkstmt(int t, void *p1, void *p2, void *p3) { @@ -533,7 +545,6 @@ stmts: stmts stmt { $$ = mkstmt(Seq, $1, $2, 0); } ; expr: pref - | '(' expr ')' { $$ = $2; } | expr '=' expr { $$ = mknode('=', $1, $3); } | expr '+' expr { $$ = mknode('+', $1, $3); } | expr '-' expr { $$ = mknode('-', $1, $3); } @@ -549,12 +560,14 @@ expr: pref ; pref: post + | '-' pref { $$ = mkneg($2); } | '*' pref { $$ = mknode('@', $2, 0); } | '&' pref { $$ = mknode('&', $2, 0); } ; post: NUM | IDENT + | '(' expr ')' { $$ = $2; } | post '[' expr ']' { $$ = mkidx($1, $3); } | post PP { $$ = mknode('P', $1, 0); } | post MM { $$ = mknode('M', $1, 0); } |