From 9e2087d37770e4201db1975a051d3287b93b6bc3 Mon Sep 17 00:00:00 2001 From: Otto Moerbeek Date: Sun, 19 Oct 2003 19:21:49 +0000 Subject: Allow the expressions in for (E ; E ; E ) to be empty. --- usr.bin/bc/bc.1 | 8 +++++--- usr.bin/bc/bc.y | 26 +++++++++++++++++++++----- 2 files changed, 26 insertions(+), 8 deletions(-) diff --git a/usr.bin/bc/bc.1 b/usr.bin/bc/bc.1 index d6734a810fc..26ed11be713 100644 --- a/usr.bin/bc/bc.1 +++ b/usr.bin/bc/bc.1 @@ -1,4 +1,4 @@ -.\" $OpenBSD: bc.1,v 1.6 2003/10/18 19:57:10 otto Exp $ +.\" $OpenBSD: bc.1,v 1.7 2003/10/19 19:21:48 otto Exp $ .\" .\" Copyright (C) Caldera International Inc. 2001-2002. .\" All rights reserved. @@ -125,6 +125,10 @@ quit a string of characters, enclosed in double quotes .Ed .Pp +The E's in a for statement may all three be empty. +This is a non-portable extension. +The continue statement also is a non-portable extension. +.Pp Function definitions .Bd -unfilled -offset indent -compact define L ( L ,..., L ) { @@ -232,8 +236,6 @@ or .Sq \&! operators. .Pp -.Ql For -statements must have all three E's. .Pp .Ql Quit is interpreted when read, not when executed. diff --git a/usr.bin/bc/bc.y b/usr.bin/bc/bc.y index c97fbeb803a..e0f876f8a00 100644 --- a/usr.bin/bc/bc.y +++ b/usr.bin/bc/bc.y @@ -1,5 +1,5 @@ %{ -/* $OpenBSD: bc.y,v 1.12 2003/10/18 20:35:36 otto Exp $ */ +/* $OpenBSD: bc.y,v 1.13 2003/10/19 19:21:48 otto Exp $ */ /* * Copyright (c) 2003, Otto Moerbeek @@ -31,7 +31,7 @@ */ #ifndef lint -static const char rcsid[] = "$OpenBSD: bc.y,v 1.12 2003/10/18 20:35:36 otto Exp $"; +static const char rcsid[] = "$OpenBSD: bc.y,v 1.13 2003/10/19 19:21:48 otto Exp $"; #endif /* not lint */ #include @@ -138,6 +138,8 @@ extern char *__progname; %type function_header %type input_item %type opt_argument_list +%type opt_expression +%type opt_relational_expression %type opt_statement %type relational_expression %type return_expression @@ -278,9 +280,9 @@ statement : expression } $$ = $3; } - | FOR LPAR alloc_macro expression SEMICOLON - relational_expression SEMICOLON - expression RPAR opt_statement pop_nesting + | FOR LPAR alloc_macro opt_expression SEMICOLON + opt_relational_expression SEMICOLON + opt_expression RPAR opt_statement pop_nesting { ssize_t n; @@ -443,6 +445,13 @@ argument_list : expression } ; +opt_relational_expression + : /* empty */ + { + $$ = cs(" 0 0="); + } + | relational_expression + ; relational_expression : expression @@ -490,6 +499,13 @@ return_expression ; +opt_expression : /* empty */ + { + $$ = cs(" 0"); + } + | expression + ; + expression : named_expression { $$ = node($1.load, END_NODE); -- cgit v1.2.3