diff options
author | Otto Moerbeek <otto@cvs.openbsd.org> | 2003-10-22 12:24:42 +0000 |
---|---|---|
committer | Otto Moerbeek <otto@cvs.openbsd.org> | 2003-10-22 12:24:42 +0000 |
commit | 85e9f30cf17824bfbc8ed7c5f3e975855c32f194 (patch) | |
tree | aca65a996b9d647ecd10a8001f065ac82192d25a /usr.bin/bc | |
parent | f3b6972c1606fe0546e568d467e61160906ad238 (diff) |
Implement if ... else statement. If you do not use 'else', code generated
is still classic dc(1) compatible. If you do use 'else', you'll need a dc(1)
that implements the new extended comparison operators like '=xey'.
Diffstat (limited to 'usr.bin/bc')
-rw-r--r-- | usr.bin/bc/bc.1 | 4 | ||||
-rw-r--r-- | usr.bin/bc/bc.y | 12 |
2 files changed, 13 insertions, 3 deletions
diff --git a/usr.bin/bc/bc.1 b/usr.bin/bc/bc.1 index ee20078f1f3..a71577f4106 100644 --- a/usr.bin/bc/bc.1 +++ b/usr.bin/bc/bc.1 @@ -1,4 +1,4 @@ -.\" $OpenBSD: bc.1,v 1.8 2003/10/20 09:27:48 jmc Exp $ +.\" $OpenBSD: bc.1,v 1.9 2003/10/22 12:24:41 otto Exp $ .\" .\" Copyright (C) Caldera International Inc. 2001-2002. .\" All rights reserved. @@ -116,6 +116,7 @@ Statements E { S ; ... ; S } if ( E ) S +if ( E ) S else S while ( E ) S for ( E ; E ; E ) S null statement @@ -125,6 +126,7 @@ quit a string of characters, enclosed in double quotes .Ed .Pp +The if statement with an else branch is a non-portable extension. All three E's in a for statement may be empty. This is a non-portable extension. The continue statement is also a non-portable extension. diff --git a/usr.bin/bc/bc.y b/usr.bin/bc/bc.y index e0f876f8a00..7db4a3c64b9 100644 --- a/usr.bin/bc/bc.y +++ b/usr.bin/bc/bc.y @@ -1,5 +1,5 @@ %{ -/* $OpenBSD: bc.y,v 1.13 2003/10/19 19:21:48 otto Exp $ */ +/* $OpenBSD: bc.y,v 1.14 2003/10/22 12:24:41 otto Exp $ */ /* * Copyright (c) 2003, Otto Moerbeek <otto@drijf.net> @@ -31,7 +31,7 @@ */ #ifndef lint -static const char rcsid[] = "$OpenBSD: bc.y,v 1.13 2003/10/19 19:21:48 otto Exp $"; +static const char rcsid[] = "$OpenBSD: bc.y,v 1.14 2003/10/22 12:24:41 otto Exp $"; #endif /* not lint */ #include <ctype.h> @@ -303,6 +303,14 @@ statement : expression emit_macro($3, $7); $$ = node($5, $3, cs(" "), END_NODE); } + | IF LPAR alloc_macro pop_nesting relational_expression RPAR + opt_statement ELSE alloc_macro pop_nesting opt_statement + { + emit_macro($3, $7); + emit_macro($9, $11); + $$ = node($5, $3, cs("e"), $9, cs(" "), + END_NODE); + } | WHILE LPAR alloc_macro relational_expression RPAR opt_statement pop_nesting { |