summaryrefslogtreecommitdiff
path: root/usr.bin
diff options
context:
space:
mode:
authorOtto Moerbeek <otto@cvs.openbsd.org>2003-11-11 19:49:03 +0000
committerOtto Moerbeek <otto@cvs.openbsd.org>2003-11-11 19:49:03 +0000
commit08e87522daa4ae9783fe55187a5bbe8e8d2e79f7 (patch)
treefc5e9fce9329b983f0814fe63a8eb16aa84dfa56 /usr.bin
parent48b10c5711116214489988743774a7450e9755d2 (diff)
Some syntactic sugar (all non-portable extensions):
- a line comment, starting with # - opening brace of define statement may be on next line - return expression, equivalent to return (expression)
Diffstat (limited to 'usr.bin')
-rw-r--r--usr.bin/bc/bc.y30
-rw-r--r--usr.bin/bc/scan.l5
2 files changed, 18 insertions, 17 deletions
diff --git a/usr.bin/bc/bc.y b/usr.bin/bc/bc.y
index 992d200e4e6..91438ed20d8 100644
--- a/usr.bin/bc/bc.y
+++ b/usr.bin/bc/bc.y
@@ -1,5 +1,5 @@
%{
-/* $OpenBSD: bc.y,v 1.15 2003/11/11 09:15:36 otto Exp $ */
+/* $OpenBSD: bc.y,v 1.16 2003/11/11 19:49:02 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.15 2003/11/11 09:15:36 otto Exp $";
+static const char rcsid[] = "$OpenBSD: bc.y,v 1.16 2003/11/11 19:49:02 otto Exp $";
#endif /* not lint */
#include <ctype.h>
@@ -266,22 +266,13 @@ statement : expression
fflush(stdout);
exit(0);
}
- | RETURN
+ | RETURN return_expression
{
if (nesting == 0) {
warning("return must be in a function");
YYERROR;
}
- $$ = node(cs("0"), epilogue,
- numnode(nesting), cs("Q"), END_NODE);
- }
- | RETURN LPAR return_expression RPAR
- {
- if (nesting == 0) {
- warning("return must be in a function");
- YYERROR;
- }
- $$ = $3;
+ $$ = $2;
}
| FOR LPAR alloc_macro opt_expression SEMICOLON
opt_relational_expression SEMICOLON
@@ -362,11 +353,11 @@ pop_nesting : /* empty */
}
;
-function : function_header opt_parameter_list RPAR
+function : function_header opt_parameter_list RPAR opt_newline
LBRACE NEWLINE opt_auto_define_list
statement_list RBRACE
{
- int n = node(prologue, $7, epilogue,
+ int n = node(prologue, $8, epilogue,
cs("0"), numnode(nesting),
cs("Q"), END_NODE);
emit_macro($1, n);
@@ -387,6 +378,10 @@ function_header : DEFINE LETTER LPAR
}
;
+opt_newline : /* empty */
+ | NEWLINE
+ ;
+
opt_parameter_list
: /* empty */
| parameter_list
@@ -511,6 +506,11 @@ return_expression
$$ = node($1, epilogue,
numnode(nesting), cs("Q"), END_NODE);
}
+ | LPAR RPAR
+ {
+ $$ = node(cs("0"), epilogue,
+ numnode(nesting), cs("Q"), END_NODE);
+ }
;
diff --git a/usr.bin/bc/scan.l b/usr.bin/bc/scan.l
index d6de138c6f3..6b419ad5256 100644
--- a/usr.bin/bc/scan.l
+++ b/usr.bin/bc/scan.l
@@ -1,5 +1,5 @@
%{
-/* $OpenBSD: scan.l,v 1.11 2003/11/11 09:15:36 otto Exp $ */
+/* $OpenBSD: scan.l,v 1.12 2003/11/11 19:49:02 otto Exp $ */
/*
* Copyright (c) 2003, Otto Moerbeek <otto@drijf.net>
@@ -18,7 +18,7 @@
*/
#ifndef lint
-static const char rcsid[] = "$OpenBSD: scan.l,v 1.11 2003/11/11 09:15:36 otto Exp $";
+static const char rcsid[] = "$OpenBSD: scan.l,v 1.12 2003/11/11 19:49:02 otto Exp $";
#endif /* not lint */
#include <err.h>
@@ -163,6 +163,7 @@ DIGIT [0-9A-F]
\\\n lineno++;
\n lineno++; return NEWLINE;
+#[^\n]* ;
[ \t] ;
. yyerror("illegal character");